[orca] Improve identification of numlocked keypad keys



commit ab0e3d413c51f96659fa5abf486609cd705a5887
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Mon Jul 6 12:57:19 2020 +0200

    Improve identification of numlocked keypad keys
    
    Some implementors do not include numlock in the modifiers so add a
    heuristic to try to identify those cases. Also associate the numlock
    state with the input event because it gets filtered out now that we
    check for reserved modifiers.

 src/orca/input_event.py | 13 +++++++++++++
 src/orca/keybindings.py |  3 +--
 2 files changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/src/orca/input_event.py b/src/orca/input_event.py
index d92411ab3..b685f45cd 100644
--- a/src/orca/input_event.py
+++ b/src/orca/input_event.py
@@ -248,6 +248,7 @@ class KeyboardEvent(InputEvent):
         self._did_consume = None
         self._result_reason = None
         self._bypassOrca = None
+        self._is_kp_with_numlock = False
 
         # Some implementors don't populate this field at all. More often than not,
         # the event_string and the keyval_name coincide for input events.
@@ -261,6 +262,13 @@ class KeyboardEvent(InputEvent):
                 self.id in KeyboardEvent.GDK_ACCENTED_LETTER_KEYS):
             self.event_string = chr(self.id)
 
+        # Some implementors don't include numlock in the modifiers.
+        if self.keyval_name.startswith("KP"):
+            if event.modifiers & (1 << pyatspi.MODIFIER_NUMLOCK):
+                self._is_kp_with_numlock = True
+            else:
+                self._is_kp_with_numlock = self.isPrintableKey()
+
         if self._script:
             self._app = self._script.app
             if not self._window:
@@ -615,6 +623,11 @@ class KeyboardEvent(InputEvent):
 
         return self.modifiers & keybindings.ORCA_MODIFIER_MASK
 
+    def isKeyPadKeyWithNumlockOn(self):
+        """Return True if this is a key pad key with numlock on."""
+
+        return self._is_kp_with_numlock
+
     def isPrintableKey(self):
         """Return True if this is a printable key."""
 
diff --git a/src/orca/keybindings.py b/src/orca/keybindings.py
index 5bb5dfba0..cf5eb287d 100644
--- a/src/orca/keybindings.py
+++ b/src/orca/keybindings.py
@@ -401,8 +401,7 @@ class KeyBindings:
                 if keyBinding.keysymstring:
                     candidates.append(keyBinding)
 
-        if keyboardEvent.modifiers & (1 << pyatspi.MODIFIER_NUMLOCK) \
-            and keyboardEvent.keyval_name.startswith("KP"):
+        if keyboardEvent.isKeyPadKeyWithNumlockOn():
             return None
 
         # If we're still here, we don't have an exact match. Prefer


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