Mercurial > vim
comparison src/mouse.c @ 21114:d0265fdadec9 v8.2.1108
patch 8.2.1108: mouse left-right scroll is not supported in terminal window
Commit: https://github.com/vim/vim/commit/d58d4f90aeb381045000ea46493b5bd9b9d1fa23
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jul 1 15:49:29 2020 +0200
patch 8.2.1108: mouse left-right scroll is not supported in terminal window
Problem: Mouse left-right scroll is not supported in terminal window.
Solution: Implement mouse codes 6 and 7. (Trygve Aaberge, closes https://github.com/vim/vim/issues/6363)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 01 Jul 2020 16:00:05 +0200 |
parents | 22f0dda71638 |
children | 51ff7e5abdda |
comparison
equal
deleted
inserted
replaced
21113:e0f65780cc0a | 21114:d0265fdadec9 |
---|---|
2117 char_u bytes[6]; | 2117 char_u bytes[6]; |
2118 int num_bytes; | 2118 int num_bytes; |
2119 # endif | 2119 # endif |
2120 int mouse_code = 0; // init for GCC | 2120 int mouse_code = 0; // init for GCC |
2121 int is_click, is_drag; | 2121 int is_click, is_drag; |
2122 int is_release, release_is_ambiguous; | |
2122 int wheel_code = 0; | 2123 int wheel_code = 0; |
2123 int current_button; | 2124 int current_button; |
2124 static int held_button = MOUSE_RELEASE; | 2125 static int held_button = MOUSE_RELEASE; |
2125 static int orig_num_clicks = 1; | 2126 static int orig_num_clicks = 1; |
2126 static int orig_mouse_code = 0x0; | 2127 static int orig_mouse_code = 0x0; |
2131 // time of previous mouse click | 2132 // time of previous mouse click |
2132 struct timeval mouse_time; // time of current mouse click | 2133 struct timeval mouse_time; // time of current mouse click |
2133 long timediff; // elapsed time in msec | 2134 long timediff; // elapsed time in msec |
2134 # endif | 2135 # endif |
2135 | 2136 |
2136 is_click = is_drag = FALSE; | 2137 is_click = is_drag = is_release = release_is_ambiguous = FALSE; |
2137 | 2138 |
2138 # if !defined(UNIX) || defined(FEAT_MOUSE_XTERM) || defined(FEAT_GUI) \ | 2139 # if !defined(UNIX) || defined(FEAT_MOUSE_XTERM) || defined(FEAT_GUI) \ |
2139 || defined(FEAT_MOUSE_GPM) || defined(FEAT_SYSMOUSE) | 2140 || defined(FEAT_MOUSE_GPM) || defined(FEAT_SYSMOUSE) |
2140 if (key_name[0] == KS_MOUSE | 2141 if (key_name[0] == KS_MOUSE |
2141 # ifdef FEAT_MOUSE_GPM | 2142 # ifdef FEAT_MOUSE_GPM |
2254 // when mouse reporting is SGR, add 32 to mouse code | 2255 // when mouse reporting is SGR, add 32 to mouse code |
2255 if (key_name[0] == KS_SGR_MOUSE | 2256 if (key_name[0] == KS_SGR_MOUSE |
2256 || key_name[0] == KS_SGR_MOUSE_RELEASE) | 2257 || key_name[0] == KS_SGR_MOUSE_RELEASE) |
2257 mouse_code += 32; | 2258 mouse_code += 32; |
2258 | 2259 |
2259 if (key_name[0] == KS_SGR_MOUSE_RELEASE) | |
2260 mouse_code |= MOUSE_RELEASE; | |
2261 | |
2262 mouse_col = getdigits(&p) - 1; | 2260 mouse_col = getdigits(&p) - 1; |
2263 if (*p++ != ';') | 2261 if (*p++ != ';') |
2264 return -1; | 2262 return -1; |
2265 | 2263 |
2266 mouse_row = getdigits(&p) - 1; | 2264 mouse_row = getdigits(&p) - 1; |
2267 | 2265 |
2268 // The modifiers were the mouse coordinates, not the | 2266 // The modifiers were the mouse coordinates, not the |
2269 // modifier keys (alt/shift/ctrl/meta) state. | 2267 // modifier keys (alt/shift/ctrl/meta) state. |
2270 *modifiers = 0; | 2268 *modifiers = 0; |
2269 } | |
2270 | |
2271 if (key_name[0] == KS_SGR_MOUSE | |
2272 || key_name[0] == KS_SGR_MOUSE_RELEASE) | |
2273 { | |
2274 if (key_name[0] == KS_SGR_MOUSE_RELEASE) | |
2275 is_release = TRUE; | |
2276 } | |
2277 else | |
2278 { | |
2279 release_is_ambiguous = TRUE; | |
2280 if ((mouse_code & MOUSE_RELEASE) == MOUSE_RELEASE) | |
2281 is_release = TRUE; | |
2271 } | 2282 } |
2272 | 2283 |
2273 if (key_name[0] == KS_MOUSE | 2284 if (key_name[0] == KS_MOUSE |
2274 # ifdef FEAT_MOUSE_GPM | 2285 # ifdef FEAT_MOUSE_GPM |
2275 || key_name[0] == KS_GPM_MOUSE | 2286 || key_name[0] == KS_GPM_MOUSE |
2329 } | 2340 } |
2330 # endif | 2341 # endif |
2331 # ifdef FEAT_XCLIPBOARD | 2342 # ifdef FEAT_XCLIPBOARD |
2332 else if (!(mouse_code & MOUSE_DRAG & ~MOUSE_CLICK_MASK)) | 2343 else if (!(mouse_code & MOUSE_DRAG & ~MOUSE_CLICK_MASK)) |
2333 { | 2344 { |
2334 if ((mouse_code & MOUSE_RELEASE) == MOUSE_RELEASE) | 2345 if (is_release) |
2335 stop_xterm_trace(); | 2346 stop_xterm_trace(); |
2336 else | 2347 else |
2337 start_xterm_trace(mouse_code); | 2348 start_xterm_trace(mouse_code); |
2338 } | 2349 } |
2339 # endif | 2350 # endif |
2467 if (button & 4) mouse_code |= MOUSE_RIGHT; | 2478 if (button & 4) mouse_code |= MOUSE_RIGHT; |
2468 if (button & 8) mouse_code |= MOUSE_SHIFT; | 2479 if (button & 8) mouse_code |= MOUSE_SHIFT; |
2469 if (button & 16) mouse_code |= MOUSE_CTRL; | 2480 if (button & 16) mouse_code |= MOUSE_CTRL; |
2470 break; | 2481 break; |
2471 case 'u': // Button Up | 2482 case 'u': // Button Up |
2483 is_release = TRUE; | |
2472 if (button & 1) | 2484 if (button & 1) |
2473 mouse_code |= MOUSE_LEFT | MOUSE_RELEASE; | 2485 mouse_code |= MOUSE_LEFT; |
2474 if (button & 2) | 2486 if (button & 2) |
2475 mouse_code |= MOUSE_MIDDLE | MOUSE_RELEASE; | 2487 mouse_code |= MOUSE_MIDDLE; |
2476 if (button & 4) | 2488 if (button & 4) |
2477 mouse_code |= MOUSE_RIGHT | MOUSE_RELEASE; | 2489 mouse_code |= MOUSE_RIGHT; |
2478 if (button & 8) | 2490 if (button & 8) |
2479 mouse_code |= MOUSE_SHIFT; | 2491 mouse_code |= MOUSE_SHIFT; |
2480 if (button & 16) | 2492 if (button & 16) |
2481 mouse_code |= MOUSE_CTRL; | 2493 mouse_code |= MOUSE_CTRL; |
2482 break; | 2494 break; |
2596 showmode(); | 2608 showmode(); |
2597 break; | 2609 break; |
2598 case 2: mouse_code = MOUSE_LEFT; | 2610 case 2: mouse_code = MOUSE_LEFT; |
2599 WantQueryMouse = TRUE; | 2611 WantQueryMouse = TRUE; |
2600 break; | 2612 break; |
2601 case 3: mouse_code = MOUSE_RELEASE | MOUSE_LEFT; | 2613 case 3: mouse_code = MOUSE_LEFT; |
2614 is_release = TRUE; | |
2602 break; | 2615 break; |
2603 case 4: mouse_code = MOUSE_MIDDLE; | 2616 case 4: mouse_code = MOUSE_MIDDLE; |
2604 WantQueryMouse = TRUE; | 2617 WantQueryMouse = TRUE; |
2605 break; | 2618 break; |
2606 case 5: mouse_code = MOUSE_RELEASE | MOUSE_MIDDLE; | 2619 case 5: mouse_code = MOUSE_MIDDLE; |
2620 is_release = TRUE; | |
2607 break; | 2621 break; |
2608 case 6: mouse_code = MOUSE_RIGHT; | 2622 case 6: mouse_code = MOUSE_RIGHT; |
2609 WantQueryMouse = TRUE; | 2623 WantQueryMouse = TRUE; |
2610 break; | 2624 break; |
2611 case 7: mouse_code = MOUSE_RELEASE | MOUSE_RIGHT; | 2625 case 7: mouse_code = MOUSE_RIGHT; |
2626 is_release = TRUE; | |
2612 break; | 2627 break; |
2613 case 8: return -1; // fourth button down | 2628 case 8: return -1; // fourth button down |
2614 case 9: return -1; // fourth button up | 2629 case 9: return -1; // fourth button up |
2615 case 10: return -1; // mouse outside of filter rectangle | 2630 case 10: return -1; // mouse outside of filter rectangle |
2616 default: return -1; // should never occur | 2631 default: return -1; // should never occur |
2659 | 2674 |
2660 num_clicks = getdigits(&p); // Not used | 2675 num_clicks = getdigits(&p); // Not used |
2661 break; | 2676 break; |
2662 | 2677 |
2663 case 32: // Release | 2678 case 32: // Release |
2664 mouse_code |= MOUSE_RELEASE; | 2679 is_release = TRUE; |
2665 break; | 2680 break; |
2666 | 2681 |
2667 case 33: // Drag | 2682 case 33: // Drag |
2668 held_button = mouse_code; | 2683 held_button = mouse_code; |
2669 mouse_code |= MOUSE_DRAG; | 2684 mouse_code |= MOUSE_DRAG; |
2680 } | 2695 } |
2681 # endif // FEAT_MOUSE_PTERM | 2696 # endif // FEAT_MOUSE_PTERM |
2682 | 2697 |
2683 // Interpret the mouse code | 2698 // Interpret the mouse code |
2684 current_button = (mouse_code & MOUSE_CLICK_MASK); | 2699 current_button = (mouse_code & MOUSE_CLICK_MASK); |
2700 if (is_release) | |
2701 current_button |= MOUSE_RELEASE; | |
2702 | |
2685 if (current_button == MOUSE_RELEASE | 2703 if (current_button == MOUSE_RELEASE |
2686 # ifdef FEAT_MOUSE_XTERM | 2704 # ifdef FEAT_MOUSE_XTERM |
2687 && wheel_code == 0 | 2705 && wheel_code == 0 |
2688 # endif | 2706 # endif |
2689 ) | 2707 ) |
2784 *modifiers |= MOD_MASK_4CLICK; | 2802 *modifiers |= MOD_MASK_4CLICK; |
2785 | 2803 |
2786 // Work out our pseudo mouse event. Note that MOUSE_RELEASE gets | 2804 // Work out our pseudo mouse event. Note that MOUSE_RELEASE gets |
2787 // added, then it's not mouse up/down. | 2805 // added, then it's not mouse up/down. |
2788 key_name[0] = KS_EXTRA; | 2806 key_name[0] = KS_EXTRA; |
2789 if (wheel_code != 0 | 2807 if (wheel_code != 0 && (!is_release || release_is_ambiguous)) |
2790 && (wheel_code & MOUSE_RELEASE) != MOUSE_RELEASE) | |
2791 { | 2808 { |
2792 if (wheel_code & MOUSE_CTRL) | 2809 if (wheel_code & MOUSE_CTRL) |
2793 *modifiers |= MOD_MASK_CTRL; | 2810 *modifiers |= MOD_MASK_CTRL; |
2794 if (wheel_code & MOUSE_ALT) | 2811 if (wheel_code & MOUSE_ALT) |
2795 *modifiers |= MOD_MASK_ALT; | 2812 *modifiers |= MOD_MASK_ALT; |
2796 key_name[1] = (wheel_code & 1) | 2813 |
2797 ? (int)KE_MOUSEUP : (int)KE_MOUSEDOWN; | 2814 if (wheel_code & 1 && wheel_code & 2) |
2815 key_name[1] = (int)KE_MOUSELEFT; | |
2816 else if (wheel_code & 2) | |
2817 key_name[1] = (int)KE_MOUSERIGHT; | |
2818 else if (wheel_code & 1) | |
2819 key_name[1] = (int)KE_MOUSEUP; | |
2820 else | |
2821 key_name[1] = (int)KE_MOUSEDOWN; | |
2822 | |
2798 held_button = MOUSE_RELEASE; | 2823 held_button = MOUSE_RELEASE; |
2799 } | 2824 } |
2800 else | 2825 else |
2801 key_name[1] = get_pseudo_mouse_code(current_button, | 2826 key_name[1] = get_pseudo_mouse_code(current_button, |
2802 is_click, is_drag); | 2827 is_click, is_drag); |