commit 584f3928add5146e9fc678743a72e1ee35d42d74
parent 4aa698999395d20f6a1a58ea3c60980b7bfe68c5
Author: bakkeby <bakkeby@gmail.com>
Date: Tue, 24 Mar 2020 14:02:07 +0100
mouse shortcuts: allow same functions as kb shortcuts (410651)
Diffstat:
3 files changed, 20 insertions(+), 16 deletions(-)
diff --git 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
@@ -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
@@ -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 *);
@@ -309,6 +311,12 @@ clippaste(const Arg *dummy)
}
void
+numlock(const Arg *dummy)
+{
+ win.mode ^= MODE_NUMLOCK;
+}
+
+void
selpaste(const Arg *dummy)
{
XConvertSelection(xw.dpy, XA_PRIMARY, xsel.xtarget, XA_PRIMARY,
@@ -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;
}
}