Browse Source

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.
master
Avi Halachmi (:avih) 5 years ago
committed by Hiltjo Posthuma
parent
commit
ba7f4d69af
3 changed files with 18 additions and 9 deletions
  1. +3
    -3
      config.def.h
  2. +1
    -0
      st.h
  3. +14
    -6
      x.c

+ 3
- 3
config.def.h View File

@ -155,9 +155,9 @@ static unsigned int defaultattr = 11;
* Beware that overloading Button1 will disable the selection. * Beware that overloading Button1 will disable the selection.
*/ */
static MouseShortcut mshortcuts[] = { 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. */ /* Internal keyboard shortcuts. */


+ 1
- 0
st.h View File

@ -74,6 +74,7 @@ typedef union {
uint ui; uint ui;
float f; float f;
const void *v; const void *v;
const char *s;
} Arg; } Arg;
void die(const char *, ...); void die(const char *, ...);


+ 14
- 6
x.c View File

@ -29,9 +29,10 @@ typedef struct {
} Shortcut; } Shortcut;
typedef struct { typedef struct {
uint b;
uint mask;
char *s;
uint mod;
uint button;
void (*func)(const Arg *);
const Arg arg;
} MouseShortcut; } MouseShortcut;
typedef struct { typedef struct {
@ -56,6 +57,7 @@ static void selpaste(const Arg *);
static void zoom(const Arg *); static void zoom(const Arg *);
static void zoomabs(const Arg *); static void zoomabs(const Arg *);
static void zoomreset(const Arg *); static void zoomreset(const Arg *);
static void ttysend(const Arg *);
/* config.h for applying patches and the configuration. */ /* config.h for applying patches and the configuration. */
#include "config.h" #include "config.h"
@ -312,6 +314,12 @@ zoomreset(const Arg *arg)
} }
} }
void
ttysend(const Arg *arg)
{
ttywrite(arg->s, strlen(arg->s), 1);
}
int int
evcol(XEvent *e) evcol(XEvent *e)
{ {
@ -421,9 +429,9 @@ bpress(XEvent *e)
} }
for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) { 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; return;
} }
} }


Loading…
Cancel
Save