diff options
author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2019-10-11 02:26:10 +0300 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2019-10-13 21:46:31 +0200 |
commit | d2b75db8d7519a20af8bf09e9c205507f9ff828c (patch) | |
tree | 1e17b52c9f25afa685e2e3e5ce7fbd23ef7127d6 | |
parent | b6d280de6df30167ce9cf30fadefc362e77729e7 (diff) | |
download | st-d2b75db8d7519a20af8bf09e9c205507f9ff828c.tar.gz st-d2b75db8d7519a20af8bf09e9c205507f9ff828c.zip |
mouse shortcuts: don't hardcode selpaste
Because selpaste is activated on release, a release flag was added to
mouse shortcuts which controls whether activation is on press/release,
and selpaste binding to button2 was moved to config.h .
button1 remains the only hardcoded mouse button - for selection + copy.
-rw-r--r-- | config.def.h | 3 | ||||
-rw-r--r-- | x.c | 35 |
2 files changed, 26 insertions, 12 deletions
diff --git a/config.def.h b/config.def.h index a0a0d2d..546edda 100644 --- a/config.def.h +++ b/config.def.h | |||
@@ -162,7 +162,8 @@ static uint forcemousemod = ShiftMask; | |||
162 | * Beware that overloading Button1 will disable the selection. | 162 | * Beware that overloading Button1 will disable the selection. |
163 | */ | 163 | */ |
164 | static MouseShortcut mshortcuts[] = { | 164 | static MouseShortcut mshortcuts[] = { |
165 | /* mask button function argument */ | 165 | /* mask button function argument release */ |
166 | { XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 }, | ||
166 | { XK_ANY_MOD, Button4, ttysend, {.s = "\031"} }, | 167 | { XK_ANY_MOD, Button4, ttysend, {.s = "\031"} }, |
167 | { XK_ANY_MOD, Button5, ttysend, {.s = "\005"} }, | 168 | { XK_ANY_MOD, Button5, ttysend, {.s = "\005"} }, |
168 | }; | 169 | }; |
@@ -33,6 +33,7 @@ typedef struct { | |||
33 | uint button; | 33 | uint button; |
34 | void (*func)(const Arg *); | 34 | void (*func)(const Arg *); |
35 | const Arg arg; | 35 | const Arg arg; |
36 | uint release; | ||
36 | } MouseShortcut; | 37 | } MouseShortcut; |
37 | 38 | ||
38 | typedef struct { | 39 | typedef struct { |
@@ -165,6 +166,7 @@ static void kpress(XEvent *); | |||
165 | static void cmessage(XEvent *); | 166 | static void cmessage(XEvent *); |
166 | static void resize(XEvent *); | 167 | static void resize(XEvent *); |
167 | static void focus(XEvent *); | 168 | static void focus(XEvent *); |
169 | static int mouseaction(XEvent *, uint); | ||
168 | static void brelease(XEvent *); | 170 | static void brelease(XEvent *); |
169 | static void bpress(XEvent *); | 171 | static void bpress(XEvent *); |
170 | static void bmotion(XEvent *); | 172 | static void bmotion(XEvent *); |
@@ -416,11 +418,27 @@ mousereport(XEvent *e) | |||
416 | ttywrite(buf, len, 0); | 418 | ttywrite(buf, len, 0); |
417 | } | 419 | } |
418 | 420 | ||
421 | int | ||
422 | mouseaction(XEvent *e, uint release) | ||
423 | { | ||
424 | MouseShortcut *ms; | ||
425 | |||
426 | for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) { | ||
427 | if (ms->release == release && | ||
428 | ms->button == e->xbutton.button && | ||
429 | match(ms->mod, e->xbutton.state & ~forcemousemod)) { | ||
430 | ms->func(&(ms->arg)); | ||
431 | return 1; | ||
432 | } | ||
433 | } | ||
434 | |||
435 | return 0; | ||
436 | } | ||
437 | |||
419 | void | 438 | void |
420 | bpress(XEvent *e) | 439 | bpress(XEvent *e) |
421 | { | 440 | { |
422 | struct timespec now; | 441 | struct timespec now; |
423 | MouseShortcut *ms; | ||
424 | int snap; | 442 | int snap; |
425 | 443 | ||
426 | if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) { | 444 | if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) { |
@@ -428,13 +446,8 @@ bpress(XEvent *e) | |||
428 | return; | 446 | return; |
429 | } | 447 | } |
430 | 448 | ||
431 | for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) { | 449 | if (mouseaction(e, 0)) |
432 | if (e->xbutton.button == ms->button && | 450 | return; |
433 | match(ms->mod, e->xbutton.state & ~forcemousemod)) { | ||
434 | ms->func(&(ms->arg)); | ||
435 | return; | ||
436 | } | ||
437 | } | ||
438 | 451 | ||
439 | if (e->xbutton.button == Button1) { | 452 | if (e->xbutton.button == Button1) { |
440 | /* | 453 | /* |
@@ -655,9 +668,9 @@ brelease(XEvent *e) | |||
655 | return; | 668 | return; |
656 | } | 669 | } |
657 | 670 | ||
658 | if (e->xbutton.button == Button2) | 671 | if (mouseaction(e, 1)) |
659 | selpaste(NULL); | 672 | return; |
660 | else if (e->xbutton.button == Button1) | 673 | if (e->xbutton.button == Button1) |
661 | mousesel(e, 1); | 674 | mousesel(e, 1); |
662 | } | 675 | } |
663 | 676 | ||