diff --git a/CHANGELOG.md b/CHANGELOG.md index 404d9e3b..8aa01c8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,11 @@ and this project (partially) adheres to [Semantic Versioning](https://semver.org ## [Unreleased] ### Added - Official EndeavourOS distribution support +- Display server protocol to `WindowManager` ### Changed - Allow `df` output to contain Unicode characters +- `WindowManager` API value format: now an object with `name` and `display_server_protocol` attributes ## [v4.14.2.0] - 2023-08-26 ### Added diff --git a/archey/entries/window_manager.py b/archey/entries/window_manager.py index c62ba307..77e16630 100644 --- a/archey/entries/window_manager.py +++ b/archey/entries/window_manager.py @@ -1,5 +1,6 @@ """Windows manager detection class""" +import os import platform import re from subprocess import DEVNULL, CalledProcessError, check_output @@ -47,6 +48,11 @@ "yabai": "Yabai", } +DSP_DICT = { + "x11": "X11", + "wayland": "Wayland", +} + class WindowManager(Entry): """ @@ -59,8 +65,9 @@ class WindowManager(Entry): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + name = None try: - self.value = re.search( # type: ignore + name = re.search( # type: ignore r"(?<=Name: ).*", check_output(["wmctrl", "-m"], stderr=DEVNULL, universal_newlines=True), ).group(0) @@ -68,8 +75,27 @@ def __init__(self, *args, **kwargs): processes = Processes().list for wm_id, wm_name in WM_DICT.items(): if wm_id in processes: - self.value = wm_name + name = wm_name break else: if platform.system() == "Darwin": - self.value = "Quartz Compositor" + name = "Quartz Compositor" + + display_server_protocol = DSP_DICT.get(os.getenv("XDG_SESSION_TYPE", "")) + + self.value = { + "name": name, + "display_server_protocol": display_server_protocol, + } + + def output(self, output) -> None: + # No WM could be detected. + if self.value["name"] is None: + output.append(self.name, self._default_strings.get("not_detected")) + return + + text_output = self.value["name"] + if self.value["display_server_protocol"] is not None: + text_output += f" ({self.value['display_server_protocol']})" + + output.append(self.name, text_output) diff --git a/archey/test/entries/test_archey_window_manager.py b/archey/test/entries/test_archey_window_manager.py index 89384454..4fb9d49f 100644 --- a/archey/test/entries/test_archey_window_manager.py +++ b/archey/test/entries/test_archey_window_manager.py @@ -30,7 +30,7 @@ class TestWindowManagerEntry(unittest.TestCase): ) def test_wmctrl(self, _, __): """Test `wmctrl` output parsing""" - self.assertEqual(WindowManager().value, "WINDOW MANAGER") + self.assertEqual(WindowManager().value["name"], "WINDOW MANAGER") @patch( "archey.entries.window_manager.check_output", @@ -46,9 +46,15 @@ def test_wmctrl(self, _, __): "here", ), ) - def test_no_wmctrl_match(self, _, __): + @patch( + "archey.entries.desktop_environment.os.getenv", + return_value="wayland", + ) + def test_no_wmctrl_match(self, _, __, ___): """Test basic detection based on a (fake) processes list""" - self.assertEqual(WindowManager().value, "Awesome") + window_manager = WindowManager() + self.assertEqual(window_manager.value["name"], "Awesome") + self.assertEqual(window_manager.value["display_server_protocol"], "Wayland") @patch( "archey.entries.window_manager.check_output", @@ -72,7 +78,7 @@ def test_no_wmctrl_mismatch(self, _, __): output_mock = MagicMock() window_manager.output(output_mock) - self.assertIsNone(window_manager.value) + self.assertIsNone(window_manager.value["name"]) self.assertEqual( output_mock.append.call_args[0][1], DEFAULT_CONFIG["default_strings"]["not_detected"] )