Skip to content

Commit ff6b0f4

Browse files
authored
[Windows] Use frameless window to implement fullscreen (#531)
* use frameless window to implement fullscreen on windows * remove force refresh to avoid freezing the UI
1 parent 4999804 commit ff6b0f4

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

packages/window_manager/lib/src/window_manager.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ class WindowManager {
263263
await _channel.invokeMethod('setFullScreen', arguments);
264264
// (Windows) Force refresh the app so it 's back to the correct size
265265
// (see GitHub issue #311)
266-
if (Platform.isWindows) {
267-
final size = await getSize();
268-
setSize(size + const Offset(1, 1));
269-
setSize(size);
270-
}
266+
// if (Platform.isWindows) {
267+
// final size = await getSize();
268+
// setSize(size + const Offset(1, 1));
269+
// setSize(size);
270+
// }
271271
}
272272

273273
/// Returns `bool` - Whether the window is dockable or not.

packages/window_manager/windows/window_manager.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ void WindowManager::SetFullScreen(const flutter::EncodableMap& args) {
589589
g_is_window_fullscreen = isFullScreen;
590590

591591
if (isFullScreen) { // Set to fullscreen
592-
::SendMessage(mainWindow, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
592+
// ::SendMessage(mainWindow, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
593593
if (!is_frameless_) {
594594
auto monitor = MONITORINFO{};
595595
auto placement = WINDOWPLACEMENT{};
@@ -598,19 +598,26 @@ void WindowManager::SetFullScreen(const flutter::EncodableMap& args) {
598598
::GetWindowPlacement(mainWindow, &placement);
599599
::GetMonitorInfo(
600600
::MonitorFromWindow(mainWindow, MONITOR_DEFAULTTONEAREST), &monitor);
601-
::SetWindowLongPtr(mainWindow, GWL_STYLE,
602-
g_style_before_fullscreen & ~WS_OVERLAPPEDWINDOW);
601+
if (!g_maximized_before_fullscreen) {
602+
SetAsFrameless();
603+
}
604+
::SetWindowLongPtr(
605+
mainWindow, GWL_STYLE,
606+
g_style_before_fullscreen & ~(WS_THICKFRAME | WS_MAXIMIZEBOX));
603607
::SetWindowPos(mainWindow, HWND_TOP, monitor.rcMonitor.left,
604-
monitor.rcMonitor.top,
608+
monitor.rcMonitor.top, 0, 0,
609+
SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
610+
::SetWindowPos(mainWindow, HWND_TOP, 0, 0,
605611
monitor.rcMonitor.right - monitor.rcMonitor.left,
606612
monitor.rcMonitor.bottom - monitor.rcMonitor.top,
607-
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
613+
SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
608614
}
609615
} else { // Restore from fullscreen
610-
if (!g_maximized_before_fullscreen)
611-
Restore();
612-
::SetWindowLongPtr(mainWindow, GWL_STYLE,
613-
g_style_before_fullscreen | WS_OVERLAPPEDWINDOW);
616+
// if (!g_maximized_before_fullscreen)
617+
// Restore();
618+
::SetWindowLongPtr(
619+
mainWindow, GWL_STYLE,
620+
g_style_before_fullscreen | (WS_THICKFRAME | WS_MAXIMIZEBOX));
614621
if (::IsZoomed(mainWindow)) {
615622
// Refresh the parent mainWindow.
616623
::SetWindowPos(mainWindow, nullptr, 0, 0, 0, 0,
@@ -632,6 +639,17 @@ void WindowManager::SetFullScreen(const flutter::EncodableMap& args) {
632639
g_frame_before_fullscreen.right - g_frame_before_fullscreen.left,
633640
g_frame_before_fullscreen.bottom - g_frame_before_fullscreen.top,
634641
SWP_NOACTIVATE | SWP_NOZORDER);
642+
643+
// restore titlebar style
644+
title_bar_style_ = g_title_bar_style_before_fullscreen;
645+
is_frameless_ = false;
646+
MARGINS margins = {0, 0, 0, 0};
647+
RECT rect1;
648+
GetWindowRect(mainWindow, &rect1);
649+
DwmExtendFrameIntoClientArea(mainWindow, &margins);
650+
SetWindowPos(mainWindow, nullptr, rect1.left, rect1.top, 0, 0,
651+
SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE |
652+
SWP_FRAMECHANGED);
635653
}
636654
}
637655
}

0 commit comments

Comments
 (0)