commit ab7c232ecb4f943bc0e63d0955a2979fccbd13d3
parent 87ee7adf5481522c0f81301e45fcc437daa3f959
Author: Cem Keylan <cem@ckyln.com>
Date: Tue, 12 Nov 2019 06:25:19 +0300
mouse shortcuts: don't hardcode selpaste
Diffstat:
M | config.h | | | 3 | ++- |
M | x.c | | | 36 | +++++++++++++++++++++++++----------- |
2 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/config.h b/config.h
@@ -199,7 +199,8 @@ static uint forcemousemod = ShiftMask;
* Beware that overloading Button1 will disable the selection.
*/
static MouseShortcut mshortcuts[] = {
- /* mask button function argument */
+ /* mask button function argument release */
+ { XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 },
{ XK_ANY_MOD, Button4, ttysend, {.s = "\031"} },
{ XK_ANY_MOD, Button5, ttysend, {.s = "\005"} },
};
diff --git a/x.c b/x.c
@@ -27,6 +27,7 @@ typedef struct {
KeySym keysym;
void (*func)(const Arg *);
const Arg arg;
+ uint release;
} Shortcut;
typedef struct {
@@ -180,6 +181,7 @@ static void kpress(XEvent *);
static void cmessage(XEvent *);
static void resize(XEvent *);
static void focus(XEvent *);
+static int mouseaction(XEvent *, uint);
static void brelease(XEvent *);
static void bpress(XEvent *);
static void bmotion(XEvent *);
@@ -432,11 +434,27 @@ mousereport(XEvent *e)
ttywrite(buf, len, 0);
}
+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
bpress(XEvent *e)
{
struct timespec now;
- MouseShortcut *ms;
int snap;
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
@@ -444,13 +462,9 @@ bpress(XEvent *e)
return;
}
- 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 (e->xbutton.button == Button1) {
/*
@@ -671,9 +685,9 @@ brelease(XEvent *e)
return;
}
- if (e->xbutton.button == Button2)
- selpaste(NULL);
- else if (e->xbutton.button == Button1)
+ if (mouseaction(e, 1))
+ return;
+ if (e->xbutton.button == Button1)
mousesel(e, 1);
}