Skip to content

Commit

Permalink
Remove Wayland detection logic from code
Browse files Browse the repository at this point in the history
This logic was used to disable keyboard switching for given system.
However, we we support even Wayland systems with the new solution, so
let's remove this.
  • Loading branch information
jkonecny12 committed Sep 10, 2024
1 parent 20c4748 commit 992d8b9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 81 deletions.
1 change: 0 additions & 1 deletion anaconda.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ BuildRequires: desktop-file-utils
# live installation currently implies a graphical installation
Requires: anaconda-gui = %{version}-%{release}
Requires: zenity
Requires: xisxwayland
Recommends: xhost

%description live
Expand Down
5 changes: 0 additions & 5 deletions pyanaconda/core/configuration/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ def can_configure_keyboard(self):
"""Can we configure the keyboard?"""
return self._is_boot_iso or self._is_live_os or self._is_booted_os

@property
def can_run_on_xwayland(self):
"""Could we run on XWayland?"""
return self._is_live_os

@property
def can_modify_syslog(self):
"""Can we modify syslog?"""
Expand Down
43 changes: 5 additions & 38 deletions pyanaconda/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from pyanaconda.core.configuration.anaconda import conf
from pyanaconda import localization
from pyanaconda.core.constants import DEFAULT_KEYBOARD
from pyanaconda.core.util import execWithRedirect
from pyanaconda.modules.common.task import sync_run_task
from pyanaconda.modules.common.constants.services import LOCALIZATION

Expand Down Expand Up @@ -56,47 +55,15 @@ class InvalidLayoutVariantSpec(Exception):
pass


def _is_xwayland():
"""Is Anaconda running in XWayland environment?
This can't be easily detected from the Anaconda because Anaconda
is running as XWayland app. Use xisxwayland tool for the detection.
"""
try:
rc = execWithRedirect('xisxwayland', [])

if rc == 0:
return True

log.debug(
"Anaconda doesn't run on XWayland. "
"See xisxwayland --help for more info."
)
except FileNotFoundError:
log.warning(
"The xisxwayland tool is not available! "
"Taking the environment as not Wayland."
)

return False


def can_configure_keyboard():
"""Can we configure the keyboard?
FIXME: This is a temporary solution.
The is_wayland logic is not part of the configuration so we would
have to add it to the configuration otherwise it won't be accessible
in the Anaconda modules.
NOTE:
This function could be inlined, however, this give us a possibility for future limitation
when needed. For example we could use this method to limit keyboard configuration if we
are able to detect that current system doesn't support localed keyboard layout switching.
"""
if not conf.system.can_configure_keyboard:
return False

if conf.system.can_run_on_xwayland and _is_xwayland():
return False

return True
return conf.system.can_configure_keyboard


def parse_layout_variant(layout_variant_str):
Expand Down
38 changes: 1 addition & 37 deletions tests/unit_tests/pyanaconda_tests/test_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,51 +26,15 @@ class KeyboardUtilsTestCase(unittest.TestCase):
"""Test the keyboard utils."""

@patch("pyanaconda.keyboard.conf")
@patch("pyanaconda.keyboard.execWithRedirect")
def test_can_configure_keyboard(self, exec_mock, conf_mock):
def test_can_configure_keyboard(self, conf_mock):
"""Check if the keyboard configuration is enabled or disabled."""
# It's a dir installation.
conf_mock.system.can_configure_keyboard = False
conf_mock.system.can_run_on_xwayland = False
assert keyboard.can_configure_keyboard() is False
exec_mock.assert_not_called()

# It's a boot.iso.
conf_mock.system.can_configure_keyboard = True
conf_mock.system.can_run_on_xwayland = False
assert keyboard.can_configure_keyboard() is True
exec_mock.assert_not_called()

# It's a Live installation on Wayland.
conf_mock.system.can_configure_keyboard = True
conf_mock.system.can_run_on_xwayland = True
exec_mock.return_value = 0
assert keyboard.can_configure_keyboard() is False
exec_mock.assert_called_once_with('xisxwayland', [])
exec_mock.reset_mock()

# It's a Live installation and not on Wayland.
conf_mock.system.can_configure_keyboard = True
conf_mock.system.can_run_on_xwayland = True
exec_mock.return_value = 1 # xisxwayland returns 1 if it is not XWayland
assert keyboard.can_configure_keyboard() is True
exec_mock.assert_called_once_with('xisxwayland', [])
exec_mock.reset_mock()

# It's a Live installation and probably not on Wayland,
# because the xisxwayland tooling is not present.
conf_mock.system.can_configure_keyboard = True
conf_mock.system.can_run_on_xwayland = True
exec_mock.side_effect = FileNotFoundError()

with self.assertLogs(level="WARNING") as cm:
keyboard.can_configure_keyboard()

msg = "The xisxwayland tool is not available!"
assert any(map(lambda x: msg in x, cm.output))

exec_mock.assert_called_once_with('xisxwayland', [])
exec_mock.reset_mock()


class ParsingAndJoiningTests(unittest.TestCase):
Expand Down

0 comments on commit 992d8b9

Please sign in to comment.