Repository: electron/electron
Pull request: fix: take Snapped status into account when showing a window

Backport of #46006

See that PR for details.


Notes: Fixed an issue where snapped windows in Windows may sometimes be improperly restored.


Changed files:
filename: patches/chromium/.patches
patch: @@ -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
\ No newline at end of file
+allow_denormal_flushing_to_outlive_scoped_object.patch
+fix_take_snapped_status_into_account_when_showing_a_window.patch

filename: patches/chromium/fix_take_snapped_status_into_account_when_showing_a_window.patch
patch: @@ -0,0 +1,57 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Shelley Vohr <shelley.vohr@gmail.com>
+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: