[orca: 1/2] Issue # 71 - Re-create the Xmodmap on keyboard changes



commit 415bd697cc9ea1e2bdc53019dd2dd0211abb8739
Author: Mike Zhukovskiy <misha354 gmail com>
Date:   Mon Feb 17 13:34:29 2020 +0000

    Issue # 71 - Re-create the Xmodmap on keyboard changes
    
    When a new keyboard is plugged in, the Xmodmap gets reset.
    This stomps on on our changes to the Xmodmap (related to Orca modifier keys).
    This change introduces event handlers that listen to 'device-added' and 'device-removed'
    events. If the device being added or removed is a keyboard, we re-create our key mappings.

 src/orca/orca.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
---
diff --git a/src/orca/orca.py b/src/orca/orca.py
index 1e4faa787..d45daec82 100644
--- a/src/orca/orca.py
+++ b/src/orca/orca.py
@@ -223,6 +223,14 @@ def _processBrailleEvent(event):
 #                                                                      #
 ########################################################################
 
+def deviceChangeHandler(deviceManager, device):
+    """New keyboards being plugged in stomp on our changes to the keymappings, so we have to re-apply"""
+    source = device.get_source()
+    if source == Gdk.InputSource.KEYBOARD:
+        msg = "Keyboard change detected, re-creating the xmodmap"
+        debug.println(debug.LEVEL_ALL, msg, True)
+        _createOrcaXmodmap()
+
 def updateKeyMap(keyboardEvent):
     """Unsupported convenience method to call sad hacks which should go away."""
 
@@ -576,6 +584,15 @@ def start(registry, cacheValues):
     if cacheValues:
         pyatspi.setCacheLevel(pyatspi.CACHE_PROPERTIES)
 
+    # Event handlers for input devices being plugged in/unplugged.
+    # Used to re-create the Xmodmap when a new keyboard is plugged in.
+    # Necessary, because plugging in a new keyboard resets the Xmodmap
+    # and stomps our changes
+    display = Gdk.Display.get_default()
+    devmanager=display.get_device_manager()
+    devmanager.connect("device-added", deviceChangeHandler)
+    devmanager.connect("device-removed", deviceChangeHandler)
+
     Gdk.notify_startup_complete()
     msg = 'ORCA: Startup complete notification made'
     debug.println(debug.LEVEL_INFO, msg, True)


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