def set_default_keymap(self): """ assign a default keymap based on the current X11 server keymap sets up the translation tables so we can lookup keys without setting a client keymap. """ if not self.enabled: return with xsync: clean_keyboard_state() #keycodes: keycode_to_keynames = get_keycode_mappings() self.keycode_translation = {} #prefer keycodes that don't use the lowest level+mode: default_for_keyname = {} for keycode, keynames in keycode_to_keynames.items(): for i, keyname in enumerate(keynames): self.keycode_translation[(keyname, i)] = keycode if keyname in DEBUG_KEYSYMS: log.info("set_default_keymap: %s=%s", (keyname, i), keycode) kd = default_for_keyname.get(keyname) if kd is None or kd[1] > i: default_for_keyname[keyname] = (keycode, i) for keyname, kd in default_for_keyname.items(): keycode = kd[0] self.keycode_translation[keyname] = keycode if keyname in DEBUG_KEYSYMS: log.info("set_default_keymap: %s=%s", keyname, keycode) self.add_gtk_keynames() log("set_default_keymap: keycode_translation=%s", self.keycode_translation) #modifiers: self.keynames_for_mod = {} #ie: {'control': [(37, 'Control_L'), (105, 'Control_R')], ...} mod_mappings = X11Keyboard.get_modifier_mappings() log("set_default_keymap: using modifier mappings=%s", mod_mappings) for modifier, mappings in mod_mappings.items(): keynames = [] for m in mappings: #ie: (37, 'Control_L'), (105, 'Control_R') if len(m) == 2: keynames.append(m[1]) #ie: 'Control_L' self.keynames_for_mod[modifier] = set(keynames) self.compute_modifier_keynames() self.compute_client_modifier_keycodes() log("set_default_keymap: keynames_for_mod=%s", self.keynames_for_mod) log("set_default_keymap: keycodes_for_modifier_keynames=%s", self.keycodes_for_modifier_keynames) log("set_default_keymap: modifier_map=%s", self.modifier_map) self.update_keycode_mappings()
def update_keycode_mappings(self): self.keycode_mappings = get_keycode_mappings()