mirror of
https://github.com/HorlogeSkynet/archey4
synced 2025-04-30 04:00:16 +02:00
[WINDOW_MANAGER] Adds display server protocol to entry
Co-Authored-By: Tobilike <80016610+Tobilike@users.noreply.github.com>
This commit is contained in:
parent
7da714b0ba
commit
d3a08e6ff0
@ -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
|
||||
|
@ -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 @@ WM_DICT = {
|
||||
"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 @@ class WindowManager(Entry):
|
||||
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)
|
||||
|
@ -30,7 +30,7 @@ Window manager's "showing the desktop" mode: OFF
|
||||
)
|
||||
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 @@ Window manager's "showing the desktop" mode: OFF
|
||||
"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 @@ Window manager's "showing the desktop" mode: OFF
|
||||
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"]
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user