Skip to content

Commit

Permalink
Propagate window style changes to the titlebar and minmax
Browse files Browse the repository at this point in the history
Fixes #1780
  • Loading branch information
DHowett committed Oct 1, 2019
1 parent 0ce08af commit 601f257
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 19 deletions.
25 changes: 15 additions & 10 deletions src/cascadia/TerminalApp/MinMaxCloseControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ namespace winrt::TerminalApp::implementation
InitializeComponent();
}

void MinMaxCloseControl::Maximize()
{
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateMaximized", false);
}

void MinMaxCloseControl::RestoreDown()
{
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateNormal", false);
}

// These event handlers simply forward each buttons click events up to the
// events we've exposed.
void MinMaxCloseControl::_MinimizeClick(winrt::Windows::Foundation::IInspectable const& sender,
Expand All @@ -48,6 +38,21 @@ namespace winrt::TerminalApp::implementation
_closeClickHandlers(*this, e);
}

void MinMaxCloseControl::SetWindowVisualState(WindowVisualState visualState)
{
switch (visualState)
{
case WindowVisualState::WindowVisualStateMaximized:
winrt::Windows::UI::Xaml::VisualStateManager::GoToState(MaximizeButton(), L"WindowStateMaximized", false);
break;
case WindowVisualState::WindowVisualStateNormal:
case WindowVisualState::WindowVisualStateIconified:
default:
winrt::Windows::UI::Xaml::VisualStateManager::GoToState(MaximizeButton(), L"WindowStateNormal", false);
break;
}
}

DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, MinimizeClick, _minimizeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, MaximizeClick, _maximizeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, CloseClick, _closeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
Expand Down
3 changes: 1 addition & 2 deletions src/cascadia/TerminalApp/MinMaxCloseControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ namespace winrt::TerminalApp::implementation
{
MinMaxCloseControl();

void Maximize();
void RestoreDown();
void SetWindowVisualState(WindowVisualState visualState);

void _MinimizeClick(winrt::Windows::Foundation::IInspectable const& sender,
winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
Expand Down
5 changes: 3 additions & 2 deletions src/cascadia/TerminalApp/MinMaxCloseControl.idl
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import "..\TitlebarControl.idl";

namespace TerminalApp
{
[default_interface] runtimeclass MinMaxCloseControl : Windows.UI.Xaml.Controls.StackPanel
{
MinMaxCloseControl();

void Maximize();
void RestoreDown();
void SetWindowVisualState(WindowVisualState visualState);

event Windows.Foundation.TypedEventHandler<MinMaxCloseControl, Windows.UI.Xaml.RoutedEventArgs> MinimizeClick;
event Windows.Foundation.TypedEventHandler<MinMaxCloseControl, Windows.UI.Xaml.RoutedEventArgs> MaximizeClick;
Expand Down
7 changes: 5 additions & 2 deletions src/cascadia/TerminalApp/TitlebarControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ namespace winrt::TerminalApp::implementation
::GetWindowPlacement(_window, &placement);
if (placement.showCmd == SW_SHOWNORMAL)
{
MinMaxCloseControl().Maximize();
::PostMessage(_window, WM_SYSCOMMAND, SC_MAXIMIZE | flag, lParam);
}
else if (placement.showCmd == SW_SHOWMAXIMIZED)
{
MinMaxCloseControl().RestoreDown();
::PostMessage(_window, WM_SYSCOMMAND, SC_RESTORE | flag, lParam);
}
}
Expand Down Expand Up @@ -92,4 +90,9 @@ namespace winrt::TerminalApp::implementation
::PostQuitMessage(0);
}

void TitlebarControl::SetWindowVisualState(WindowVisualState visualState)
{
MinMaxCloseControl().SetWindowVisualState(visualState);
}

}
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/TitlebarControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace winrt::TerminalApp::implementation
Windows::UI::Xaml::UIElement Content();
void Content(Windows::UI::Xaml::UIElement content);

void SetWindowVisualState(WindowVisualState visualState);

void Root_SizeChanged(const IInspectable& sender, Windows::UI::Xaml::SizeChangedEventArgs const& e);

void Minimize_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
Expand Down
8 changes: 8 additions & 0 deletions src/cascadia/TerminalApp/TitlebarControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@

namespace TerminalApp
{
enum WindowVisualState
{
WindowVisualStateNormal = 0,
WindowVisualStateMaximized,
WindowVisualStateIconified
};

[default_interface] runtimeclass TitlebarControl : Windows.UI.Xaml.Controls.Grid
{
TitlebarControl(UInt64 parentWindowHandle);
void SetWindowVisualState(WindowVisualState visualState);

Windows.UI.Xaml.UIElement Content;
Windows.UI.Xaml.Controls.Border DragBar { get; };
Expand Down
14 changes: 11 additions & 3 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,17 @@ bool NonClientIslandWindow::_HandleWindowPosChanging(WINDOWPOS* const windowPos)
return false;
}

const auto windowStyle = GetWindowStyle(_window.get());
const auto isMaximized = WI_IsFlagSet(windowStyle, WS_MAXIMIZE);
const auto isIconified = WI_IsFlagSet(windowStyle, WS_ICONIC);

if (_titlebar)
{
_titlebar.SetWindowVisualState(isMaximized ? winrt::TerminalApp::WindowVisualState::WindowVisualStateMaximized :
isIconified ? winrt::TerminalApp::WindowVisualState::WindowVisualStateIconified :
winrt::TerminalApp::WindowVisualState::WindowVisualStateNormal);
}

// Figure out the suggested dimensions
RECT rcSuggested;
rcSuggested.left = windowPos->x;
Expand Down Expand Up @@ -726,9 +737,6 @@ bool NonClientIslandWindow::_HandleWindowPosChanging(WINDOWPOS* const windowPos)
}
}

const auto windowStyle = GetWindowStyle(_window.get());
const auto isMaximized = WI_IsFlagSet(windowStyle, WS_MAXIMIZE);

// If we're about to maximize the window, determine how much we're about to
// overhang by, and adjust for that.
// We need to do this because maximized windows will typically overhang the
Expand Down

0 comments on commit 601f257

Please sign in to comment.