commit 0cdfd86e5eda55f2545fa375e93c775ceddaa8e1
parent ed7837a816b40b7a06fcbef209ae2dfb01dd07e9
Author: bakkeby <bakkeby@gmail.com>
Date: Tue, 24 Mar 2020 14:14:10 +0100
mouse shortcuts: don't hardcode selpaste (ff828c)
Diffstat:
2 files changed, 31 insertions(+), 16 deletions(-)
diff --git 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
@@ -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)