st-hidecursor-0.5.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
st-hidecursor-0.5.diff (2423B)
---
1 diff --git a/st.c b/st.c
2 index 392f12d..52deb92 100644
3 --- a/st.c
4 +++ b/st.c
5 @@ -248,6 +248,8 @@ typedef struct {
6 Draw draw;
7 Visual *vis;
8 XSetWindowAttributes attrs;
9 + Cursor cursor, bcursor; /* visible and blank cursors */
10 + bool cursorstate; /* is cursor currently visible */
11 int scr;
12 bool isfixed; /* is fixed geometry? */
13 int fx, fy, fw, fh; /* fixed geometry */
14 @@ -1112,6 +1114,13 @@ void
15 bmotion(XEvent *e) {
16 int oldey, oldex, oldsby, oldsey;
17
18 + if(!xw.cursorstate) {
19 + XDefineCursor(xw.dpy, xw.win, xw.cursor);
20 + xw.cursorstate = true;
21 + if(!IS_SET(MODE_MOUSEMANY))
22 + xsetpointermotion(0);
23 + }
24 +
25 if(IS_SET(MODE_MOUSE)) {
26 mousereport(e);
27 return;
28 @@ -2984,10 +2993,12 @@ xzoom(const Arg *arg) {
29 void
30 xinit(void) {
31 XGCValues gcvalues;
32 - Cursor cursor;
33 Window parent;
34 int sw, sh;
35 pid_t thispid = getpid();
36 + XColor xcwhite = {.red = 0xffff, .green = 0xffff, .blue = 0xffff};
37 + XColor xcblack = {.red = 0x0000, .green = 0x0000, .blue = 0x0000};
38 + Pixmap blankpm;
39
40 if(!(xw.dpy = XOpenDisplay(NULL)))
41 die("Can't open display\n");
42 @@ -3071,11 +3082,13 @@ xinit(void) {
43 die("XCreateIC failed. Could not obtain input method.\n");
44
45 /* white cursor, black outline */
46 - cursor = XCreateFontCursor(xw.dpy, XC_xterm);
47 - XDefineCursor(xw.dpy, xw.win, cursor);
48 - XRecolorCursor(xw.dpy, cursor,
49 - &(XColor){.red = 0xffff, .green = 0xffff, .blue = 0xffff},
50 - &(XColor){.red = 0x0000, .green = 0x0000, .blue = 0x0000});
51 + xw.cursor = XCreateFontCursor(xw.dpy, XC_xterm);
52 + XDefineCursor(xw.dpy, xw.win, xw.cursor);
53 + XRecolorCursor(xw.dpy, xw.cursor, &xcwhite, &xcblack);
54 + xw.cursorstate = true;
55 + blankpm = XCreateBitmapFromData(xw.dpy, xw.win, &(char){0}, 1, 1);
56 + xw.bcursor = XCreatePixmapCursor(xw.dpy, blankpm, blankpm,
57 + &xcblack, &xcblack, 0, 0);
58
59 xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
60 xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
61 @@ -3537,6 +3550,8 @@ unmap(XEvent *ev) {
62
63 void
64 xsetpointermotion(int set) {
65 + if(!set && !xw.cursorstate)
66 + return;
67 MODBIT(xw.attrs.event_mask, set, PointerMotionMask);
68 XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs);
69 }
70 @@ -3630,6 +3645,12 @@ kpress(XEvent *ev) {
71 Status status;
72 Shortcut *bp;
73
74 + if(xw.cursorstate) {
75 + XDefineCursor(xw.dpy, xw.win, xw.bcursor);
76 + xsetpointermotion(1);
77 + xw.cursorstate = false;
78 + }
79 +
80 if(IS_SET(MODE_KBDLOCK))
81 return;
82