Skip to content

Commit

Permalink
Add support for virtual console keymap from live
Browse files Browse the repository at this point in the history
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 8, 2023
1 parent 583a7cd commit 1455f32
Show file tree
Hide file tree
Showing 3 changed files with 288 additions and 70 deletions.
33 changes: 31 additions & 2 deletions pyanaconda/modules/localization/live_system.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,33 @@ 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"
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
18 changes: 13 additions & 5 deletions pyanaconda/modules/localization/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,32 @@ def get_missing_keyboard_configuration(localed_wrapper, live_wrapper, x_layouts,
log.debug("Keyboard layouts and virtual console keymap already set - nothing to do")
return x_layouts, vc_keymap

x_layouts = _resolve_missing_from_live(live_wrapper, x_layouts)
x_layouts, vc_keymap = _resolve_missing_from_live(localed_wrapper,
live_wrapper,
x_layouts,
vc_keymap)

if not vc_keymap or not x_layouts:
x_layouts, vc_keymap = _resolve_missing_from_default(localed_wrapper, x_layouts, vc_keymap)

return x_layouts, vc_keymap


def _resolve_missing_from_live(live_wrapper, x_layouts):
def _resolve_missing_from_live(localed_wrapper, live_wrapper, x_layouts, vc_keymap):
if not live_wrapper:
return x_layouts
return x_layouts, vc_keymap

log.debug("Keyboad configuration from Live system is available")

if not x_layouts:
return live_wrapper.read_keyboard_layouts()
x_layouts = live_wrapper.read_keyboard_layouts()

if not vc_keymap:
live_layout = live_wrapper.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_from_default(localed_wrapper, x_layouts, vc_keymap):
Expand Down
Loading

0 comments on commit 1455f32

Please sign in to comment.