Skip to content

[Windows] Use frameless window to implement fullscreen #531

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
use frameless window to implement fullscreen on windows
YuiHrsw committed Feb 21, 2025
commit bf7aa230cf1dbe180f56e38fbb5073a4892dfe51
36 changes: 27 additions & 9 deletions packages/window_manager/windows/window_manager.cpp
Original file line number Diff line number Diff line change
@@ -589,7 +589,7 @@ void WindowManager::SetFullScreen(const flutter::EncodableMap& args) {
g_is_window_fullscreen = isFullScreen;

if (isFullScreen) { // Set to fullscreen
::SendMessage(mainWindow, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
// ::SendMessage(mainWindow, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
if (!is_frameless_) {
auto monitor = MONITORINFO{};
auto placement = WINDOWPLACEMENT{};
@@ -598,19 +598,26 @@ void WindowManager::SetFullScreen(const flutter::EncodableMap& args) {
::GetWindowPlacement(mainWindow, &placement);
::GetMonitorInfo(
::MonitorFromWindow(mainWindow, MONITOR_DEFAULTTONEAREST), &monitor);
::SetWindowLongPtr(mainWindow, GWL_STYLE,
g_style_before_fullscreen & ~WS_OVERLAPPEDWINDOW);
if (!g_maximized_before_fullscreen) {
SetAsFrameless();
}
::SetWindowLongPtr(
mainWindow, GWL_STYLE,
g_style_before_fullscreen & ~(WS_THICKFRAME | WS_MAXIMIZEBOX));
::SetWindowPos(mainWindow, HWND_TOP, monitor.rcMonitor.left,
monitor.rcMonitor.top,
monitor.rcMonitor.top, 0, 0,
SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
::SetWindowPos(mainWindow, HWND_TOP, 0, 0,
monitor.rcMonitor.right - monitor.rcMonitor.left,
monitor.rcMonitor.bottom - monitor.rcMonitor.top,
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
}
} else { // Restore from fullscreen
if (!g_maximized_before_fullscreen)
Restore();
::SetWindowLongPtr(mainWindow, GWL_STYLE,
g_style_before_fullscreen | WS_OVERLAPPEDWINDOW);
// if (!g_maximized_before_fullscreen)
// Restore();
::SetWindowLongPtr(
mainWindow, GWL_STYLE,
g_style_before_fullscreen | (WS_THICKFRAME | WS_MAXIMIZEBOX));
if (::IsZoomed(mainWindow)) {
// Refresh the parent mainWindow.
::SetWindowPos(mainWindow, nullptr, 0, 0, 0, 0,
@@ -632,6 +639,17 @@ void WindowManager::SetFullScreen(const flutter::EncodableMap& args) {
g_frame_before_fullscreen.right - g_frame_before_fullscreen.left,
g_frame_before_fullscreen.bottom - g_frame_before_fullscreen.top,
SWP_NOACTIVATE | SWP_NOZORDER);

// restore titlebar style
title_bar_style_ = g_title_bar_style_before_fullscreen;
is_frameless_ = false;
MARGINS margins = {0, 0, 0, 0};
RECT rect1;
GetWindowRect(mainWindow, &rect1);
DwmExtendFrameIntoClientArea(mainWindow, &margins);
SetWindowPos(mainWindow, nullptr, rect1.left, rect1.top, 0, 0,
SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE |
SWP_FRAMECHANGED);
}
}
}