Tuesday·26·October·2010
ratpoison and focus follows mouse //at 00:22 //by abe
I use ratpoison as window manager on my ASUS EeePC netbook “nemo” for more than two years now. But although I’m very happy with ratpoison in the EeePC, there are two feature wishes which have been refused by upstream: One is more flexibel window name matching for the unmanage command. The other one is “focus follows mouse” between ratpoison frames.
Well, I always guessed that it was possible, but it took until now to find outhow to implement “focus follows mouse” for ratpoison.
There’s an ancient but still useful tool called Not a Window Manager (nawm) which is a small awk-like interpreter offering mostly window handling functions.
The following .nawmrc implements “focus follows mouse” in nawm:
window newwin; # stores window to raise window lastwin; # stores previous window to prevent race conditions leave { lastwin = currentwindow; } enter { newwin = pointerwindow(); if (name(newwin) != "" && newwin != lastwin) { raise newwin; sync; } }
The leave hook is necessary to prevent flapping between two windows if switched between them via ratpoison’s commands.
I also had to add the following hook to my .ratpoisonrc to work around some cases where ratpoison’s own window switching didn’t work anymore. Only happened with more than one frame — with one frame banishing the mouse cursor was annoying, so I filtered that case:
addhook switchwin exec if [ `ratpoison -c fdump|fgrep -o frame|wc -l` -gt 1 ]; then ratpoison -c banish; fi
Unfortunately nawm has been removed from Debian Sid about a year ago due to being buggy and orphaned. There was not upstream development for seven years or so either.
So for the moment you can get nawm either from Debian Lenny or from snapshot.debian.org.
But I had to fix a segfault in nawm when calling name() on a window without name to be able to use it at all, so you will probably have to rebuild it anyway with the following patch:
diff -u nawm-0.0.20030130/builtins.c nawm-0.0.20030130-patched/builtins.c --- nawm-0.0.20030130/builtins.c 2010-10-25 06:00:02.000000000 +0200 +++ nawm-0.0.20030130-patched/builtins.c 2010-10-25 04:15:25.000000000 +0200 @@ -546,8 +546,12 @@ *name = gcstrdup(""); else { - *name = gcstrdup((char *)nm); - XFree(nm); + if ((char *)nm) { + *name = gcstrdup((char *)nm); + XFree(nm); + } else { + *name = gcstrdup(""); + } } }
And yes, I’m thinking about adopting and reintroducing the nawm package into Debian Sid.
But I’d prefer if anyone could give me a hint how to do this with more
current and still maintained tools (or a patch against ratpoison :-).
I looked into suckless-tools, but I haven’t found anything in
there which provides hooks on X events. And the Perl module Tk seems
to be able to set X event hooks, but only within the application being
written itself.
Tagged as: ASUS, awk, Debian, dwm, EeePC, FocusFollowsMouse, Hack, Hacks, hook, Lenny, nawm, nemo, ratpoison, segfault, Sid, Squeeze, suckless, Window Manager, X
// show without comments // write a comment