sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

toggle-mouse-cursor.diff (1623B)


      1 diff --git a/config.def.h b/config.def.h
      2 index 6ecc267..96acbe1 100644
      3 --- a/config.def.h
      4 +++ b/config.def.h
      5 @@ -39,4 +39,5 @@ static Shortcut shortcuts[] = {
      6  	{ XK_Up,          advance,        {.i = -1} },
      7  	{ XK_Next,        advance,        {.i = +1} },
      8  	{ XK_Prior,       advance,        {.i = -1} },
      9 +	{ XK_x,           toggle_cursor,  {0} },
     10  };
     11 diff --git a/sent.c b/sent.c
     12 index 4e2e810..a14c49b 100644
     13 --- a/sent.c
     14 +++ b/sent.c
     15 @@ -13,6 +13,7 @@
     16  #include <X11/Xlib.h>
     17  #include <X11/Xutil.h>
     18  #include <X11/Xft/Xft.h>
     19 +#include <X11/cursorfont.h>
     20  
     21  #include "arg.h"
     22  #include "drw.h"
     23 @@ -92,6 +93,7 @@ static void eprintf(const char *, ...);
     24  static void die(const char *, ...);
     25  static void load(FILE *fp);
     26  static void advance(const Arg *arg);
     27 +static void toggle_cursor(const Arg *arg);
     28  static void quit(const Arg *arg);
     29  static void resize(int width, int height);
     30  static void run();
     31 @@ -476,6 +478,30 @@ void advance(const Arg *arg)
     32  	}
     33  }
     34  
     35 +void toggle_cursor(const Arg *arg)
     36 +{
     37 +	Cursor cursor;
     38 +	XColor color;
     39 +	Pixmap bitmapNoData;
     40 +	char noData[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
     41 +	static int cursor_visible = 1;
     42 +
     43 +	memset(&color, 0, sizeof(color));
     44 +
     45 +
     46 +	if (cursor_visible) {
     47 +		bitmapNoData = XCreateBitmapFromData(xw.dpy, xw.win, noData, 8, 8);
     48 +		cursor = XCreatePixmapCursor(xw.dpy, bitmapNoData,
     49 +					     bitmapNoData, &color, &color, 0, 0);
     50 +		XFreePixmap(xw.dpy, bitmapNoData);
     51 +	} else {
     52 +		cursor = XCreateFontCursor(xw.dpy, XC_left_ptr);
     53 +	}
     54 +	XDefineCursor(xw.dpy, xw.win, cursor);
     55 +	XFreeCursor(xw.dpy, cursor);
     56 +	cursor_visible ^= 1;
     57 +}
     58 +
     59  void quit(const Arg *arg)
     60  {
     61  	running = 0;