def set_x_keyboard_defaults(localization_proxy, xkl_wrapper): """ Set default keyboard settings (layouts, layout switching). :param localization_proxy: DBus proxy of the localization module or None :type ksdata: object instance :param xkl_wrapper: XklWrapper instance :type xkl_wrapper: object instance :raise InvalidLocaleSpec: if an invalid locale is given (see localization.is_valid_langcode) """ x_layouts = localization_proxy.XLayouts # remove all X layouts that are not valid X layouts (unsupported) valid_layouts = [] for layout in x_layouts: if xkl_wrapper.is_valid_layout(layout): valid_layouts.append(layout) localization_proxy.XLayouts = valid_layouts if valid_layouts: # do not add layouts if there are any specified in the kickstart # (the x_layouts list comes from kickstart) return locale = localization_proxy.Language layouts = localization.get_locale_keyboards(locale) if layouts: # take the first locale (with highest rank) from the list and # store it normalized new_layouts = [normalize_layout_variant(layouts[0])] if not langtable.supports_ascii(layouts[0]): # The default keymap setting should have "us" before the native layout # which does not support ascii, # refer: https://bugzilla.redhat.com/show_bug.cgi?id=1039185 new_layouts.insert(0, DEFAULT_KEYBOARD) else: log.error("Failed to get layout for chosen locale '%s'", locale) new_layouts = [DEFAULT_KEYBOARD] localization_proxy.XLayouts = new_layouts if can_configure_keyboard(): xkl_wrapper.replace_layouts(new_layouts) # the console layout configured should be "native" by default, # setting that explicitly for non-ascii layouts where we prepend "us" # refer: https://bugzilla.redhat.com/show_bug.cgi?id=1912609 if len(new_layouts) >= 2 and not langtable.supports_ascii(new_layouts[1]): localization_proxy.VirtualConsoleKeymap = new_layouts[1] if len(new_layouts) >= 2 and not localization_proxy.LayoutSwitchOptions: # initialize layout switching if needed localization_proxy.LayoutSwitchOptions = ["grp:alt_shift_toggle"] if can_configure_keyboard(): xkl_wrapper.set_switching_options(["grp:alt_shift_toggle"]) # activate the language-default layout instead of the additional # one xkl_wrapper.activate_default_layout()
def _set_keyboard_defaults(self, locale): """ Set default keyboard settings (layouts, layout switching). :param locale: locale string (see localization.LANGCODE_RE) :type locale: str :return: list of preferred keyboard layouts :rtype: list of strings :raise InvalidLocaleSpec: if an invalid locale is given (see localization.LANGCODE_RE) """ #remove all X layouts that are not valid X layouts (unsupported) #from the ksdata #XXX: could go somewhere else, but we need X running and we have # XklWrapper instance here for layout in self.data.keyboard.x_layouts: if not self._xklwrapper.is_valid_layout(layout): self.data.keyboard.x_layouts.remove(layout) if self.data.keyboard.x_layouts: #do not add layouts if there are any specified in the kickstart return layouts = localization.get_locale_keyboards(locale) if layouts: # take the first locale (with highest rank) from the list and # store it normalized new_layouts = [keyboard.normalize_layout_variant(layouts[0])] if not langtable.supports_ascii(layouts[0]): # does not support typing ASCII chars, append the default layout new_layouts.append(DEFAULT_KEYBOARD) else: log.error("Failed to get layout for chosen locale '%s'", locale) new_layouts = [DEFAULT_KEYBOARD] self.data.keyboard.x_layouts = new_layouts if flags.can_touch_runtime_system("replace runtime X layouts", touch_live=True): self._xklwrapper.replace_layouts(new_layouts) if len(new_layouts) >= 2 and not self.data.keyboard.switch_options: #initialize layout switching if needed self.data.keyboard.switch_options = ["grp:alt_shift_toggle"] if flags.can_touch_runtime_system("init layout switching", touch_live=True): self._xklwrapper.set_switching_options( ["grp:alt_shift_toggle"]) # activate the language-default layout instead of the additional # one self._xklwrapper.activate_default_layout()
def _set_keyboard_defaults(self, locale): """ Set default keyboard settings (layouts, layout switching). :param locale: locale string (see localization.LANGCODE_RE) :type locale: str :return: list of preferred keyboard layouts :rtype: list of strings :raise InvalidLocaleSpec: if an invalid locale is given (see localization.LANGCODE_RE) """ #remove all X layouts that are not valid X layouts (unsupported) #from the ksdata #XXX: could go somewhere else, but we need X running and we have # XklWrapper instance here for layout in self.data.keyboard.x_layouts: if not self._xklwrapper.is_valid_layout(layout): self.data.keyboard.x_layouts.remove(layout) if self.data.keyboard.x_layouts: #do not add layouts if there are any specified in the kickstart return layouts = localization.get_locale_keyboards(locale) if layouts: # take the first locale (with highest rank) from the list and # store it normalized new_layouts = [keyboard.normalize_layout_variant(layouts[0])] if not langtable.supports_ascii(layouts[0]): # does not support typing ASCII chars, append the default layout new_layouts.append(DEFAULT_KEYBOARD) else: log.error("Failed to get layout for chosen locale '%s'", locale) new_layouts = [DEFAULT_KEYBOARD] self.data.keyboard.x_layouts = new_layouts if flags.can_touch_runtime_system("replace runtime X layouts", touch_live=True): self._xklwrapper.replace_layouts(new_layouts) if len(new_layouts) >= 2 and not self.data.keyboard.switch_options: #initialize layout switching if needed self.data.keyboard.switch_options = ["grp:alt_shift_toggle"] if flags.can_touch_runtime_system("init layout switching", touch_live=True): self._xklwrapper.set_switching_options(["grp:alt_shift_toggle"]) # activate the language-default layout instead of the additional # one self._xklwrapper.activate_default_layout()
def set_x_keyboard_defaults(localization_proxy, xkl_wrapper): """ Set default keyboard settings (layouts, layout switching). :param localization_proxy: DBus proxy of the localization module or None :type ksdata: object instance :param xkl_wrapper: XklWrapper instance :type xkl_wrapper: object instance :raise InvalidLocaleSpec: if an invalid locale is given (see localization.LANGCODE_RE) """ x_layouts = localization_proxy.XLayouts # remove all X layouts that are not valid X layouts (unsupported) valid_layouts = [] for layout in x_layouts: if xkl_wrapper.is_valid_layout(layout): valid_layouts.append(layout) localization_proxy.SetXLayouts(valid_layouts) if valid_layouts: # do not add layouts if there are any specified in the kickstart # (the x_layouts list comes from kickstart) return locale = localization_proxy.Language layouts = localization.get_locale_keyboards(locale) if layouts: # take the first locale (with highest rank) from the list and # store it normalized new_layouts = [normalize_layout_variant(layouts[0])] if not langtable.supports_ascii(layouts[0]): # does not support typing ASCII chars, append the default layout new_layouts.append(DEFAULT_KEYBOARD) else: log.error("Failed to get layout for chosen locale '%s'", locale) new_layouts = [DEFAULT_KEYBOARD] localization_proxy.SetXLayouts(new_layouts) if can_touch_runtime_system("replace runtime X layouts", touch_live=True): xkl_wrapper.replace_layouts(new_layouts) if len(new_layouts) >= 2 and not localization_proxy.LayoutSwitchOptions: # initialize layout switching if needed localization_proxy.SetLayoutSwitchOptions(["grp:alt_shift_toggle"]) if can_touch_runtime_system("init layout switching", touch_live=True): xkl_wrapper.set_switching_options(["grp:alt_shift_toggle"]) # activate the language-default layout instead of the additional # one xkl_wrapper.activate_default_layout()
def set_x_keyboard_defaults(localization_proxy, xkl_wrapper): """ Set default keyboard settings (layouts, layout switching). :param localization_proxy: DBus proxy of the localization module or None :type ksdata: object instance :param xkl_wrapper: XklWrapper instance :type xkl_wrapper: object instance :raise InvalidLocaleSpec: if an invalid locale is given (see localization.LANGCODE_RE) """ x_layouts = localization_proxy.XLayouts # remove all X layouts that are not valid X layouts (unsupported) valid_layouts = [] for layout in x_layouts: if xkl_wrapper.is_valid_layout(layout): valid_layouts.append(layout) localization_proxy.SetXLayouts(valid_layouts) if valid_layouts: # do not add layouts if there are any specified in the kickstart # (the x_layouts list comes from kickstart) return locale = localization_proxy.Language layouts = localization.get_locale_keyboards(locale) if layouts: # take the first locale (with highest rank) from the list and # store it normalized new_layouts = [normalize_layout_variant(layouts[0])] if not langtable.supports_ascii(layouts[0]): # does not support typing ASCII chars, append the default layout new_layouts.append(DEFAULT_KEYBOARD) else: log.error("Failed to get layout for chosen locale '%s'", locale) new_layouts = [DEFAULT_KEYBOARD] localization_proxy.SetXLayouts(new_layouts) if conf.system.can_configure_keyboard: xkl_wrapper.replace_layouts(new_layouts) if len(new_layouts) >= 2 and not localization_proxy.LayoutSwitchOptions: # initialize layout switching if needed localization_proxy.SetLayoutSwitchOptions(["grp:alt_shift_toggle"]) if conf.system.can_configure_keyboard: xkl_wrapper.set_switching_options(["grp:alt_shift_toggle"]) # activate the language-default layout instead of the additional # one xkl_wrapper.activate_default_layout()
def set_x_keyboard_defaults(ksdata, xkl_wrapper): """ Set default keyboard settings (layouts, layout switching). :param ksdata: kickstart instance :type ksdata: object instance :param xkl_wrapper: XklWrapper instance :type xkl_wrapper: object instance :raise InvalidLocaleSpec: if an invalid locale is given (see localization.LANGCODE_RE) """ locale = ksdata.lang.lang # remove all X layouts that are not valid X layouts (unsupported) for layout in ksdata.keyboard.x_layouts: if not xkl_wrapper.is_valid_layout(layout): ksdata.keyboard.x_layouts.remove(layout) if ksdata.keyboard.x_layouts: # do not add layouts if there are any specified in the kickstart # (the x_layouts list comes from kickstart) return layouts = localization.get_locale_keyboards(locale) if layouts: # take the first locale (with highest rank) from the list and # store it normalized new_layouts = [normalize_layout_variant(layouts[0])] if not langtable.supports_ascii(layouts[0]): # does not support typing ASCII chars, append the default layout new_layouts.append(DEFAULT_KEYBOARD) else: log.error("Failed to get layout for chosen locale '%s'", locale) new_layouts = [DEFAULT_KEYBOARD] ksdata.keyboard.x_layouts = new_layouts if can_touch_runtime_system("replace runtime X layouts", touch_live=True): xkl_wrapper.replace_layouts(new_layouts) if len(new_layouts) >= 2 and not ksdata.keyboard.switch_options: # initialize layout switching if needed ksdata.keyboard.switch_options = ["grp:alt_shift_toggle"] if can_touch_runtime_system("init layout switching", touch_live=True): xkl_wrapper.set_switching_options(["grp:alt_shift_toggle"]) # activate the language-default layout instead of the additional # one xkl_wrapper.activate_default_layout()
def collect_requirements(self): """Return installation requirements for this module. :return: a list of requirements """ requirements = [] # Install support for non-ascii keyboard layouts (#1919483). if self.vc_keymap and not langtable.supports_ascii(self.vc_keymap): requirements.append( Requirement.for_package( package_name="kbd-legacy", reason="Required to support the '{}' keymap.".format( self.vc_keymap))) return requirements