Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure caption controls "dim out" when window loses NC focus #6577

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/spell-check/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,7 @@ natvis
naws
nbsp
Nc
NCACTIVATE
NCCALCSIZE
NCCREATE
NCLBUTTONDOWN
Expand Down
11 changes: 11 additions & 0 deletions src/cascadia/TerminalApp/MinMaxCloseControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ namespace winrt::TerminalApp::implementation
MaximizeButton().Height(maximizedHeight);
CloseButton().Height(maximizedHeight);
break;
case WindowVisualState::WindowVisualStateUnfocused:
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateUnfocused", false);
VisualStateManager::GoToState(MinimizeButton(), L"WindowStateUnfocused", false);
VisualStateManager::GoToState(CloseButton(), L"WindowStateUnfocused", false);
break;

case WindowVisualState::WindowVisualStateFocused:
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateFocused", false);
VisualStateManager::GoToState(MinimizeButton(), L"WindowStateFocused", false);
VisualStateManager::GoToState(CloseButton(), L"WindowStateFocused", false);
break;

case WindowVisualState::WindowVisualStateNormal:
case WindowVisualState::WindowVisualStateIconified:
Expand Down
12 changes: 12 additions & 0 deletions src/cascadia/TerminalApp/MinMaxCloseControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ the MIT License. See LICENSE in the project root for license information. -->
<StaticResource x:Key="CaptionButtonStrokePointerOver" ResourceKey="SystemControlForegroundBaseHighBrush"/>
<StaticResource x:Key="CaptionButtonStrokePressed" ResourceKey="SystemControlForegroundBaseHighBrush"/>
<SolidColorBrush x:Key="CaptionButtonBackground" Color="Transparent" />
<SolidColorBrush x:Key="CaptionButtonStrokeWindowUnfocused" Color="Red" />
<SolidColorBrush x:Key="CloseButtonBackgroundPointerOver" Color="#e81123"/>
<SolidColorBrush x:Key="CloseButtonStrokePointerOver" Color="White"/>
<SolidColorBrush x:Key="CloseButtonBackgroundPressed" Color="#f1707a"/>
Expand All @@ -38,6 +39,7 @@ the MIT License. See LICENSE in the project root for license information. -->
<StaticResource x:Key="CaptionButtonStrokePointerOver" ResourceKey="SystemControlForegroundBaseHighBrush"/>
<StaticResource x:Key="CaptionButtonStrokePressed" ResourceKey="SystemControlForegroundBaseHighBrush"/>
<SolidColorBrush x:Key="CaptionButtonBackground" Color="Transparent" />
<SolidColorBrush x:Key="CaptionButtonStrokeWindowUnfocused" Color="Red" />
<SolidColorBrush x:Key="CloseButtonBackgroundPointerOver" Color="#e81123"/>
<SolidColorBrush x:Key="CloseButtonStrokePointerOver" Color="White"/>
<SolidColorBrush x:Key="CloseButtonBackgroundPressed" Color="#f1707a"/>
Expand Down Expand Up @@ -125,6 +127,16 @@ the MIT License. See LICENSE in the project root for license information. -->
<VisualState x:Name="Disabled" />
</VisualStateGroup>

<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="WindowStateFocused" />

<VisualState x:Name="WindowStateUnfocused">
<VisualState.Setters>
<Setter Target="Path.Stroke" Value="{ThemeResource CaptionButtonStrokeWindowUnfocused}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>

<VisualStateGroup x:Name="MinMaxStates">
<VisualState x:Name="WindowStateNormal" />

Expand Down
4 changes: 3 additions & 1 deletion src/cascadia/TerminalApp/TitlebarControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace TerminalApp
{
WindowVisualStateNormal = 0,
WindowVisualStateMaximized,
WindowVisualStateIconified
WindowVisualStateIconified,
WindowVisualStateFocused,
WindowVisualStateUnfocused
};

[default_interface] runtimeclass TitlebarControl : Windows.UI.Xaml.Controls.Grid
Expand Down
30 changes: 30 additions & 0 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,34 @@ int NonClientIslandWindow::_GetResizeHandleHeight() const noexcept
return 0;
}

// Method Description:
// - Responds to the WM_NCACTIVATE message by changing the focus state of
// the window.
[[nodiscard]] LRESULT NonClientIslandWindow::_OnFocusChanged(const WPARAM wParam, const LPARAM lParam) noexcept
{
const auto windowStyle = GetWindowStyle(_window.get());
const auto isIconified = WI_IsFlagSet(windowStyle, WS_ICONIC);

if (isIconified)
{
return DefWindowProc(_window.get(), WM_NCACTIVATE, wParam, lParam);
}

if (_titlebar)
{
_isFocused = wParam;
const auto state = _isFocused ? winrt::TerminalApp::WindowVisualState::WindowVisualStateFocused :
winrt::TerminalApp::WindowVisualState::WindowVisualStateUnfocused;
try
{
_titlebar.SetWindowVisualState(state);
}
CATCH_LOG();
}

return TRUE;
}

// Method Description:
// - Hit test the frame for resizing and moving.
// Arguments:
Expand Down Expand Up @@ -688,6 +716,8 @@ void NonClientIslandWindow::_UpdateFrameMargins() const noexcept
return 0;
case WM_NCCALCSIZE:
return _OnNcCalcSize(wParam, lParam);
case WM_NCACTIVATE:
return _OnFocusChanged(wParam, lParam);
case WM_NCHITTEST:
return _OnNcHitTest({ GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) });
case WM_PAINT:
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class NonClientIslandWindow : public IslandWindow
winrt::Windows::UI::Xaml::ElementTheme _theme;

bool _isMaximized;
bool _isFocused;

[[nodiscard]] static LRESULT __stdcall _StaticInputSinkWndProc(HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept;
[[nodiscard]] LRESULT _InputSinkMessageHandler(UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept;
Expand All @@ -73,6 +74,7 @@ class NonClientIslandWindow : public IslandWindow

[[nodiscard]] LRESULT _OnNcCreate(WPARAM wParam, LPARAM lParam) noexcept override;
[[nodiscard]] LRESULT _OnNcCalcSize(const WPARAM wParam, const LPARAM lParam) noexcept;
[[nodiscard]] LRESULT _OnFocusChanged(const WPARAM wParam, const LPARAM lParam) noexcept;
[[nodiscard]] LRESULT _OnNcHitTest(POINT ptMouse) const noexcept;
[[nodiscard]] LRESULT _OnPaint() noexcept;
[[nodiscard]] LRESULT _OnSetCursor(WPARAM wParam, LPARAM lParam) const noexcept;
Expand Down