From 30fdb96f39f9e4488a36e64205533f0a4fd05290 Mon Sep 17 00:00:00 2001 From: IWAMOTO Kouichi Date: Sun, 9 Aug 2015 06:36:25 +0900 Subject: Support SGR style mouse handler for menu cf. https://github.com/tats/w3m/issues/5 Origin: https://gist.github.com/ttdoda/83fbcf676a21da28432b Bug: https://sourceforge.net/p/w3m/patches/65/ --- menu.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'menu.c') diff --git a/menu.c b/menu.c index 0f66583..7c08703 100644 --- a/menu.c +++ b/menu.c @@ -57,6 +57,7 @@ static int mCancel(char c); 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 @@ static int (*MenuEscBKeymap[128]) (char c) = { 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 @@ mMouse(char c) 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' && ch != ';') + 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) -- cgit v1.2.3