[orca] Script+Event Managers: Take active window into account for mouse button events



commit 2d76ffc63f32d9ca43292de2c7a3877d48c7101f
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Tue May 17 17:13:17 2022 +0200

    Script+Event Managers: Take active window into account for mouse button events
    
    Now that mouse button events are processed asynchronously, we can take
    the active window into account when determining which script should
    process the event. This should eliminate (or at least greatly reduce)
    the possibility that we process mouse button events with the script
    from a no-longer-active app.

 src/orca/event_manager.py  |  2 +-
 src/orca/script_manager.py | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
---
diff --git a/src/orca/event_manager.py b/src/orca/event_manager.py
index ce383afdf..6a45d949c 100644
--- a/src/orca/event_manager.py
+++ b/src/orca/event_manager.py
@@ -708,7 +708,7 @@ class EventManager:
         """Returns the script associated with event."""
 
         if event.type.startswith("mouse:"):
-            return orca_state.activeScript
+            return _scriptManager.getScriptForMouseButtonEvent(event)
 
         script = None
         app = None
diff --git a/src/orca/script_manager.py b/src/orca/script_manager.py
index b504618d5..5e9ac2748 100644
--- a/src/orca/script_manager.py
+++ b/src/orca/script_manager.py
@@ -248,6 +248,32 @@ class ScriptManager:
         debug.println(debug.LEVEL_INFO, msg, True)
         return script
 
+    def getScriptForMouseButtonEvent(self, event):
+        try:
+            state = orca_state.activeWindow.getState()
+            isActive = state.contains(pyatspi.STATE_ACTIVE)
+        except:
+            msg = "SCRIPT MANAGER: Exception checking state of %s" % orca_state.activeWindow
+            debug.println(debug.LEVEL_INFO, msg, True)
+            isActive = False
+        else:
+            msg = "SCRIPT MANAGER: %s is active: %s" % (orca_state.activeWindow, isActive)
+            debug.println(debug.LEVEL_INFO, msg, True)
+
+        if isActive and orca_state.activeScript:
+            return orca_state.activeScript
+
+        script = self.getDefaultScript()
+        activeWindow = script.utilities.activeWindow()
+        if not activeWindow:
+            return script
+
+        focusedObject = script.utilities.focusedObject(activeWindow)
+        if focusedObject:
+            return self.getScript(focusedObject.getApplication(), focusedObject)
+
+        return self.getScript(activeWindow.getApplication(), activeWindow)
+
     def getScript(self, app, obj=None, sanityCheck=False):
         """Get a script for an app (and make it if necessary).  This is used
         instead of a simple calls to Script's constructor.


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