Skip to content

Instantly share code, notes, and snippets.

@ttdoda
Forked from saitoha/w3m-sgr-style.diff
Last active August 29, 2015 14:26
Show Gist options
  • Save ttdoda/b4e226494fb847e11b66 to your computer and use it in GitHub Desktop.
Save ttdoda/b4e226494fb847e11b66 to your computer and use it in GitHub Desktop.
SGR 1006 mouse reporting for w3m
Index: keybind.c
===================================================================
RCS file: /cvsroot/w3m/w3m/keybind.c,v
retrieving revision 1.10
diff -u -r1.10 keybind.c
--- keybind.c 29 May 2006 12:17:25 -0000 1.10
+++ keybind.c 14 Jul 2012 21:20:27 -0000
@@ -91,7 +91,7 @@
/* 0 1 2 3 4 5 6 7 */
nulcmd, nulcmd, nulcmd, nulcmd, nulcmd, nulcmd, nulcmd, nulcmd,
/* 8 9 : ; < = > ? */
- nulcmd, nulcmd, nulcmd, nulcmd, nulcmd, nulcmd, nulcmd, nulcmd,
+ nulcmd, nulcmd, nulcmd, nulcmd, sgrmouse, nulcmd, nulcmd, nulcmd,
/* @ A B C D E F G */
nulcmd, movU, movD, movR, movL, nulcmd, goLineL, pgFore,
/* H I J K L M N O */
Index: main.c
===================================================================
RCS file: /cvsroot/w3m/w3m/main.c,v
retrieving revision 1.270
diff -u -r1.270 main.c
--- main.c 24 Aug 2010 10:11:51 -0000 1.270
+++ main.c 14 Jul 2012 21:20:27 -0000
@@ -5398,6 +5398,60 @@
process_mouse(btn, x, y);
}
+DEFUN(sgrmouse, SGRMOUSE, "SGR 1006 mouse operation")
+{
+ int btn = 0, x = 0, y = 0;
+ unsigned char c;
+
+ do {
+ c = getch();
+ if (IS_DIGIT(c))
+ btn = btn * 10 + c - '0';
+ else if (c == ';')
+ break;
+ else
+ return;
+ } while (1);
+
+#if defined(__CYGWIN__) && CYGWIN_VERSION_DLL_MAJOR < 1005
+ if (cygwin_mouse_btn_swapped) {
+ if (btn == MOUSE_BTN2_DOWN)
+ btn = MOUSE_BTN3_DOWN;
+ else if (btn == MOUSE_BTN3_DOWN)
+ btn = MOUSE_BTN2_DOWN;
+ };
+#endif
+
+ do {
+ c = getch();
+ if (IS_DIGIT(c))
+ x = x * 10 + c - '0';
+ else if (c == ';')
+ break;
+ else
+ return;
+ } while (1);
+ if (x>0) x--;
+
+ do {
+ c = getch();
+ if (IS_DIGIT(c))
+ y = y * 10 + c - '0';
+ else if (c == 'M')
+ break;
+ else if (c == 'm') {
+ btn |= 3;
+ break;
+ } else
+ return;
+ } while (1);
+ if (y>0) y--;
+
+ if (x < 0 || x >= COLS || y < 0 || y > LASTLINE)
+ return;
+ process_mouse(btn, x, y);
+}
+
#ifdef USE_GPM
int
gpm_process_mouse(Gpm_Event * event, void *data)
Index: proto.h
===================================================================
RCS file: /cvsroot/w3m/w3m/proto.h,v
retrieving revision 1.104
diff -u -r1.104 proto.h
--- proto.h 25 Jul 2010 09:55:05 -0000 1.104
+++ proto.h 14 Jul 2012 21:20:27 -0000
@@ -683,6 +683,7 @@
#ifdef USE_MOUSE
extern void mouse(void);
+extern void sgrmouse(void);
extern void mouse_init(void);
extern void mouse_end(void);
extern void mouse_active(void);
Index: terms.c
===================================================================
RCS file: /cvsroot/w3m/w3m/terms.c,v
retrieving revision 1.63
diff -u -r1.63 terms.c
--- terms.c 20 Aug 2010 09:34:47 -0000 1.63
+++ terms.c 14 Jul 2012 21:20:27 -0000
@@ -2027,8 +2027,8 @@
#ifdef USE_MOUSE
-#define XTERM_ON {fputs("\033[?1001s\033[?1000h",ttyf); flush_tty();}
-#define XTERM_OFF {fputs("\033[?1000l\033[?1001r",ttyf); flush_tty();}
+#define XTERM_ON {fputs("\033[?1001s\033[?1000h\033[?1006h",ttyf); flush_tty();}
+#define XTERM_OFF {fputs("\033[?1006l\033[?1000l\033[?1001r",ttyf); flush_tty();}
#define CYGWIN_ON {fputs("\033[?1000h",ttyf); flush_tty();}
#define CYGWIN_OFF {fputs("\033[?1000l",ttyf); flush_tty();}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment