Skip to content

Commit 0d8bb2c

Browse files
zadjii-msftjelster
authored andcommitted
Add support for fullscreen launchMode (microsoft#6060)
## Summary of the Pull Request Adds `"launchMode": "fullscreen"`, which does what it says on the box. ## PR Checklist * [x] Closes microsoft#288 * [x] I work here * [ ] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments It's important to let the winow get created, _then_ fullscreen it, because otherwise, when the user exits fullscreen, the window is sized to like, 0x0 or something, and that's just annoying.
1 parent 904ca64 commit 0d8bb2c

File tree

7 files changed

+90
-56
lines changed

7 files changed

+90
-56
lines changed

src/cascadia/TerminalApp/AppLogic.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace TerminalApp
1111
{
1212
DefaultMode,
1313
MaximizedMode,
14+
FullscreenMode,
1415
};
1516

1617
[default_interface] runtimeclass AppLogic : IF7Listener

src/cascadia/TerminalApp/GlobalAppSettings.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static constexpr std::string_view ConfirmCloseAllKey{ "confirmCloseAllTabs" };
3838
static constexpr std::string_view SnapToGridOnResizeKey{ "snapToGridOnResize" };
3939
static constexpr std::wstring_view DefaultLaunchModeValue{ L"default" };
4040
static constexpr std::wstring_view MaximizedLaunchModeValue{ L"maximized" };
41+
static constexpr std::wstring_view FullscreenLaunchModeValue{ L"fullscreen" };
4142
static constexpr std::wstring_view LightThemeValue{ L"light" };
4243
static constexpr std::wstring_view DarkThemeValue{ L"dark" };
4344
static constexpr std::wstring_view SystemThemeValue{ L"system" };
@@ -473,6 +474,10 @@ LaunchMode GlobalAppSettings::_ParseLaunchMode(const std::wstring& launchModeStr
473474
{
474475
return LaunchMode::MaximizedMode;
475476
}
477+
else if (launchModeString == FullscreenLaunchModeValue)
478+
{
479+
return LaunchMode::FullscreenMode;
480+
}
476481

477482
return LaunchMode::DefaultMode;
478483
}
@@ -490,6 +495,8 @@ std::wstring_view GlobalAppSettings::_SerializeLaunchMode(const LaunchMode launc
490495
{
491496
case LaunchMode::MaximizedMode:
492497
return MaximizedLaunchModeValue;
498+
case LaunchMode::FullscreenMode:
499+
return FullscreenLaunchModeValue;
493500
default:
494501
return DefaultLaunchModeValue;
495502
}

src/cascadia/TerminalApp/TerminalPage.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ namespace winrt::TerminalApp::implementation
188188
if (_appArgs.GetStartupActions().empty())
189189
{
190190
_OpenNewTab(nullptr);
191-
_startupState = StartupState::Initialized;
192-
_InitializedHandlers(*this, nullptr);
191+
192+
_CompleteInitialization();
193193
}
194194
else
195195
{
@@ -222,9 +222,31 @@ namespace winrt::TerminalApp::implementation
222222
{
223223
_actionDispatch->DoAction(action);
224224
}
225-
_startupState = StartupState::Initialized;
226-
_InitializedHandlers(*this, nullptr);
225+
226+
_CompleteInitialization();
227+
}
228+
}
229+
230+
// Method Description:
231+
// - Perform and steps that need to be done once our initial state is all
232+
// set up. This includes entering fullscreen mode and firing our
233+
// Initialized event.
234+
// Arguments:
235+
// - <none>
236+
// Return Value:
237+
// - <none>
238+
void TerminalPage::_CompleteInitialization()
239+
{
240+
// GH#288 - When we finish initialization, if the user wanted us
241+
// launched _fullscreen_, toggle fullscreen mode. This will make sure
242+
// that the window size is _first_ set up as something sensible, so
243+
// leaving fullscreen returns to a reasonable size.
244+
if (_settings->GlobalSettings().GetLaunchMode() == winrt::TerminalApp::LaunchMode::FullscreenMode)
245+
{
246+
_ToggleFullscreen();
227247
}
248+
_startupState = StartupState::Initialized;
249+
_InitializedHandlers(*this, nullptr);
228250
}
229251

230252
// Method Description:

src/cascadia/TerminalApp/TerminalPage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ namespace winrt::TerminalApp::implementation
173173
void _SetNewTabButtonColor(const Windows::UI::Color& color, const Windows::UI::Color& accentColor);
174174
void _ClearNewTabButtonColor();
175175

176+
void _CompleteInitialization();
177+
176178
#pragma region ActionHandlers
177179
// These are all defined in AppActionHandlers.cpp
178180
void _HandleOpenNewTabDropdown(const IInspectable& sender, const TerminalApp::ActionEventArgs& args);

src/cascadia/WindowsTerminal/AppHost.cpp

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -239,61 +239,59 @@ void AppHost::_HandleCreateWindow(const HWND hwnd, RECT proposedRect, winrt::Ter
239239

240240
long adjustedHeight = 0;
241241
long adjustedWidth = 0;
242-
if (launchMode == winrt::TerminalApp::LaunchMode::DefaultMode)
242+
243+
// Find nearest monitor.
244+
HMONITOR hmon = MonitorFromRect(&proposedRect, MONITOR_DEFAULTTONEAREST);
245+
246+
// Get nearest monitor information
247+
MONITORINFO monitorInfo;
248+
monitorInfo.cbSize = sizeof(MONITORINFO);
249+
GetMonitorInfo(hmon, &monitorInfo);
250+
251+
// This API guarantees that dpix and dpiy will be equal, but neither is an
252+
// optional parameter so give two UINTs.
253+
UINT dpix = USER_DEFAULT_SCREEN_DPI;
254+
UINT dpiy = USER_DEFAULT_SCREEN_DPI;
255+
// If this fails, we'll use the default of 96.
256+
GetDpiForMonitor(hmon, MDT_EFFECTIVE_DPI, &dpix, &dpiy);
257+
258+
// We need to check if the top left point of the titlebar of the window is within any screen
259+
RECT offScreenTestRect;
260+
offScreenTestRect.left = proposedRect.left;
261+
offScreenTestRect.top = proposedRect.top;
262+
offScreenTestRect.right = offScreenTestRect.left + 1;
263+
offScreenTestRect.bottom = offScreenTestRect.top + 1;
264+
265+
bool isTitlebarIntersectWithMonitors = false;
266+
EnumDisplayMonitors(
267+
nullptr, &offScreenTestRect, [](HMONITOR, HDC, LPRECT, LPARAM lParam) -> BOOL {
268+
auto intersectWithMonitor = reinterpret_cast<bool*>(lParam);
269+
*intersectWithMonitor = true;
270+
// Continue the enumeration
271+
return FALSE;
272+
},
273+
reinterpret_cast<LPARAM>(&isTitlebarIntersectWithMonitors));
274+
275+
if (!isTitlebarIntersectWithMonitors)
243276
{
244-
// Find nearest monitor.
245-
HMONITOR hmon = MonitorFromRect(&proposedRect, MONITOR_DEFAULTTONEAREST);
246-
247-
// Get nearest monitor information
248-
MONITORINFO monitorInfo;
249-
monitorInfo.cbSize = sizeof(MONITORINFO);
250-
GetMonitorInfo(hmon, &monitorInfo);
251-
252-
// This API guarantees that dpix and dpiy will be equal, but neither is an
253-
// optional parameter so give two UINTs.
254-
UINT dpix = USER_DEFAULT_SCREEN_DPI;
255-
UINT dpiy = USER_DEFAULT_SCREEN_DPI;
256-
// If this fails, we'll use the default of 96.
257-
GetDpiForMonitor(hmon, MDT_EFFECTIVE_DPI, &dpix, &dpiy);
258-
259-
// We need to check if the top left point of the titlebar of the window is within any screen
260-
RECT offScreenTestRect;
261-
offScreenTestRect.left = proposedRect.left;
262-
offScreenTestRect.top = proposedRect.top;
263-
offScreenTestRect.right = offScreenTestRect.left + 1;
264-
offScreenTestRect.bottom = offScreenTestRect.top + 1;
265-
266-
bool isTitlebarIntersectWithMonitors = false;
267-
EnumDisplayMonitors(
268-
nullptr, &offScreenTestRect, [](HMONITOR, HDC, LPRECT, LPARAM lParam) -> BOOL {
269-
auto intersectWithMonitor = reinterpret_cast<bool*>(lParam);
270-
*intersectWithMonitor = true;
271-
// Continue the enumeration
272-
return FALSE;
273-
},
274-
reinterpret_cast<LPARAM>(&isTitlebarIntersectWithMonitors));
275-
276-
if (!isTitlebarIntersectWithMonitors)
277-
{
278-
// If the title bar is out-of-screen, we set the initial position to
279-
// the top left corner of the nearest monitor
280-
proposedRect.left = monitorInfo.rcWork.left;
281-
proposedRect.top = monitorInfo.rcWork.top;
282-
}
277+
// If the title bar is out-of-screen, we set the initial position to
278+
// the top left corner of the nearest monitor
279+
proposedRect.left = monitorInfo.rcWork.left;
280+
proposedRect.top = monitorInfo.rcWork.top;
281+
}
283282

284-
auto initialSize = _logic.GetLaunchDimensions(dpix);
283+
auto initialSize = _logic.GetLaunchDimensions(dpix);
285284

286-
const short islandWidth = Utils::ClampToShortMax(
287-
static_cast<long>(ceil(initialSize.X)), 1);
288-
const short islandHeight = Utils::ClampToShortMax(
289-
static_cast<long>(ceil(initialSize.Y)), 1);
285+
const short islandWidth = Utils::ClampToShortMax(
286+
static_cast<long>(ceil(initialSize.X)), 1);
287+
const short islandHeight = Utils::ClampToShortMax(
288+
static_cast<long>(ceil(initialSize.Y)), 1);
290289

291-
// Get the size of a window we'd need to host that client rect. This will
292-
// add the titlebar space.
293-
const auto nonClientSize = _window->GetTotalNonClientExclusiveSize(dpix);
294-
adjustedWidth = islandWidth + nonClientSize.cx;
295-
adjustedHeight = islandHeight + nonClientSize.cy;
296-
}
290+
// Get the size of a window we'd need to host that client rect. This will
291+
// add the titlebar space.
292+
const auto nonClientSize = _window->GetTotalNonClientExclusiveSize(dpix);
293+
adjustedWidth = islandWidth + nonClientSize.cx;
294+
adjustedHeight = islandHeight + nonClientSize.cy;
297295

298296
const COORD origin{ gsl::narrow<short>(proposedRect.left),
299297
gsl::narrow<short>(proposedRect.top) };

src/cascadia/WindowsTerminal/IslandWindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ void IslandWindow::_HandleCreateWindow(const WPARAM, const LPARAM lParam) noexce
143143
}
144144

145145
ShowWindow(_window.get(), nCmdShow);
146+
146147
UpdateWindow(_window.get());
147148
}
148149

src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,10 @@ void NonClientIslandWindow::OnApplicationThemeChanged(const ElementTheme& reques
838838
void NonClientIslandWindow::_SetIsFullscreen(const bool fullscreenEnabled)
839839
{
840840
IslandWindow::_SetIsFullscreen(fullscreenEnabled);
841-
_titlebar.Visibility(!fullscreenEnabled ? Visibility::Visible : Visibility::Collapsed);
841+
if (_titlebar)
842+
{
843+
_titlebar.Visibility(!fullscreenEnabled ? Visibility::Visible : Visibility::Collapsed);
844+
}
842845
// GH#4224 - When the auto-hide taskbar setting is enabled, then we don't
843846
// always get another window message to trigger us to remove the drag bar.
844847
// So, make sure to update the size of the drag region here, so that it

0 commit comments

Comments
 (0)