From 0cdfd86e5eda55f2545fa375e93c775ceddaa8e1 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Tue, 24 Mar 2020 14:14:10 +0100 Subject: [PATCH] mouse shortcuts: don't hardcode selpaste (ff828c) --- config.def.h | 7 ++++++- x.c | 40 +++++++++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/config.def.h b/config.def.h index eae70c4..4bba084 100644 --- a/config.def.h +++ b/config.def.h @@ -274,7 +274,12 @@ static uint forcemousemod = ShiftMask; * Beware that overloading Button1 will disable the selection. */ static MouseShortcut mshortcuts[] = { - /* mask button function argument */ + /* mask button function argument release */ + #if CLIPBOARD_PATCH + { XK_ANY_MOD, Button2, clippaste, {.i = 0}, 1 }, + #else + { XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 }, + #endif // CLIPBOARD_PATCH { XK_ANY_MOD, Button4, ttysend, {.s = "\031"} }, { XK_ANY_MOD, Button5, ttysend, {.s = "\005"} }, }; diff --git a/x.c b/x.c index 776d12b..e600128 100644 --- a/x.c +++ b/x.c @@ -37,6 +37,7 @@ typedef struct { uint button; void (*func)(const Arg *); const Arg arg; + uint release; } MouseShortcut; typedef struct { @@ -200,6 +201,7 @@ static void selnotify(XEvent *); static void selclear_(XEvent *); static void selrequest(XEvent *); static void setsel(char *, Time); +static int mouseaction(XEvent *, uint); static void mousesel(XEvent *, int); static void mousereport(XEvent *); static char *kmap(KeySym, uint); @@ -386,6 +388,24 @@ evrow(XEvent *e) return y / win.ch; } + +int +mouseaction(XEvent *e, uint release) +{ + MouseShortcut *ms; + + for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) { + if (ms->release == release && + ms->button == e->xbutton.button && + match(ms->mod, e->xbutton.state & ~forcemousemod)) { + ms->func(&(ms->arg)); + return 1; + } + } + + return 0; +} + void mousesel(XEvent *e, int done) { @@ -470,7 +490,6 @@ void bpress(XEvent *e) { struct timespec now; - MouseShortcut *ms; #if SCROLLBACK_MOUSE_PATCH || SCROLLBACK_MOUSE_ALTSCREEN_PATCH MouseKey *mk; #endif // SCROLLBACK_MOUSE_PATCH / SCROLLBACK_MOUSE_ALTSCREEN_PATCH @@ -484,13 +503,8 @@ bpress(XEvent *e) #if SCROLLBACK_MOUSE_ALTSCREEN_PATCH if (tisaltscr()) #endif // SCROLLBACK_MOUSE_ALTSCREEN_PATCH - for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) { - if (e->xbutton.button == ms->button && - match(ms->mod, e->xbutton.state & ~forcemousemod)) { - ms->func(&(ms->arg)); - return; - } - } + if (mouseaction(e, 0)) + return; #if SCROLLBACK_MOUSE_PATCH || SCROLLBACK_MOUSE_ALTSCREEN_PATCH for (mk = mkeys; mk < mkeys + LEN(mkeys); mk++) { @@ -725,13 +739,9 @@ brelease(XEvent *e) return; } - if (e->xbutton.button == Button2) - #if CLIPBOARD_PATCH - clippaste(NULL); - #else - selpaste(NULL); - #endif // CLIPBOARD_PATCH - else if (e->xbutton.button == Button1) + if (mouseaction(e, 1)) + return; + if (e->xbutton.button == Button1) mousesel(e, 1); #if RIGHTCLICKTOPLUMB_PATCH else if (e->xbutton.button == Button3)