Skip to content

Commit

Permalink
Disable keyboard shortcut switching on gnome-kiosk
Browse files Browse the repository at this point in the history
This is a workaround for https://issues.redhat.com/browse/RHEL-71880.

We need this workaround to avoid users confusion. Without this the
keyboard switching will work but it is not visible to users, so they
could easily switch layouts without noticing it and wrote passwords
wrong.
  • Loading branch information
jkonecny12 committed Jan 20, 2025
1 parent b13180d commit 6352cff
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 9 deletions.
5 changes: 5 additions & 0 deletions pyanaconda/core/configuration/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,8 @@ def can_use_driver_disks(self):
def supports_web_ui(self):
"""Can we run Web UI on this system?"""
return self._is_boot_iso or self._is_live_os

@property
def supports_compositor_keyboard_layout_shortcut(self):
"""Does the compositor support keyboard layout options correctly?"""
return not self._is_boot_iso
15 changes: 13 additions & 2 deletions pyanaconda/modules/localization/localed.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,19 @@ def _set_layouts(self, layouts_variants, options=None, convert=False):
# If options are not set let's use from a system so we don't change the system settings
if options is None:
options = self.options
log.debug("Keyboard layouts for compositor are missing options. "
"Use compositor options: %s", options)
log.debug(
"Keyboard layouts for compositor are missing options. Use compositor options: %s",
options,
)

# TODO: Remove when https://issues.redhat.com/browse/RHEL-71880 is fixed
# Because of the bug above Anaconda is not able to detect keyboard layout changed by the
# keyboard shortcuts, however, layouts will change. To avoid confusion of users
# let's rather disable this feature completely.
if conf.system.supports_compositor_keyboard_layout_shortcut is not True:
log.debug("Keyboard layout switching from shortcut is broken in compositor. "
"Filter these out from the options: '%s'.", options)
options = list(filter(lambda x: not x.startswith("grp:"), options))

