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
     self.is_native_keymap = False
     clean_keyboard_state()
     #keycodes:
     keycode_to_keynames = X11Keyboard.get_keycode_mappings()
     self.keycode_translation = {}
     for keycode, keynames in keycode_to_keynames.items():
         for keyname in keynames:
             self.keycode_translation[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()
     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)
Exemple #2
0
 def do_cleanup(self):
     log("do_cleanup() x11_filter=%s", self.x11_filter)
     if self.x11_filter:
         self.x11_filter = False
         cleanup_x11_filter()
         #try a few times:
         #errors happen because windows are being destroyed
         #(even more so when we cleanup)
         #and we don't really care too much about this
         for l in (log, log, log, log, log.warn):
             try:
                 with xsync:
                     cleanup_all_event_receivers()
                     #all went well, we're done
                     log("all event receivers have been removed")
                     break
             except Exception as e:
                 l("failed to remove event receivers: %s", e)
     if self.fake_xinerama:
         cleanup_fakeXinerama()
     with xlog:
         clean_keyboard_state()
     #prop_del does its own xsync:
     self.clean_x11_properties()
     super().do_cleanup()
     log("close_gdk_display_source()")
     close_gdk_display_source()
Exemple #3
0
 def x11_init(self):
     if FAKE_X11_INIT_ERROR:
         raise Exception("fake x11 init error")
     self.init_fake_xinerama()
     with xlog:
         clean_keyboard_state()
     with xlog:
         if not X11Keyboard.hasXFixes() and self.cursors:
             log.error("Error: cursor forwarding support disabled")
         if not X11Keyboard.hasXTest():
             log.error("Error: keyboard and mouse disabled")
         elif not X11Keyboard.hasXkb():
             log.error("Error: limited keyboard support")
     with xsync:
         self.init_x11_atoms()
     with xlog:
         if self.randr:
             self.init_randr()
     with xlog:
         self.init_cursor()
     with xlog:
         self.x11_filter = init_x11_filter()
     assert self.x11_filter
     with xlog:
         self.save_mode()
 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
     self.is_native_keymap = False
     clean_keyboard_state()
     #keycodes:
     keycode_to_keynames = X11Keyboard.get_keycode_mappings()
     self.keycode_translation = {}
     for keycode, keynames in keycode_to_keynames.items():
         for keyname in keynames:
             self.keycode_translation[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()
     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)
Exemple #5
0
 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 set_keymap(self):
        if not self.enabled:
            return
        clean_keyboard_state()
        try:
            do_set_keymap(self.xkbmap_layout, self.xkbmap_variant,
                          self.xkbmap_print, self.xkbmap_query)
        except:
            log.error("error setting new keymap", exc_info=True)
        self.is_native_keymap = self.xkbmap_print != "" or self.xkbmap_query != ""
        try:
            #first clear all existing modifiers:
            clean_keyboard_state()
            clear_modifiers(
                ALL_X11_MODIFIERS.keys())  #just clear all of them (set or not)

            #now set all the keycodes:
            clean_keyboard_state()
            self.keycode_translation = {}

            has_keycodes = (self.xkbmap_x11_keycodes and len(self.xkbmap_x11_keycodes)>0) or \
                            (self.xkbmap_keycodes and len(self.xkbmap_keycodes)>0)
            assert has_keycodes, "client failed to provide any keycodes!"
            #first compute the modifier maps as this may have an influence
            #on the keycode mappings (at least for the from_keycodes case):
            if self.xkbmap_mod_meanings:
                #Unix-like OS provides modifier meanings:
                self.keynames_for_mod = get_modifiers_from_meanings(
                    self.xkbmap_mod_meanings)
            elif self.xkbmap_keycodes:
                #non-Unix-like OS provides just keycodes for now:
                self.keynames_for_mod = get_modifiers_from_keycodes(
                    self.xkbmap_keycodes)
            else:
                log.error(
                    "missing both xkbmap_mod_meanings and xkbmap_keycodes, modifiers will probably not work as expected!"
                )
                self.keynames_for_mod = {}
            #if the client does not provide a full keymap,
            #try to preserve the initial server keycodes
            #(used by non X11 clients like osx,win32 or Android)
            preserve_server_keycodes = not self.xkbmap_print and not self.xkbmap_query
            self.keycode_translation = set_all_keycodes(
                self.xkbmap_x11_keycodes, self.xkbmap_keycodes,
                preserve_server_keycodes, self.keynames_for_mod)
            self.add_gtk_keynames()

            #now set the new modifier mappings:
            clean_keyboard_state()
            log(
                "going to set modifiers, xkbmap_mod_meanings=%s, len(xkbmap_keycodes)=%s",
                self.xkbmap_mod_meanings, len(self.xkbmap_keycodes or []))
            if self.keynames_for_mod:
                set_modifiers(self.keynames_for_mod)
            self.compute_modifier_keynames()
            self.compute_client_modifier_keycodes()
            log("keyname_for_mod=%s", self.keynames_for_mod)
        except:
            log.error("error setting xmodmap", exc_info=True)
Exemple #7
0
 def clear_keys_pressed(self):
     if self.readonly:
         return
     keylog("clear_keys_pressed()")
     #make sure the timer doesn't fire and interfere:
     self.cancel_key_repeat_timer()
     #clear all the keys we know about:
     if self.keys_pressed:
         keylog("clearing keys pressed: %s", self.keys_pressed)
         with xsync:
             for keycode in self.keys_pressed:
                 self.fake_key(keycode, False)
         self.keys_pressed = {}
     #this will take care of any remaining ones we are not aware of:
     #(there should not be any - but we want to be certain)
     clean_keyboard_state()
Exemple #8
0
 def x11_init(self):
     clean_keyboard_state()
     if self.fake_xinerama:
         self.libfakeXinerama_so = find_libfakeXinerama()
     else:
         self.libfakeXinerama_so = None
     if not X11Keyboard.hasXFixes() and self.cursors:
         log.error("Error: cursor forwarding support disabled")
     if not X11Keyboard.hasXTest():
         log.error("Error: keyboard and mouse disabled")
     elif not X11Keyboard.hasXkb():
         log.error("Error: limited keyboard support")
     self.init_x11_atoms()
     if self.randr:
         self.init_randr()
     self.init_cursor()
     self.query_opengl()
    def set_keymap(self, client_platform):
        if not self.enabled:
            return
        clean_keyboard_state()
        try:
            do_set_keymap(self.xkbmap_layout, self.xkbmap_variant,
                          self.xkbmap_print, self.xkbmap_query)
        except:
            log.error("error setting new keymap", exc_info=True)
        self.is_native_keymap = self.xkbmap_print!="" or self.xkbmap_query!=""
        try:
            #first clear all existing modifiers:
            clean_keyboard_state()
            clear_modifiers(ALL_X11_MODIFIERS.keys())       #just clear all of them (set or not)

            #now set all the keycodes:
            clean_keyboard_state()
            self.keycode_translation = {}

            has_keycodes = (self.xkbmap_x11_keycodes and len(self.xkbmap_x11_keycodes)>0) or \
                            (self.xkbmap_keycodes and len(self.xkbmap_keycodes)>0)
            assert has_keycodes, "client failed to provide any keycodes!"
            #first compute the modifier maps as this may have an influence
            #on the keycode mappings (at least for the from_keycodes case):
            if self.xkbmap_mod_meanings:
                #Unix-like OS provides modifier meanings:
                self.keynames_for_mod = get_modifiers_from_meanings(self.xkbmap_mod_meanings)
            elif self.xkbmap_keycodes:
                #non-Unix-like OS provides just keycodes for now:
                self.keynames_for_mod = get_modifiers_from_keycodes(self.xkbmap_keycodes)
            else:
                log.error("missing both xkbmap_mod_meanings and xkbmap_keycodes, modifiers will probably not work as expected!")
                self.keynames_for_mod = {}
            #if the client does not provide a full keymap,
            #try to preserve the initial server keycodes
            #(used by non X11 clients like osx,win32 or Android)
            preserve_server_keycodes = not self.xkbmap_print and not self.xkbmap_query
            self.keycode_translation = set_all_keycodes(self.xkbmap_x11_keycodes, self.xkbmap_keycodes, preserve_server_keycodes, self.keynames_for_mod)

            #now set the new modifier mappings:
            clean_keyboard_state()
            debug("going to set modifiers, xkbmap_mod_meanings=%s, len(xkbmap_keycodes)=%s", self.xkbmap_mod_meanings, len(self.xkbmap_keycodes or []))
            if self.keynames_for_mod:
                set_modifiers(self.keynames_for_mod)
            self.compute_modifier_keynames()
            self.compute_client_modifier_keycodes()
            debug("keyname_for_mod=%s", self.keynames_for_mod)
        except:
            log.error("error setting xmodmap", exc_info=True)
        if (client_platform and client_platform.startswith("win")) and not self.is_native_keymap:
            self.modifiers_filter = ["lock"]
            num_mods = [mod for mod,keynames in self.keynames_for_mod.items() if "Num_Lock" in keynames]
            if len(num_mods)==1:
                self.modifiers_filter.append(num_mods[0])
            else:
                log.warn("found more than one modifier for 'Num_Lock': %s", num_mods)
    def set_keymap(self):
        if not self.enabled:
            return
        clean_keyboard_state()
        try:
            do_set_keymap(self.xkbmap_layout, self.xkbmap_variant,
                          self.xkbmap_print, self.xkbmap_query)
        except:
            log.error("error setting new keymap", exc_info=True)
        self.is_native_keymap = bool(self.xkbmap_print) or bool(self.xkbmap_query)
        log("set_keymap() is_native_keymap=%s, print=%s, query=%s", self.is_native_keymap, self.xkbmap_print, self.xkbmap_query)
        try:
            #first clear all existing modifiers:
            clean_keyboard_state()
            clear_modifiers(ALL_X11_MODIFIERS.keys())       #just clear all of them (set or not)

            #now set all the keycodes:
            clean_keyboard_state()
            self.keycode_translation = {}

            has_keycodes = (self.xkbmap_x11_keycodes and len(self.xkbmap_x11_keycodes)>0) or \
                            (self.xkbmap_keycodes and len(self.xkbmap_keycodes)>0)
            assert has_keycodes, "client failed to provide any keycodes!"
            #first compute the modifier maps as this may have an influence
            #on the keycode mappings (at least for the from_keycodes case):
            if self.xkbmap_mod_meanings:
                #Unix-like OS provides modifier meanings:
                self.keynames_for_mod = get_modifiers_from_meanings(self.xkbmap_mod_meanings)
            elif self.xkbmap_keycodes:
                #non-Unix-like OS provides just keycodes for now:
                self.keynames_for_mod = get_modifiers_from_keycodes(self.xkbmap_keycodes)
            else:
                log.error("missing both xkbmap_mod_meanings and xkbmap_keycodes, modifiers will probably not work as expected!")
                self.keynames_for_mod = {}
            #if the client does not provide a full keymap,
            #try to preserve the initial server keycodes
            #(used by non X11 clients like osx,win32 or Android)
            preserve_server_keycodes = not self.xkbmap_print and not self.xkbmap_query
            self.keycode_translation = set_all_keycodes(self.xkbmap_x11_keycodes, self.xkbmap_keycodes, preserve_server_keycodes, self.keynames_for_mod)
            self.add_gtk_keynames()

            #now set the new modifier mappings:
            clean_keyboard_state()
            log("going to set modifiers, xkbmap_mod_meanings=%s, len(xkbmap_keycodes)=%s", self.xkbmap_mod_meanings, len(self.xkbmap_keycodes or []))
            if self.keynames_for_mod:
                set_modifiers(self.keynames_for_mod)
            self.compute_modifier_keynames()
            self.compute_client_modifier_keycodes()
            log("keyname_for_mod=%s", self.keynames_for_mod)
        except:
            log.error("error setting xmodmap", exc_info=True)
 def x11_init(self):
     clean_keyboard_state()
     if self.fake_xinerama in FALSE_OPTIONS:
         self.libfakeXinerama_so = None
     elif os.path.isabs(self.fake_xinerama):
         self.libfakeXinerama_so = self.fake_xinerama
     else:
         self.libfakeXinerama_so = find_libfakeXinerama()
     if not X11Keyboard.hasXFixes() and self.cursors:
         log.error("Error: cursor forwarding support disabled")
     if not X11Keyboard.hasXTest():
         log.error("Error: keyboard and mouse disabled")
     elif not X11Keyboard.hasXkb():
         log.error("Error: limited keyboard support")
     self.init_x11_atoms()
     if self.randr:
         self.init_randr()
     self.init_cursor()
     self.query_opengl()
     self.x11_filter = init_x11_filter()
     assert self.x11_filter
