Skip to content

Commit 5b33c66

Browse files
committed
Propagate window style changes to the titlebar and minmax (#3025)
Fixes #1780
1 parent 42e281d commit 5b33c66

File tree

7 files changed

+45
-19
lines changed

7 files changed

+45
-19
lines changed

src/cascadia/TerminalApp/MinMaxCloseControl.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ namespace winrt::TerminalApp::implementation
1919
InitializeComponent();
2020
}
2121

22-
void MinMaxCloseControl::Maximize()
23-
{
24-
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateMaximized", false);
25-
}
26-
27-
void MinMaxCloseControl::RestoreDown()
28-
{
29-
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateNormal", false);
30-
}
31-
3222
// These event handlers simply forward each buttons click events up to the
3323
// events we've exposed.
3424
void MinMaxCloseControl::_MinimizeClick(winrt::Windows::Foundation::IInspectable const& sender,
@@ -48,6 +38,21 @@ namespace winrt::TerminalApp::implementation
4838
_closeClickHandlers(*this, e);
4939
}
5040

41+
void MinMaxCloseControl::SetWindowVisualState(WindowVisualState visualState)
42+
{
43+
switch (visualState)
44+
{
45+
case WindowVisualState::WindowVisualStateMaximized:
46+
winrt::Windows::UI::Xaml::VisualStateManager::GoToState(MaximizeButton(), L"WindowStateMaximized", false);
47+
break;
48+
case WindowVisualState::WindowVisualStateNormal:
49+
case WindowVisualState::WindowVisualStateIconified:
50+
default:
51+
winrt::Windows::UI::Xaml::VisualStateManager::GoToState(MaximizeButton(), L"WindowStateNormal", false);
52+
break;
53+
}
54+
}
55+
5156
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, MinimizeClick, _minimizeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
5257
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, MaximizeClick, _maximizeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
5358
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, CloseClick, _closeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);

src/cascadia/TerminalApp/MinMaxCloseControl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ namespace winrt::TerminalApp::implementation
1818
{
1919
MinMaxCloseControl();
2020

21-
void Maximize();
22-
void RestoreDown();
21+
void SetWindowVisualState(WindowVisualState visualState);
2322

2423
void _MinimizeClick(winrt::Windows::Foundation::IInspectable const& sender,
2524
winrt::Windows::UI::Xaml::RoutedEventArgs const& e);

src/cascadia/TerminalApp/MinMaxCloseControl.idl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4+
import "..\TitlebarControl.idl";
5+
46
namespace TerminalApp
57
{
68
[default_interface] runtimeclass MinMaxCloseControl : Windows.UI.Xaml.Controls.StackPanel
79
{
810
MinMaxCloseControl();
911

10-
void Maximize();
11-
void RestoreDown();
12+
void SetWindowVisualState(WindowVisualState visualState);
1213

1314
event Windows.Foundation.TypedEventHandler<MinMaxCloseControl, Windows.UI.Xaml.RoutedEventArgs> MinimizeClick;
1415
event Windows.Foundation.TypedEventHandler<MinMaxCloseControl, Windows.UI.Xaml.RoutedEventArgs> MaximizeClick;

src/cascadia/TerminalApp/TitlebarControl.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,10 @@ namespace winrt::TerminalApp::implementation
5959
::GetWindowPlacement(_window, &placement);
6060
if (placement.showCmd == SW_SHOWNORMAL)
6161
{
62-
MinMaxCloseControl().Maximize();
6362
::PostMessage(_window, WM_SYSCOMMAND, SC_MAXIMIZE | flag, lParam);
6463
}
6564
else if (placement.showCmd == SW_SHOWMAXIMIZED)
6665
{
67-
MinMaxCloseControl().RestoreDown();
6866
::PostMessage(_window, WM_SYSCOMMAND, SC_RESTORE | flag, lParam);
6967
}
7068
}
@@ -92,4 +90,9 @@ namespace winrt::TerminalApp::implementation
9290
::PostQuitMessage(0);
9391
}
9492

93+
void TitlebarControl::SetWindowVisualState(WindowVisualState visualState)
94+
{
95+
MinMaxCloseControl().SetWindowVisualState(visualState);
96+
}
97+
9598
}

src/cascadia/TerminalApp/TitlebarControl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ namespace winrt::TerminalApp::implementation
2020
Windows::UI::Xaml::UIElement Content();
2121
void Content(Windows::UI::Xaml::UIElement content);
2222

23+
void SetWindowVisualState(WindowVisualState visualState);
24+
2325
void Root_SizeChanged(const IInspectable& sender, Windows::UI::Xaml::SizeChangedEventArgs const& e);
2426

2527
void Minimize_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e);

src/cascadia/TerminalApp/TitlebarControl.idl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33

44
namespace TerminalApp
55
{
6+
enum WindowVisualState
7+
{
8+
WindowVisualStateNormal = 0,
9+
WindowVisualStateMaximized,
10+
WindowVisualStateIconified
11+
};
12+
613
[default_interface] runtimeclass TitlebarControl : Windows.UI.Xaml.Controls.Grid
714
{
815
TitlebarControl(UInt64 parentWindowHandle);
16+
void SetWindowVisualState(WindowVisualState visualState);
917

1018
Windows.UI.Xaml.UIElement Content;
1119
Windows.UI.Xaml.Controls.Border DragBar { get; };

src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,17 @@ bool NonClientIslandWindow::_HandleWindowPosChanging(WINDOWPOS* const windowPos)
667667
return false;
668668
}
669669

670+
const auto windowStyle = GetWindowStyle(_window.get());
671+
const auto isMaximized = WI_IsFlagSet(windowStyle, WS_MAXIMIZE);
672+
const auto isIconified = WI_IsFlagSet(windowStyle, WS_ICONIC);
673+
674+
if (_titlebar)
675+
{
676+
_titlebar.SetWindowVisualState(isMaximized ? winrt::TerminalApp::WindowVisualState::WindowVisualStateMaximized :
677+
isIconified ? winrt::TerminalApp::WindowVisualState::WindowVisualStateIconified :
678+
winrt::TerminalApp::WindowVisualState::WindowVisualStateNormal);
679+
}
680+
670681
// Figure out the suggested dimensions
671682
RECT rcSuggested;
672683
rcSuggested.left = windowPos->x;
@@ -714,9 +725,6 @@ bool NonClientIslandWindow::_HandleWindowPosChanging(WINDOWPOS* const windowPos)
714725
}
715726
}
716727

717-
const auto windowStyle = GetWindowStyle(_window.get());
718-
const auto isMaximized = WI_IsFlagSet(windowStyle, WS_MAXIMIZE);
719-
720728
// If we're about to maximize the window, determine how much we're about to
721729
// overhang by, and adjust for that.
722730
// We need to do this because maximized windows will typically overhang the

0 commit comments

Comments
 (0)