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 MinMaxCloseControl supports fullscreen and tablet mode #6660

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
3 changes: 3 additions & 0 deletions .github/actions/spell-check/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ coord
coordnew
COPYCOLOR
CORESYSTEM
corewrappers
cotaskmem
countof
cout
Expand Down Expand Up @@ -2519,13 +2520,15 @@ VFT
vga
vgaoem
viewkind
viewmanagement
viewports
Virt
VIRTTERM
Virtualizing
vk
vkey
VKKEYSCAN
vm
VMs
VPA
VPATH
Expand Down
7 changes: 7 additions & 0 deletions src/cascadia/TerminalApp/MinMaxCloseControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ namespace winrt::TerminalApp::implementation
CloseButton().Height(maximizedHeight);
break;


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

case WindowVisualState::WindowVisualStateNormal:
case WindowVisualState::WindowVisualStateIconified:
default:
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/MinMaxCloseControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ the MIT License. See LICENSE in the project root for license information. -->

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

<VisualState x:Name="WindowStateMaximized">
<VisualState.Setters>
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalApp/TitlebarControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace TerminalApp
{
WindowVisualStateNormal = 0,
WindowVisualStateMaximized,
WindowVisualStateIconified
WindowVisualStateIconified,
WindowVisualStateTablet
};

[default_interface] runtimeclass TitlebarControl : Windows.UI.Xaml.Controls.Grid
Expand Down
31 changes: 31 additions & 0 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ using namespace winrt::Windows::Foundation::Numerics;
using namespace ::Microsoft::Console;
using namespace ::Microsoft::Console::Types;

namespace vm = winrt::Windows::UI::ViewManagement;

static constexpr int AutohideTaskbarSize = 2;

NonClientIslandWindow::NonClientIslandWindow(const ElementTheme& requestedTheme) noexcept :
Expand Down Expand Up @@ -304,6 +306,7 @@ RECT NonClientIslandWindow::_GetDragAreaRect() const noexcept
void NonClientIslandWindow::OnSize(const UINT width, const UINT height)
{
_UpdateMaximizedState();
_CheckTabletMode();

if (_interopWindowHandle)
{
Expand Down Expand Up @@ -354,6 +357,25 @@ void NonClientIslandWindow::_OnMaximizeChange() noexcept
_UpdateFrameMargins();
}


void NonClientIslandWindows::_CheckTabletMode(HWND hwnd)
{
winrt::com_ptr<vm::IUIViewSettings> viewSettings;
vm::UserInteractionMode mode = vm::UserInteractionMode_Mouse;

if (viewSettings)
{
vm::UserInteractionMode currentMode;
viewSettings->get_UserInteractionMode(&currentMode);
if (g_mode != currentMode)
{
g_mode = currentMode;
_isTabletMode = true;
const auto state = winrt::TerminalApp::WindowVisualState::WindowVisualStateTablet
_titlebar.SetWindowVisualState(state);
}
}
}
// Method Description:
// - Called when the size of the window changes for any reason. Updates the
// sizes of our child XAML Islands to match our new sizing.
Expand Down Expand Up @@ -788,6 +810,15 @@ void NonClientIslandWindow::_UpdateFrameMargins() const noexcept
return FALSE;
}

WRL::ComPtr<IUIViewSettingsInterop> interop;
Windows::Foundation::GetActivationFactory(WRL::Wrappers::HStringReference(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DHowett Please tell me how to convert it from WRL to winrt🙏🙏

Copy link
Member

@DHowett DHowett Jul 7, 2020

Choose a reason for hiding this comment

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

So, to convert this from WRL to WinRT, all you need to do is.. replace all this code with:

auto viewSettingsForWindow = winrt::Windows::UI::ViewManagement::UIViewSettings::GetForWindow(hwnd);

C++/WinRT makes winrt look like modern C++, so you don't need to do any weird smart pointer types or IID management.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, but if you have to use an Interop class... then things get weird and annoying. You actually can't use c++/winrt directly for this. lol ☹️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, using an interop class is the only way I know of. Summoning the legend himself for guidance : @oldnewthing

Copy link
Member

Choose a reason for hiding this comment

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

Oh you mean

    UIViewSettings viewSettingsForWindow{ nullptr };
    get_activation_factory<IUIViewSettingsInterop>(name_of<UIViewSettings>())->
        GetForWindow(hwnd, guid_of<UIViewSettings>(), put_abi(viewSettingsForWindow));

or if you like one-liners

    auto viewSettingsForWindow =
        capture<IInspectable>(
            get_activation_factory<IUIViewSettingsInterop>(name_of<UIViewSettings>()),
            &IUIViewSettingsInterop::GetForWindow,
            hwnd).as<UIViewSettings>();

RuntimeClass_Windows_UI_ViewManagement_UIViewSettings).Get(),
&interop);

interop->GetForWindow(hwnd, IID_PPV_ARGS(&g_viewSettings));

_CheckTabletMode(hwnd);

// This is a hack to make the window borders dark instead of light.
// It must be done before WM_NCPAINT so that the borders are rendered with
// the correct theme.
Expand Down
8 changes: 8 additions & 0 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Author(s):
#include "../../types/inc/Viewport.hpp"
#include <dwmapi.h>
#include <wil/resource.h>
#include <windows.ui.viewmanagement.h>
#include <UIViewSettingsInterop.h>
#include <wrl/client.h>
#include <wrl/wrappers/corewrappers.h>

class NonClientIslandWindow : public IslandWindow
{
Expand Down Expand Up @@ -61,6 +65,7 @@ class NonClientIslandWindow : public IslandWindow
winrt::Windows::UI::Xaml::ElementTheme _theme;

bool _isMaximized;
bool _isTabletMode;

[[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 @@ -77,11 +82,14 @@ class NonClientIslandWindow : public IslandWindow
[[nodiscard]] LRESULT _OnPaint() noexcept;
[[nodiscard]] LRESULT _OnSetCursor(WPARAM wParam, LPARAM lParam) const noexcept;
void _OnMaximizeChange() noexcept;
void _OnFullscreenChange() noexcept;
void _OnDragBarSizeChanged(winrt::Windows::Foundation::IInspectable sender, winrt::Windows::UI::Xaml::SizeChangedEventArgs eventArgs);

void _SetIsFullscreen(const bool fFullscreenEnabled) override;
bool _IsTitlebarVisible() const;

void _CheckTabletMode(HWND hwnd) noexcept;

void _UpdateFrameMargins() const noexcept;
void _UpdateMaximizedState();
void _UpdateIslandPosition(const UINT windowWidth, const UINT windowHeight);
Expand Down