|
@@ -155,17 +155,6 @@ def x_find_window_by_pid(display, pid):
|
|
return x_find_window(display.screen().root, filter_callback)
|
|
return x_find_window(display.screen().root, filter_callback)
|
|
|
|
|
|
|
|
|
|
-def wait_for_engine_window(xdisplay, engine_process, timeout_seconds=20, search_interval_seconds=2):
|
|
|
|
- start_epoch = time.time()
|
|
|
|
- while engine_process.poll() is None and (time.time() - start_epoch) <= timeout_seconds:
|
|
|
|
- windows = x_find_window_by_pid(xdisplay, engine_process.pid)
|
|
|
|
- assert len(windows) <= 1
|
|
|
|
- if len(windows) == 1:
|
|
|
|
- return windows[0]
|
|
|
|
- time.sleep(search_interval_seconds)
|
|
|
|
- return None
|
|
|
|
-
|
|
|
|
-
|
|
|
|
class ExtendedControls:
|
|
class ExtendedControls:
|
|
|
|
|
|
def __init__(self, engine_process, toggle_keysym_name):
|
|
def __init__(self, engine_process, toggle_keysym_name):
|
|
@@ -194,11 +183,21 @@ class ExtendedControls:
|
|
self._engine_window = None
|
|
self._engine_window = None
|
|
self._enabled = False
|
|
self._enabled = False
|
|
|
|
|
|
|
|
+ def _wait_for_engine_window(self, timeout_seconds=20, search_interval_seconds=2):
|
|
|
|
+ start_epoch = time.time()
|
|
|
|
+ while self._engine_process.poll() is None and (time.time() - start_epoch) <= timeout_seconds:
|
|
|
|
+ windows = x_find_window_by_pid(
|
|
|
|
+ self._xdisplay,
|
|
|
|
+ self._engine_process.pid,
|
|
|
|
+ )
|
|
|
|
+ assert len(windows) <= 1
|
|
|
|
+ if len(windows) == 1:
|
|
|
|
+ return windows[0]
|
|
|
|
+ time.sleep(search_interval_seconds)
|
|
|
|
+ return None
|
|
|
|
+
|
|
def run(self):
|
|
def run(self):
|
|
- self._engine_window = wait_for_engine_window(
|
|
|
|
- self._xdisplay,
|
|
|
|
- self._engine_process,
|
|
|
|
- )
|
|
|
|
|
|
+ self._engine_window = self._wait_for_engine_window()
|
|
if not self._engine_window:
|
|
if not self._engine_window:
|
|
raise Exception('Could not find the game\'s window.')
|
|
raise Exception('Could not find the game\'s window.')
|
|
self._grab_key(
|
|
self._grab_key(
|