Skip to content

Commit f9b7b77

Browse files
committed
minimize windows on windows. fix theme restart.
1 parent abf31e4 commit f9b7b77

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

frontend/api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,16 @@ def launch_table(self, index):
353353
self._track_table_play(table)
354354

355355
cmd = [Path(vpxbin).expanduser(), "-play", vpx]
356-
# VPX takes focus naturally - no fullscreen toggle needed with Chromium
356+
# Minimize Chromium windows so VPX gets focus cleanly
357+
if self.chromium_manager:
358+
self.chromium_manager.minimize_all()
357359
process = subprocess.Popen(cmd, stdout=subprocess.DEVNULL,
358360
stderr=subprocess.DEVNULL,
359361
stdin=subprocess.DEVNULL)
360362
process.wait()
363+
# Restore Chromium windows after VPX exits
364+
if self.chromium_manager:
365+
self.chromium_manager.restore_all()
361366
self.send_event_all_windows_incself({"type": "TableLaunchComplete"})
362367

363368
def _track_table_play(self, table):

frontend/chromium_manager.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)