[PATCH] a shortcut to toggle the mouse cursor

From: Alex Kozadaev <snobb_AT_gmx.com>
Date: Tue, 17 Nov 2015 12:06:35 +0000

---
 config.def.h |  1 +
 sent.c       | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
diff --git a/config.def.h b/config.def.h
index 6ecc267..96acbe1 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -39,4 +39,5 @@ static Shortcut shortcuts[] = {
 	{ XK_Up,          advance,        {.i = -1} },
 	{ XK_Next,        advance,        {.i = +1} },
 	{ XK_Prior,       advance,        {.i = -1} },
+	{ XK_x,           toggle_cursor,  {0} },
 };
diff --git a/sent.c b/sent.c
index 4e2e810..a14c49b 100644
--- a/sent.c
+++ b/sent.c
_AT_@ -13,6 +13,7 @@
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/Xft/Xft.h>
+#include <X11/cursorfont.h>
 
 #include "arg.h"
 #include "drw.h"
_AT_@ -92,6 +93,7 @@ static void eprintf(const char *, ...);
 static void die(const char *, ...);
 static void load(FILE *fp);
 static void advance(const Arg *arg);
+static void toggle_cursor(const Arg *arg);
 static void quit(const Arg *arg);
 static void resize(int width, int height);
 static void run();
_AT_@ -476,6 +478,30 @@ void advance(const Arg *arg)
 	}
 }
 
+void toggle_cursor(const Arg *arg)
+{
+	Cursor cursor;
+	XColor color;
+	Pixmap bitmapNoData;
+	char noData[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+	static int cursor_visible = 1;
+
+	memset(&color, 0, sizeof(color));
+
+	if (cursor_visible) {
+		bitmapNoData = XCreateBitmapFromData(xw.dpy, xw.win, noData, 8, 8);
+		cursor = XCreatePixmapCursor(xw.dpy, bitmapNoData,
+					     bitmapNoData, &color, &color, 0, 0);
+		XFreePixmap(xw.dpy, bitmapNoData);
+	} else {
+		cursor = XCreateFontCursor(xw.dpy, XC_left_ptr);
+	}
+	XDefineCursor(xw.dpy, xw.win, cursor);
+	XFreeCursor(xw.dpy, cursor);
+	cursor_visible ^= 1;
+}
+
 void quit(const Arg *arg)
 {
 	running = 0;
-- 
2.1.4
--jRHKVT23PllUwdXP--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Tue Nov 17 2015 - 13:24:10 CET