diff options
author | Aurélien Aptel <aurelien.aptel@gmail.com> | 2011-05-10 22:22:44 +0200 |
---|---|---|
committer | Aurélien Aptel <aurelien.aptel@gmail.com> | 2011-05-10 22:22:44 +0200 |
commit | 9760a7a831584ca8e0bbd4bc6b6895c61ff7c97e (patch) | |
tree | de2455274a70a6f74c3bdba613d349e5aeccf0ea | |
parent | 9a3cc64f9d7e6b7b58b060dc9a33d293cc3e6c19 (diff) | |
download | st-patched-9760a7a831584ca8e0bbd4bc6b6895c61ff7c97e.tar.bz2 st-patched-9760a7a831584ca8e0bbd4bc6b6895c61ff7c97e.tar.xz st-patched-9760a7a831584ca8e0bbd4bc6b6895c61ff7c97e.zip |
support for x11 xterm mouse reporting
-rw-r--r-- | st.c | 37 |
1 files changed, 36 insertions, 1 deletions
@@ -62,7 +62,7 @@ enum { CURSOR_UP, CURSOR_DOWN, CURSOR_LEFT, CURSOR_RIGHT, | |||
62 | enum { CURSOR_DEFAULT = 0, CURSOR_HIDE = 1, CURSOR_WRAPNEXT = 2 }; | 62 | enum { CURSOR_DEFAULT = 0, CURSOR_HIDE = 1, CURSOR_WRAPNEXT = 2 }; |
63 | enum { GLYPH_SET=1, GLYPH_DIRTY=2 }; | 63 | enum { GLYPH_SET=1, GLYPH_DIRTY=2 }; |
64 | enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4, MODE_ALTSCREEN=8, | 64 | enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4, MODE_ALTSCREEN=8, |
65 | MODE_CRLF=16 }; | 65 | MODE_CRLF=16, MODE_MOUSE=32 }; |
66 | enum { ESC_START=1, ESC_CSI=2, ESC_OSC=4, ESC_TITLE=8, ESC_ALTCHARSET=16 }; | 66 | enum { ESC_START=1, ESC_CSI=2, ESC_OSC=4, ESC_TITLE=8, ESC_ALTCHARSET=16 }; |
67 | enum { WIN_VISIBLE=1, WIN_REDRAW=2, WIN_FOCUSED=4 }; | 67 | enum { WIN_VISIBLE=1, WIN_REDRAW=2, WIN_FOCUSED=4 }; |
68 | 68 | ||
@@ -410,7 +410,35 @@ getbuttoninfo(XEvent *e, int *b, int *x, int *y) { | |||
410 | } | 410 | } |
411 | 411 | ||
412 | void | 412 | void |
413 | mousereport(XEvent *e) { | ||
414 | int x = (e->xbutton.x - BORDER)/xw.cw; | ||
415 | int y = (e->xbutton.y - BORDER)/xw.ch; | ||
416 | int button = e->xbutton.button; | ||
417 | int state = e->xbutton.state; | ||
418 | char buf[] = { '\033', '[', 'M', 0, 32+x+1, 32+y+1 }; | ||
419 | |||
420 | if(!IS_SET(MODE_MOUSE)) | ||
421 | return; | ||
422 | |||
423 | /* from urxvt */ | ||
424 | if(e->xbutton.type == ButtonRelease || button == AnyButton) | ||
425 | button = 3; | ||
426 | else { | ||
427 | button -= Button1; | ||
428 | if(button >= 3) | ||
429 | button += 64 - 3; | ||
430 | } | ||
431 | |||
432 | buf[3] = 32 + button + (state & ShiftMask ? 4 : 0) | ||
433 | + (state & Mod4Mask ? 8 : 0) | ||
434 | + (state & ControlMask ? 16 : 0); | ||
435 | |||
436 | ttywrite(buf, sizeof(buf)); | ||
437 | } | ||
438 | |||
439 | void | ||
413 | bpress(XEvent *e) { | 440 | bpress(XEvent *e) { |
441 | mousereport(e); | ||
414 | sel.mode = 1; | 442 | sel.mode = 1; |
415 | sel.ex = sel.bx = (e->xbutton.x - BORDER)/xw.cw; | 443 | sel.ex = sel.bx = (e->xbutton.x - BORDER)/xw.cw; |
416 | sel.ey = sel.by = (e->xbutton.y - BORDER)/xw.ch; | 444 | sel.ey = sel.by = (e->xbutton.y - BORDER)/xw.ch; |
@@ -526,6 +554,7 @@ brelease(XEvent *e) { | |||
526 | 554 | ||
527 | sel.mode = 0; | 555 | sel.mode = 0; |
528 | getbuttoninfo(e, &b, &sel.ex, &sel.ey); | 556 | getbuttoninfo(e, &b, &sel.ex, &sel.ey); |
557 | mousereport(e); | ||
529 | if(sel.bx == sel.ex && sel.by == sel.ey) { | 558 | if(sel.bx == sel.ex && sel.by == sel.ey) { |
530 | sel.bx = -1; | 559 | sel.bx = -1; |
531 | if(b == 2) | 560 | if(b == 2) |
@@ -1085,6 +1114,9 @@ csihandle(void) { | |||
1085 | case 25: | 1114 | case 25: |
1086 | term.c.state |= CURSOR_HIDE; | 1115 | term.c.state |= CURSOR_HIDE; |
1087 | break; | 1116 | break; |
1117 | case 1000: /* disable X11 xterm mouse reporting */ | ||
1118 | term.mode &= ~MODE_MOUSE; | ||
1119 | break; | ||
1088 | case 1049: /* = 1047 and 1048 */ | 1120 | case 1049: /* = 1047 and 1048 */ |
1089 | case 1047: | 1121 | case 1047: |
1090 | if(IS_SET(MODE_ALTSCREEN)) { | 1122 | if(IS_SET(MODE_ALTSCREEN)) { |
@@ -1148,6 +1180,9 @@ csihandle(void) { | |||
1148 | case 25: | 1180 | case 25: |
1149 | term.c.state &= ~CURSOR_HIDE; | 1181 | term.c.state &= ~CURSOR_HIDE; |
1150 | break; | 1182 | break; |
1183 | case 1000: /* enable X11 xterm mouse reporting */ | ||
1184 | term.mode |= MODE_MOUSE; | ||
1185 | break; | ||
1151 | case 1049: /* = 1047 and 1048 */ | 1186 | case 1049: /* = 1047 and 1048 */ |
1152 | case 1047: | 1187 | case 1047: |
1153 | if(IS_SET(MODE_ALTSCREEN)) | 1188 | if(IS_SET(MODE_ALTSCREEN)) |