diff --git a/st.c b/st.c index b89d094..d2979ff 100644 --- a/st.c +++ b/st.c @@ -257,6 +257,11 @@ typedef struct { Draw draw; Visual *vis; XSetWindowAttributes attrs; + /* Here, we use the term *pointer* to differentiate the cursor + * one sees when hovering the mouse over the terminal from, e.g., + * a green rectangle where text would be entered. */ + Cursor vpointer, bpointer; /* visible and hidden pointers */ + bool pointerisvisible; int scr; bool isfixed; /* is fixed geometry? */ int l, t; /* left and top offset */ @@ -1181,6 +1186,13 @@ void bmotion(XEvent *e) { int oldey, oldex, oldsby, oldsey; + if(!xw.pointerisvisible) { + XDefineCursor(xw.dpy, xw.win, xw.vpointer); + xw.pointerisvisible = true; + if(!IS_SET(MODE_MOUSEMANY)) + xsetpointermotion(0); + } + if(IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) { mousereport(e); return; @@ -3182,9 +3194,11 @@ xzoomreset(const Arg *arg) { void xinit(void) { XGCValues gcvalues; - Cursor cursor; Window parent; pid_t thispid = getpid(); + XColor xcwhite = {.red = 0xffff, .green = 0xffff, .blue = 0xffff}; + XColor xcblack = {.red = 0x0000, .green = 0x0000, .blue = 0x0000}; + Pixmap blankpm; if(!(xw.dpy = XOpenDisplay(NULL))) die("Can't open display\n"); @@ -3257,11 +3271,13 @@ xinit(void) { die("XCreateIC failed. Could not obtain input method.\n"); /* white cursor, black outline */ - cursor = XCreateFontCursor(xw.dpy, XC_xterm); - XDefineCursor(xw.dpy, xw.win, cursor); - XRecolorCursor(xw.dpy, cursor, - &(XColor){.red = 0xffff, .green = 0xffff, .blue = 0xffff}, - &(XColor){.red = 0x0000, .green = 0x0000, .blue = 0x0000}); + xw.vpointer = XCreateFontCursor(xw.dpy, XC_xterm); + XDefineCursor(xw.dpy, xw.win, xw.vpointer); + XRecolorCursor(xw.dpy, xw.vpointer, &xcwhite, &xcblack); + xw.pointerisvisible = true; + blankpm = XCreateBitmapFromData(xw.dpy, xw.win, &(char){0}, 1, 1); + xw.bpointer = XCreatePixmapCursor(xw.dpy, blankpm, blankpm, + &xcblack, &xcblack, 0, 0); xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False); xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False); @@ -3725,6 +3741,8 @@ unmap(XEvent *ev) { void xsetpointermotion(int set) { + if(!set && !xw.pointerisvisible) + return; MODBIT(xw.attrs.event_mask, set, PointerMotionMask); XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs); } @@ -3818,6 +3836,12 @@ kpress(XEvent *ev) { Status status; Shortcut *bp; + if(xw.pointerisvisible) { + XDefineCursor(xw.dpy, xw.win, xw.bpointer); + xsetpointermotion(1); + xw.pointerisvisible = false; + } + if(IS_SET(MODE_KBDLOCK)) return;