Skip to content

Commit

Permalink
win32: disable quickedit mode when enabling mouse support
Browse files Browse the repository at this point in the history
The Windows conpty layer now allows terminal emulators other
than the classic conhost.exe to host win32 console applications that
use mouse events.

For mouse events to function correctly, mouse input needs to be
enabled and quick edit mode needs to be disabled.

This commit teaches vim to make this change when it enables mouse
mode.

I have no special knowledge of vim, and this patch is roughly based
on the suggested changes in this discussion:

https://groups.google.com/g/vim_dev/c/bQ7jfMwa8Zg

The intent is to enable mouse input and disable quickedit when
enabling mouse mode, and to disable mouse input and restore the
prior quickedit mode state when mouse mode is disabled.

refs: microsoft/terminal#9970
  • Loading branch information
wez committed May 28, 2021
1 parent dc3275a commit 783d3c3
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/os_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ decode_key_event(

#endif // FEAT_GUI_MSWIN

static DWORD g_cmodein = 0;

/*
* For the GUI the mouse handling is in gui_w32.c.
Expand Down Expand Up @@ -1200,9 +1201,15 @@ mch_setmouse(int on)
GetConsoleMode(g_hConIn, &cmodein);

if (g_fMouseActive)
{
cmodein |= ENABLE_MOUSE_INPUT;
cmodein &= ~ENABLE_QUICK_EDIT_MODE;

This comment has been minimized.

Copy link
@DHowett

DHowett May 28, 2021

You'll need to set ENABLE_EXTENDED_FLAGS to set/clear the QE mode, as it is ignored by default.

This comment has been minimized.

Copy link
@k-takata

k-takata May 28, 2021

The document says

To enable this mode, use ENABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS. To disable this mode, use ENABLE_EXTENDED_FLAGS without this flag.

Is ENABLE_EXTENDED_FLAGS needed when clearing?

This comment has been minimized.

Copy link
@DHowett

DHowett May 28, 2021

Yes, and only when you explicitly want to clear it.

This comment has been minimized.

Copy link
@DHowett

DHowett May 28, 2021

(Like: don’t set it if you do not want to risk changing QuickEdit)

}
else
{
cmodein &= ~ENABLE_MOUSE_INPUT;
cmodein |= g_cmodein & ENABLE_QUICK_EDIT_MODE;
}

SetConsoleMode(g_hConIn, cmodein);
}
Expand Down Expand Up @@ -2782,7 +2789,6 @@ SaveConsoleTitleAndIcon(void)
static int g_fWindInitCalled = FALSE;
static int g_fTermcapMode = FALSE;
static CONSOLE_CURSOR_INFO g_cci;
static DWORD g_cmodein = 0;
static DWORD g_cmodeout = 0;

/*
Expand Down Expand Up @@ -3747,7 +3753,14 @@ mch_settmode(tmode_T tmode)
cmodein &= ~(ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT |
ENABLE_ECHO_INPUT);
if (g_fMouseActive)
{
cmodein |= ENABLE_MOUSE_INPUT;
cmodein &= ~ENABLE_QUICK_EDIT_MODE;
}
else
{
cmodein |= g_cmodein & ENABLE_QUICK_EDIT_MODE;
}
cmodeout &= ~(
# ifdef FEAT_TERMGUICOLORS
// Do not turn off the ENABLE_PROCESSED_OUTPUT flag when using
Expand Down Expand Up @@ -5621,9 +5634,15 @@ termcap_mode_start(void)

GetConsoleMode(g_hConIn, &cmodein);
if (g_fMouseActive)
{
cmodein |= ENABLE_MOUSE_INPUT;
cmodein &= ~ENABLE_QUICK_EDIT_MODE;
}
else
{
cmodein &= ~ENABLE_MOUSE_INPUT;
cmodein |= g_cmodein & ENABLE_QUICK_EDIT_MODE;
}
cmodein |= ENABLE_WINDOW_INPUT;
SetConsoleMode(g_hConIn, cmodein);

Expand All @@ -5650,6 +5669,7 @@ termcap_mode_end(void)

GetConsoleMode(g_hConIn, &cmodein);
cmodein &= ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT);
cmodein |= g_cmodein & ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(g_hConIn, cmodein);

# ifdef FEAT_RESTORE_ORIG_SCREEN
Expand Down

0 comments on commit 783d3c3

Please sign in to comment.