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

Propagate window style changes to the titlebar and minmax #3025

Merged
merged 1 commit into from
Oct 2, 2019
Merged
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
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i do not yet intend to unify these string names. sorry.

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 :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my only complaint is that these lines are too damn long. But that's a stylistic choice for someone with split panes in their editor :)

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