]> git.armaanb.net Git - st.git/commitdiff
mouse shortcuts: allow same functions as kb shortcuts
authorAvi Halachmi (:avih) <avihpit@yahoo.com>
Thu, 10 Oct 2019 20:02:26 +0000 (23:02 +0300)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Sun, 13 Oct 2019 19:46:31 +0000 (21:46 +0200)
Previously mouse shortcuts supported only ttywrite.

This required adding an "Arg" function ttysend - which does what the
original mouse shortcuts did.

config.def.h
st.h
x.c

index 6ebea98593193aa0bd592782e91d58fe3faf6bdd..36ff6ce98f4d847295758c6b9a13175693dbcf37 100644 (file)
@@ -155,9 +155,9 @@ static unsigned int defaultattr = 11;
  * Beware that overloading Button1 will disable the selection.
  */
 static MouseShortcut mshortcuts[] = {
-       /* button               mask            string */
-       { Button4,              XK_ANY_MOD,     "\031" },
-       { Button5,              XK_ANY_MOD,     "\005" },
+       /* mask                 button   function        argument */
+       { XK_ANY_MOD,           Button4, ttysend,        {.s = "\031"} },
+       { XK_ANY_MOD,           Button5, ttysend,        {.s = "\005"} },
 };
 
 /* Internal keyboard shortcuts. */
diff --git a/st.h b/st.h
index 4da30515901a2ff726ceefcf5015bcc6cf338de9..a1928cae4b818f03d220adb015f70a2e424c610f 100644 (file)
--- a/st.h
+++ b/st.h
@@ -74,6 +74,7 @@ typedef union {
        uint ui;
        float f;
        const void *v;
+       const char *s;
 } Arg;
 
 void die(const char *, ...);
diff --git a/x.c b/x.c
index 5828a3b1a42ee0fa1fd04ced06515eca05eb5651..2a05a81435f9cdd6de5cb641edace1bd8c98c8be 100644 (file)
--- a/x.c
+++ b/x.c
@@ -29,9 +29,10 @@ typedef struct {
 } Shortcut;
 
 typedef struct {
-       uint b;
-       uint mask;
-       char *s;
+       uint mod;
+       uint button;
+       void (*func)(const Arg *);
+       const Arg arg;
 } MouseShortcut;
 
 typedef struct {
@@ -56,6 +57,7 @@ static void selpaste(const Arg *);
 static void zoom(const Arg *);
 static void zoomabs(const Arg *);
 static void zoomreset(const Arg *);
+static void ttysend(const Arg *);
 
 /* config.h for applying patches and the configuration. */
 #include "config.h"
@@ -312,6 +314,12 @@ zoomreset(const Arg *arg)
        }
 }
 
+void
+ttysend(const Arg *arg)
+{
+       ttywrite(arg->s, strlen(arg->s), 1);
+}
+
 int
 evcol(XEvent *e)
 {
@@ -421,9 +429,9 @@ bpress(XEvent *e)
        }
 
        for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
-               if (e->xbutton.button == ms->b
-                               && match(ms->mask, e->xbutton.state)) {
-                       ttywrite(ms->s, strlen(ms->s), 1);
+               if (e->xbutton.button == ms->button
+                               && match(ms->mod, e->xbutton.state)) {
+                       ms->func(&(ms->arg));
                        return;
                }
        }