Browse Source

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

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

+ 1 - 0
patches/chromium/.patches

@@ -142,3 +142,4 @@ feat_separate_content_settings_callback_for_sync_and_async_clipboard.patch
 fix_win32_synchronous_spellcheck.patch
 chore_remove_conflicting_allow_unsafe_libc_calls.patch
 fix_linter_error.patch
+fix_take_snapped_status_into_account_when_showing_a_window.patch

+ 58 - 0
patches/chromium/fix_take_snapped_status_into_account_when_showing_a_window.patch

@@ -0,0 +1,58 @@
+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 22ed43bdf4dbaccc598135807abc8383c52db50e..c5457e3e58b53ca04697b22a885da654c6c0655f 100644
+--- a/ui/views/win/hwnd_message_handler.cc
++++ b/ui/views/win/hwnd_message_handler.cc
+@@ -676,7 +676,8 @@ void HWNDMessageHandler::Show(ui::mojom::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.
+@@ -686,7 +687,8 @@ void HWNDMessageHandler::Show(ui::mojom::WindowShowState show_state,
+     // position, some do not. See crbug.com/1296710
+     switch (show_state) {
+       case ui::mojom::WindowShowState::kInactive:
+-        native_show_state = is_maximized ? SW_SHOWNA : SW_SHOWNOACTIVATE;
++        native_show_state =
++            is_maximized_or_arranged ? SW_SHOWNA : SW_SHOWNOACTIVATE;
+         break;
+       case ui::mojom::WindowShowState::kMaximized:
+         native_show_state = SW_SHOWMAXIMIZED;
+@@ -697,9 +699,11 @@ void HWNDMessageHandler::Show(ui::mojom::WindowShowState show_state,
+       case ui::mojom::WindowShowState::kNormal:
+         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::mojom::WindowShowState::kFullscreen: