From babc76905a54a322a7194a8eb6007e6b7fd38938 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Sun, 16 Sep 2018 14:47:35 +0000 Subject: [PATCH] #1902: add translation map for keysym with level, use modifier state (shift only for now) to locate the correct keycode match git-svn-id: https://xpra.org/svn/Xpra/trunk@20420 3bb7dfac-3a0b-4e04-842a-767bc560f471 --- src/xpra/x11/server_keyboard_config.py | 24 ++++++++++++++++++------ src/xpra/x11/xkbhelper.py | 20 +++++++++++++++++++- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/xpra/x11/server_keyboard_config.py b/src/xpra/x11/server_keyboard_config.py index 8aaa290f62..e0999a2e53 100644 --- a/src/xpra/x11/server_keyboard_config.py +++ b/src/xpra/x11/server_keyboard_config.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # This file is part of Xpra. # Copyright (C) 2011 Serviware (Arthur Huillet, ) -# Copyright (C) 2010-2017 Antoine Martin +# Copyright (C) 2010-2018 Antoine Martin # Copyright (C) 2008 Nathaniel Smith # Xpra is released under the terms of the GNU GPL v2, or, at your option, any # later version. See the file COPYING for details. @@ -77,12 +77,18 @@ def get_info(self): #keycodes: if self.keycode_translation: ksinfo = info.setdefault("keysym", {}) + kssinf = info.setdefault("keysyms", {}) kcinfo = info.setdefault("keycode", {}) for kc, keycode in self.keycode_translation.items(): if type(kc)==tuple: - client_keycode, keysym = kc - ksinfo.setdefault(keysym, {})[client_keycode] = keycode - kcinfo.setdefault(client_keycode, {})[keysym] = keycode + a, b = kc + if isinstance(a, int): + client_keycode, keysym = a, b + ksinfo.setdefault(keysym, {})[client_keycode] = keycode + kcinfo.setdefault(client_keycode, {})[keysym] = keycode + elif isinstance(b, int): + keysym, index = a, b + kssinf.setdefault(keycode, []).append((index, keysym)) else: kcinfo[kc] = keycode if self.xkbmap_keycodes: @@ -400,8 +406,14 @@ def get_keycode(self, client_keycode, keyname, modifiers): log("get_keycode(%s, %s, %s) native keymap, using client keycode %s", client_keycode, keyname, modifiers, client_keycode) else: #non-native: try harder to find matching keysym - keycode = self.keycode_translation.get(keyname, client_keycode) - log("get_keycode(%s, %s, %s) keyname lookup: %s", client_keycode, keyname, modifiers, keycode) + #first, try to honour shift state: + shift = "shift" in modifiers + mode = 0 #TODO: find AltGr modifier + i = int(shift) + int(mode)*2 + keycode = self.keycode_translation.get((keyname, i)) + if keycode is None: + keycode = self.keycode_translation.get(keyname, client_keycode) + log("get_keycode(%s, %s, %s) i=%i, keyname lookup: %s", client_keycode, keyname, modifiers, i, keycode) else: log("get_keycode(%s, %s, %s) keyname+keycode lookup: %s", client_keycode, keyname, modifiers, keycode) return keycode diff --git a/src/xpra/x11/xkbhelper.py b/src/xpra/x11/xkbhelper.py index be9866f02d..fcc55a12b3 100644 --- a/src/xpra/x11/xkbhelper.py +++ b/src/xpra/x11/xkbhelper.py @@ -1,5 +1,5 @@ # This file is part of Xpra. -# Copyright (C) 2011-2017 Antoine Martin +# Copyright (C) 2011-2018 Antoine Martin # Xpra is released under the terms of the GNU GPL v2, or, at your option, any # later version. See the file COPYING for details. @@ -149,10 +149,13 @@ def set_keycode_translation(xkbmap_x11_keycodes, xkbmap_keycodes): keycodes = indexed_mappings(xkbmap_x11_keycodes) else: keycodes = gtk_keycodes_to_mappings(xkbmap_keycodes) + log("set_keycode_translation(%s, %s) keycodes=%s", xkbmap_x11_keycodes, xkbmap_keycodes) + log(" keycodes=%s", keycodes) #keycodes = { # 9: set([('', 1), ('Escape', 4), ('', 3), ('Escape', 0), ('Escape', 2)]), # 10: set([('onesuperior', 4), ('onesuperior', 8), ('exclam', 1), ('1', 6), ('exclam', 3), ('1', 2), ('exclamdown', 9), ('exclamdown', 5), ('1', 0), ('exclam', 7)]), x11_keycodes = X11Keyboard.get_keycode_mappings() + log(" x11_keycodes=%s", x11_keycodes) #x11_keycodes = { # 8: ['Mode_switch', '', 'Mode_switch', '', 'Mode_switch'], # 9: ['Escape', '', 'Escape', '', 'Escape'], @@ -192,7 +195,22 @@ def rlog(v, msg): x11_keycode = find_keycode(keycode, keysym, i) if x11_keycode: trans[(keycode, keysym)] = x11_keycode + trans[(keysym, i)] = x11_keycode trans[keysym] = x11_keycode + if not xkbmap_x11_keycodes: + #now add all the keycodes we may not have mapped yet + #(present in x11_keycodes but not keycodes) + for keycode, keysyms in x11_keycodes.items(): + for i, keysym in enumerate(keysyms): + if keysym not in trans: + if keysym in DEBUG_KEYSYMS: + log.info("x11 keycode %s: %s", keycode, keysym) + trans[keysym] = keycode + key = (keysym, i) + if key not in trans: + if keysym in DEBUG_KEYSYMS: + log.info("x11 keycode %s: %s", keycode, key) + trans[key] = keycode log("set_keycode_translation(..)=%s", trans) return trans