@@ -63,6 +63,17 @@ static const wchar_t* kMouseInputPolicyProperty = L"NativeAPIMouseInputPolicy";
6363// DwmGetWindowAttribute(DWMWA_NCRENDERING_ENABLED), which flips to TRUE the
6464// instant WS_CAPTION is restored in user mode, this tracks dwm.exe's actual state.
6565static const wchar_t * kDwmNcDisabledProperty = L" NativeAPIDwmNcDisabled" ;
66+ // Set when a fullscreen transition has scheduled a deferred client/surface sync
67+ // (after the caller's synchronous FFI/thread call returns) or awaits dwm.exe's
68+ // asynchronous WM_DWMNCRENDERINGCHANGED notification.
69+ static const wchar_t * kFullScreenSyncPendingProperty = L" NativeAPIFullScreenSyncPending" ;
70+ static const wchar_t * kFullScreenDwmSyncProperty = L" NativeAPIFullScreenDwmSync" ;
71+
72+ static UINT SyncFullScreenClientMessage () {
73+ static const UINT message = RegisterWindowMessageW (L" NativeAPISyncFullScreenClient" );
74+ return message;
75+ }
76+ static void SyncFullScreenClientArea (HWND hwnd, bool schedule_deferred = false );
6677
6778struct MouseInputPolicy {
6879 bool forward = false ;
@@ -902,6 +913,8 @@ static LRESULT WindowLifetimeMessage(HWND hwnd, UINT message, WPARAM wp, LPARAM
902913 RemovePropW (hwnd, kBackgroundColorProperty );
903914 RemovePropW (hwnd, kTranslucentBackgroundProperty );
904915 RemovePropW (hwnd, kDwmNcDisabledProperty );
916+ RemovePropW (hwnd, kFullScreenSyncPendingProperty );
917+ RemovePropW (hwnd, kFullScreenDwmSyncProperty );
905918 g_full_screen_windows.erase (hwnd);
906919 const auto result = DefSubclassProc (hwnd, message, wp, lp);
907920 WindowRegistry::GetInstance ().Remove (static_cast <WindowId>(reference));
@@ -934,6 +947,11 @@ static LRESULT WindowLifetimeMessage(HWND hwnd, UINT message, WPARAM wp, LPARAM
934947 if (RemovePropW (hwnd, kShowMaximizedProperty )) ShowWindow (hwnd, SW_SHOWMAXIMIZED );
935948 return 0 ;
936949 }
950+ if (message == SyncFullScreenClientMessage ()) {
951+ if (RemovePropW (hwnd, kFullScreenSyncPendingProperty ))
952+ SyncFullScreenClientArea (hwnd, /* schedule_deferred=*/ false );
953+ return 0 ;
954+ }
937955 if (message == WM_WINDOWPOSCHANGED ) {
938956 const auto * pos = reinterpret_cast <const WINDOWPOS *>(lp);
939957 const LRESULT result = DefSubclassProc (hwnd, message, wp, lp);
@@ -957,6 +975,10 @@ static LRESULT WindowLifetimeMessage(HWND hwnd, UINT message, WPARAM wp, LPARAM
957975 !GetPropW (hwnd, kFramelessClientProperty )) {
958976 ClearHiddenTitleBarNonClientBorder (hwnd);
959977 }
978+ if (RemovePropW (hwnd, kFullScreenDwmSyncProperty )) {
979+ SetPropW (hwnd, kFullScreenSyncPendingProperty , reinterpret_cast <HANDLE >(1 ));
980+ PostMessageW (hwnd, SyncFullScreenClientMessage (), 0 , 0 );
981+ }
960982 return result;
961983 }
962984 if (auto handled = HandleMaximizeButtonArea (hwnd, message, wp, lp)) return *handled;
@@ -1483,19 +1505,55 @@ bool Window::IsMinimized() const {
14831505// resize their child surface to the final post-frame-change client rect and
14841506// repaint immediately after entering or leaving fullscreen, without waiting
14851507// for a focus change (Alt+Tab).
1486- static void SyncFullScreenClientArea (HWND hwnd) {
1508+ static void SyncFullScreenClientArea (HWND hwnd, bool schedule_deferred ) {
14871509 if (!hwnd || !IsWindow (hwnd) || IsIconic (hwnd))
14881510 return ;
14891511 RECT client = {};
14901512 if (GetClientRect (hwnd, &client)) {
1513+ const int width = client.right - client.left ;
1514+ const int height = client.bottom - client.top ;
14911515 const WPARAM size_type = IsZoomed (hwnd) ? SIZE_MAXIMIZED : SIZE_RESTORED ;
1492- SendMessageW (hwnd, WM_SIZE , size_type,
1493- MAKELPARAM (client.right - client.left , client.bottom - client.top ));
1516+ const LPARAM size_param = MAKELPARAM (width, height);
1517+ SendMessageW (hwnd, WM_SIZE , size_type, size_param);
1518+
1519+ // Win32's MoveWindow/SetWindowPos skips WM_SIZE on a child whose HWND
1520+ // rect already matches (width, height), even if the child's swapchain or
1521+ // Flutter view missed or timed out an earlier resize while Dart was
1522+ // blocked inside the synchronous FFI call or while DWM was transitioning
1523+ // fullscreen state. Ensure any FLUTTERVIEW child both matches the final
1524+ // client rect and receives WM_SIZE directly.
1525+ HWND flutter_view = FindWindowExW (hwnd, nullptr , L" FLUTTERVIEW" , nullptr );
1526+ if (flutter_view && IsWindow (flutter_view)) {
1527+ RECT view_rect = {};
1528+ if (!GetClientRect (flutter_view, &view_rect) ||
1529+ (view_rect.right - view_rect.left ) != width ||
1530+ (view_rect.bottom - view_rect.top ) != height) {
1531+ SetWindowPos (flutter_view, nullptr , client.left , client.top , width, height,
1532+ SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE );
1533+ }
1534+ SendMessageW (flutter_view, WM_SIZE , size_type, size_param);
1535+ RedrawWindow (flutter_view, nullptr , nullptr ,
1536+ RDW_INVALIDATE | RDW_NOERASE | RDW_UPDATENOW );
1537+ if (GetForegroundWindow () == hwnd) {
1538+ HWND focused = GetFocus ();
1539+ if (!focused || GetAncestor (focused, GA_ROOT ) != hwnd)
1540+ SetFocus (flutter_view);
1541+ }
1542+ }
14941543 }
14951544 UINT flags = RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN | RDW_UPDATENOW ;
14961545 if (!GetPropW (hwnd, kTitleBarHiddenProperty ))
14971546 flags |= RDW_FRAME ;
14981547 RedrawWindow (hwnd, nullptr , nullptr , flags);
1548+
1549+ if (schedule_deferred) {
1550+ // Re-sync on the next message-loop turn (after SetFullScreen returns and
1551+ // unblocks the caller's thread/isolate) and again once dwm.exe delivers
1552+ // its asynchronous WM_DWMNCRENDERINGCHANGED notification.
1553+ SetPropW (hwnd, kFullScreenSyncPendingProperty , reinterpret_cast <HANDLE >(1 ));
1554+ SetPropW (hwnd, kFullScreenDwmSyncProperty , reinterpret_cast <HANDLE >(1 ));
1555+ PostMessageW (hwnd, SyncFullScreenClientMessage (), 0 , 0 );
1556+ }
14991557}
15001558
15011559static bool ExitFullScreen (HWND hwnd, bool restore_maximized, bool sync_client) {
@@ -1539,7 +1597,7 @@ static bool ExitFullScreen(HWND hwnd, bool restore_maximized, bool sync_client)
15391597 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE |
15401598 SWP_NOCOPYBITS | SWP_FRAMECHANGED );
15411599 if (sync_client)
1542- SyncFullScreenClientArea (hwnd);
1600+ SyncFullScreenClientArea (hwnd, /* schedule_deferred= */ true );
15431601 NotifyWindowFullScreenChanged (hwnd, false );
15441602 return true ;
15451603}
@@ -1613,7 +1671,7 @@ void Window::SetFullScreen(bool is_full_screen) {
16131671 monitor.rcMonitor .right - monitor.rcMonitor .left ,
16141672 monitor.rcMonitor .bottom - monitor.rcMonitor .top ,
16151673 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_FRAMECHANGED );
1616- SyncFullScreenClientArea (hwnd);
1674+ SyncFullScreenClientArea (hwnd, /* schedule_deferred= */ true );
16171675 NotifyWindowFullScreenChanged (hwnd, true );
16181676 return ;
16191677 }
0 commit comments