summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2020-06-23 02:03:24 -0400
committerMalfurious <m@lfurio.us>2024-08-12 13:15:09 -0400
commitb3b90931f13ee65c4713963327f82778d7c75495 (patch)
treec2ccfe75f9b76311ad04ad3b05ddc61943f835a2
parent27c4eb4b2d57099b2383f5e954b24b80946b5c57 (diff)
downloadst-b3b90931f13ee65c4713963327f82778d7c75495.tar.gz
st-b3b90931f13ee65c4713963327f82778d7c75495.zip
patch: hidecursor
Hide the X cursor whenever a key is pressed and show it back when the mouse is moved in the terminal window. An alternative to this patch might be xbanish or unclutter.
-rw-r--r--x.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/x.c b/x.c
index 19d057f..f600dd1 100644
--- a/x.c
+++ b/x.c
@@ -104,6 +104,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 */
+ int pointerisvisible;
int scr;
int isfixed; /* is fixed geometry? */
int depth; /* bit depth */
@@ -719,6 +724,13 @@ brelease(XEvent *e)
void
bmotion(XEvent *e)
{
+ if (!xw.pointerisvisible) {
+ XDefineCursor(xw.dpy, xw.win, xw.vpointer);
+ xw.pointerisvisible = 1;
+ if (!IS_SET(MODE_MOUSEMANY))
+ xsetpointermotion(0);
+ }
+
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
mousereport(e);
return;
@@ -1143,12 +1155,12 @@ void
xinit(int cols, int rows)
{
XGCValues gcvalues;
- Cursor cursor;
Window parent;
pid_t thispid = getpid();
XColor xmousefg, xmousebg;
XWindowAttributes attr;
XVisualInfo vis;
+ Pixmap blankpm;
if (!(xw.dpy = XOpenDisplay(NULL)))
die("can't open display\n");
@@ -1218,8 +1230,9 @@ xinit(int cols, int rows)
}
/* white cursor, black outline */
- cursor = XCreateFontCursor(xw.dpy, mouseshape);
- XDefineCursor(xw.dpy, xw.win, cursor);
+ xw.pointerisvisible = 1;
+ xw.vpointer = XCreateFontCursor(xw.dpy, mouseshape);
+ XDefineCursor(xw.dpy, xw.win, xw.vpointer);
if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) {
xmousefg.red = 0xffff;
@@ -1233,7 +1246,10 @@ xinit(int cols, int rows)
xmousebg.blue = 0x0000;
}
- XRecolorCursor(xw.dpy, cursor, &xmousefg, &xmousebg);
+ XRecolorCursor(xw.dpy, xw.vpointer, &xmousefg, &xmousebg);
+ blankpm = XCreateBitmapFromData(xw.dpy, xw.win, &(char){0}, 1, 1);
+ xw.bpointer = XCreatePixmapCursor(xw.dpy, blankpm, blankpm,
+ &xmousefg, &xmousebg, 0, 0);
xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
@@ -1748,6 +1764,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);
}
@@ -1867,6 +1885,12 @@ kpress(XEvent *ev)
Status status;
Shortcut *bp;
+ if (xw.pointerisvisible) {
+ XDefineCursor(xw.dpy, xw.win, xw.bpointer);
+ xsetpointermotion(1);
+ xw.pointerisvisible = 0;
+ }
+
if (IS_SET(MODE_KBDLOCK))
return;