@@ -2603,14 +2603,21 @@ def __exit__(self, *a):
26032603def 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