X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=x.c;h=bc3ad5a4667fa870bc4ea6485e6fdf9b032bbcaa;hb=384830110bddcebed00b6530a5336f07ad7c405f;hp=c967caf2cf0ce3a548bc36414bb6410ae75fb3a4;hpb=b6d280de6df30167ce9cf30fadefc362e77729e7;p=st.git diff --git a/x.c b/x.c index c967caf..bc3ad5a 100644 --- a/x.c +++ b/x.c @@ -33,6 +33,7 @@ typedef struct { uint button; void (*func)(const Arg *); const Arg arg; + uint release; } MouseShortcut; typedef struct { @@ -165,6 +166,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 *); @@ -416,11 +418,28 @@ 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) || /* exact or forced */ + 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)) { @@ -428,13 +447,8 @@ 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) { /* @@ -655,9 +669,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); } @@ -1140,8 +1154,8 @@ xinit(int cols, int rows) win.mode = MODE_NUMLOCK; resettitle(); - XMapWindow(xw.dpy, xw.win); xhints(); + XMapWindow(xw.dpy, xw.win); XSync(xw.dpy, False); clock_gettime(CLOCK_MONOTONIC, &xsel.tclick1);