Skip to content

Commit

Permalink
Enable fullscreen mode (#3408)
Browse files Browse the repository at this point in the history
## Summary of the Pull Request

Enables the `toggleFullscreen` action to be able to enter fullscreen mode, bound by default to <kbd>alt+enter</kbd>.

The action is bubbled up to the WindowsTerminal (Win32) layer, where the window resizes itself to take the entire size of the monitor.

This largely reuses code from conhost. Conhost already had a fullscreen mode, so I figured I might as well re-use that.

## References

Unfortunately there are still very thin borders around the window when the NonClientIslandWindow is fullscreened. I think I know where the problem is. However, that area of code is about to get a massive overhaul with #3064, so I didn't want to necessarily make it worse right now.  

A follow up should be filed to add support for "Always show / reveal / never show tabs in fullscreen mode". Currently, the only mode is "never show tabs".

Additionally, some of this code (particularily re:drawing the nonclient area) could be re-used for #2238.

## PR Checklist
* [x] Closes #531, #3411
* [x] I work here
* [n/a] Tests added/passed 😭
* [x] Requires documentation to be updated


## Validation Steps Performed
* Manually tested both the NonClientIslandWindow and the IslandWindow.

* Cherry-pick commit 8e56bfe

* Don't draw the tab strip when maximized

(cherry picked from commit bac4be7)

* Fix the vista window flash for the NCIW

(cherry picked from commit 7d3a18a)

* Some code cleanup for review

(cherry picked from commit 9e22b77)

* A tad bit more notes and cleanup

* Update schema, docs

* Most of the PR comments

* I'm not sure this actually works, so I'm committing it to revert it and check

* Update some comments that were lost.

* Fix a build break?

* oh no
  • Loading branch information
zadjii-msft authored Nov 5, 2019
1 parent 94213ad commit 388b975
Show file tree
Hide file tree
Showing 21 changed files with 335 additions and 66 deletions.
3 changes: 2 additions & 1 deletion doc/cascadia/SettingsSchema.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ Bindings listed below are per the implementation in `src/cascadia/TerminalApp/Ap
- moveFocusRight
- moveFocusUp
- moveFocusDown
- toggleFullscreen

## Background Images and Icons
Some Terminal settings allow you to specify custom background images and icons. It is recommended that custom images and icons are stored in system-provided folders and are referred to using the correct [URI Schemes](https://docs.microsoft.com/en-us/windows/uwp/app-resources/uri-schemes). URI Schemes provide a way to reference files independent of their physical paths (which may change in the future).
Expand Down Expand Up @@ -176,4 +177,4 @@ For example:
With these settings, your Terminal's Ubuntu profile would look similar to this:

![Custom icon and background image](../images/custom-icon-and-background-image.jpg)
![Custom icon and background image](../images/custom-icon-and-background-image.jpg)
5 changes: 3 additions & 2 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
"switchToTab5",
"switchToTab6",
"switchToTab7",
"switchToTab8"
"switchToTab8",
"toggleFullscreen"
],
"type": "string"
},
Expand Down Expand Up @@ -535,4 +536,4 @@
]
}
]
}
}
28 changes: 0 additions & 28 deletions src/cascadia/TerminalApp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,34 +662,6 @@ namespace winrt::TerminalApp::implementation
}
}

// Methods that proxy typed event handlers through TerminalPage
winrt::event_token App::SetTitleBarContent(Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::UIElement> const& handler)
{
return _root->SetTitleBarContent(handler);
}
void App::SetTitleBarContent(winrt::event_token const& token) noexcept
{
return _root->SetTitleBarContent(token);
}

winrt::event_token App::TitleChanged(Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable, winrt::hstring> const& handler)
{
return _root->TitleChanged(handler);
}
void App::TitleChanged(winrt::event_token const& token) noexcept
{
return _root->TitleChanged(token);
}

winrt::event_token App::LastTabClosed(Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::LastTabClosedEventArgs> const& handler)
{
return _root->LastTabClosed(handler);
}
void App::LastTabClosed(winrt::event_token const& token) noexcept
{
return _root->LastTabClosed(token);
}

// -------------------------------- WinRT Events ---------------------------------
// Winrt events need a method for adding a callback to the event and removing the callback.
// These macros will define them both for you.
Expand Down
11 changes: 8 additions & 3 deletions src/cascadia/TerminalApp/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ namespace winrt::TerminalApp::implementation
void WindowCloseButtonClicked();

// -------------------------------- WinRT Events ---------------------------------
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(TitleChanged, _titleChangeHandlers, winrt::Windows::Foundation::IInspectable, winrt::hstring);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(LastTabClosed, _lastTabClosedHandlers, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::LastTabClosedEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(SetTitleBarContent, _setTitleBarContentHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::UIElement);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(RequestedThemeChanged, _requestedThemeChangedHandlers, TerminalApp::App, winrt::Windows::UI::Xaml::ElementTheme);

private:
Expand Down Expand Up @@ -82,6 +79,14 @@ namespace winrt::TerminalApp::implementation
void _ReloadSettings();

void _ApplyTheme(const Windows::UI::Xaml::ElementTheme& newTheme);

// These are events that are handled by the TerminalPage, but are
// exposed through the App. This macro is used to forward the event
// directly to them.
FORWARDED_TYPED_EVENT(SetTitleBarContent, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::UIElement, _root, SetTitleBarContent);
FORWARDED_TYPED_EVENT(TitleChanged, winrt::Windows::Foundation::IInspectable, winrt::hstring, _root, TitleChanged);
FORWARDED_TYPED_EVENT(LastTabClosed, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::LastTabClosedEventArgs, _root, LastTabClosed);
FORWARDED_TYPED_EVENT(ToggleFullscreen, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::ToggleFullscreenEventArgs, _root, ToggleFullscreen);
};
}

Expand Down
5 changes: 3 additions & 2 deletions src/cascadia/TerminalApp/App.idl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import "../TerminalPage.idl";

namespace TerminalApp
{
enum LaunchMode
Expand All @@ -9,10 +11,8 @@ namespace TerminalApp
MaximizedMode,
};

delegate void LastTabClosedEventArgs();
[default_interface] runtimeclass App : Microsoft.Toolkit.Win32.UI.XamlHost.XamlApplication
{

App();

void Initialize();
Expand Down Expand Up @@ -41,5 +41,6 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<Object, String> TitleChanged;
event Windows.Foundation.TypedEventHandler<Object, LastTabClosedEventArgs> LastTabClosed;
event Windows.Foundation.TypedEventHandler<App, Windows.UI.Xaml.ElementTheme> RequestedThemeChanged;
event Windows.Foundation.TypedEventHandler<Object, ToggleFullscreenEventArgs> ToggleFullscreen;
}
}
8 changes: 8 additions & 0 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,12 @@ namespace winrt::TerminalApp::implementation
args.Handled(true);
}
}

void TerminalPage::_HandleToggleFullscreen(const IInspectable& /*sender*/,
const TerminalApp::ActionEventArgs& args)
{
_ToggleFullscreen();
args.Handled(true);
}

}
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/AppKeyBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ namespace winrt::TerminalApp::implementation
_AdjustFontSizeHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::ToggleFullscreen:
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_ToggleFullscreenHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
default:
return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/AppKeyBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace winrt::TerminalApp::implementation
TYPED_EVENT(OpenSettings, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
TYPED_EVENT(ResizePane, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
TYPED_EVENT(MoveFocus, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
TYPED_EVENT(ToggleFullscreen, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
// clang-format on

private:
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/AppKeyBindings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace TerminalApp
MoveFocusRight,
MoveFocusUp,
MoveFocusDown,
ToggleFullscreen,
OpenSettings
};

Expand Down Expand Up @@ -87,5 +88,6 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> OpenSettings;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> ResizePane;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> MoveFocus;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> ToggleFullscreen;
}
}
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/AppKeyBindingsSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static constexpr std::string_view MoveFocusLeftKey{ "moveFocusLeft" };
static constexpr std::string_view MoveFocusRightKey{ "moveFocusRight" };
static constexpr std::string_view MoveFocusUpKey{ "moveFocusUp" };
static constexpr std::string_view MoveFocusDownKey{ "moveFocusDown" };
static constexpr std::string_view ToggleFullscreenKey{ "toggleFullscreen" };

// Specifically use a map here over an unordered_map. We want to be able to
// iterate over these entries in-order when we're serializing the keybindings.
Expand Down Expand Up @@ -127,6 +128,7 @@ static const std::map<std::string_view, ShortcutAction, std::less<>> commandName
{ MoveFocusUpKey, ShortcutAction::MoveFocusUp },
{ MoveFocusDownKey, ShortcutAction::MoveFocusDown },
{ OpenSettingsKey, ShortcutAction::OpenSettings },
{ ToggleFullscreenKey, ShortcutAction::ToggleFullscreen },
{ UnboundKey, ShortcutAction::Invalid },
};

Expand Down
26 changes: 23 additions & 3 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ namespace winrt::TerminalApp::implementation
bindings.MoveFocus({ this, &TerminalPage::_HandleMoveFocus });
bindings.CopyText({ this, &TerminalPage::_HandleCopyText });
bindings.AdjustFontSize({ this, &TerminalPage::_HandleAdjustFontSize });
bindings.ToggleFullscreen({ this, &TerminalPage::_HandleToggleFullscreen });
}

// Method Description:
Expand Down Expand Up @@ -606,11 +607,13 @@ namespace winrt::TerminalApp::implementation
// - Handle changes in tab layout.
void TerminalPage::_UpdateTabView()
{
// Never show the tab row when we're fullscreen. Otherwise:
// Show tabs when there's more than 1, or the user has chosen to always
// show the tab bar.
const bool isVisible = _settings->GlobalSettings().GetShowTabsInTitlebar() ||
(_tabs.size() > 1) ||
_settings->GlobalSettings().GetAlwaysShowTabs();
const bool isVisible = (!_isFullscreen) &&
(_settings->GlobalSettings().GetShowTabsInTitlebar() ||
(_tabs.size() > 1) ||
_settings->GlobalSettings().GetAlwaysShowTabs());

// collapse/show the tabs themselves
_tabView.Visibility(isVisible ? Visibility::Visible : Visibility::Collapsed);
Expand Down Expand Up @@ -1323,11 +1326,28 @@ namespace winrt::TerminalApp::implementation
}
}

// Method Description:
// - Toggles fullscreen mode. Hides the tab row, and raises our
// ToggleFullscreen event.
// Arguments:
// - <none>
// Return Value:
// - <none>
void TerminalPage::_ToggleFullscreen()
{
_toggleFullscreenHandlers(*this, nullptr);

_isFullscreen = !_isFullscreen;

_UpdateTabView();
}

// -------------------------------- WinRT Events ---------------------------------
// Winrt events need a method for adding a callback to the event and removing the callback.
// These macros will define them both for you.
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, TitleChanged, _titleChangeHandlers, winrt::Windows::Foundation::IInspectable, winrt::hstring);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, LastTabClosed, _lastTabClosedHandlers, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::LastTabClosedEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, SetTitleBarContent, _setTitleBarContentHandlers, winrt::Windows::Foundation::IInspectable, UIElement);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, ShowDialog, _showDialogHandlers, winrt::Windows::Foundation::IInspectable, WUX::Controls::ContentDialog);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, ToggleFullscreen, _toggleFullscreenHandlers, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::ToggleFullscreenEventArgs);
}
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace winrt::TerminalApp::implementation
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(LastTabClosed, _lastTabClosedHandlers, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::LastTabClosedEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(SetTitleBarContent, _setTitleBarContentHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::UIElement);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(ShowDialog, _showDialogHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::Controls::ContentDialog);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(ToggleFullscreen, _toggleFullscreenHandlers, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::ToggleFullscreenEventArgs);

private:
// If you add controls here, but forget to null them either here or in
Expand All @@ -57,6 +58,8 @@ namespace winrt::TerminalApp::implementation

std::vector<std::shared_ptr<Tab>> _tabs;

bool _isFullscreen{ false };

void _ShowAboutDialog();
void _ShowCloseWarningDialog();

Expand Down Expand Up @@ -120,6 +123,8 @@ namespace winrt::TerminalApp::implementation

void _RefreshUIForSettingsReload();

void _ToggleFullscreen();

#pragma region ActionHandlers
// These are all defined in AppActionHandlers.cpp
void _HandleNewTab(const IInspectable& sender, const TerminalApp::ActionEventArgs& args);
Expand All @@ -144,6 +149,7 @@ namespace winrt::TerminalApp::implementation
void _HandleCopyText(const IInspectable& sender, const TerminalApp::ActionEventArgs& args);
void _HandleCloseWindow(const IInspectable&, const TerminalApp::ActionEventArgs& args);
void _HandleAdjustFontSize(const IInspectable& sender, const TerminalApp::ActionEventArgs& args);
void _HandleToggleFullscreen(const IInspectable& sender, const TerminalApp::ActionEventArgs& args);
#pragma endregion
};
}
Expand Down
5 changes: 4 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.idl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import "..\App.idl";

namespace TerminalApp
{
delegate void LastTabClosedEventArgs();
delegate void ToggleFullscreenEventArgs();

[default_interface] runtimeclass TerminalPage : Windows.UI.Xaml.Controls.Page
{
TerminalPage();
Expand All @@ -12,5 +14,6 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<Object, LastTabClosedEventArgs> LastTabClosed;
event Windows.Foundation.TypedEventHandler<Object, Windows.UI.Xaml.UIElement> SetTitleBarContent;
event Windows.Foundation.TypedEventHandler<Object, Windows.UI.Xaml.Controls.ContentDialog> ShowDialog;
event Windows.Foundation.TypedEventHandler<Object, ToggleFullscreenEventArgs> ToggleFullscreen;
}
}
4 changes: 3 additions & 1 deletion src/cascadia/TerminalApp/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@
{ "command": "switchToTab7", "keys": ["ctrl+alt+8"] },
{ "command": "switchToTab8", "keys": ["ctrl+alt+9"] },
{ "command": "decreaseFontSize", "keys": ["ctrl+-"] },
{ "command": "increaseFontSize", "keys": ["ctrl+="] }
{ "command": "increaseFontSize", "keys": ["ctrl+="] },
{ "command": "toggleFullscreen", "keys": ["alt+enter"] },
{ "command": "toggleFullscreen", "keys": ["f11"] }
]
}
7 changes: 7 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void AppHost::Initialize()
_window->DragRegionClicked([this]() { _app.TitlebarClicked(); });

_app.RequestedThemeChanged({ this, &AppHost::_UpdateTheme });
_app.ToggleFullscreen({ this, &AppHost::_ToggleFullscreen });

_app.Create();

Expand Down Expand Up @@ -267,3 +268,9 @@ void AppHost::_UpdateTheme(const winrt::TerminalApp::App&, const winrt::Windows:
{
_window->OnApplicationThemeChanged(arg);
}

void AppHost::_ToggleFullscreen(const winrt::Windows::Foundation::IInspectable&,
const winrt::TerminalApp::ToggleFullscreenEventArgs&)
{
_window->ToggleFullscreen();
}
2 changes: 2 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ class AppHost
const winrt::Windows::UI::Xaml::UIElement& arg);
void _UpdateTheme(const winrt::TerminalApp::App&,
const winrt::Windows::UI::Xaml::ElementTheme& arg);
void _ToggleFullscreen(const winrt::Windows::Foundation::IInspectable& sender,
const winrt::TerminalApp::ToggleFullscreenEventArgs& arg);
};
Loading

0 comments on commit 388b975

Please sign in to comment.