Exemple #12
0
 def do_cleanup(self):
     if self.x11_filter:
         self.x11_filter = False
         cleanup_x11_filter()
         #try a few times:
         #errors happen because windows are being destroyed
         #(even more so when we cleanup)
         #and we don't really care too much about this
         for l in (log, log, log, log, log.warn):
             try:
                 with xsync:
                     cleanup_all_event_receivers()
                     #all went well, we're done
                     break
             except Exception as e:
                 l("failed to remove event receivers: %s", e)
     if self.fake_xinerama:
         cleanup_fakeXinerama()
     with xswallow:
         clean_keyboard_state()
     GTKServerBase.do_cleanup(self)
     log("close_gdk_display_source()")
     close_gdk_display_source()
Exemple #13
0
 def init_keyboard(self):
     GTKServerBase.init_keyboard(self)
     self.current_keyboard_group = None
     #clear all modifiers
     clean_keyboard_state()
    def set_keymap(self, translate_only=False):
        if not self.enabled:
            return
        log("set_keymap(%s) layout=%s, variant=%s, print=%s, query=%s",
            translate_only, self.xkbmap_layout, self.xkbmap_variant,
            nonl(self.xkbmap_print), nonl(self.xkbmap_query))
        if translate_only:
            self.keycode_translation = set_keycode_translation(
                self.xkbmap_x11_keycodes, self.xkbmap_keycodes)
            self.add_gtk_keynames()
            self.compute_modifier_keynames()
            return

        try:
            with xsync:
                clean_keyboard_state()
                do_set_keymap(self.xkbmap_layout, self.xkbmap_variant,
                              self.xkbmap_print, self.xkbmap_query,
                              self.xkbmap_query_struct)
        except:
            log.error("Error setting up new keymap", exc_info=True)
        self.is_native_keymap = bool(self.xkbmap_print) or bool(
            self.xkbmap_query)
        try:
            with xsync:
                #first clear all existing modifiers:
                clean_keyboard_state()

                if not self.xkbmap_raw:
                    clear_modifiers(ALL_X11_MODIFIERS.keys()
                                    )  #just clear all of them (set or not)

                    #now set all the keycodes:
                    clean_keyboard_state()

                    has_keycodes = (self.xkbmap_x11_keycodes and len(self.xkbmap_x11_keycodes)>0) or \
                                    (self.xkbmap_keycodes and len(self.xkbmap_keycodes)>0)
                    assert has_keycodes, "client failed to provide any keycodes!"
                    #first compute the modifier maps as this may have an influence
                    #on the keycode mappings (at least for the from_keycodes case):
                    if self.xkbmap_mod_meanings:
                        #Unix-like OS provides modifier meanings:
                        self.keynames_for_mod = get_modifiers_from_meanings(
                            self.xkbmap_mod_meanings)
                    elif self.xkbmap_keycodes:
                        #non-Unix-like OS provides just keycodes for now:
                        self.keynames_for_mod = get_modifiers_from_keycodes(
                            self.xkbmap_keycodes)
                    else:
                        log.error(
                            "missing both xkbmap_mod_meanings and xkbmap_keycodes, modifiers will probably not work as expected!"
                        )
                        self.keynames_for_mod = {}
                    #if the client does not provide a full keymap,
                    #try to preserve the initial server keycodes
                    #(used by non X11 clients like osx,win32 or Android)
                    preserve_server_keycodes = not self.xkbmap_print and not self.xkbmap_query
                    self.keycode_translation = set_all_keycodes(
                        self.xkbmap_x11_keycodes, self.xkbmap_keycodes,
                        preserve_server_keycodes, self.keynames_for_mod)
                    self.add_gtk_keynames()

                    #now set the new modifier mappings:
                    clean_keyboard_state()
                    log(
                        "going to set modifiers, xkbmap_mod_meanings=%s, len(xkbmap_keycodes)=%s",
                        self.xkbmap_mod_meanings,
                        len(self.xkbmap_keycodes or []))
                    if self.keynames_for_mod:
                        set_modifiers(self.keynames_for_mod)
                    log("keynames_for_mod=%s", self.keynames_for_mod)
                    self.compute_modifier_keynames()
                else:
                    self.keycode_translation = {}
                    log("keyboard raw mode, keycode translation left empty")
                    log("keycode mappings=%s",
                        X11Keyboard.get_keycode_mappings())
                    mod_mappings = X11Keyboard.get_modifier_mappings()
                    self.xkbmap_mod_meanings = {}
                    for mod, mod_defs in mod_mappings.items():
                        for mod_def in mod_defs:
                            for v in mod_def:
                                if type(v) == int:
                                    l = self.keycodes_for_modifier_keynames.setdefault(
                                        mod, [])
                                else:
                                    self.xkbmap_mod_meanings[v] = mod
                                    l = self.keynames_for_mod.setdefault(
                                        mod, [])
                                if v not in l:
                                    l.append(v)
                    log("keynames_for_mod=%s", self.keynames_for_mod)
                    log("keycodes_for_modifier_keynames=%s",
                        self.keycodes_for_modifier_keynames)
                    log("mod_meanings=%s", self.xkbmap_mod_meanings)
                self.compute_client_modifier_keycodes()
                log("keyname_for_mod=%s", self.keynames_for_mod)
                clean_keyboard_state()
        except:
            log.error("Error setting X11 keyboard modifier map", exc_info=True)
