diff options
| author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2019-10-10 23:02:26 +0300 |
|---|---|---|
| committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2019-10-13 21:46:31 +0200 |
| commit | ba7f4d69af62d20e13fea78a408095e017410651 (patch) | |
| tree | 332669fc04751b43eae42cf8e074d394203f5f8d | |
| parent | 2b8333f553c14c15398e810353e192eb05938580 (diff) | |
| download | st-ba7f4d69af62d20e13fea78a408095e017410651.tar.gz st-ba7f4d69af62d20e13fea78a408095e017410651.zip | |
mouse shortcuts: allow same functions as kb shortcuts
Previously mouse shortcuts supported only ttywrite.
This required adding an "Arg" function ttysend - which does what the
original mouse shortcuts did.
| -rw-r--r-- | config.def.h | 6 | ||||
| -rw-r--r-- | st.h | 1 | ||||
| -rw-r--r-- | x.c | 20 |
3 files changed, 18 insertions, 9 deletions
diff --git a/config.def.h b/config.def.h index 6ebea98..36ff6ce 100644 --- a/config.def.h +++ b/config.def.h | |||
| @@ -155,9 +155,9 @@ static unsigned int defaultattr = 11; | |||
| 155 | * Beware that overloading Button1 will disable the selection. | 155 | * Beware that overloading Button1 will disable the selection. |
| 156 | */ | 156 | */ |
| 157 | static MouseShortcut mshortcuts[] = { | 157 | static MouseShortcut mshortcuts[] = { |
| 158 | /* button mask string */ | 158 | /* mask button function argument */ |
| 159 | { Button4, XK_ANY_MOD, "\031" }, | 159 | { XK_ANY_MOD, Button4, ttysend, {.s = "\031"} }, |
| 160 | { Button5, XK_ANY_MOD, "\005" }, | 160 | { XK_ANY_MOD, Button5, ttysend, {.s = "\005"} }, |
| 161 | }; | 161 | }; |
| 162 | 162 | ||
| 163 | /* Internal keyboard shortcuts. */ | 163 | /* Internal keyboard shortcuts. */ |
| @@ -74,6 +74,7 @@ typedef union { | |||
| 74 | uint ui; | 74 | uint ui; |
| 75 | float f; | 75 | float f; |
| 76 | const void *v; | 76 | const void *v; |
| 77 | const char *s; | ||
| 77 | } Arg; | 78 | } Arg; |
| 78 | 79 | ||
| 79 | void die(const char *, ...); | 80 | void die(const char *, ...); |
| @@ -29,9 +29,10 @@ typedef struct { | |||
| 29 | } Shortcut; | 29 | } Shortcut; |
| 30 | 30 | ||
| 31 | typedef struct { | 31 | typedef struct { |
| 32 | uint b; | 32 | uint mod; |
| 33 | uint mask; | 33 | uint button; |
| 34 | char *s; | 34 | void (*func)(const Arg *); |
| 35 | const Arg arg; | ||
| 35 | } MouseShortcut; | 36 | } MouseShortcut; |
| 36 | 37 | ||
| 37 | typedef struct { | 38 | typedef struct { |
| @@ -56,6 +57,7 @@ static void selpaste(const Arg *); | |||
| 56 | static void zoom(const Arg *); | 57 | static void zoom(const Arg *); |
| 57 | static void zoomabs(const Arg *); | 58 | static void zoomabs(const Arg *); |
| 58 | static void zoomreset(const Arg *); | 59 | static void zoomreset(const Arg *); |
| 60 | static void ttysend(const Arg *); | ||
| 59 | 61 | ||
| 60 | /* config.h for applying patches and the configuration. */ | 62 | /* config.h for applying patches and the configuration. */ |
| 61 | #include "config.h" | 63 | #include "config.h" |
| @@ -312,6 +314,12 @@ zoomreset(const Arg *arg) | |||
| 312 | } | 314 | } |
| 313 | } | 315 | } |
| 314 | 316 | ||
| 317 | void | ||
| 318 | ttysend(const Arg *arg) | ||
| 319 | { | ||
| 320 | ttywrite(arg->s, strlen(arg->s), 1); | ||
| 321 | } | ||
| 322 | |||
| 315 | int | 323 | int |
| 316 | evcol(XEvent *e) | 324 | evcol(XEvent *e) |
| 317 | { | 325 | { |
| @@ -421,9 +429,9 @@ bpress(XEvent *e) | |||
| 421 | } | 429 | } |
| 422 | 430 | ||
| 423 | for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) { | 431 | for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) { |
| 424 | if (e->xbutton.button == ms->b | 432 | if (e->xbutton.button == ms->button |
| 425 | && match(ms->mask, e->xbutton.state)) { | 433 | && match(ms->mod, e->xbutton.state)) { |
| 426 | ttywrite(ms->s, strlen(ms->s), 1); | 434 | ms->func(&(ms->arg)); |
| 427 | return; | 435 | return; |
| 428 | } | 436 | } |
| 429 | } | 437 | } |
