mouse shortcuts: allow using forcemousemod (e.g. shift)
authorAvi Halachmi (:avih) <avihpit@yahoo.com>
Thu, 24 Oct 2019 12:42:07 +0000 (15:42 +0300)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Thu, 24 Oct 2019 13:34:25 +0000 (15:34 +0200)
The recent mouse shurtcuts commits allow customization, but ignore
forcemousemod mask (default: shift) as a modifier, for no good reason
other than following the behavior of the KB shortcuts.

Allow using forcemousemod too, which now can be used to invoke
different shortcuts, though the automatic effect of forcemousemod will
be lost for buttons which use mask with forcemousemod.

E.g. the default is:

static uint forcemousemod = ShiftMask;
...
{ XK_ANY_MOD,           Button4, ttysend,        {.s = "\031"} },
...

where ttysend will be invoked for button4 with any mod when not in mouse
mode, and with shift when in mouse mode.

Now it's possible to do this:
{ ShiftMask,            Button4, ttysend,        {.s = "foo"} },
{ XK_ANY_MOD,           Button4, ttysend,        {.s = "\031"} },

Which will invoke ttysend("foo") while shift is held and ttysend("\031")
otherwise. Shift still overrides mouse mode, but will now send "foo".

Previously with this setup the second binding was always invoked
because the forceousemod mask was always removed from the event.

Buttons which don't use forcemousemod behave the same as before.

This is useful e.g. for the scrollback mouse patch, which wants to
configure shift+wheel for scrollback, while keeping the normal behavior
without shift.

x.c

diff --git a/x.c b/x.c
index 8f570c2..6406925 100644 (file)
--- a/x.c
+++ b/x.c
@@ -426,7 +426,8 @@ mouseaction(XEvent *e, uint release)
        for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
                if (ms->release == release &&
                    ms->button == e->xbutton.button &&
-                   match(ms->mod, e->xbutton.state & ~forcemousemod)) {
+                   (match(ms->mod, e->xbutton.state) ||  /* exact or forced */
+                    match(ms->mod, e->xbutton.state & ~forcemousemod))) {
                        ms->func(&(ms->arg));
                        return 1;
                }