http://www.midnight-commander.org/ticket/2662
diff -ur mc-4.8.0.orig/lib/tty/key.c mc-4.8.0/lib/tty/key.c
old
|
new
|
|
518 | 518 | |
519 | 519 | static int *pending_keys = NULL; |
520 | 520 | |
| 521 | static int mouse_btn, mouse_x, mouse_y; |
| 522 | |
521 | 523 | #ifdef __QNXNTO__ |
522 | 524 | ph_dv_f ph_attach; |
523 | 525 | ph_ov_f ph_input_group; |
… |
… |
|
708 | 710 | static void |
709 | 711 | xmouse_get_event (Gpm_Event * ev) |
710 | 712 | { |
711 | | int btn; |
712 | 713 | static struct timeval tv1 = { 0, 0 }; /* Force first click as single */ |
713 | 714 | static struct timeval tv2; |
714 | 715 | static int clicks = 0; |
… |
… |
|
716 | 717 | |
717 | 718 | /* Decode Xterm mouse information to a GPM style event */ |
718 | 719 | |
719 | | /* Variable btn has following meaning: */ |
720 | | /* 0 = btn1 dn, 1 = btn2 dn, 2 = btn3 dn, 3 = btn up */ |
721 | | btn = tty_lowlevel_getch () - 32; |
722 | | |
723 | 720 | /* There seems to be no way of knowing which button was released */ |
724 | 721 | /* So we assume all the buttons were released */ |
725 | 722 | |
| 723 | int btn = mouse_btn; |
726 | 724 | if (btn == 3) |
727 | 725 | { |
728 | 726 | if (last_btn != 0) |
… |
… |
|
797 | 795 | } |
798 | 796 | last_btn = ev->buttons; |
799 | 797 | } |
800 | | /* Coordinates are 33-based */ |
801 | | /* Transform them to 1-based */ |
802 | | ev->x = tty_lowlevel_getch () - 32; |
803 | | ev->y = tty_lowlevel_getch () - 32; |
| 798 | ev->x = mouse_x; |
| 799 | ev->y = mouse_y; |
804 | 800 | } |
805 | 801 | |
806 | 802 | /* --------------------------------------------------------------------------------------------- */ |
… |
… |
|
935 | 931 | } |
936 | 932 | |
937 | 933 | /* --------------------------------------------------------------------------------------------- */ |
| 934 | /* Parse extended mouse coordinates. |
| 935 | Returns -1 if pending_keys cannot be a prefix of extended mouse coordinates. |
| 936 | Returns 0 if pending_keys is a valid (but still incomplete) prefix for extended mouse coordinates, e.g. "^[[32;4". |
| 937 | Returns 1 and fills the mouse_btn, mouse_x, mouse_y values if pending_keys is a complete extended mouse sequence, e.g. "^[[32;42;5M" */ |
| 938 | static int |
| 939 | parse_extended_mouse_coordinates (void) |
| 940 | { |
| 941 | int c, btn = 0, x = 0, y = 0; |
| 942 | const int *p = pending_keys; |
| 943 | |
| 944 | c = *p++; |
| 945 | if (c == 0) |
| 946 | return 0; |
| 947 | else if (c != ESC_CHAR) |
| 948 | return -1; |
| 949 | |
| 950 | c = *p++; |
| 951 | if (c == 0) |
| 952 | return 0; |
| 953 | else if (c != '[') |
| 954 | return -1; |
| 955 | |
| 956 | while (1) { |
| 957 | c = *p++; |
| 958 | if (c == 0) |
| 959 | return 0; |
| 960 | if (c == ';') |
| 961 | break; |
| 962 | if (c < '0' || c > '9') |
| 963 | return -1; |
| 964 | btn = 10 * btn + c - '0'; |
| 965 | } |
| 966 | if (btn < 32) |
| 967 | return -1; |
| 968 | btn -= 32; |
| 969 | |
| 970 | while (1) { |
| 971 | c = *p++; |
| 972 | if (c == 0) |
| 973 | return 0; |
| 974 | if (c == ';') |
| 975 | break; |
| 976 | if (c < '0' || c > '9') |
| 977 | return -1; |
| 978 | x = 10 * x + c - '0'; |
| 979 | } |
| 980 | if (x < 1) |
| 981 | return -1; |
| 982 | |
| 983 | while (1) { |
| 984 | c = *p++; |
| 985 | if (c == 0) |
| 986 | return 0; |
| 987 | if (c == 'M') |
| 988 | break; |
| 989 | if (c < '0' || c > '9') |
| 990 | return -1; |
| 991 | y = 10 * y + c - '0'; |
| 992 | } |
| 993 | if (y < 1) |
| 994 | return -1; |
| 995 | |
| 996 | mouse_btn = btn; |
| 997 | mouse_x = x; |
| 998 | mouse_y = y; |
| 999 | return 1; |
| 1000 | } |
| 1001 | |
| 1002 | /* --------------------------------------------------------------------------------------------- */ |
938 | 1003 | /* Apply corrections for the keycode generated in get_key_code() */ |
939 | 1004 | |
940 | 1005 | static int |
… |
… |
|
1693 | 1758 | pend_send: |
1694 | 1759 | if (pending_keys != NULL) |
1695 | 1760 | { |
1696 | | int d = *pending_keys++; |
1697 | | check_pend: |
1698 | | if (*pending_keys == 0) |
1699 | | { |
1700 | | pending_keys = NULL; |
1701 | | seq_append = NULL; |
1702 | | } |
1703 | | if ((d == ESC_CHAR) && (pending_keys != NULL)) |
1704 | | { |
1705 | | d = ALT (*pending_keys++); |
1706 | | goto check_pend; |
| 1761 | int m = parse_extended_mouse_coordinates(); |
| 1762 | if (m == 1) { |
| 1763 | pending_keys = seq_append = NULL; |
| 1764 | this = NULL; |
| 1765 | return MCKEY_EXTENDED_MOUSE; |
| 1766 | } |
| 1767 | else if (m == -1) { |
| 1768 | int d = *pending_keys++; |
| 1769 | check_pend: |
| 1770 | if (*pending_keys == 0) |
| 1771 | { |
| 1772 | pending_keys = NULL; |
| 1773 | seq_append = NULL; |
| 1774 | } |
| 1775 | if ((d == ESC_CHAR) && (pending_keys != NULL)) |
| 1776 | { |
| 1777 | d = ALT (*pending_keys++); |
| 1778 | goto check_pend; |
| 1779 | } |
| 1780 | if ((d > 127 && d < 256) && use_8th_bit_as_meta) |
| 1781 | d = ALT (d & 0x7f); |
| 1782 | this = NULL; |
| 1783 | return correct_key_code (d); |
1707 | 1784 | } |
1708 | | if ((d > 127 && d < 256) && use_8th_bit_as_meta) |
1709 | | d = ALT (d & 0x7f); |
1710 | | this = NULL; |
1711 | | return correct_key_code (d); |
| 1785 | /* else if (m == 0), just let it continue */ |
1712 | 1786 | } |
1713 | 1787 | |
1714 | 1788 | nodelay_try_again: |
… |
… |
|
2015 | 2089 | #ifdef KEY_MOUSE |
2016 | 2090 | || c == KEY_MOUSE |
2017 | 2091 | #endif /* KEY_MOUSE */ |
| 2092 | || c == MCKEY_EXTENDED_MOUSE |
2018 | 2093 | )) |
2019 | 2094 | { |
2020 | 2095 | /* Mouse event */ |
| 2096 | /* In case of extended coordinates, mouse_btn, mouse_x and mouse_y are already filled in. */ |
| 2097 | if (c != MCKEY_EXTENDED_MOUSE) { |
| 2098 | /* Variable btn has following meaning: */ |
| 2099 | /* 0 = btn1 dn, 1 = btn2 dn, 2 = btn3 dn, 3 = btn up */ |
| 2100 | mouse_btn = tty_lowlevel_getch () - 32; |
| 2101 | /* Coordinates are 33-based */ |
| 2102 | /* Transform them to 1-based */ |
| 2103 | mouse_x = tty_lowlevel_getch () - 32; |
| 2104 | mouse_y = tty_lowlevel_getch () - 32; |
| 2105 | } |
2021 | 2106 | xmouse_get_event (event); |
2022 | 2107 | return (event->type != 0) ? EV_MOUSE : EV_NONE; |
2023 | 2108 | } |
diff -ur mc-4.8.0.orig/lib/tty/key.h mc-4.8.0/lib/tty/key.h
old
|
new
|
|
33 | 33 | /* Return code for the mouse sequence */ |
34 | 34 | #define MCKEY_MOUSE -2 |
35 | 35 | |
| 36 | /* Return code for the extended mouse sequence */ |
| 37 | #define MCKEY_EXTENDED_MOUSE -3 |
| 38 | |
36 | 39 | /*** enums ***************************************************************************************/ |
37 | 40 | |
38 | 41 | /*** structures declarations (and typedefs of structures)*****************************************/ |
diff -ur mc-4.8.0.orig/lib/tty/mouse.c mc-4.8.0/lib/tty/mouse.c
old
|
new
|
|
138 | 138 | /* enable mouse tracking */ |
139 | 139 | printf (ESC_STR "[?1000h"); |
140 | 140 | |
| 141 | /* enable urxvt extended mouse coordinate reporting */ |
| 142 | printf (ESC_STR "[?1015h"); |
| 143 | |
141 | 144 | fflush (stdout); |
142 | 145 | mouse_enabled = TRUE; |
143 | 146 | break; |
… |
… |
|
149 | 152 | /* enable mouse tracking */ |
150 | 153 | printf (ESC_STR "[?1002h"); |
151 | 154 | |
| 155 | /* enable urxvt extended mouse coordinate reporting */ |
| 156 | printf (ESC_STR "[?1015h"); |
| 157 | |
152 | 158 | fflush (stdout); |
153 | 159 | mouse_enabled = TRUE; |
154 | 160 | break; |
… |
… |
|
176 | 182 | break; |
177 | 183 | #endif |
178 | 184 | case MOUSE_XTERM_NORMAL_TRACKING: |
| 185 | /* disable urxvt extended mouse coordinate reporting */ |
| 186 | printf (ESC_STR "[?1015l"); |
| 187 | |
179 | 188 | /* disable mouse tracking */ |
180 | 189 | printf (ESC_STR "[?1000l"); |
181 | 190 | |
… |
… |
|
185 | 194 | fflush (stdout); |
186 | 195 | break; |
187 | 196 | case MOUSE_XTERM_BUTTON_EVENT_TRACKING: |
| 197 | /* disable urxvt extended mouse coordinate reporting */ |
| 198 | printf (ESC_STR "[?1015l"); |
| 199 | |
188 | 200 | /* disable mouse tracking */ |
189 | 201 | printf (ESC_STR "[?1002l"); |
190 | 202 | |