To: vim_dev@googlegroups.com Subject: Patch 9.0.0775 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0775 Problem: MS-Windows: mouse scrolling not supported in the console. Solution: Add event handling for mouse scroll events. (Christopher Plewright, closes #11374) Files: .gitignore, src/os_win32.c, src/INSTALLpc.txt *** ../vim-9.0.0774/.gitignore 2022-08-24 11:26:12.868214983 +0100 --- .gitignore 2022-10-16 19:43:33.619416413 +0100 *************** *** 44,49 **** --- 44,51 ---- gvim.lib runtime/doc/uganda.nsis.txt nsis/icons/* + /vim90/ + .vscode/ # NetBeans nbproject/* *** ../vim-9.0.0774/src/os_win32.c 2022-10-04 13:17:27.496307898 +0100 --- src/os_win32.c 2022-10-16 19:44:54.547077198 +0100 *************** *** 1231,1236 **** --- 1231,1330 ---- } # endif + + /* + * Win32 console mouse scroll event handler. + * Loosely based on the _OnMouseWheel() function in gui_w32.c + * + * This encodes the mouse scroll direction and keyboard modifiers into + * g_nMouseClick, and the mouse position into g_xMouse and g_yMouse + * + * The direction of the scroll is decoded from two fields of the win32 console + * mouse event record; + * 1. The axis - vertical or horizontal flag - from dwEventFlags, and + * 2. The sign - positive or negative (aka delta flag) - from dwButtonState + * + * When scroll axis is HORIZONTAL + * - If the high word of the dwButtonState member contains a positive + * value, the wheel was rotated to the right. + * - Otherwise, the wheel was rotated to the left. + * When scroll axis is VERTICAL + * - If the high word of the dwButtonState member contains a positive value, + * the wheel was rotated forward, away from the user. + * - Otherwise, the wheel was rotated backward, toward the user. + */ + static void + decode_mouse_wheel(MOUSE_EVENT_RECORD *pmer) + { + win_T *wp; + int horizontal = (pmer->dwEventFlags == MOUSE_HWHEELED); + int zDelta = pmer->dwButtonState; + + g_xMouse = pmer->dwMousePosition.X; + g_yMouse = pmer->dwMousePosition.Y; + + #ifdef FEAT_PROP_POPUP + int lcol; + int lrow; + lcol = g_xMouse; + lrow = g_yMouse; + wp = mouse_find_win(&lrow, &lcol, FAIL_POPUP); + if (wp != NULL && popup_is_popup(wp)) + { + g_nMouseClick = -1; + cmdarg_T cap; + oparg_T oa; + CLEAR_FIELD(cap); + clear_oparg(&oa); + cap.oap = &oa; + if (horizontal) + { + cap.arg = zDelta < 0 ? MSCR_LEFT : MSCR_RIGHT; + cap.cmdchar = zDelta < 0 ? K_MOUSELEFT : K_MOUSERIGHT; + } + else + { + cap.cmdchar = zDelta < 0 ? K_MOUSEUP : K_MOUSEDOWN; + cap.arg = zDelta < 0 ? MSCR_UP : MSCR_DOWN; + } + + // Mouse hovers over popup window, scroll it if possible. + mouse_row = wp->w_winrow; + mouse_col = wp->w_wincol; + nv_mousescroll(&cap); + update_screen(0); + setcursor(); + out_flush(); + return; + } + #endif + mouse_col = g_xMouse; + mouse_row = g_yMouse; + + char_u modifiers = 0; + char_u direction = 0; + + // Decode the direction into an event that Vim can process + if (horizontal) + direction = zDelta >= 0 ? KE_MOUSELEFT : KE_MOUSERIGHT; + else + direction = zDelta >= 0 ? KE_MOUSEDOWN : KE_MOUSEUP; + + // Decode the win32 console key modifers into Vim mouse modifers. + if (pmer->dwControlKeyState & SHIFT_PRESSED) + modifiers |= MOD_MASK_SHIFT; //MOUSE_SHIFT; + if (pmer->dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) + modifiers |= MOD_MASK_CTRL; //MOUSE_CTRL; + if (pmer->dwControlKeyState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) + modifiers |= MOD_MASK_ALT; // MOUSE_ALT; + + // add (bitwise or) the scroll direction and the key modifier chars + // together. + g_nMouseClick = ((direction << 8) | modifiers); + + return; + } + /* * Decode a MOUSE_EVENT. If it's a valid event, return MOUSE_LEFT, * MOUSE_MIDDLE, or MOUSE_RIGHT for a click; MOUSE_DRAG for a mouse *************** *** 1304,1309 **** --- 1398,1410 ---- if (g_nMouseClick != -1) return TRUE; + if (pmer->dwEventFlags == MOUSE_WHEELED + || pmer->dwEventFlags == MOUSE_HWHEELED) + { + decode_mouse_wheel(pmer); + return TRUE; // we now should have a mouse scroll in g_nMouseClick + } + nButton = -1; g_xMouse = pmer->dwMousePosition.X; g_yMouse = pmer->dwMousePosition.Y; *************** *** 1939,1950 **** fprintf(fdDump, "{%02x @ %d, %d}", g_nMouseClick, g_xMouse, g_yMouse); # endif ! typeahead[typeaheadlen++] = ESC + 128; ! typeahead[typeaheadlen++] = 'M'; ! typeahead[typeaheadlen++] = g_nMouseClick; ! typeahead[typeaheadlen++] = g_xMouse + '!'; ! typeahead[typeaheadlen++] = g_yMouse + '!'; ! g_nMouseClick = -1; } else { --- 2040,2073 ---- fprintf(fdDump, "{%02x @ %d, %d}", g_nMouseClick, g_xMouse, g_yMouse); # endif ! char_u modifiers = ((char_u *)(&g_nMouseClick))[0]; ! char_u scroll_dir = ((char_u *)(&g_nMouseClick))[1]; ! ! if (scroll_dir == KE_MOUSEDOWN ! || scroll_dir == KE_MOUSEUP ! || scroll_dir == KE_MOUSELEFT ! || scroll_dir == KE_MOUSERIGHT) ! { ! if (modifiers > 0) ! { ! typeahead[typeaheadlen++] = CSI; ! typeahead[typeaheadlen++] = KS_MODIFIER; ! typeahead[typeaheadlen++] = modifiers; ! } ! typeahead[typeaheadlen++] = CSI; ! typeahead[typeaheadlen++] = KS_EXTRA; ! typeahead[typeaheadlen++] = scroll_dir; ! g_nMouseClick = -1; ! } ! else ! { ! typeahead[typeaheadlen++] = ESC + 128; ! typeahead[typeaheadlen++] = 'M'; ! typeahead[typeaheadlen++] = g_nMouseClick; ! typeahead[typeaheadlen++] = g_xMouse + '!'; ! typeahead[typeaheadlen++] = g_yMouse + '!'; ! g_nMouseClick = -1; ! } } else { *************** *** 8361,8367 **** { if (timer_active) { ! BOOL ret = DeleteTimerQueueTimer(NULL, timer_handle, NULL); timer_active = FALSE; if (!ret && GetLastError() != ERROR_IO_PENDING) { --- 8484,8490 ---- { if (timer_active) { ! BOOL ret = DeleteTimerQueueTimer(NULL, timer_handle, NULL); timer_active = FALSE; if (!ret && GetLastError() != ERROR_IO_PENDING) { *** ../vim-9.0.0774/src/INSTALLpc.txt 2022-09-21 11:56:02.047948576 +0100 --- src/INSTALLpc.txt 2022-10-16 19:35:54.998363426 +0100 *************** *** 686,692 **** Ruby ver. | Ruby API ver. ========================= - 1.8.X | 1.8 1.9.[1-3] | 1.9.1 2.0.0 | 2.0.0 2.X.Y | 2.X.0 --- 686,691 ---- *************** *** 897,941 **** After you've built the Vim binaries as described above, you're ready to install Vim on your system. However, if you've obtained the Vim sources using Git, Mercurial or by downloading them as a unix tar file, you must ! first create a "vim82" directory. If you instead downloaded the sources as zip files, you can skip this setup as the zip archives already have the correct directory structure. ! A. Create a Vim "runtime" subdirectory named "vim82" ----------------------------------------------------- If you obtained your Vim sources as zip files, you can skip this step. Otherwise, continue reading. Go to the directory that contains the Vim "src" and "runtime" ! directories and create a new subdirectory named "vim82". ! Copy the "runtime" files into "vim82": ! copy runtime\* vim82 ! xcopy /s runtime\* vim82 ! B. Copy the new binaries into the "vim82" directory ---------------------------------------------------- Regardless of how you installed the Vim sources, you need to copy the ! new binaries you created above into "vim82": ! copy src\*.exe vim82 ! copy src\tee\tee.exe vim82 ! copy src\xxd\xxd.exe vim82 To install the "Edit with Vim" popup menu, you need both 32-bit and 64-bit ! versions of gvimext.dll. They should be copied to "vim82\GvimExt32" and ! "vim82\GvimExt64" respectively. First, build the 32-bit version, then: ! mkdir vim82\GvimExt32 ! copy src\GvimExt\gvimext.dll vim82\GvimExt32 Next, clean the 32-bit version and build the 64-bit version, then: ! mkdir vim82\GvimExt64 ! copy src\GvimExt\gvimext.dll vim82\GvimExt64 ! C. Copy gettext and iconv DLLs into the "vim82" directory ---------------------------------------------------------- Get gettext and iconv DLLs from the following site: https://github.com/mlocati/gettext-iconv-windows/releases --- 896,940 ---- After you've built the Vim binaries as described above, you're ready to install Vim on your system. However, if you've obtained the Vim sources using Git, Mercurial or by downloading them as a unix tar file, you must ! first create a "vim90" directory. If you instead downloaded the sources as zip files, you can skip this setup as the zip archives already have the correct directory structure. ! A. Create a Vim "runtime" subdirectory named "vim90" ----------------------------------------------------- If you obtained your Vim sources as zip files, you can skip this step. Otherwise, continue reading. Go to the directory that contains the Vim "src" and "runtime" ! directories and create a new subdirectory named "vim90". ! Copy the "runtime" files into "vim90": ! copy runtime\* vim90 ! xcopy /s runtime\* vim90 ! B. Copy the new binaries into the "vim90" directory ---------------------------------------------------- Regardless of how you installed the Vim sources, you need to copy the ! new binaries you created above into "vim90": ! copy src\*.exe vim90 ! copy src\tee\tee.exe vim90 ! copy src\xxd\xxd.exe vim90 To install the "Edit with Vim" popup menu, you need both 32-bit and 64-bit ! versions of gvimext.dll. They should be copied to "vim90\GvimExt32" and ! "vim90\GvimExt64" respectively. First, build the 32-bit version, then: ! mkdir vim90\GvimExt32 ! copy src\GvimExt\gvimext.dll vim90\GvimExt32 Next, clean the 32-bit version and build the 64-bit version, then: ! mkdir vim90\GvimExt64 ! copy src\GvimExt\gvimext.dll vim90\GvimExt64 ! C. Copy gettext and iconv DLLs into the "vim90" directory ---------------------------------------------------------- Get gettext and iconv DLLs from the following site: https://github.com/mlocati/gettext-iconv-windows/releases *************** *** 943,949 **** Download the files gettextX.X.X.X-iconvX.XX-shared-{32,64}.zip, extract DLLs and place them as follows: ! vim82\ | libintl-8.dll | libiconv-2.dll | libgcc_s_sjlj-1.dll (only for 32-bit) --- 942,948 ---- Download the files gettextX.X.X.X-iconvX.XX-shared-{32,64}.zip, extract DLLs and place them as follows: ! vim90\ | libintl-8.dll | libiconv-2.dll | libgcc_s_sjlj-1.dll (only for 32-bit) *************** *** 957,974 **** libintl-8.dll libiconv-2.dll ! The DLLs in the "vim82" should be the same bitness with the (g)vim.exe. ! D. Move the "vim82" directory into the Vim installation subdirectory --------------------------------------------------------------------- ! Move the "vim82" subdirectory into the subdirectory where you want Vim to be installed. Typically, this subdirectory will be named "vim". ! If you already have a "vim82" subdirectory in "vim", delete it first by running its uninstall.exe program. E. Install Vim --------------- ! "cd" to your Vim installation subdirectory "vim\vim82" and run the "install.exe" program. It will ask you a number of questions about how you would like to have your Vim setup. Among these are: - You can tell it to write a "_vimrc" file with your preferences in the --- 956,973 ---- libintl-8.dll libiconv-2.dll ! The DLLs in the "vim90" should be the same bitness with the (g)vim.exe. ! D. Move the "vim90" directory into the Vim installation subdirectory --------------------------------------------------------------------- ! Move the "vim90" subdirectory into the subdirectory where you want Vim to be installed. Typically, this subdirectory will be named "vim". ! If you already have a "vim90" subdirectory in "vim", delete it first by running its uninstall.exe program. E. Install Vim --------------- ! "cd" to your Vim installation subdirectory "vim\vim90" and run the "install.exe" program. It will ask you a number of questions about how you would like to have your Vim setup. Among these are: - You can tell it to write a "_vimrc" file with your preferences in the *** ../vim-9.0.0774/src/version.c 2022-10-16 19:26:31.680328579 +0100 --- src/version.c 2022-10-16 19:41:31.828007053 +0100 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 775, /**/ -- Men may not be seen publicly in any kind of strapless gown. [real standing law in Florida, United States of America] /// 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 ///