aboutsummaryrefslogtreecommitdiff
path: root/x.c
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2019-10-11 02:26:10 +0300
committerHiltjo Posthuma <hiltjo@codemadness.org>2019-10-13 21:46:31 +0200
commitd2b75db8d7519a20af8bf09e9c205507f9ff828c (patch)
tree1e17b52c9f25afa685e2e3e5ce7fbd23ef7127d6 /x.c
parentb6d280de6df30167ce9cf30fadefc362e77729e7 (diff)
downloadst-patched-d2b75db8d7519a20af8bf09e9c205507f9ff828c.tar.bz2
st-patched-d2b75db8d7519a20af8bf09e9c205507f9ff828c.tar.xz
st-patched-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.
Diffstat (limited to 'x.c')
-rw-r--r--x.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/x.c b/x.c
index c967caf..8f570c2 100644
--- a/x.c
+++ b/x.c
@@ -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
38typedef struct { 39typedef struct {
@@ -165,6 +166,7 @@ static void kpress(XEvent *);
165static void cmessage(XEvent *); 166static void cmessage(XEvent *);
166static void resize(XEvent *); 167static void resize(XEvent *);
167static void focus(XEvent *); 168static void focus(XEvent *);
169static int mouseaction(XEvent *, uint);
168static void brelease(XEvent *); 170static void brelease(XEvent *);
169static void bpress(XEvent *); 171static void bpress(XEvent *);
170static void bmotion(XEvent *); 172static void bmotion(XEvent *);
@@ -416,11 +418,27 @@ mousereport(XEvent *e)
416 ttywrite(buf, len, 0); 418 ttywrite(buf, len, 0);
417} 419}
418 420
421int
422mouseaction(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
419void 438void
420bpress(XEvent *e) 439bpress(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