From 584f3928add5146e9fc678743a72e1ee35d42d74 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Tue, 24 Mar 2020 14:02:07 +0100 Subject: [PATCH] mouse shortcuts: allow same functions as kb shortcuts (410651) --- config.def.h | 11 +++-------- st.h | 1 + x.c | 24 ++++++++++++++++-------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/config.def.h b/config.def.h index a359500..22b692b 100644 --- a/config.def.h +++ b/config.def.h @@ -267,14 +267,9 @@ ResourcePref resources[] = { * Beware that overloading Button1 will disable the selection. */ static MouseShortcut mshortcuts[] = { - /* button mask string */ - #if SCROLLBACK_MOUSE_PATCH || SCROLLBACK_MOUSE_ALTSCREEN_PATCH - { Button4, XK_NO_MOD, "\031" }, - { Button5, XK_NO_MOD, "\005" }, - #else - { Button4, XK_ANY_MOD, "\031" }, - { Button5, XK_ANY_MOD, "\005" }, - #endif // SCROLLBACK_MOUSE_PATCH / SCROLLBACK_MOUSE_ALTSCREEN_PATCH + /* mask button function argument */ + { XK_ANY_MOD, Button4, ttysend, {.s = "\031"} }, + { XK_ANY_MOD, Button5, ttysend, {.s = "\005"} }, }; #if SCROLLBACK_MOUSE_PATCH || SCROLLBACK_MOUSE_ALTSCREEN_PATCH diff --git a/st.h b/st.h index 832642a..f8fa2be 100644 --- a/st.h +++ b/st.h @@ -78,6 +78,7 @@ typedef union { uint ui; float f; const void *v; + const char *s; } Arg; void die(const char *, ...); diff --git a/x.c b/x.c index f3f0dab..1467839 100644 --- a/x.c +++ b/x.c @@ -33,9 +33,10 @@ typedef struct { } Shortcut; typedef struct { - uint b; - uint mask; - char *s; + uint mod; + uint button; + void (*func)(const Arg *); + const Arg arg; } MouseShortcut; typedef struct { @@ -57,6 +58,7 @@ static void clipcopy(const Arg *); static void clippaste(const Arg *); static void numlock(const Arg *); static void selpaste(const Arg *); +static void ttysend(const Arg *); static void zoom(const Arg *); static void zoomabs(const Arg *); static void zoomreset(const Arg *); @@ -308,6 +310,12 @@ clippaste(const Arg *dummy) xw.win, CurrentTime); } +void +numlock(const Arg *dummy) +{ + win.mode ^= MODE_NUMLOCK; +} + void selpaste(const Arg *dummy) { @@ -316,9 +324,9 @@ selpaste(const Arg *dummy) } void -numlock(const Arg *dummy) +ttysend(const Arg *arg) { - win.mode ^= MODE_NUMLOCK; + ttywrite(arg->s, strlen(arg->s), 1); } void @@ -477,9 +485,9 @@ bpress(XEvent *e) if (tisaltscr()) #endif // SCROLLBACK_MOUSE_ALTSCREEN_PATCH for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) { - if (e->xbutton.button == ms->b - && match(ms->mask, e->xbutton.state)) { - ttywrite(ms->s, strlen(ms->s), 1); + if (e->xbutton.button == ms->button + && match(ms->mod, e->xbutton.state)) { + ms->func(&(ms->arg)); return; } }