[orca] Ignore window deactivations we believe are not user-triggered



commit 15ce8bc2146daa3ac635b382a569c89178a9edcc
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Mon Jan 7 12:29:33 2019 -0500

    Ignore window deactivations we believe are not user-triggered
    
    This attempts to hack around window-deactivation events we get as a
    result of window-manager shortcuts (e.g. increase/decrease volume).
    It takes advantage of the fact that window-manager shortcuts are not
    exposed to us. If that ever gets fixed, we can presumably modify this
    hack.

 src/orca/script_utilities.py | 14 ++++++++++++++
 src/orca/scripts/default.py  | 10 ++++++++++
 2 files changed, 24 insertions(+)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index 237298232..1a0c9ba80 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -5072,6 +5072,20 @@ class Utilities:
 
         return False
 
+    def eventIsUserTriggered(self, event):
+        if not orca_state.lastInputEvent:
+            msg = "INFO: Not user triggered: No last input event."
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return False
+
+        delta = time.time() - orca_state.lastInputEvent.time
+        if delta > 1:
+            msg = "INFO: Not user triggered: Last input event %.2fs ago." % delta
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return False
+
+        return True
+
     def presentFocusChangeReason(self):
         if self.handleUndoLocusOfFocusChange():
             return True
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index eaf4bcdba..643139969 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -2154,6 +2154,11 @@ class Script(script.Script):
                     debug.println(debug.LEVEL_INFO, msg, True)
                     return
 
+                if not self.utilities.eventIsUserTriggered(event):
+                    msg = "DEFAULT: Not clearing state. Event is not user triggered."
+                    debug.println(debug.LEVEL_INFO, msg, True)
+                    return
+
                 msg = "DEFAULT: Event is for active window. Clearing state."
                 debug.println(debug.LEVEL_INFO, msg, True)
                 orca_state.activeWindow = None
@@ -2872,6 +2877,11 @@ class Script(script.Script):
         # an event from the current activeWindow.
         #
         if event.source == orca_state.activeWindow:
+            if not self.utilities.eventIsUserTriggered(event):
+                msg = "DEFAULT: Not clearing state. Event is not user triggered."
+                debug.println(debug.LEVEL_INFO, msg, True)
+                return
+
             orca.setLocusOfFocus(event, None)
             orca_state.activeWindow = None
             orca_state.activeScript = None


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]