st-hidecursor-0.7.diff (2563B)
1 diff --git a/st.c b/st.c 2 index 2594c65..2a031f0 100644 3 --- a/st.c 4 +++ b/st.c 5 @@ -260,6 +260,11 @@ typedef struct { 6 Draw draw; 7 Visual *vis; 8 XSetWindowAttributes attrs; 9 + /* Here, we use the term *pointer* to differentiate the cursor 10 + * one sees when hovering the mouse over the terminal from, e.g., 11 + * a green rectangle where text would be entered. */ 12 + Cursor vpointer, bpointer; /* visible and hidden pointers */ 13 + int pointerisvisible; 14 int scr; 15 int isfixed; /* is fixed geometry? */ 16 int l, t; /* left and top offset */ 17 @@ -1291,6 +1296,13 @@ bmotion(XEvent *e) 18 { 19 int oldey, oldex, oldsby, oldsey; 20 21 + if(!xw.pointerisvisible) { 22 + XDefineCursor(xw.dpy, xw.win, xw.vpointer); 23 + xw.pointerisvisible = 1; 24 + if(!IS_SET(MODE_MOUSEMANY)) 25 + xsetpointermotion(0); 26 + } 27 + 28 if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) { 29 mousereport(e); 30 return; 31 @@ -3435,10 +3447,10 @@ void 32 xinit(void) 33 { 34 XGCValues gcvalues; 35 - Cursor cursor; 36 Window parent; 37 pid_t thispid = getpid(); 38 XColor xmousefg, xmousebg; 39 + Pixmap blankpm; 40 41 if (!(xw.dpy = XOpenDisplay(NULL))) 42 die("Can't open display\n"); 43 @@ -3511,8 +3523,9 @@ xinit(void) 44 die("XCreateIC failed. Could not obtain input method.\n"); 45 46 /* white cursor, black outline */ 47 - cursor = XCreateFontCursor(xw.dpy, mouseshape); 48 - XDefineCursor(xw.dpy, xw.win, cursor); 49 + xw.pointerisvisible = 1; 50 + xw.vpointer = XCreateFontCursor(xw.dpy, mouseshape); 51 + XDefineCursor(xw.dpy, xw.win, xw.vpointer); 52 53 if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) { 54 xmousefg.red = 0xffff; 55 @@ -3526,7 +3539,10 @@ xinit(void) 56 xmousebg.blue = 0x0000; 57 } 58 59 - XRecolorCursor(xw.dpy, cursor, &xmousefg, &xmousebg); 60 + XRecolorCursor(xw.dpy, xw.vpointer, &xmousefg, &xmousebg); 61 + blankpm = XCreateBitmapFromData(xw.dpy, xw.win, &(char){0}, 1, 1); 62 + xw.bpointer = XCreatePixmapCursor(xw.dpy, blankpm, blankpm, 63 + &xmousefg, &xmousebg, 0, 0); 64 65 xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False); 66 xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False); 67 @@ -4026,6 +4042,8 @@ unmap(XEvent *ev) 68 void 69 xsetpointermotion(int set) 70 { 71 + if(!set && !xw.pointerisvisible) 72 + return; 73 MODBIT(xw.attrs.event_mask, set, PointerMotionMask); 74 XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs); 75 } 76 @@ -4125,6 +4143,12 @@ kpress(XEvent *ev) 77 Status status; 78 Shortcut *bp; 79 80 + if(xw.pointerisvisible) { 81 + XDefineCursor(xw.dpy, xw.win, xw.bpointer); 82 + xsetpointermotion(1); 83 + xw.pointerisvisible = 0; 84 + } 85 + 86 if (IS_SET(MODE_KBDLOCK)) 87 return; 88