Skip to content

Commit

Permalink
#1902: add translation map for keysym with level, use modifier state …
Browse files Browse the repository at this point in the history
…(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
  • Loading branch information
totaam committed Sep 16, 2018
1 parent 71d17e1 commit babc769
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
24 changes: 18 additions & 6 deletions src/xpra/x11/server_keyboard_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# This file is part of Xpra.
# Copyright (C) 2011 Serviware (Arthur Huillet, <[email protected]>)
# Copyright (C) 2010-2017 Antoine Martin <[email protected]>
# Copyright (C) 2010-2018 Antoine Martin <[email protected]>
# Copyright (C) 2008 Nathaniel Smith <[email protected]>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion src/xpra/x11/xkbhelper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is part of Xpra.
# Copyright (C) 2011-2017 Antoine Martin <[email protected]>
# Copyright (C) 2011-2018 Antoine Martin <[email protected]>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit babc769

Please sign in to comment.