Browse Source

fix: take Snapped status into account when showing a window (#46038)

* fix: take Snapped status into account when showing a window

Co-authored-by: Shelley Vohr <[email protected]>

* fixup! fix: take Snapped status into account when showing a window

fix: bad trop

* fixup! fix: take Snapped status into account when showing a window

apply patch manually due to context shear in Chromium versions

* fix: bad ckerr

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <[email protected]>
Co-authored-by: Charles Kerr <[email protected]>
trop[bot] 1 month ago
parent
commit
88cc057000

+ 2 - 1
patches/chromium/.patches

@@ -148,4 +148,5 @@ cherry-pick-9dacf5694dfd.patch
 cherry-pick-0adceb6159fb.patch
 add_a_flag_to_enable_strict_js_compliance_in_audioworklet.patch
 remove_denormalenabler_from_scriptprocessornode.patch
-allow_denormal_flushing_to_outlive_scoped_object.patch
+allow_denormal_flushing_to_outlive_scoped_object.patch
+fix_take_snapped_status_into_account_when_showing_a_window.patch

+ 57 - 0
patches/chromium/fix_take_snapped_status_into_account_when_showing_a_window.patch

@@ -0,0 +1,57 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Shelley Vohr <[email protected]>
+Date: Thu, 13 Mar 2025 10:47:00 +0100
+Subject: fix: take Snapped status into account when showing a window
+
+Adjusts HWNDMessageHandler::Show to correctly restore windows that were
+in a snapped state prior to being hidden or maximized. From Windows
+documentation at
+https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-iswindowarranged:
+
+> A snapped window (see Snap your windows) is considered to be arranged.
+> You should treat arranged as a window state similar to maximized. Arranged,
+> maximized, and minimized are mutually exclusive states.
+
+The logic already took into account a window being maximized and
+correctly restored it, but if the window was snapped prior to this CL it
+would be removed from its snapped state when re-shown. This fixes that.
+
+Upstreamed at https://chromium-review.googlesource.com/c/chromium/src/+/6330848.
+
+diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
+index c77c90d949d6e50d99412cda0510dce1239010de..b4e64272f0c089ee6d48456f6973e715832e3001 100644
+--- a/ui/views/win/hwnd_message_handler.cc
++++ b/ui/views/win/hwnd_message_handler.cc
+@@ -656,7 +656,8 @@ void HWNDMessageHandler::Show(ui::WindowShowState show_state,
+     SetWindowPlacement(hwnd(), &placement);
+     native_show_state = SW_SHOWMAXIMIZED;
+   } else {
+-    const bool is_maximized = IsMaximized();
++    const bool is_maximized_or_arranged =
++        IsMaximized() || IsWindowArranged(hwnd());
+ 
+     // Use SW_SHOW/SW_SHOWNA instead of SW_SHOWNORMAL/SW_SHOWNOACTIVATE so that
+     // the window is not restored to its original position if it is maximized.
+@@ -665,7 +666,7 @@ void HWNDMessageHandler::Show(ui::WindowShowState show_state,
+     // some platforms restore the position, some do not. See crbug.com/1296710
+     switch (show_state) {
+       case ui::SHOW_STATE_INACTIVE:
+-        native_show_state = is_maximized ? SW_SHOWNA : SW_SHOWNOACTIVATE;
++        native_show_state = is_maximized_or_arranged ? SW_SHOWNA : SW_SHOWNOACTIVATE;
+         break;
+       case ui::SHOW_STATE_MAXIMIZED:
+         native_show_state = SW_SHOWMAXIMIZED;
+@@ -676,9 +677,11 @@ void HWNDMessageHandler::Show(ui::WindowShowState show_state,
+       case ui::SHOW_STATE_NORMAL:
+         if ((GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_TRANSPARENT) ||
+             (GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_NOACTIVATE)) {
+-          native_show_state = is_maximized ? SW_SHOWNA : SW_SHOWNOACTIVATE;
++          native_show_state =
++              is_maximized_or_arranged ? SW_SHOWNA : SW_SHOWNOACTIVATE;
+         } else {
+-          native_show_state = is_maximized ? SW_SHOW : SW_SHOWNORMAL;
++          native_show_state =
++              is_maximized_or_arranged ? SW_SHOW : SW_SHOWNORMAL;
+         }
+         break;
+       case ui::SHOW_STATE_FULLSCREEN: