[hackers] [st] Mouse buttons binding

From: Alexander Rezinsky <alexrez_AT_gmail.com>
Date: Fri, 26 Apr 2013 10:31:30 -0700

diff --git a/config.def.h b/config.def.h
index b44fe17..a35aaa9 100644
--- a/config.def.h
+++ b/config.def.h
_AT__AT_ -322,6 +322,19 @@ static Key key[] = {
 };

 /*
+ * Special mouse buttons
+ */
+#define SCREEN_ESC "\001"
+
+static MouseB mouseb[] = {
+ { Button4, ShiftMask, SCREEN_ESC "\0331\025" },
+ { Button4, ControlMask, SCREEN_ESC "\033\002" },
+ { Button4, XK_ANY_MOD, SCREEN_ESC "\03320\025" },
+ { Button5, ShiftMask, SCREEN_ESC "\0331\004" },
+ { Button5, ControlMask, SCREEN_ESC "\033\006" },
+ { Button5, XK_ANY_MOD, SCREEN_ESC "\03320\004" },
+};
+/*
  * Selection types' masks.
  * Use the same masks as usual.
  * Button1Mask is always unset, to make masks match between ButtonPress.
diff --git a/st.c b/st.c
index 07940d2..5dd6958 100644
--- a/st.c
+++ b/st.c
_AT__AT_ -238,6 +238,12 @@ typedef struct {
     signed char crlf; /* crlf mode */
 } Key;

+typedef struct {
+ int b;
+ uint mask;
+ char s[ESC_BUF_SIZ];
+} MouseB;
+
 /* TODO: use better name for vars... */
 typedef struct {
     int mode;
_AT__AT_ -771,6 +777,19 @@ mousereport(XEvent *e) {
 void
 bpress(XEvent *e) {
     struct timeval now;
+ MouseB *m;
+
+ for(m = mouseb; m < mouseb + LEN(mouseb); m++) {
+ if(m->b != e->xbutton.button)
+ continue;
+ if(!match(m->mask, e->xbutton.state))
+ continue;
+
+ ttywrite(m->s, strlen(m->s));
+ if(IS_SET(MODE_ECHO))
+ techo(m->s, strlen(m->s));
+ return;
+ }

     if(IS_SET(MODE_MOUSE)) {
         mousereport(e);
_AT__AT_ -817,10 +836,6 @@ bpress(XEvent *e) {
         }
         sel.tclick2 = sel.tclick1;
         sel.tclick1 = now;
- } else if(e->xbutton.button == Button4) {
- ttywrite("\031", 1);
- } else if(e->xbutton.button == Button5) {
- ttywrite("\005", 1);
     }
 }
Received on Fri Apr 26 2013 - 19:31:30 CEST

This archive was generated by hypermail 2.3.0 : Fri Apr 26 2013 - 19:36:10 CEST