[hackers] [st] Adding extended mouse reporting in st. || Christoph Lohmann

From: <git_AT_suckless.org>
Date: Sat, 26 Jan 2013 15:14:18 +0100

commit 384fabdb5b2ac6c700a974a7fac539c8c14107f6
Author: Christoph Lohmann <20h_AT_r-36.net>
Date: Sat Jan 26 15:13:56 2013 +0100

    Adding extended mouse reporting in st.
    
    Thanks Egmont Koblinger <egmont_AT_gmail.com>!

diff --git a/st.c b/st.c
index 96e66fb..38cec50 100644
--- a/st.c
+++ b/st.c
_AT_@ -117,7 +117,8 @@ enum term_mode {
         MODE_KBDLOCK = 256,
         MODE_HIDE = 512,
         MODE_ECHO = 1024,
- MODE_APPCURSOR = 2048
+ MODE_APPCURSOR = 2048,
+ MODE_MOUSESGR = 4096,
 };
 
 enum escape_state {
_AT_@ -666,11 +667,10 @@ getbuttoninfo(XEvent *e) {
 
 void
 mousereport(XEvent *e) {
- int x = x2col(e->xbutton.x);
- int y = y2row(e->xbutton.y);
- int button = e->xbutton.button;
- int state = e->xbutton.state;
- char buf[] = { '', '[', 'M', 0, 32+x+1, 32+y+1 };
+ int x = x2col(e->xbutton.x), y = y2row(e->xbutton.y),
+ button = e->xbutton.button, state = e->xbutton.state,
+ len;
+ char buf[40];
         static int ob, ox, oy;
 
         /* from urxvt */
_AT_@ -679,7 +679,9 @@ mousereport(XEvent *e) {
                         return;
                 button = ob + 32;
                 ox = x, oy = y;
- } else if(e->xbutton.type == ButtonRelease || button == AnyButton) {
+ } else if(!IS_SET(MODE_MOUSESGR)
+ && (e->xbutton.type == ButtonRelease
+ || button == AnyButton)) {
                 button = 3;
         } else {
                 button -= Button1;
_AT_@ -691,11 +693,23 @@ mousereport(XEvent *e) {
                 }
         }
 
- buf[3] = 32 + button + (state & ShiftMask ? 4 : 0)
+ button += (state & ShiftMask ? 4 : 0)
                 + (state & Mod4Mask ? 8 : 0)
                 + (state & ControlMask ? 16 : 0);
 
- ttywrite(buf, sizeof(buf));
+ len = 0;
+ if(IS_SET(MODE_MOUSESGR)) {
+ len = snprintf(buf, sizeof(buf), "[<%d;%d;%d%c",
+ button, x+1, y+1,
+ e->xbutton.type == ButtonRelease ? 'm' : 'M');
+ } else if(x < 223 && y < 223) {
+ len = snprintf(buf, sizeof(buf), "%c%c%c",
+ 32+button, 32+x+1, 32+y+1);
+ } else {
+ return;
+ }
+
+ ttywrite(buf, len);
 }
 
 void
_AT_@ -1547,6 +1561,9 @@ tsetmode(bool priv, bool set, int *args, int narg) {
                         case 1002:
                                 MODBIT(term.mode, set, MODE_MOUSEMOTION);
                                 break;
+ case 1006:
+ MODBIT(term.mode, set, MODE_MOUSESGR);
+ break;
                         case 1049: /* = 1047 and 1048 */
                         case 47:
                         case 1047: {
Received on Sat Jan 26 2013 - 15:14:18 CET

This archive was generated by hypermail 2.3.0 : Sat Jan 26 2013 - 15:24:11 CET