@@ -157,6 +157,71 @@ def terminate_all(self):
157157 self ._exit_event .set ()
158158 print ("[Chromium] All browser windows closed." )
159159
160+ def minimize_all (self ):
161+ """Minimize all Chromium windows (used before VPX table launch)."""
162+ system = platform .system ()
163+ for window_name , proc , temp_dir in self ._processes :
164+ if proc .poll () is not None :
165+ continue
166+ try :
167+ if system == "Windows" :
168+ import ctypes
169+ import ctypes .wintypes
170+
171+ def _enum_callback (hwnd , pid ):
172+ """Find windows belonging to the given PID."""
173+ tid_pid = ctypes .wintypes .DWORD ()
174+ ctypes .windll .user32 .GetWindowThreadProcessId (hwnd , ctypes .byref (tid_pid ))
175+ if tid_pid .value == pid :
176+ ctypes .windll .user32 .ShowWindow (hwnd , 6 ) # SW_MINIMIZE
177+ return True
178+
179+ WNDENUMPROC = ctypes .WINFUNCTYPE (ctypes .c_bool , ctypes .wintypes .HWND , ctypes .wintypes .LPARAM )
180+ ctypes .windll .user32 .EnumWindows (WNDENUMPROC (_enum_callback ), proc .pid )
181+ elif system == "Linux" :
182+ subprocess .run (["xdotool" , "search" , "--pid" , str (proc .pid ), "--name" , "." ,
183+ "windowminimize" ], capture_output = True , timeout = 5 )
184+ elif system == "Darwin" :
185+ subprocess .run (["osascript" , "-e" ,
186+ f'tell application "System Events" to set visible of (first process whose unix id is { proc .pid } ) to false' ],
187+ capture_output = True , timeout = 5 )
188+ except Exception as e :
189+ print (f"[Chromium] Error minimizing '{ window_name } ': { e } " )
190+ print ("[Chromium] All windows minimized" )
191+
192+ def restore_all (self ):
193+ """Restore all Chromium windows to fullscreen (used after VPX table exit)."""
194+ system = platform .system ()
195+ for window_name , proc , temp_dir in self ._processes :
196+ if proc .poll () is not None :
197+ continue
198+ try :
199+ if system == "Windows" :
200+ import ctypes
201+ import ctypes .wintypes
202+
203+ def _enum_callback (hwnd , pid ):
204+ tid_pid = ctypes .wintypes .DWORD ()
205+ ctypes .windll .user32 .GetWindowThreadProcessId (hwnd , ctypes .byref (tid_pid ))
206+ if tid_pid .value == pid :
207+ ctypes .windll .user32 .ShowWindow (hwnd , 9 ) # SW_RESTORE
208+ ctypes .windll .user32 .SetForegroundWindow (hwnd )
209+ return True
210+
211+ WNDENUMPROC = ctypes .WINFUNCTYPE (ctypes .c_bool , ctypes .wintypes .HWND , ctypes .wintypes .LPARAM )
212+ ctypes .windll .user32 .EnumWindows (WNDENUMPROC (_enum_callback ), proc .pid )
213+ elif system == "Linux" :
214+ subprocess .run (["xdotool" , "search" , "--pid" , str (proc .pid ), "--name" , "." ,
215+ "windowactivate" , "--sync" , "windowfocus" ],
216+ capture_output = True , timeout = 5 )
217+ elif system == "Darwin" :
218+ subprocess .run (["osascript" , "-e" ,
219+ f'tell application "System Events" to set visible of (first process whose unix id is { proc .pid } ) to true' ],
220+ capture_output = True , timeout = 5 )
221+ except Exception as e :
222+ print (f"[Chromium] Error restoring '{ window_name } ': { e } " )
223+ print ("[Chromium] All windows restored" )
224+
160225 def wait_for_exit (self ):
161226 """Block until all Chromium processes have exited.
162227
0 commit comments