Skip to content

Instantly share code, notes, and snippets.

@ttdoda
Last active August 29, 2015 14:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttdoda/83fbcf676a21da28432b to your computer and use it in GitHub Desktop.
Save ttdoda/83fbcf676a21da28432b to your computer and use it in GitHub Desktop.
SGR 1006 mouse reporting for w3m's menu
--- menu.c.orig 2011-01-04 18:22:23.000000000 +0900
+++ menu.c 2015-08-05 17:37:19.035511000 +0900
@@ -57,6 +57,7 @@
static int mClose(char c);
static int mSusp(char c);
static int mMouse(char c);
+static int mSgrMouse(char c);
static int mSrchF(char c);
static int mSrchB(char c);
static int mSrchN(char c);
@@ -137,7 +138,8 @@
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
- mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
+/* 8 9 : ; < = > ? */
+ mNull, mNull, mNull, mNull, mSgrMouse,mNull,mNull, mNull,
/* A B C D E */
mNull, mUp, mDown, mOk, mCancel,mClose, mNull, mNull,
/* L M */
@@ -1203,6 +1205,48 @@
return process_mMouse(btn, x, y);
}
+static int
+mSgrMouse(char c)
+{
+ int btn = 0, x = 0, y = 0;
+ unsigned char ch;
+
+ for (ch = getch(); IS_DIGIT(ch); ch = getch())
+ btn = btn * 10 + ch - '0';
+ if (ch != ';')
+ return MENU_NOTHING;
+
+#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
+
+ for (ch = getch(); IS_DIGIT(ch); ch = getch())
+ x = x * 10 + ch - '0';
+ if (ch != ';')
+ return MENU_NOTHING;
+ if (x > 0)
+ x--;
+
+ for (ch = getch(); IS_DIGIT(ch); ch = getch())
+ y = y * 10 + ch - '0';
+ if (ch == 'm')
+ btn |= 3;
+ else if (ch != 'M')
+ return MENU_NOTHING;
+ if (y > 0)
+ y--;
+
+ if (x < 0 || x >= COLS || y < 0 || y > LASTLINE)
+ return MENU_NOTHING;
+
+ return process_mMouse(btn, x, y);
+}
+
#ifdef USE_GPM
static int
gpm_process_menu_mouse(Gpm_Event * event, void *data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment