Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use keyboard configuration from Gnome Shell live #4976

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add support for virtual console keymap from live
Look for currently used keyboard layout and set that as virtual console
keymap after conversion. It's probably what user wants to use because it
was used during the installation.
  • Loading branch information
jkonecny12 committed Aug 10, 2023
commit 696f1f5d7bb8a130ece845abdfb252daf8938460
34 changes: 32 additions & 2 deletions pyanaconda/modules/localization/live_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ def read_keyboard_layouts(self):
"""
pass

@abstractmethod
def read_current_keyboard_layout(self):
"""Read keyboard layout currently used.

It is the best candidate for the virtual console keymap.

:return: keyboard layout used for virtual_console (e.g: LUKS during boot)
:rtype: str
"""
pass

@staticmethod
def _run_as_liveuser(argv):
"""Run the command in a system as liveuser user.
Expand All @@ -74,15 +85,34 @@ def read_keyboard_layouts(self):
"""
command_args = ["gsettings", "get", "org.gnome.desktop.input-sources", "sources"]
sources = self._run_as_liveuser(command_args)
result = self._convert_to_xkb_format(sources)
return result

def read_current_keyboard_layout(self):
"""Read keyboard layout currently used.

# convert output "[('xkb', 'us'), ('xkb', 'cz+qwerty')]\n"
It is the best candidate for the virtual console keymap.

:return: keyboard layout used for virtual_console (e.g: LUKS during boot)
:rtype: str
"""
command_args = ["gsettings", "get", "org.gnome.desktop.input-sources", "mru-sources"]
sources = self._run_as_liveuser(command_args)
result = self._convert_to_xkb_format(sources)
# take first recently used which is the currently used
if result:
return result[0]
return ""

def _convert_to_xkb_format(self, sources):
# convert input "[('xkb', 'us'), ('xkb', 'cz+qwerty')]\n"
# to a python list of '["us", "cz (qwerty)"]'
try:
sources = eval(sources.rstrip())
except SyntaxError:
log.error("Gnome Shell keyboard configuration can't be obtained from source %s!",
sources)
return []

result = []

for t in sources:
Expand Down
20 changes: 13 additions & 7 deletions pyanaconda/modules/localization/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ def get_missing_keyboard_configuration(localed_wrapper, x_layouts, vc_keymap):
return x_layouts, vc_keymap

live_keyboard = get_live_keyboard_instance()

if live_keyboard:
# layouts are not set by user, we should take a look for live configuration if available
if not x_layouts and live_keyboard:
log.debug("Keyboad configuration from Live system is available")
x_layouts = _resolve_missing_from_live(live_keyboard, x_layouts)
x_layouts, vc_keymap = _resolve_missing_from_live(localed_wrapper,
live_keyboard,
x_layouts,
vc_keymap)

if not vc_keymap and not x_layouts:
log.debug("Using default value %s for missing virtual console keymap", DEFAULT_KEYBOARD)
Expand All @@ -65,12 +68,15 @@ def get_missing_keyboard_configuration(localed_wrapper, x_layouts, vc_keymap):
return x_layouts, vc_keymap


def _resolve_missing_from_live(live_keyboard, x_layouts):
def _resolve_missing_from_live(localed_wrapper, live_keyboard, x_layouts, vc_keymap):
x_layouts = live_keyboard.read_keyboard_layouts()

if not x_layouts:
return live_keyboard.read_keyboard_layouts()
if not vc_keymap:
live_layout = live_keyboard.read_current_keyboard_layout()
if live_layout:
vc_keymap = localed_wrapper.convert_layouts([live_layout])

return x_layouts
return x_layouts, vc_keymap


def _resolve_missing_by_conversion(localed_wrapper, x_layouts, vc_keymap):
Expand Down
Loading