Exemple #15
0
 def init_keyboard(self):
     GTKServerBase.init_keyboard(self)
     self.current_keyboard_group = None
     #clear all modifiers
     clean_keyboard_state()
Exemple #16
0
    def set_keymap(self, translate_only=False):
        if not self.enabled:
            return
        log(
            "set_keymap(%s) layout=%s, variant=%s, options=%s, print=%s, query=%s",
            translate_only, self.xkbmap_layout, self.xkbmap_variant,
            self.xkbmap_options, nonl(self.xkbmap_print),
            nonl(self.xkbmap_query))
        if translate_only:
            self.keycode_translation = set_keycode_translation(
                self.xkbmap_x11_keycodes, self.xkbmap_keycodes)
            self.add_gtk_keynames()
            self.compute_modifiers()
            self.compute_modifier_keynames()
            self.compute_client_modifier_keycodes()
            self.update_keycode_mappings()
            return

        with xlog:
            clean_keyboard_state()
            do_set_keymap(self.xkbmap_layout, self.xkbmap_variant,
                          self.xkbmap_options, self.xkbmap_print,
                          self.xkbmap_query, self.xkbmap_query_struct)
        log("set_keymap: xkbmap_print=%s, xkbmap_query=%s",
            nonl(self.xkbmap_print), nonl(self.xkbmap_query))
        with xlog:
            #first clear all existing modifiers:
            clean_keyboard_state()

            if not self.xkbmap_raw:
                has_keycodes = bool(self.xkbmap_x11_keycodes) or bool(
                    self.xkbmap_keycodes)
                assert has_keycodes, "client failed to provide any keycodes!"

                clear_modifiers(ALL_X11_MODIFIERS.keys()
                                )  #just clear all of them (set or not)
                clean_keyboard_state()

                #now set all the keycodes:
                #first compute the modifier maps as this may have an influence
                #on the keycode mappings (at least for the from_keycodes case):
                self.compute_modifiers()
                #key translation:
                if bool(self.xkbmap_query):
                    #native full mapping of all keycodes:
                    self.keycode_translation = set_all_keycodes(
                        self.xkbmap_x11_keycodes, self.xkbmap_keycodes, False,
                        self.keynames_for_mod)
                else:
                    #if the client does not provide a full native keymap with all the keycodes,
                    #try to preserve the initial server keycodes and translate the client keycodes instead:
                    #(used by non X11 clients like osx,win32 or HTML5)
                    self.keycode_translation = set_keycode_translation(
                        self.xkbmap_x11_keycodes, self.xkbmap_keycodes)
                self.add_gtk_keynames()

                #now set the new modifier mappings:
                clean_keyboard_state()
                log(
                    "going to set modifiers, xkbmap_mod_meanings=%s, len(xkbmap_keycodes)=%s, keynames_for_mod=%s",
                    self.xkbmap_mod_meanings, len(self.xkbmap_keycodes or []),
                    self.keynames_for_mod)
                if self.keynames_for_mod:
                    set_modifiers(self.keynames_for_mod)
                log("keynames_for_mod=%s", self.keynames_for_mod)
                self.compute_modifier_keynames()
            else:
                self.keycode_translation = {}
                log("keyboard raw mode, keycode translation left empty")
                self.compute_modifiers()
            self.compute_client_modifier_keycodes()
            log("keyname_for_mod=%s", self.keynames_for_mod)
            clean_keyboard_state()
            self.update_keycode_mappings()
    def set_keymap(self, translate_only=False):
        if not self.enabled:
            return
        log(
            "set_keymap(%s) layout=%s, variant=%s, options=%s, print=%s, query=%s",
            translate_only, self.xkbmap_layout, self.xkbmap_variant,
            self.xkbmap_options, nonl(self.xkbmap_print),
            nonl(self.xkbmap_query))
        if translate_only:
            self.keycode_translation = set_keycode_translation(
                self.xkbmap_x11_keycodes, self.xkbmap_keycodes)
            self.add_gtk_keynames()
            self.compute_modifier_keynames()
            self.compute_client_modifier_keycodes()
            return

        try:
            with xsync:
                clean_keyboard_state()
                do_set_keymap(self.xkbmap_layout, self.xkbmap_variant,
                              self.xkbmap_options, self.xkbmap_print,
                              self.xkbmap_query, self.xkbmap_query_struct)
        except:
            log.error("Error setting up new keymap", exc_info=True)
        log("set_keymap: xkbmap_print=%s, xkbmap_query=%s",
            nonl(self.xkbmap_print), nonl(self.xkbmap_query))
        try:
            with xsync:
                #first clear all existing modifiers:
                clean_keyboard_state()

                if not self.xkbmap_raw:
                    has_keycodes = bool(self.xkbmap_x11_keycodes) or bool(
                        self.xkbmap_keycodes)
                    assert has_keycodes, "client failed to provide any keycodes!"

                    clear_modifiers(ALL_X11_MODIFIERS.keys()
                                    )  #just clear all of them (set or not)

                    #now set all the keycodes:
                    clean_keyboard_state()

                    #first compute the modifier maps as this may have an influence
                    #on the keycode mappings (at least for the from_keycodes case):
                    if self.xkbmap_mod_meanings:
                        #Unix-like OS provides modifier meanings:
                        self.keynames_for_mod = get_modifiers_from_meanings(
                            self.xkbmap_mod_meanings)
                    elif self.xkbmap_keycodes:
                        #non-Unix-like OS provides just keycodes for now:
                        self.keynames_for_mod = get_modifiers_from_keycodes(
                            self.xkbmap_keycodes, MAP_MISSING_MODIFIERS)
                        if MAP_MISSING_MODIFIERS:
                            map_missing_modifiers(self.keynames_for_mod)
                    else:
                        log.warn(
                            "Warning: client did not supply any modifier definitions"
                        )
                        self.keynames_for_mod = {}
                    if bool(self.xkbmap_query):
                        #native full mapping of all keycodes:
                        self.keycode_translation = set_all_keycodes(
                            self.xkbmap_x11_keycodes, self.xkbmap_keycodes,
                            False, self.keynames_for_mod)
                    else:
                        #if the client does not provide a full native keymap with all the keycodes,
                        #try to preserve the initial server keycodes and translate the client keycodes instead:
                        #(used by non X11 clients like osx,win32 or HTML5)
                        self.keycode_translation = set_keycode_translation(
                            self.xkbmap_x11_keycodes, self.xkbmap_keycodes)
                    self.add_gtk_keynames()

                    #now set the new modifier mappings:
                    clean_keyboard_state()
                    log(
                        "going to set modifiers, xkbmap_mod_meanings=%s, len(xkbmap_keycodes)=%s, keynames_for_mod=%s",
                        self.xkbmap_mod_meanings,
                        len(self.xkbmap_keycodes or []), self.keynames_for_mod)
                    if self.keynames_for_mod:
                        set_modifiers(self.keynames_for_mod)
                    log("keynames_for_mod=%s", self.keynames_for_mod)
                    self.compute_modifier_keynames()
                else:
                    self.keycode_translation = {}
                    log("keyboard raw mode, keycode translation left empty")
                    log("keycode mappings=%s",
                        X11Keyboard.get_keycode_mappings())
                    mod_mappings = X11Keyboard.get_modifier_mappings()
                    self.xkbmap_mod_meanings = {}
                    for mod, mod_defs in mod_mappings.items():
                        for mod_def in mod_defs:
                            for v in mod_def:
                                if type(v) == int:
                                    l = self.keycodes_for_modifier_keynames.setdefault(
                                        mod, [])
                                else:
                                    self.xkbmap_mod_meanings[v] = mod
                                    l = self.keynames_for_mod.setdefault(
                                        mod, [])
                                if v not in l:
                                    l.append(v)
                    log("keynames_for_mod=%s", self.keynames_for_mod)
                    log("keycodes_for_modifier_keynames=%s",
                        self.keycodes_for_modifier_keynames)
                    log("mod_meanings=%s", self.xkbmap_mod_meanings)
                self.compute_client_modifier_keycodes()
                log("keyname_for_mod=%s", self.keynames_for_mod)
                clean_keyboard_state()
        except:
            log.error("Error setting X11 keymap", exc_info=True)
Exemple #18
0
 def do_cleanup(self):
     GTKServerBase.do_cleanup(self)
     if self.fake_xinerama:
         cleanup_fakeXinerama()
     with xswallow:
         clean_keyboard_state()
Exemple #19
0
 def init_keyboard(self):
     GTKServerBase.init_keyboard(self)
     #clear all modifiers
     clean_keyboard_state()
Exemple #20
0
 def init_keyboard(self):
     GTKServerBase.init_keyboard(self)
     #clear all modifiers
     clean_keyboard_state()