Respect the console's Quick Edit mode -- it suppresses mouse events

* winpty-agent: Respect the ENABLE_QUICK_EDIT_MODE flag.  If it's set,
   then mouse events are not generated (because they're supposed to control
   selection).

 * winpty-agent: Because of the above, turn ENABLE_QUICK_EDIT_MODE off at
   startup.

 * winpty-agent --show-input: Enable ENABLE_WINDOW_INPUT so we can see
   buffer resize events.

 * winpty-agent --show-input: Disable ENABLE_QUICK_EDIT_MODE with
   --with-mouse.  When Quick Edit mode is enabled, the mouse controls
   selection and does not produce mouse events in the input queue.
This commit is contained in:
Ryan Prichard 2015-12-16 19:52:45 -06:00
parent f7e5e1f69a
commit 75fe19ae96
3 changed files with 32 additions and 11 deletions

View File

@ -160,7 +160,20 @@ Agent::Agent(LPCWSTR controlPipeName,
SetConsoleCtrlHandler(NULL, FALSE); SetConsoleCtrlHandler(NULL, FALSE);
SetConsoleCtrlHandler(consoleCtrlHandler, TRUE); SetConsoleCtrlHandler(consoleCtrlHandler, TRUE);
updateMouseInputFlag(true); // Disable Quick Edit mode. The user has little control over winpty's
// console, and I think it's better to default it off for the sake of
// programs that care about mouse input.
DWORD mode = 0;
if (!GetConsoleMode(m_console->conin(), &mode)) {
trace("Agent startup: GetConsoleMode failed");
} else {
mode &= ~ENABLE_QUICK_EDIT_MODE;
if (!SetConsoleMode(m_console->conin(), mode)) {
trace("Agent startup: SetConsoleMode failed");
}
}
updateMouseInputFlags(true);
setPollInterval(25); setPollInterval(25);
} }
@ -361,23 +374,28 @@ void Agent::pollDataSocket()
} }
} }
void Agent::updateMouseInputFlag(bool forceTrace) void Agent::updateMouseInputFlags(bool forceTrace)
{ {
DWORD mode = 0; DWORD mode = 0;
GetConsoleMode(m_console->conin(), &mode); GetConsoleMode(m_console->conin(), &mode);
bool newFlag = mode & ENABLE_MOUSE_INPUT; bool newFlagMI = mode & ENABLE_MOUSE_INPUT;
if (forceTrace || newFlag != m_consoleMouseInputFlag) { bool newFlagQE = mode & ENABLE_QUICK_EDIT_MODE;
trace("CONIN mode ENABLE_MOUSE_INPUT: %s", if (forceTrace ||
newFlag ? "enabled" : "disabled"); newFlagMI != m_consoleMouseInputEnabled ||
newFlagQE != m_consoleQuickEditEnabled) {
trace("CONIN mode: ENABLE_MOUSE_INPUT=%s ENABLE_QUICK_EDIT_MODE=%s",
newFlagMI ? "enabled" : "disabled",
newFlagQE ? "enabled" : "disabled");
} }
m_consoleMouseInputFlag = newFlag; m_consoleMouseInputEnabled = newFlagMI;
m_consoleInput->setMouseInputEnabled(newFlag); m_consoleQuickEditEnabled = newFlagQE;
m_consoleInput->setMouseInputEnabled(newFlagMI && !newFlagQE);
} }
void Agent::onPollTimeout() void Agent::onPollTimeout()
{ {
// Check the mouse input flag so we can output a trace message. // Check the mouse input flag so we can output a trace message.
updateMouseInputFlag(); updateMouseInputFlags();
// Give the ConsoleInput object a chance to flush input from an incomplete // Give the ConsoleInput object a chance to flush input from an incomplete
// escape sequence (e.g. pressing ESC). // escape sequence (e.g. pressing ESC).

View File

@ -69,7 +69,7 @@ private:
int handleStartProcessPacket(ReadBuffer &packet); int handleStartProcessPacket(ReadBuffer &packet);
int handleSetSizePacket(ReadBuffer &packet); int handleSetSizePacket(ReadBuffer &packet);
void pollDataSocket(); void pollDataSocket();
void updateMouseInputFlag(bool forceTrace=false); void updateMouseInputFlags(bool forceTrace=false);
protected: protected:
virtual void onPollTimeout(); virtual void onPollTimeout();
@ -95,7 +95,8 @@ private:
private: private:
bool m_useMark; bool m_useMark;
Win32Console *m_console; Win32Console *m_console;
bool m_consoleMouseInputFlag; bool m_consoleMouseInputEnabled;
bool m_consoleQuickEditEnabled;
NamedPipe *m_controlSocket; NamedPipe *m_controlSocket;
NamedPipe *m_dataSocket; NamedPipe *m_dataSocket;
bool m_closingDataSocket; bool m_closingDataSocket;

View File

@ -145,8 +145,10 @@ void debugShowInput(bool enableMouse) {
newConsoleMode &= ~ENABLE_PROCESSED_INPUT; newConsoleMode &= ~ENABLE_PROCESSED_INPUT;
newConsoleMode &= ~ENABLE_LINE_INPUT; newConsoleMode &= ~ENABLE_LINE_INPUT;
newConsoleMode &= ~ENABLE_ECHO_INPUT; newConsoleMode &= ~ENABLE_ECHO_INPUT;
newConsoleMode |= ENABLE_WINDOW_INPUT;
if (enableMouse) { if (enableMouse) {
newConsoleMode |= ENABLE_MOUSE_INPUT; newConsoleMode |= ENABLE_MOUSE_INPUT;
newConsoleMode &= ~ENABLE_QUICK_EDIT_MODE;
} else { } else {
newConsoleMode &= ~ENABLE_MOUSE_INPUT; newConsoleMode &= ~ENABLE_MOUSE_INPUT;
} }