1
0
mirror of https://github.com/HorlogeSkynet/archey4 synced 2025-05-09 20:00:11 +02:00

Merge remote-tracking branch 'origin/master' into Icons

This commit is contained in:
Samuel FORESTIER 2024-01-13 17:55:53 +01:00
commit b4a6e6299f
4 changed files with 42 additions and 8 deletions

@ -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

@ -449,7 +449,7 @@ Below stand further descriptions for each available (default) option :
// A custom program and its arguments to execute.
"shell": false,
"command": ["echo", "My super GPU model !"],
// Whether or not command exit status code should be ignored (defaults to `true`).
// Whether or not command exit status code should be checked (defaults to `true`).
"check": true,
// Whether or not STDERR should be silenced instead of logged (defaults to `true`).
"log_stderr": true,

@ -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):
"""
@ -60,8 +66,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)
@ -69,8 +76,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"]
)