@@ -2603,14 +2603,21 @@ def __exit__(self, *a):
2603
2603
def move_browser_window (pid , x , y ):
2604
2604
"""Utility function to move the top-level window owned by given process to
2605
2605
(x,y) coordinate. Used to ensure each browser window has some visible area."""
2606
+ import win32con
2606
2607
import win32gui
2607
2608
import win32process
2608
2609
2609
2610
def enum_windows_callback (hwnd , _unused ):
2610
2611
_ , win_pid = win32process .GetWindowThreadProcessId (hwnd )
2611
2612
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 )
2614
2621
return True
2615
2622
2616
2623
win32gui .EnumWindows (enum_windows_callback , None )
0 commit comments