banish.c (1517B)
1 static int cursor_hidden = 0; 2 /* mouse_x and mouse_y are used to store the actual co-ordinates of the mouse cursor when 3 * hidden. These can be manipulated freely, e.g. when using the warp patch, to set a new 4 * cursor position for when the cursor is to be revealed again. */ 5 static int mouse_x = 0; 6 static int mouse_y = 0; 7 static int xi_opcode; 8 static unsigned long long last_button_press = 0; 9 10 void 11 genericevent(XEvent *e) 12 { 13 if (e->xcookie.extension != xi_opcode) 14 return; 15 16 if (!XGetEventData(dpy, &e->xcookie)) 17 return; 18 19 switch (e->xcookie.evtype) { 20 case XI_RawMotion: 21 if (cursor_hidden) 22 showcursor(NULL); 23 break; 24 case XI_RawTouchBegin: 25 case XI_RawTouchEnd: 26 case XI_RawTouchUpdate: 27 if (!cursor_hidden) 28 hidecursor(NULL); 29 break; 30 case XI_RawKeyRelease: 31 if (now() - last_button_press > 2000 && !cursor_hidden) { 32 hidecursor(NULL); 33 } 34 break; 35 } 36 37 XFreeEventData(dpy, &e->xcookie); 38 } 39 40 void 41 hidecursor(const Arg *arg) 42 { 43 if (cursor_hidden) 44 return; 45 46 XFixesHideCursor(dpy, root); 47 if (getrootptr(&mouse_x, &mouse_y)) { 48 XWarpPointer(dpy, None, root, 0, 0, 0, 0, selmon->mx + selmon->mw, selmon->my); 49 } 50 51 cursor_hidden = 1; 52 } 53 54 unsigned long long 55 now(void) { 56 struct timespec currentTime; 57 clock_gettime(CLOCK_REALTIME, ¤tTime); 58 return currentTime.tv_sec * 1000LL + currentTime.tv_nsec / 1000000LL; 59 } 60 61 void 62 showcursor(const Arg *arg) 63 { 64 if (!cursor_hidden) 65 return; 66 67 XWarpPointer(dpy, None, root, 0, 0, 0, 0, mouse_x, mouse_y); 68 XFixesShowCursor(dpy, root); 69 70 cursor_hidden = 0; 71 }