From ed1616d64c047a4335fd0d15ec79520ad38e7e19 Mon Sep 17 00:00:00 2001 From: sezanzeb Date: Sun, 27 Dec 2020 18:08:50 +0100 Subject: [PATCH] improved logs, removed redundant start_reading, fixed unresponsive keyboard --- keymapper/dev/injector.py | 8 +++++++- keymapper/gtk/window.py | 14 +++++--------- readme/development.md | 1 + tests/testcases/test_injector.py | 4 +++- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/keymapper/dev/injector.py b/keymapper/dev/injector.py index 48a3df2c..5f909c7b 100644 --- a/keymapper/dev/injector.py +++ b/keymapper/dev/injector.py @@ -247,7 +247,6 @@ class KeycodeInjector: capabilities[EV_KEY] += list(macro.get_capabilities()) if abs_to_rel: - del capabilities[EV_ABS] # those are the requirements to recognize it as mouse # on my system. REL_X and REL_Y are of course required to # accept the events that the mouse-movement-mapper writes. @@ -270,6 +269,10 @@ class KeycodeInjector: del capabilities[ecodes.EV_SYN] if ecodes.EV_FF in capabilities: del capabilities[ecodes.EV_FF] + if ecodes.EV_ABS in capabilities: + # EV_KEY events are ignoerd by the os when EV_ABS capabilities + # are present + del capabilities[ecodes.EV_ABS] return capabilities @@ -327,6 +330,9 @@ class KeycodeInjector: macros[key] = macro + if len(macros) == 0: + logger.debug('No macros configured') + # certain capabilities can have side effects apparently. with an # EV_ABS capability, EV_REL won't move the mouse pointer anymore. # so don't merge all InputDevices into one UInput device. diff --git a/keymapper/gtk/window.py b/keymapper/gtk/window.py index 3b423b7a..cdd46649 100755 --- a/keymapper/gtk/window.py +++ b/keymapper/gtk/window.py @@ -24,9 +24,6 @@ import math -import evdev - -from evdev.ecodes import EV_KEY from gi.repository import Gtk, Gdk, GLib from keymapper.data import get_data_path @@ -368,6 +365,7 @@ class Window: """Load the mapping.""" self.dbus.stop_injecting(self.selected_device) self.show_status(CTX_APPLY, 'Applied the system default') + logger.info('Applied system default for "%s"', self.selected_preset) GLib.timeout_add(10, self.show_device_mapping_status) def show_status(self, context_id, message, tooltip=None): @@ -438,7 +436,7 @@ class Window: preset = self.selected_preset device = self.selected_device - logger.debug('Applying preset "%s" for "%s"', preset, device) + logger.info('Applying preset "%s" for "%s"', preset, device) if custom_mapping.changed: self.show_status( @@ -456,9 +454,6 @@ class Window: if not success: self.show_status(CTX_ERROR, 'Error: Could not grab devices!') - # restart reading because after injecting the device landscape - # changes a bit - keycode_reader.start_reading(device) GLib.timeout_add(10, self.show_device_mapping_status) def on_autoload_switch(self, _, active): @@ -495,8 +490,9 @@ class Window: def show_device_mapping_status(self): """Figure out if this device is currently under keymappers control.""" - if self.dbus.is_injecting(self.selected_device): - logger.info('This device is currently mapped.') + device = self.selected_device + if self.dbus.is_injecting(device): + logger.info('Device "%s" is currently mapped', device) self.get('apply_system_layout').set_opacity(1) else: self.get('apply_system_layout').set_opacity(0.4) diff --git a/readme/development.md b/readme/development.md index c46fb699..721bcfe8 100644 --- a/readme/development.md +++ b/readme/development.md @@ -98,3 +98,4 @@ inject the users autoloaded presets instead (if any are configured) ## Resources [PyGObject API Reference](https://lazka.github.io/pgi-docs/) +[python-evdev](https://python-evdev.readthedocs.io/en/stable/) diff --git a/tests/testcases/test_injector.py b/tests/testcases/test_injector.py index ca262c91..fd4e3ad5 100644 --- a/tests/testcases/test_injector.py +++ b/tests/testcases/test_injector.py @@ -71,7 +71,8 @@ class TestInjector(unittest.TestCase): assert absinfo is False return { evdev.ecodes.EV_SYN: [1, 2, 3], - evdev.ecodes.EV_FF: [1, 2, 3] + evdev.ecodes.EV_FF: [1, 2, 3], + evdev.ecodes.EV_ABS: [1, 2, 3] } mapping = Mapping() @@ -109,6 +110,7 @@ class TestInjector(unittest.TestCase): self.assertNotIn(evdev.ecodes.EV_SYN, capabilities) self.assertNotIn(evdev.ecodes.EV_FF, capabilities) self.assertNotIn(evdev.ecodes.EV_REL, capabilities) + self.assertNotIn(evdev.ecodes.EV_ABS, capabilities) def test_grab(self): # path is from the fixtures