From cb732a4bccea02e9036c281bbb0a192c46de2ccc Mon Sep 17 00:00:00 2001 From: Don-Vito Date: Wed, 14 Oct 2020 01:40:56 +0300 Subject: [PATCH] 7571: do not activate terminal window upon settings modificaion (#7887) Took this as an easy starter. The method IslandWindow::SetAlwaysOnTop is triggered once terminal settings are reloaded (in TerminalPage::_RefreshUIForSettingsReload flow). This method calls SetWindowPos without SWP_NOACTIVATE. As a result the window gets activated, the focus is set and the cursor starts blinking. Added SWP_NOACTIVATE in all SetWindowPos calls from IslandWindow and NoClientIslandWindow (where it was missing). Please let me know if this is an overkill - it is not required to fix the issue, however seems a good practice, that might help if we decide to apply more settings immediately. ## Validation Steps Performed * Only manual testing - please guide me to the relevant UT framework, if exists. * Trying to reproduce this with VS attached doesn't work - the window gets the focus in any case. * Tested as a standalone application, by modifying different settings (and comparing the results before and after the fix). * Checked with Spy++ that no WM_ACTIVATE / WM_SETFOCUS is thrown upon settings modification * Applied terminal resizing, toggling full screen and focus mode to check no regression was introduced. Closes #7571 --- src/cascadia/WindowsTerminal/IslandWindow.cpp | 8 ++++---- src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cascadia/WindowsTerminal/IslandWindow.cpp b/src/cascadia/WindowsTerminal/IslandWindow.cpp index 4312fb59df8..34dc72d85ac 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.cpp +++ b/src/cascadia/WindowsTerminal/IslandWindow.cpp @@ -263,7 +263,7 @@ void IslandWindow::Initialize() void IslandWindow::OnSize(const UINT width, const UINT height) { // update the interop window size - SetWindowPos(_interopWindowHandle, nullptr, 0, 0, width, height, SWP_SHOWWINDOW); + SetWindowPos(_interopWindowHandle, nullptr, 0, 0, width, height, SWP_SHOWWINDOW | SWP_NOACTIVATE); if (_rootGrid) { @@ -499,7 +499,7 @@ void IslandWindow::SetAlwaysOnTop(const bool alwaysOnTop) 0, 0, 0, - SWP_NOMOVE | SWP_NOSIZE); + SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); } } @@ -613,7 +613,7 @@ void IslandWindow::_SetIsBorderless(const bool borderlessEnabled) windowPos.top(), windowPos.width(), windowPos.height(), - SWP_SHOWWINDOW | SWP_FRAMECHANGED); + SWP_SHOWWINDOW | SWP_FRAMECHANGED | SWP_NOACTIVATE); } // Method Description: @@ -699,7 +699,7 @@ void IslandWindow::_ApplyWindowSize() newSize.top, newSize.right - newSize.left, newSize.bottom - newSize.top, - SWP_FRAMECHANGED)); + SWP_FRAMECHANGED | SWP_NOACTIVATE)); } DEFINE_EVENT(IslandWindow, DragRegionClicked, _DragRegionClickedHandlers, winrt::delegate<>); diff --git a/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp b/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp index d8e67e7dec7..17491b15ad1 100644 --- a/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp +++ b/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp @@ -370,7 +370,7 @@ void NonClientIslandWindow::_UpdateIslandPosition(const UINT windowWidth, const newIslandPos.Y, windowWidth, windowHeight - topBorderHeight, - SWP_SHOWWINDOW)); + SWP_SHOWWINDOW | SWP_NOACTIVATE)); // This happens when we go from maximized to restored or the opposite // because topBorderHeight changes. @@ -849,7 +849,7 @@ void NonClientIslandWindow::_SetIsBorderless(const bool borderlessEnabled) windowPos.top(), windowPos.width(), windowPos.height(), - SWP_SHOWWINDOW | SWP_FRAMECHANGED); + SWP_SHOWWINDOW | SWP_FRAMECHANGED | SWP_NOACTIVATE); } // Method Description: