Browse Source

extended controls: cache list of engine windows

Fabian Peter Hammerle 6 years ago
parent
commit
0e39710d4d
2 changed files with 13 additions and 4 deletions
  1. 4 4
      tooncher/actions.py
  2. 9 0
      tooncher/controls.py

+ 4 - 4
tooncher/actions.py

@@ -41,8 +41,8 @@ class SelectGagAction:
 
 class TargetEngine:
     Primary = 1 << 0
-    Others = 1 << 1
-    All = Primary | Others
+    NonPrimary = 1 << 1
+    All = Primary | NonPrimary
 
 
 class RewriteKeyEventAction:
@@ -78,8 +78,8 @@ class RewriteKeyEventAction:
                 target_window=extended_controls.engine_window,
                 **defaults,
             )
-        if self._target_engine & TargetEngine.Others:
-            for win in extended_controls.find_other_engine_windows():
+        if self._target_engine & TargetEngine.NonPrimary:
+            for win in extended_controls.other_engine_windows:
                 self._send_event(target_window=win, **defaults)
 
 

+ 9 - 0
tooncher/controls.py

@@ -97,6 +97,7 @@ class ExtendedControls:
             = ToggleExtendedControlsAction()
         self._default_action = ForwardKeyEventAction()
         self._engine_window = None
+        self._other_engine_windows = None
         self._enabled = False
 
     @property
@@ -165,6 +166,8 @@ class ExtendedControls:
                     self._xdisplay.keysym_to_keycode(keysym),
                 )
         self._enabled = True
+        # reset cache
+        self._other_engine_windows = None
         print("INFO Enabled Extended Controls")
 
     def disable(self):
@@ -207,3 +210,9 @@ class ExtendedControls:
             lambda w: w.get_wm_name() == TOONTOWN_WINDOW_NAME
                     and w.id != self.engine_window.id,
         )
+
+    @property
+    def other_engine_windows(self):
+        if not self._other_engine_windows:
+            self._other_engine_windows = self.find_other_engine_windows()
+        return self._other_engine_windows