# store configuration from user
super().set_layouts(layouts_variants, options, convert)
Expand Down
5 changes: 5 additions & 0 deletions pyanaconda/ui/gui/spokes/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from pyanaconda import flags, keyboard
from pyanaconda.anaconda_loggers import get_module_logger
from pyanaconda.core.configuration.anaconda import conf
from pyanaconda.core.constants import (
DEFAULT_KEYBOARD,
THREAD_ADD_LAYOUTS_INIT,
Expand Down Expand Up @@ -502,6 +503,10 @@ def _refresh_switching_info(self):
"supported when using RDP.\n"
"However the settings will be used "
"after the installation."))
elif not conf.system.supports_compositor_keyboard_layout_shortcut:
self._layoutSwitchLabel.set_text(_("Keyboard layouts switching by "
"keyboard shortcuts is not supported "
"right now."))
elif switch_options:
first_option = switch_options[0]
desc = self._xkl_wrapper.get_switch_opt_description(first_option)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def test_compositor_localed_wrapper_properties(
"""Test conversion of return values from Localed service to CompositorLocaledWraper."""
mocked_system_bus.check_connection.return_value = True
mocked_conf.system.provides_system_bus = True
mocked_conf.system.supports_compositor_keyboard_layout_shortcut = True
mocked_localed_proxy = Mock()
mocked_localed_service.get_proxy.return_value = mocked_localed_proxy
localed_wrapper = CompositorLocaledWrapper()
Expand Down Expand Up @@ -204,12 +205,15 @@ def test_compositor_localed_wrapper_safe_calls(
"""Test calling CopmositorLocaledWrapper with invalid values does not raise exception."""
mocked_system_bus.check_connection.return_value = True
mocked_conf.system.provides_system_bus = True
mocked_conf.system.supports_compositor_keyboard_layout_shortcut = True
mocked_localed_proxy = Mock()
mocked_localed_service.get_proxy.return_value = mocked_localed_proxy
mocked_localed_proxy.VConsoleKeymap = "cz"
mocked_localed_proxy.X11Layout = "cz,fi,us,fr"
mocked_localed_proxy.X11Variant = "qwerty,,euro"
mocked_localed_proxy.X11Options = "grp:alt_shift_toggle,grp:ctrl_alt_toggle"
mocked_localed_proxy.X11Options = (
"eurosign:2,grp:alt_shift_toggle,grp:ctrl_alt_toggle,grp_led:caps"
)
localed_wrapper = CompositorLocaledWrapper()
# valid values
localed_wrapper.set_layouts(["cz (qwerty)", "us (euro)"],
Expand All @@ -223,14 +227,14 @@ def test_compositor_localed_wrapper_safe_calls(
localed_wrapper.set_layouts(["cz", "us (euro)"])
assert localed_wrapper._user_layouts_variants == ["cz", "us (euro)"]

# test set_layout on proxy with options
# test set_layout on proxy without options
mocked_localed_proxy.SetX11Keyboard.reset_mock()
localed_wrapper.set_layouts(["cz (qwerty)", "us"])
mocked_localed_proxy.SetX11Keyboard.assert_called_once_with(
"cz,us",
"pc105", # hardcoded
"qwerty,",
"grp:alt_shift_toggle,grp:ctrl_alt_toggle", # options will be reused what is set
"eurosign:2,grp:alt_shift_toggle,grp:ctrl_alt_toggle,grp_led:caps",
False,
False
)
Expand All @@ -242,13 +246,40 @@ def test_compositor_localed_wrapper_safe_calls(
"cz,us",
"pc105", # hardcoded
"qwerty,",
"grp:alt_shift_toggle,grp:ctrl_alt_toggle", # options will be reused what is set
"eurosign:2,grp:alt_shift_toggle,grp:ctrl_alt_toggle,grp_led:caps",
False,
False
)

# test set_layout on proxy when shortcut layout switching is broken
# TODO: Remove when https://issues.redhat.com/browse/RHEL-71880 is fixed
mocked_localed_proxy.SetX11Keyboard.reset_mock()
localed_wrapper.set_layouts(["us"], "", True)
mocked_conf.system.supports_compositor_keyboard_layout_shortcut = False
localed_wrapper.set_layouts(["cz (qwerty)", "us"], options=None)
mocked_localed_proxy.SetX11Keyboard.assert_called_once_with(
"cz,us",
"pc105", # hardcoded
"qwerty,",
"eurosign:2,grp_led:caps", # Remove after fix of RHEL-71880
False,
False
)

# test set_layout on proxy when layout switching is broken and options are specified
mocked_localed_proxy.SetX11Keyboard.reset_mock()
localed_wrapper.set_layouts(["us"], options=("grp:ctrl_alt_toggle", "grp_led:caps"))
mocked_localed_proxy.SetX11Keyboard.assert_called_once_with(
"us",
"pc105", # hardcoded
"",
"grp_led:caps",
False,
False
)

# test set_layout on proxy when layout switching is broken and options are empty
mocked_localed_proxy.SetX11Keyboard.reset_mock()
localed_wrapper.set_layouts(["us"], options="", convert=True)
mocked_localed_proxy.SetX11Keyboard.assert_called_once_with(
"us",
"pc105", # hardcoded
Expand All @@ -272,6 +303,7 @@ def test_compositor_localed_wrapper_set_next_layout(
"""
mocked_system_bus.check_connection.return_value = True
mocked_conf.system.provides_system_bus = True
mocked_conf.system.supports_compositor_keyboard_layout_shortcut = True
mocked_localed_proxy = Mock()
mocked_localed_service.get_proxy.return_value = mocked_localed_proxy
# currently selected is first in this list 'cz (qwerty)'
Expand Down Expand Up @@ -397,6 +429,7 @@ def test_compositor_localed_wrapper_set_current_layout(
"""
mocked_system_bus.check_connection.return_value = True
mocked_conf.system.provides_system_bus = True
mocked_conf.system.supports_compositor_keyboard_layout_shortcut = True
mocked_localed_proxy = Mock()
mocked_localed_service.get_proxy.return_value = mocked_localed_proxy
mocked_localed_proxy.X11Layout = "cz,fi,us,fr"
Expand Down Expand Up @@ -493,6 +526,7 @@ def test_compositor_localed_wrapper_signals(self, mocked_conf,
"""
mocked_system_bus.check_connection.return_value = True
mocked_conf.system.provides_system_bus = True
mocked_conf.system.supports_compositor_keyboard_layout_shortcut = True
mocked_localed_proxy = Mock()
mocked_localed_proxy.PropertiesChanged = Signal()
mocked_localed_service.get_proxy.return_value = mocked_localed_proxy
Expand All @@ -511,8 +545,9 @@ def _check_localed_wrapper_signals(last_known_state, compositor_state,
:type last_known_state: [(str,str)] e.g.:[('cz', 'qwerty'), ('us','')...]
:param compositor_state: New state the compositor will get into.
:type compositor_state: {str: str} e.g.: {"X11Layout": "cz", "X11Variant": "qwerty"}
:param expected_selected_signal: Currently selected layout we expect CompositorLocaledWrapper
will signal out. If signal shouldn't set None.
:param expected_selected_signal: Currently selected layout we expect
CompositorLocaledWrapper will signal out. Set None if
no signal is expected to be called.
:type expected_selected_signal: str
:param expected_layouts_signal: Current configuration of the compositor signaled from
CompositorLocaledWrapper.
Expand Down

0 comments on commit 6352cff

Please sign in to comment.