From 9037afe0f721cae0e265e8b97f27f29c2d492c43 Mon Sep 17 00:00:00 2001 From: sezanzeb Date: Sun, 16 Jan 2022 13:34:20 +0100 Subject: [PATCH] Not attempting to call xmodmap -pke as the service --- inputremapper/system_mapping.py | 36 +++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/inputremapper/system_mapping.py b/inputremapper/system_mapping.py index d0085f33..2a0482f3 100644 --- a/inputremapper/system_mapping.py +++ b/inputremapper/system_mapping.py @@ -90,21 +90,27 @@ class SystemMapping: """Get a mapping of all available names to their keycodes.""" logger.debug("Gathering available keycodes") self.clear() - xmodmap_dict = {} - try: - xmodmap = subprocess.check_output( - ["xmodmap", "-pke"], stderr=subprocess.STDOUT - ).decode() - xmodmap = xmodmap - self._xmodmap = re.findall(r"(\d+) = (.+)\n", xmodmap + "\n") - xmodmap_dict = self._find_legit_mappings() - if len(xmodmap_dict) == 0: - logger.info("`xmodmap -pke` did not yield any symbol") - except (subprocess.CalledProcessError, FileNotFoundError): - # might be within a tty - logger.info("Optional `xmodmap` command not found. This is not critical.") if not is_service(): + # xmodmap is only available from within the login session. + # The service that runs via systemd can't use this. + xmodmap_dict = {} + try: + xmodmap = subprocess.check_output( + ["xmodmap", "-pke"], stderr=subprocess.STDOUT + ).decode() + xmodmap = xmodmap + self._xmodmap = re.findall(r"(\d+) = (.+)\n", xmodmap + "\n") + xmodmap_dict = self._find_legit_mappings() + if len(xmodmap_dict) == 0: + logger.info("`xmodmap -pke` did not yield any symbol") + except FileNotFoundError: + logger.info( + "Optional `xmodmap` command not found. This is not critical." + ) + except subprocess.CalledProcessError as e: + logger.error('Call to `xmodmap -pke` failed with "%s"', e) + # Clients usually take care of that, don't let the service do funny things. # Write this stuff into the input-remapper config directory, because # the systemd service won't know the user sessions xmodmap. @@ -114,8 +120,8 @@ class SystemMapping: logger.debug('Writing "%s"', path) json.dump(xmodmap_dict, file, indent=4) - for name, code in xmodmap_dict.items(): - self._set(name, code) + for name, code in xmodmap_dict.items(): + self._set(name, code) for name, ecode in evdev.ecodes.ecodes.items(): if name.startswith("KEY") or name.startswith("BTN"):