Lee Phillips’ Website


Subscribe:   RSS icon   twitter icon
Noether and friends
Emmy Noether: the book and more
Julia logo
Julia: the best language for science
Ptolemy’s Universe: play with epicycles
gnuplot brings pie
gnuplot v.6 brings pie


Keeping the pointer out of the way in dwm

Lee Phillips

After using the mouse, the pointer remains on the screen at the last point of interaction. Some programs, such as many terminal emulators, hide the pointer when you start typing, but others, such as most browsers, do not. Since I use keyboard browsing, the pointer hanging around on the page after the occasional use of the mouse is annoying. When the page has hover interactions, scrolling the page can trigger these when the control (usually a navigation menu) passes under the pointer location, potentially obscuring the text I’m trying to read.

I use the dwm window manager. Here’s a one-line addition to the main source file, dwm.c, that shoves the pointer to the extreme bottom-right corner whenever you use any keyboard shortcut known to the program. The diff is against v6.5:

diff --git a/dwm.c b/dwm.c
index f1d86b2..0a47f83 100644
--- a/dwm.c
+++ b/dwm.c
@@ -998,20 +998,21 @@ isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info)
 
 void
 keypress(XEvent *e)
 {
    unsigned int i;
    KeySym keysym;
    XKeyEvent *ev;
 
    ev = &e->xkey;
    keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
+    XWarpPointer(dpy, None, None, 0, 0, 0, 0, 3000, 3000);
    for (i = 0; i < LENGTH(keys); i++)
        if (keysym == keys[i].keysym
        && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
        && keys[i].func)
            keys[i].func(&(keys[i].arg));
 }
 
 void
 killclient(const Arg *arg)
 {

This way you don’t have to remember any new command or shortcut; the pointer gets out of the way whenever you change tags or layouts, including the noop of switching to the currently selected layout.

I haven’t submitted this as a patch to the dwm project because it’s so simple and also because it’s not good, due to the hard-coded numbers “3000” in there. It works for me (increase if your screen is bigger) and I’m too lazy to figure out what variable I can use here instead. Feel free to make this presentable and submit it as a patch if you think it worthwhile.


Share with Facebook Share with Twitter Share with Reddit Share with Slashdot lee-phillips.org is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com.
Quotilizer ... loading ...

Tenuously related: