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

[WINDOW_MANAGER] Adds display server protocol to entry #145

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 29 additions & 3 deletions archey/entries/window_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Windows manager detection class"""

import os
import platform
import re
from subprocess import DEVNULL, CalledProcessError, check_output
Expand Down Expand Up @@ -47,6 +48,11 @@
"yabai": "Yabai",
}

DSP_DICT = {
"x11": "X11",
"wayland": "Wayland",
}


class WindowManager(Entry):
"""
Expand All @@ -59,17 +65,37 @@ 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)
except (FileNotFoundError, CalledProcessError):
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)
14 changes: 10 additions & 4 deletions archey/test/entries/test_archey_window_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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"]
)
Expand Down