To: vim_dev@googlegroups.com Subject: Patch 8.2.4674 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4674 Problem: Cannot force getting MouseMove events. Solution: Add the 'mousemoveevent' option with implementaiton for the GUI. (Ernie Rael, closes #10044) Files: runtime/doc/gui.txt, runtime/doc/options.txt, runtime/doc/testing.txt, src/gui.c, src/option.h, src/optiondefs.h, src/testing.c, src/testdir/test_gui.vim *** ../vim-8.2.4673/runtime/doc/gui.txt 2021-01-31 16:02:06.250490190 +0000 --- runtime/doc/gui.txt 2022-04-03 15:26:22.057090243 +0100 *************** *** 260,265 **** --- 261,267 ---- 'mousefocus' window focus follows mouse pointer |gui-mouse-focus| 'mousemodel' what mouse button does which action 'mousehide' hide mouse pointer while typing text + 'mousemoveevent' enable mouse move events so that can be mapped 'selectmode' whether to start Select mode or Visual mode A quick way to set these is with the ":behave" command. *************** *** 405,417 **** application, with shift-left mouse allowing for extending the visual area rather than the right mouse button. Mouse mapping with modifiers does not work for modeless selection. 3.7 Drag and drop *drag-n-drop* You can drag and drop one or more files into the Vim window, where they will ! be opened as if a |:drop| command was used. If you hold down Shift while doing this, Vim changes to the first dropped file's directory. If you hold Ctrl Vim will always split a new window for the --- 407,423 ---- application, with shift-left mouse allowing for extending the visual area rather than the right mouse button. + may be mapped, but 'mousemoveevent' must be enabled to use the + mapping. + Mouse mapping with modifiers does not work for modeless selection. 3.7 Drag and drop *drag-n-drop* You can drag and drop one or more files into the Vim window, where they will ! be opened as if a |:drop| command was used. You can check if this is ! supported with the *drop_file* feature: `has('drop_file')`. If you hold down Shift while doing this, Vim changes to the first dropped file's directory. If you hold Ctrl Vim will always split a new window for the *** ../vim-8.2.4673/runtime/doc/options.txt 2022-02-24 13:28:36.566222341 +0000 --- runtime/doc/options.txt 2022-04-03 15:25:43.225290914 +0100 *************** *** 5493,5498 **** --- 5517,5534 ---- The 'mousemodel' option is set by the |:behave| command. + *'mousemoveevent'* *'mousemev'* + 'mousemoveevent' 'mousemev' boolean (default off) + global + {only works in the GUI} + When on, mouse move events are delivered to the input queue and are + available for mapping. The default, off, avoids the mouse movement + overhead except when needed. See |gui-mouse-mapping|. + Warning: Setting this option can make pending mappings to be aborted + when the mouse is moved. + Currently only works in the GUI, may be made to work in a terminal + later. + *'mouseshape'* *'mouses'* *E547* 'mouseshape' 'mouses' string (default "i-r:beam,s:updown,sd:udsizing, vs:leftright,vd:lrsizing,m:no, *** ../vim-8.2.4673/runtime/doc/testing.txt 2022-01-30 18:00:22.703274483 +0000 --- runtime/doc/testing.txt 2022-04-03 15:31:09.675873524 +0100 *************** *** 125,132 **** forward: set to 1 for forward search. "mouse": ! Inject a mouse button click event. The supported items in ! {args} are: button: mouse button. The supported values are: 0 right mouse button 1 middle mouse button --- 131,138 ---- forward: set to 1 for forward search. "mouse": ! Inject either a mouse button click, or a mouse move, event. ! The supported items in {args} are: button: mouse button. The supported values are: 0 right mouse button 1 middle mouse button *************** *** 145,150 **** --- 151,178 ---- 4 shift is pressed 8 alt is pressed 16 ctrl is pressed + move: Optional; if used and TRUE then a mouse move + event can be generated. + Only {args} row: and col: are used and + required; they are interpreted as pixels. + Only results in an event when 'mousemoveevent' + is set or a popup uses mouse move events. + + "scrollbar": + Set or drag the left, right or horizontal scrollbar. Only + works when the scrollbar actually exists. The supported + items in {args} are: + which: scrollbar. The supported values are: + left Left scrollbar of the current window + right Right scrollbar of the current window + hor Horizontal scrollbar + value: amount to scroll. For the vertical scrollbars + the value can be 1 to the line-count of the + buffer. For the horizontal scrollbar the + value can be between 1 and the maximum line + length, assuming 'wrap' is not set. + dragging: 1 to drag the scrollbar and 0 to click in the + scrollbar. "tabline": Inject a mouse click event on the tabline to select a *** ../vim-8.2.4673/src/gui.c 2022-03-24 15:15:05.352816711 +0000 --- src/gui.c 2022-04-03 15:15:10.745029995 +0100 *************** *** 3142,3154 **** if (hold_gui_events) return; string[3] = CSI; string[4] = KS_EXTRA; string[5] = (int)button_char; // Pass the pointer coordinates of the scroll event so that we // know which window to scroll. - row = gui_xy2colrow(x, y, &col); string[6] = (char_u)(col / 128 + ' ' + 1); string[7] = (char_u)(col % 128 + ' ' + 1); string[8] = (char_u)(row / 128 + ' ' + 1); --- 3142,3167 ---- if (hold_gui_events) return; + row = gui_xy2colrow(x, y, &col); + // Don't report a mouse move unless moved to a + // different character position. + if (button == MOUSE_MOVE) + { + if (row == prev_row && col == prev_col) + return; + else + { + prev_row = row >= 0 ? row : 0; + prev_col = col; + } + } + string[3] = CSI; string[4] = KS_EXTRA; string[5] = (int)button_char; // Pass the pointer coordinates of the scroll event so that we // know which window to scroll. string[6] = (char_u)(col / 128 + ' ' + 1); string[7] = (char_u)(col % 128 + ' ' + 1); string[8] = (char_u)(row / 128 + ' ' + 1); *************** *** 4967,4978 **** // apply 'mousefocus' and pointer shape gui_mouse_focus(x, y); #ifdef FEAT_PROP_POPUP ! if (popup_uses_mouse_move) ! // Generate a mouse-moved event, so that the popup can perhaps be ! // closed, just like in the terminal. ! gui_send_mouse_event(MOUSE_MOVE, x, y, FALSE, 0); #endif } /* --- 4980,4993 ---- // apply 'mousefocus' and pointer shape gui_mouse_focus(x, y); + if (p_mousemev #ifdef FEAT_PROP_POPUP ! || popup_uses_mouse_move #endif + ) + // Generate a mouse-moved event. For a mapping. Or so the + // popup can perhaps be closed, just like in the terminal. + gui_send_mouse_event(MOUSE_MOVE, x, y, FALSE, 0); } /* *** ../vim-8.2.4673/src/option.h 2022-03-28 11:55:08.675619915 +0100 --- src/option.h 2022-04-03 15:15:10.745029995 +0100 *************** *** 760,765 **** --- 760,768 ---- EXTERN int p_mh; // 'mousehide' #endif EXTERN char_u *p_mousem; // 'mousemodel' + #ifdef FEAT_GUI + EXTERN int p_mousemev; // 'mousemoveevent' + #endif EXTERN long p_mouset; // 'mousetime' EXTERN int p_more; // 'more' #ifdef FEAT_MZSCHEME *** ../vim-8.2.4673/src/optiondefs.h 2022-01-31 14:59:33.522943638 +0000 --- src/optiondefs.h 2022-04-03 15:15:10.745029995 +0100 *************** *** 1746,1751 **** --- 1746,1758 ---- # endif #endif (char_u *)0L} SCTX_INIT}, + {"mousemoveevent", "mousemev", P_BOOL|P_VI_DEF, + #ifdef FEAT_GUI + (char_u *)&p_mousemev, PV_NONE, + #else + (char_u *)NULL, PV_NONE, + #endif + {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, #ifdef FEAT_MOUSESHAPE (char_u *)&p_mouseshape, PV_NONE, *** ../vim-8.2.4673/src/testing.c 2022-02-16 12:16:15.553130173 +0000 --- src/testing.c 2022-04-03 15:29:05.056349751 +0100 *************** *** 1368,1389 **** int col; int repeated_click; int_u mods; ! if (dict_find(args, (char_u *)"button", -1) == NULL ! || dict_find(args, (char_u *)"row", -1) == NULL ! || dict_find(args, (char_u *)"col", -1) == NULL || dict_find(args, (char_u *)"multiclick", -1) == NULL ! || dict_find(args, (char_u *)"modifiers", -1) == NULL) return FALSE; - button = (int)dict_get_number(args, (char_u *)"button"); row = (int)dict_get_number(args, (char_u *)"row"); col = (int)dict_get_number(args, (char_u *)"col"); - repeated_click = (int)dict_get_number(args, (char_u *)"multiclick"); - mods = (int)dict_get_number(args, (char_u *)"modifiers"); ! gui_send_mouse_event(button, TEXT_X(col - 1), TEXT_Y(row - 1), repeated_click, mods); return TRUE; } --- 1368,1402 ---- int col; int repeated_click; int_u mods; + int move; ! if (dict_find(args, (char_u *)"row", -1) == NULL ! || dict_find(args, (char_u *)"col", -1) == NULL) ! return FALSE; ! ! // Note: "move" is optional, requires fewer arguments ! move = (int)dict_get_bool(args, (char_u *)"move", FALSE); ! ! if (!move && (dict_find(args, (char_u *)"button", -1) == NULL || dict_find(args, (char_u *)"multiclick", -1) == NULL ! || dict_find(args, (char_u *)"modifiers", -1) == NULL)) return FALSE; row = (int)dict_get_number(args, (char_u *)"row"); col = (int)dict_get_number(args, (char_u *)"col"); ! if (move) ! gui_mouse_moved(col, row); ! else ! { ! button = (int)dict_get_number(args, (char_u *)"button"); ! repeated_click = (int)dict_get_number(args, (char_u *)"multiclick"); ! mods = (int)dict_get_number(args, (char_u *)"modifiers"); ! ! gui_send_mouse_event(button, TEXT_X(col - 1), TEXT_Y(row - 1), repeated_click, mods); + } + return TRUE; } *** ../vim-8.2.4673/src/testdir/test_gui.vim 2022-03-22 21:14:51.752456009 +0000 --- src/testdir/test_gui.vim 2022-04-03 15:15:10.745029995 +0100 *************** *** 1194,1199 **** --- 1194,1271 ---- set mousemodel& endfunc + func Test_gui_mouse_move_event() + let args = #{move: 1, button: 0, multiclick: 0, modifiers: 0} + + " default, do not generate mouse move events + set mousemev& + call assert_false(&mousemev) + + let n_event = 0 + nnoremap :let n_event += 1 + + " start at mouse pos (1,1), clear counter + call extend(args, #{row: 1, col:1}) + call test_gui_event('mouse', args) + call feedkeys('', 'Lx!') + let n_event = 0 + + call extend(args, #{row: 30, col:300}) + call test_gui_event('mouse', args) + call feedkeys('', 'Lx!') + + call extend(args, #{row: 100, col:300}) + call test_gui_event('mouse', args) + call feedkeys('', 'Lx!') + + " no events since mousemev off + call assert_equal(0, n_event) + + " turn on mouse events and try the same thing + set mousemev + call extend(args, #{row: 1, col:1}) + call test_gui_event('mouse', args) + call feedkeys('', 'Lx!') + let n_event = 0 + + call extend(args, #{row: 30, col:300}) + call test_gui_event('mouse', args) + call feedkeys('', 'Lx!') + + call extend(args, #{row: 100, col:300}) + call test_gui_event('mouse', args) + call feedkeys('', 'Lx!') + + call assert_equal(2, n_event) + + " wiggle the mouse around, shouldn't get events + call extend(args, #{row: 1, col:1}) + call test_gui_event('mouse', args) + call feedkeys('', 'Lx!') + let n_event = 0 + + call extend(args, #{row: 1, col:2}) + call test_gui_event('mouse', args) + call feedkeys('', 'Lx!') + + call extend(args, #{row: 2, col:2}) + call test_gui_event('mouse', args) + call feedkeys('', 'Lx!') + + call extend(args, #{row: 2, col:1}) + call test_gui_event('mouse', args) + call feedkeys('', 'Lx!') + + call extend(args, #{row: 1, col:1}) + call test_gui_event('mouse', args) + call feedkeys('', 'Lx!') + + call assert_equal(0, n_event) + + unmap + set mousemev& + endfunc + " Test for 'guitablabel' and 'guitabtooltip' options func TestGuiTabLabel() call add(g:TabLabels, v:lnum + 100) *** ../vim-8.2.4673/src/version.c 2022-04-03 13:23:18.982779936 +0100 --- src/version.c 2022-04-03 15:16:01.213011630 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 4674, /**/ -- ARTHUR: No, hang on! Just answer the five questions ... GALAHAD: Three questions ... ARTHUR: Three questions ... And we shall watch ... and pray. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///