Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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/spelling/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,7 @@ Mypair
Myval
NAMELENGTH
namestream
NCACTIVATE
NCCALCSIZE
NCCREATE
NCLBUTTONDOWN
Expand Down
43 changes: 25 additions & 18 deletions src/cascadia/TerminalApp/MinMaxCloseControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ namespace winrt::TerminalApp::implementation
}
}

static const winrt::param::hstring& normalState(bool focused)
{
static winrt::param::hstring normal = L"Normal";
static winrt::param::hstring unfocused = L"Unfocused";
return (focused ? normal : unfocused);
}

MinMaxCloseControl::MinMaxCloseControl()
{
// Get our dispatcher. This will get us the same dispatcher as
Expand Down Expand Up @@ -152,7 +159,7 @@ namespace winrt::TerminalApp::implementation
// - dismiss any open tooltips on other buttons.
// Arguments:
// - button: the button that was hovered
void MinMaxCloseControl::HoverButton(CaptionButton button)
void MinMaxCloseControl::HoverButton(CaptionButton button, bool focused)
{
// Keep track of the button that's been pressed. we get a mouse move
// message when we open the tooltip. If we move the mouse on top of this
Expand All @@ -169,25 +176,25 @@ namespace winrt::TerminalApp::implementation
// animate the fade in/out transition between colors.
case CaptionButton::Minimize:
VisualStateManager::GoToState(MinimizeButton(), L"PointerOver", true);
VisualStateManager::GoToState(MaximizeButton(), L"Normal", true);
VisualStateManager::GoToState(CloseButton(), L"Normal", true);
VisualStateManager::GoToState(MaximizeButton(), normalState(focused), true);
VisualStateManager::GoToState(CloseButton(), normalState(focused), true);

_displayToolTip->Run(MinimizeButton());
closeToolTipForButton(MaximizeButton());
closeToolTipForButton(CloseButton());
break;
case CaptionButton::Maximize:
VisualStateManager::GoToState(MinimizeButton(), L"Normal", true);
VisualStateManager::GoToState(MinimizeButton(), normalState(focused), true);
VisualStateManager::GoToState(MaximizeButton(), L"PointerOver", true);
VisualStateManager::GoToState(CloseButton(), L"Normal", true);
VisualStateManager::GoToState(CloseButton(), normalState(focused), true);

closeToolTipForButton(MinimizeButton());
_displayToolTip->Run(MaximizeButton());
closeToolTipForButton(CloseButton());
break;
case CaptionButton::Close:
VisualStateManager::GoToState(MinimizeButton(), L"Normal", true);
VisualStateManager::GoToState(MaximizeButton(), L"Normal", true);
VisualStateManager::GoToState(MinimizeButton(), normalState(focused), true);
VisualStateManager::GoToState(MaximizeButton(), normalState(focused), true);
VisualStateManager::GoToState(CloseButton(), L"PointerOver", true);

closeToolTipForButton(MinimizeButton());
Expand All @@ -204,23 +211,23 @@ namespace winrt::TerminalApp::implementation
// - Transition that button to `Pressed`
// Arguments:
// - button: the button that was pressed
void MinMaxCloseControl::PressButton(CaptionButton button)
void MinMaxCloseControl::PressButton(CaptionButton button, bool focused)
{
switch (button)
{
case CaptionButton::Minimize:
VisualStateManager::GoToState(MinimizeButton(), L"Pressed", true);
VisualStateManager::GoToState(MaximizeButton(), L"Normal", true);
VisualStateManager::GoToState(CloseButton(), L"Normal", true);
VisualStateManager::GoToState(MaximizeButton(), normalState(focused), true);
VisualStateManager::GoToState(CloseButton(), normalState(focused), true);
break;
case CaptionButton::Maximize:
VisualStateManager::GoToState(MinimizeButton(), L"Normal", true);
VisualStateManager::GoToState(MinimizeButton(), normalState(focused), true);
VisualStateManager::GoToState(MaximizeButton(), L"Pressed", true);
VisualStateManager::GoToState(CloseButton(), L"Normal", true);
VisualStateManager::GoToState(CloseButton(), normalState(focused), true);
break;
case CaptionButton::Close:
VisualStateManager::GoToState(MinimizeButton(), L"Normal", true);
VisualStateManager::GoToState(MaximizeButton(), L"Normal", true);
VisualStateManager::GoToState(MinimizeButton(), normalState(focused), true);
VisualStateManager::GoToState(MaximizeButton(), normalState(focused), true);
VisualStateManager::GoToState(CloseButton(), L"Pressed", true);
break;
}
Expand All @@ -230,12 +237,12 @@ namespace winrt::TerminalApp::implementation
// Method Description:
// - Called when buttons are no longer hovered or pressed. Return them all
// to the normal state, and dismiss the tooltips.
void MinMaxCloseControl::ReleaseButtons()
void MinMaxCloseControl::ReleaseButtons(bool focused)
{
_displayToolTip->Run(nullptr);
VisualStateManager::GoToState(MinimizeButton(), L"Normal", true);
VisualStateManager::GoToState(MaximizeButton(), L"Normal", true);
VisualStateManager::GoToState(CloseButton(), L"Normal", true);
VisualStateManager::GoToState(MinimizeButton(), normalState(focused), true);
VisualStateManager::GoToState(MaximizeButton(), normalState(focused), true);
VisualStateManager::GoToState(CloseButton(), normalState(focused), true);

closeToolTipForButton(MinimizeButton());
closeToolTipForButton(MaximizeButton());
Expand Down
7 changes: 4 additions & 3 deletions src/cascadia/TerminalApp/MinMaxCloseControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ namespace winrt::TerminalApp::implementation

void SetWindowVisualState(WindowVisualState visualState);

void HoverButton(CaptionButton button);
void PressButton(CaptionButton button);
void ReleaseButtons();
void HoverButton(CaptionButton button, bool focused);
void PressButton(CaptionButton button, bool focused);
void ReleaseButtons(bool focused);

void _MinimizeClick(const winrt::Windows::Foundation::IInspectable& sender,
const winrt::Windows::UI::Xaml::RoutedEventArgs& e);
Expand All @@ -32,6 +32,7 @@ namespace winrt::TerminalApp::implementation
til::typed_event<TerminalApp::MinMaxCloseControl, winrt::Windows::UI::Xaml::RoutedEventArgs> MaximizeClick;
til::typed_event<TerminalApp::MinMaxCloseControl, winrt::Windows::UI::Xaml::RoutedEventArgs> CloseClick;

bool _focused{ false };
std::shared_ptr<ThrottledFunc<winrt::Windows::UI::Xaml::Controls::Button>> _displayToolTip{ nullptr };
std::optional<CaptionButton> _lastPressedButton{ std::nullopt };
};
Expand Down
6 changes: 3 additions & 3 deletions src/cascadia/TerminalApp/MinMaxCloseControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace TerminalApp

void SetWindowVisualState(WindowVisualState visualState);

void HoverButton(CaptionButton button);
void PressButton(CaptionButton button);
void ReleaseButtons();
void HoverButton(CaptionButton button, Boolean focused);
void PressButton(CaptionButton button, Boolean focused);
void ReleaseButtons(Boolean focused);

event Windows.Foundation.TypedEventHandler<MinMaxCloseControl, Windows.UI.Xaml.RoutedEventArgs> MinimizeClick;
event Windows.Foundation.TypedEventHandler<MinMaxCloseControl, Windows.UI.Xaml.RoutedEventArgs> MaximizeClick;
Expand Down
33 changes: 33 additions & 0 deletions src/cascadia/TerminalApp/MinMaxCloseControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
ResourceKey="SystemControlForegroundBaseHighBrush" />
<StaticResource x:Key="CaptionButtonForegroundPressed"
ResourceKey="SystemControlForegroundBaseHighBrush" />
<StaticResource x:Key="CaptionButtonForegroundUnfocusedColor"
ResourceKey="TextFillColorDisabled" />
<SolidColorBrush x:Key="CaptionButtonForegroundUnfocused"
Color="{ThemeResource CaptionButtonForegroundUnfocusedColor}" />
<SolidColorBrush x:Key="CaptionButtonBackground"
Color="Transparent" />
<Color x:Key="CaptionButtonBackgroundColor">Transparent</Color>
Expand Down Expand Up @@ -66,6 +70,10 @@
ResourceKey="SystemControlForegroundBaseHighBrush" />
<StaticResource x:Key="CaptionButtonForegroundPressed"
ResourceKey="SystemControlForegroundBaseHighBrush" />
<StaticResource x:Key="CaptionButtonForegroundUnfocusedColor"
ResourceKey="TextFillColorDisabled" />
<SolidColorBrush x:Key="CaptionButtonForegroundUnfocused"
Color="{ThemeResource CaptionButtonForegroundUnfocusedColor}" />
<SolidColorBrush x:Key="CaptionButtonBackground"
Color="Transparent" />
<Color x:Key="CaptionButtonBackgroundColor">Transparent</Color>
Expand Down Expand Up @@ -103,6 +111,10 @@
Color="{ThemeResource SystemColorHighlightTextColor}" />
<SolidColorBrush x:Key="CaptionButtonForegroundPressed"
Color="{ThemeResource SystemColorHighlightTextColor}" />
<SolidColorBrush x:Key="CaptionButtonForegroundUnfocused"
Color="{ThemeResource SystemColorButtonTextColor}" />
<StaticResource x:Key="CaptionButtonForegroundUnfocusedColor"
ResourceKey="SystemColorButtonTextColor" />
<SolidColorBrush x:Key="CloseButtonBackgroundPointerOver"
Color="{ThemeResource SystemColorHighlightColor}" />
<SolidColorBrush x:Key="CloseButtonForegroundPointerOver"
Expand Down Expand Up @@ -189,6 +201,20 @@
Duration="0:0:0.1" />
</Storyboard>
</VisualTransition>

<VisualTransition From="PointerOver"
To="Unfocused">
<Storyboard>
<ColorAnimation Storyboard.TargetName="ButtonBaseElement"
Storyboard.TargetProperty="(UIElement.Background).(SolidColorBrush.Color)"
To="{ThemeResource CaptionButtonBackgroundColor}"
Duration="0:0:0.15" />
<ColorAnimation Storyboard.TargetName="ButtonIcon"
Storyboard.TargetProperty="(UIElement.Foreground).(SolidColorBrush.Color)"
To="{ThemeResource CaptionButtonForegroundUnfocusedColor}"
Duration="0:0:0.1" />
</Storyboard>
</VisualTransition>
</VisualStateGroup.Transitions>

<VisualState x:Name="Normal">
Expand All @@ -198,6 +224,13 @@
</VisualState.Setters>
</VisualState>

<VisualState x:Name="Unfocused">
<VisualState.Setters>
<Setter Target="ButtonBaseElement.Background" Value="{ThemeResource CaptionButtonBackground}" />
<Setter Target="ButtonIcon.Foreground" Value="{ThemeResource CaptionButtonForegroundUnfocused}" />
</VisualState.Setters>
</VisualState>

<VisualState x:Name="PointerOver">
<VisualState.Setters>
<Setter Target="ButtonBaseElement.Background" Value="{ThemeResource CaptionButtonBackgroundPointerOver}" />
Expand Down
18 changes: 15 additions & 3 deletions src/cascadia/TerminalApp/TitlebarControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ namespace winrt::TerminalApp::implementation
return static_cast<float>(minMaxCloseWidth) / 3.0f;
}

bool TitlebarControl::Focused() const
{
return _focused;
}

void TitlebarControl::Focused(bool focused)
{
_focused = focused;

MinMaxCloseControl().ReleaseButtons(_focused);
}

IInspectable TitlebarControl::Content()
{
return ContentRoot().Content();
Expand Down Expand Up @@ -134,11 +146,11 @@ namespace winrt::TerminalApp::implementation

void TitlebarControl::HoverButton(CaptionButton button)
{
MinMaxCloseControl().HoverButton(button);
MinMaxCloseControl().HoverButton(button, _focused);
}
void TitlebarControl::PressButton(CaptionButton button)
{
MinMaxCloseControl().PressButton(button);
MinMaxCloseControl().PressButton(button, _focused);
}
safe_void_coroutine TitlebarControl::ClickButton(CaptionButton button)
{
Expand Down Expand Up @@ -168,7 +180,7 @@ namespace winrt::TerminalApp::implementation
}
void TitlebarControl::ReleaseButtons()
{
MinMaxCloseControl().ReleaseButtons();
MinMaxCloseControl().ReleaseButtons(_focused);
}

void TitlebarControl::_backgroundChanged(winrt::Windows::UI::Xaml::Media::Brush brush)
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalApp/TitlebarControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ namespace winrt::TerminalApp::implementation
void ReleaseButtons();
float CaptionButtonWidth();

bool Focused() const;
void Focused(bool focused);

IInspectable Content();
void Content(IInspectable content);

Expand All @@ -30,6 +33,7 @@ namespace winrt::TerminalApp::implementation
void DragBar_DoubleTapped(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::Input::DoubleTappedRoutedEventArgs& e);

private:
bool _focused{ false };
void _OnMaximizeOrRestore(byte flag);
HWND _window{ nullptr }; // non-owning handle; should not be freed in the dtor.

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TitlebarControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace TerminalApp
void ClickButton(CaptionButton button);
void ReleaseButtons();
Single CaptionButtonWidth { get; };
Boolean Focused { get; set; };

IInspectable Content;
Windows.UI.Xaml.Controls.Border DragBar { get; };
Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,12 @@ void NonClientIslandWindow::_UpdateFrameMargins() const noexcept
{
switch (message)
{
case WM_NCACTIVATE:
{
const bool activated = LOWORD(wParam) != 0;
_titlebar.Focused(activated);
break;
}
case WM_SETCURSOR:
return _OnSetCursor(wParam, lParam);
case WM_DISPLAYCHANGE:
Expand Down