def get_modifiers_from_keycodes(xkbmap_keycodes): """ Some platforms can't tell us about modifier mappings So we try to find matches from the defaults below: """ from xpra.keyboard.mask import DEFAULT_MODIFIER_MEANINGS pref = DEFAULT_MODIFIER_MEANINGS #keycodes are: {keycode : (keyval, name, keycode, group, level)} matches = {} log("get_modifiers_from_keycodes(%s...)", str(xkbmap_keycodes)) log("get_modifiers_from_keycodes(%s...)", str(xkbmap_keycodes)[:160]) all_keynames = set() for entry in xkbmap_keycodes: _, keyname, _, _, _ = entry modifier = pref.get(keyname) if modifier: keynames = matches.setdefault(modifier, set()) keynames.add(keyname) all_keynames.add(keyname) #try to add missings ones (magic!) defaults = {} for keyname, modifier in DEFAULT_MODIFIER_MEANINGS.items(): if keyname in all_keynames: continue #aleady defined if modifier not in matches: #define it since it is completely missing defaults.setdefault(modifier, set()).add(keyname) elif modifier in ["shift", "lock", "control", "mod1", "mod2"] or keyname=="ISO_Level3_Shift": #these ones we always add them, even if a record for this modifier already exists matches.setdefault(modifier, set()).add(keyname) log("get_modifiers_from_keycodes(...) adding defaults: %s", defaults) matches.update(defaults) log("get_modifiers_from_keycodes(...)=%s", matches) return matches
def get_modifiers_from_keycodes(xkbmap_keycodes, add_default_modifiers=True): """ Some platforms can't tell us about modifier mappings So we try to find matches from the defaults below: """ from xpra.keyboard.mask import DEFAULT_MODIFIER_MEANINGS pref = DEFAULT_MODIFIER_MEANINGS #keycodes are: {keycode : (keyval, name, keycode, group, level)} matches = {} log("get_modifiers_from_keycodes(%s...)", str(xkbmap_keycodes)[:160]) all_keynames = set() for entry in xkbmap_keycodes: _, keyname, _, _, _ = entry modifier = pref.get(keyname) if modifier: keynames = matches.setdefault(modifier, set()) keynames.add(keyname) all_keynames.add(keyname) if add_default_modifiers: #try to add missings ones (magic!) defaults = {} for keyname, modifier in DEFAULT_MODIFIER_MEANINGS.items(): if keyname in all_keynames: continue #aleady defined if modifier not in matches: #define it since it is completely missing defaults.setdefault(modifier, set()).add(keyname) elif modifier in ["shift", "lock", "control", "mod1", "mod2" ] or keyname == "ISO_Level3_Shift": #these ones we always add them, even if a record for this modifier already exists matches.setdefault(modifier, set()).add(keyname) log("get_modifiers_from_keycodes(...) adding defaults: %s", defaults) matches.update(defaults) log("get_modifiers_from_keycodes(...)=%s", matches) return matches
def is_modifier(self, keyname, keycode): if keyname in DEFAULT_MODIFIER_MEANINGS.keys(): return True #keyboard config should always exist if we are here? if self.keyboard_config: return self.keyboard_config.is_modifier(keycode) return False