]> git.armaanb.net Git - st.git/blobdiff - x.c
mouse shortcuts: don't hardcode selpaste
[st.git] / x.c
diff --git a/x.c b/x.c
index 2a05a81435f9cdd6de5cb641edace1bd8c98c8be..8f570c25ef7e45ac40bb776f2fc84e0ed6615d02 100644 (file)
--- 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 *);
@@ -340,7 +342,7 @@ void
 mousesel(XEvent *e, int done)
 {
        int type, seltype = SEL_REGULAR;
-       uint state = e->xbutton.state & ~(Button1Mask | forceselmod);
+       uint state = e->xbutton.state & ~(Button1Mask | forcemousemod);
 
        for (type = 1; type < LEN(selmasks); ++type) {
                if (match(selmasks[type], state)) {
@@ -416,25 +418,36 @@ 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 & forceselmod)) {
+       if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
                mousereport(e);
                return;
        }
 
-       for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
-               if (e->xbutton.button == ms->button
-                               && match(ms->mod, e->xbutton.state)) {
-                       ms->func(&(ms->arg));
-                       return;
-               }
-       }
+       if (mouseaction(e, 0))
+               return;
 
        if (e->xbutton.button == Button1) {
                /*
@@ -650,21 +663,21 @@ xsetsel(char *str)
 void
 brelease(XEvent *e)
 {
-       if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
+       if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
                mousereport(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);
 }
 
 void
 bmotion(XEvent *e)
 {
-       if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
+       if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
                mousereport(e);
                return;
        }