Skip to content

Commit 6b8bba1

Browse files
authored
Improve firefox window cascading (#25339)
1 parent becc2aa commit 6b8bba1

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,5 @@ module = [
106106
ignore_errors = true
107107

108108
[[tool.mypy.overrides]]
109-
module = ["psutil", "win32gui", "win32process"]
109+
module = ["psutil", "win32con", "win32gui", "win32process"]
110110
ignore_missing_imports = true

test/common.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,14 +2603,21 @@ def __exit__(self, *a):
26032603
def move_browser_window(pid, x, y):
26042604
"""Utility function to move the top-level window owned by given process to
26052605
(x,y) coordinate. Used to ensure each browser window has some visible area."""
2606+
import win32con
26062607
import win32gui
26072608
import win32process
26082609

26092610
def enum_windows_callback(hwnd, _unused):
26102611
_, win_pid = win32process.GetWindowThreadProcessId(hwnd)
26112612
if win_pid == pid and win32gui.IsWindowVisible(hwnd):
2612-
rect = win32gui.GetWindowRect(hwnd)
2613-
win32gui.MoveWindow(hwnd, x, y, rect[2] - rect[0], rect[3] - rect[1], True)
2613+
# If the browser window is maximized, it won't react to MoveWindow, so
2614+
# un-maximize the window first to show it in windowed mode.
2615+
if win32gui.GetWindowPlacement(hwnd)[1] == win32con.SW_SHOWMAXIMIZED:
2616+
win32gui.ShowWindow(hwnd, win32con.SW_RESTORE)
2617+
2618+
# Then cascade the window, but also resize the window size to cover a
2619+
# smaller area of the desktop, in case the original size was full screen.
2620+
win32gui.MoveWindow(hwnd, x, y, 800, 600, True)
26142621
return True
26152622

26162623
win32gui.EnumWindows(enum_windows_callback, None)

0 commit comments

Comments
 (0)