510 lines
24 KiB
Python
510 lines
24 KiB
Python
import random
|
|
import unittest
|
|
import xml.etree.ElementTree as ET
|
|
from pathlib import Path
|
|
from tempfile import TemporaryDirectory
|
|
from unittest.mock import patch
|
|
|
|
from wallpaper_changer.argument_parser import parse_args
|
|
from wallpaper_changer.config import Config
|
|
from wallpaper_changer.monitor_manager import Monitor, MonitorManager, ScreenLayout
|
|
|
|
|
|
class MonitorManagerTests(unittest.TestCase):
|
|
def setUp(self) -> None:
|
|
environment = patch.dict(
|
|
"os.environ", {"XDG_SESSION_TYPE": "wayland", "XDG_CURRENT_DESKTOP": "ubuntu:GNOME"}
|
|
)
|
|
environment.start()
|
|
self.addCleanup(environment.stop)
|
|
output_patch = patch(
|
|
"wallpaper_changer.monitor_manager.subprocess.check_output",
|
|
return_value=GNOME_DISPLAY_STATE,
|
|
)
|
|
self.check_output = output_patch.start()
|
|
self.addCleanup(output_patch.stop)
|
|
|
|
def parse_args(self, *arguments: str):
|
|
return parse_args(list(arguments))
|
|
|
|
def test_screen_layout_properties(self) -> None:
|
|
"""Verify monitor count and combined aspect ratio for a layout."""
|
|
for max_monitors in range(1, 5):
|
|
x_coord = 0
|
|
layout_monitors = []
|
|
for _ in range(max_monitors):
|
|
layout_monitors.append(Monitor(1920, 1080, x_coord,set("TestMon")))
|
|
x_coord+=1920
|
|
monitors = ScreenLayout(tuple(layout_monitors))
|
|
self.assertEqual(monitors.monitor_count, max_monitors)
|
|
self.assertEqual(monitors.screen_aspect_ratio, max_monitors * 1920 / 1080)
|
|
x_coord=0
|
|
for monitor in monitors.monitors:
|
|
self.assertEqual(monitor.width, 1920)
|
|
self.assertEqual(monitor.height, 1080)
|
|
self.assertEqual(monitor.x_coord, x_coord)
|
|
x_coord+=1920
|
|
|
|
def test_headless_mode_reads_correct_config(self) -> None:
|
|
"""Verify server dimensions load from the default monitor config."""
|
|
assets = Path(__file__).resolve().parents[4] / "testassets" / "wallpaper_changer"
|
|
args = self.parse_args("--headless")
|
|
config = Config.load(args)
|
|
for file in (assets/"monitors").glob("monitors_[1-3]mon.xml"):
|
|
monitors = MonitorManager().get_screensize(config.headless_mode,
|
|
file)
|
|
monitor_number = int(file.name.split("_")[1].replace("mon.xml", ""))
|
|
self.assertEqual(monitors.monitor_count, monitor_number)
|
|
self.assertEqual(monitors.screen_aspect_ratio, monitor_number * 1920 / 1080)
|
|
x_coord=0
|
|
for monitor in monitors.monitors:
|
|
self.assertEqual(monitor.width, 1920)
|
|
self.assertEqual(monitor.height, 1080)
|
|
self.assertEqual(monitor.x_coord, x_coord)
|
|
x_coord+=1920
|
|
|
|
def test_monitor_manager_uses_correct_config(self) -> None:
|
|
"""Verify incomplete, non-positive, or inconsistent dimensions are rejected."""
|
|
assets = Path(__file__).resolve().parents[4] / "testassets" / "wallpaper_changer"
|
|
args = self.parse_args()
|
|
config = Config.load(args)
|
|
file = assets / "monitors" / "monitors_2mon.xml"
|
|
with TemporaryDirectory() as temporary_directory:
|
|
drm_root = Path(temporary_directory)
|
|
cards = ["card1-HDMI-A-1", "card1-eDP-1"]
|
|
create_drm_root(drm_root,cards)
|
|
monitors = MonitorManager().get_screensize(config.headless_mode,file,
|
|
drm_root=drm_root)
|
|
self.assertEqual(monitors.monitor_count, 2)
|
|
self.assertEqual(monitors.screen_aspect_ratio, 2 * 1920 / 1080)
|
|
x_coord=0
|
|
for monitor in monitors.monitors:
|
|
self.assertEqual(monitor.width, 1920)
|
|
self.assertEqual(monitor.height, 1080)
|
|
self.assertEqual(monitor.x_coord, x_coord)
|
|
x_coord+=1920
|
|
|
|
def test_monitor_manager_rejects_config_with_too_many_monitors(self) -> None:
|
|
"""Verify incomplete, non-positive, or inconsistent dimensions are rejected."""
|
|
assets = Path(__file__).resolve().parents[4] / "testassets" / "wallpaper_changer"
|
|
monitor_file = assets / "monitors" / "monitors_3mon.xml"
|
|
with TemporaryDirectory() as temporary_directory, \
|
|
self.assertRaisesRegex(RuntimeError, "No matching monitor configuration found"):
|
|
drm_root = Path(temporary_directory)
|
|
cards = ["card1-HDMI-A-1", "card1-eDP-1"]
|
|
create_drm_root(drm_root,cards)
|
|
MonitorManager().get_screensize(
|
|
False,
|
|
monitor_file,
|
|
drm_root=drm_root
|
|
)
|
|
|
|
def test_monitor_manager_uses_correct_config_with_multi_monitor_config_xml(self) -> None:
|
|
"""Verify incomplete, non-positive, or inconsistent dimensions are rejected."""
|
|
assets = Path(__file__).resolve().parents[4] / "testassets" / "wallpaper_changer"
|
|
args = self.parse_args()
|
|
config = Config.load(args)
|
|
file = assets / "monitors" / "monitors_all.xml"
|
|
with TemporaryDirectory() as temporary_directory:
|
|
drm_root = Path(temporary_directory)
|
|
cards = ["card1-HDMI-A-1", "card1-eDP-1"]
|
|
create_drm_root(drm_root,cards)
|
|
monitors = MonitorManager().get_screensize(config.headless_mode,file,
|
|
drm_root=drm_root)
|
|
self.assertEqual(monitors.monitor_count, 2)
|
|
self.assertEqual(monitors.screen_aspect_ratio, 2 * 1920 / 1080)
|
|
x_coord=0
|
|
for monitor in monitors.monitors:
|
|
self.assertEqual(monitor.width, 1920)
|
|
self.assertEqual(monitor.height, 1080)
|
|
self.assertEqual(monitor.x_coord, x_coord)
|
|
x_coord+=1920
|
|
|
|
def test_server_layout_rejects_missing_or_invalid_dimensions(self) -> None:
|
|
"""Verify incomplete, non-positive, or inconsistent dimensions are rejected."""
|
|
with TemporaryDirectory() as temporary_directory:
|
|
monitor_file = Path(__file__).resolve().parents[4] / "testassets" / "wallpaper_changer" / "monitors" / "monitors_2mon.xml"
|
|
args = self.parse_args()
|
|
config = Config.load(args)
|
|
|
|
for file in create_faulty_xmls(monitor_file, Path(temporary_directory)):
|
|
with TemporaryDirectory() as temporary_directory:
|
|
drm_root = Path(temporary_directory)
|
|
cards = ["card1-HDMI-A-1","card1-eDP-1"]
|
|
create_drm_root(drm_root,cards)
|
|
field = file.stem.rsplit("_", 3)[1]
|
|
if file.name.endswith("_empty.xml") and field != "y":
|
|
with self.assertRaisesRegex(ValueError, f"Missing <{field}>"):
|
|
MonitorManager().get_screensize(
|
|
config.headless_mode,
|
|
file,
|
|
drm_root=drm_root,
|
|
)
|
|
elif field in {"width", "height"}:
|
|
with self.assertRaisesRegex(
|
|
RuntimeError,
|
|
f"No matching monitor configuration found in {file}",
|
|
):
|
|
MonitorManager().get_screensize(
|
|
config.headless_mode,
|
|
file,
|
|
drm_root=drm_root,
|
|
)
|
|
else:
|
|
monitors = MonitorManager().get_screensize(
|
|
config.headless_mode,
|
|
file,
|
|
drm_root=drm_root,
|
|
)
|
|
self.assertEqual(monitors.monitor_count, 2)
|
|
|
|
# import tkinter as tk
|
|
|
|
#def test_detect_single_connected_monitor_actual_monitor(self) -> None:
|
|
# """Verify a single enabled connector produces a one-monitor layout."""
|
|
# args = self.parse_args()
|
|
# config = Config.load(args)
|
|
# monitors = MonitorManager().get_screensize(
|
|
# config.headless_mode,
|
|
# config.monitor_file,
|
|
# )
|
|
# root = tk.Tk()
|
|
# width = root.winfo_screenwidth()
|
|
# height = root.winfo_screenheight()
|
|
# self.assertEqual(monitors.monitor_count, 1)
|
|
# self.assertEqual(monitors.screen_aspect_ratio, width / height)
|
|
# self.assertEqual(monitors.monitors[0].width, width)
|
|
# self.assertEqual(monitors.monitors[0].height, height)
|
|
# self.assertEqual(monitors.monitors[0].x_coord, 0)
|
|
|
|
def test_detect_single_connected_monitor_patched_monitor(self) -> None:
|
|
"""Verify one enabled connector reports its virtual 1920x1080 size."""
|
|
assets = Path(__file__).resolve().parents[4] / "testassets" / "wallpaper_changer"
|
|
monitor_file = assets / "monitors" / "monitors_1mon.xml"
|
|
|
|
with TemporaryDirectory() as temporary_directory:
|
|
drm_root = Path(temporary_directory)
|
|
cards = ["card1-eDP-1"]
|
|
create_drm_root(drm_root,cards)
|
|
|
|
monitors = MonitorManager().get_screensize(
|
|
False,
|
|
monitor_file,
|
|
drm_root=drm_root,
|
|
)
|
|
|
|
self.assertEqual(monitors.monitor_count, 1)
|
|
self.assertEqual(monitors.screen_aspect_ratio, 1920 / 1080)
|
|
self.assertEqual(monitors.monitors[0].width, 1920)
|
|
self.assertEqual(monitors.monitors[0].height, 1080)
|
|
self.assertEqual(monitors.monitors[0].x_coord, 0)
|
|
|
|
def test_read_virtual_size_uses_current_gnome_mode(self) -> None:
|
|
"""Verify the active mode is selected from GNOME display state."""
|
|
size = MonitorManager._read_virtual_size_gnome(Path("card1-HDMI-A-2"))
|
|
|
|
self.assertEqual(size, (1920, 1080))
|
|
self.check_output.assert_called_once_with(
|
|
[
|
|
"gdbus",
|
|
"call",
|
|
"--session",
|
|
"--dest",
|
|
"org.gnome.Mutter.DisplayConfig",
|
|
"--object-path",
|
|
"/org/gnome/Mutter/DisplayConfig",
|
|
"--method",
|
|
"org.gnome.Mutter.DisplayConfig.GetCurrentState",
|
|
],
|
|
text=True,
|
|
)
|
|
|
|
def test_read_virtual_size_from_gdbus_captures(self) -> None:
|
|
assets = Path(__file__).resolve().parents[4] / "testassets" / "wallpaper_changer" / "monitors"
|
|
for filename, connector, expected in (
|
|
("gbus_call1.txt", "card1-eDP-1", (1920, 1080)),
|
|
("gbus_call2.txt", "card1-HDMI-A-1", (1920, 1080)),
|
|
):
|
|
with self.subTest(filename=filename):
|
|
self.check_output.return_value = (assets / filename).read_text()
|
|
self.assertEqual(MonitorManager._read_virtual_size_gnome(Path(connector)), expected)
|
|
|
|
def test_read_virtual_size_from_xrandr_captures(self) -> None:
|
|
assets = Path(__file__).resolve().parents[4] / "testassets" / "wallpaper_changer" / "monitors"
|
|
for filename, connector in (
|
|
("xrandr1.txt", "card0-HDMI-A-0"),
|
|
("xrandr2.txt", "card1-HDMI-A-1"),
|
|
("xrandr3.txt", "card1-eDP-1"),
|
|
):
|
|
with self.subTest(filename=filename):
|
|
self.check_output.return_value = (assets / filename).read_text()
|
|
self.check_output.reset_mock()
|
|
self.assertEqual(MonitorManager._read_virtual_size_x11(Path(connector)), (1920, 1080))
|
|
self.check_output.assert_called_once_with(["xrandr", "--query"], text=True)
|
|
|
|
def test_xrandr_does_not_use_another_connectors_mode(self) -> None:
|
|
self.check_output.return_value = (
|
|
"HDMI-1 connected\n 1920x1080 60.00+\n"
|
|
"HDMI-2 connected 1280x720+0+0\n 1280x720 60.00*+\n"
|
|
)
|
|
self.assertEqual(MonitorManager._read_virtual_size_x11(Path("card1-HDMI-A-2")), (1280, 720))
|
|
with self.assertRaisesRegex(RuntimeError, "No current X11 display mode.*HDMI-1"):
|
|
MonitorManager._read_virtual_size_x11(Path("card1-HDMI-A-1"))
|
|
with self.assertRaisesRegex(RuntimeError, "No current X11 display mode.*HDMI-3"):
|
|
MonitorManager._read_virtual_size_x11(Path("card1-HDMI-A-3"))
|
|
|
|
def test_x11_session_uses_xrandr_for_layout(self) -> None:
|
|
assets = Path(__file__).resolve().parents[4] / "testassets" / "wallpaper_changer" / "monitors"
|
|
self.check_output.return_value = (assets / "xrandr3.txt").read_text()
|
|
with TemporaryDirectory() as temporary_directory, \
|
|
patch.dict("os.environ", {"XDG_SESSION_TYPE": "x11"}):
|
|
drm_root = Path(temporary_directory)
|
|
create_drm_root(drm_root, ["card1-eDP-1"])
|
|
layout = MonitorManager().get_screensize(
|
|
False, assets / "monitors_1mon.xml", drm_root=drm_root, lid_state=""
|
|
)
|
|
self.assertEqual((layout.monitors[0].width, layout.monitors[0].height), (1920, 1080))
|
|
self.check_output.assert_called_once_with(["xrandr", "--query"], text=True)
|
|
|
|
def test_selects_display_backend_by_session_type(self) -> None:
|
|
monitor_file = Path(__file__).resolve().parents[4] / "testassets" / "wallpaper_changer" / "monitors" / "monitors_1mon.xml"
|
|
with TemporaryDirectory() as temporary_directory:
|
|
drm_root = Path(temporary_directory)
|
|
create_drm_root(drm_root, ["card1-eDP-1"])
|
|
connector = drm_root / "card1-eDP-1"
|
|
for session, desktop, selected in (
|
|
("x11", "GNOME", "_read_virtual_size_x11"),
|
|
("wayland", "ubuntu:GNOME", "_read_virtual_size_gnome"),
|
|
):
|
|
with self.subTest(session=session), \
|
|
patch.dict("os.environ", {"XDG_SESSION_TYPE": session, "XDG_CURRENT_DESKTOP": desktop}), \
|
|
patch.object(MonitorManager, "_read_virtual_size_x11", return_value=(1920, 1080)) as x11, \
|
|
patch.object(MonitorManager, "_read_virtual_size_gnome", return_value=(1920, 1080)) as gnome:
|
|
MonitorManager().get_screensize(False, monitor_file, drm_root=drm_root, lid_state="")
|
|
if selected == "_read_virtual_size_x11":
|
|
x11.assert_called_once_with(connector)
|
|
gnome.assert_not_called()
|
|
else:
|
|
gnome.assert_called_once_with(connector)
|
|
x11.assert_not_called()
|
|
|
|
with patch.dict("os.environ", {"XDG_SESSION_TYPE": "wayland", "XDG_CURRENT_DESKTOP": "KDE"}), \
|
|
self.assertRaisesRegex(RuntimeError, "Unsupported graphical session"):
|
|
MonitorManager().get_screensize(False, monitor_file, drm_root=drm_root, lid_state="")
|
|
|
|
def test_detect_multiple_monitors_from_xml_layout(self) -> None:
|
|
"""Verify two or more connected monitors map to their XML positions and sizes."""
|
|
assets = Path(__file__).resolve().parents[4] / "testassets" / "wallpaper_changer"
|
|
monitor_file = assets / "monitors" / "monitors_3mon.xml"
|
|
|
|
with TemporaryDirectory() as temporary_directory:
|
|
drm_root = Path(temporary_directory)
|
|
cards = ["card1-HDMI-A-1", "card1-HDMI-A-2", "card1-eDP-1"]
|
|
create_drm_root(drm_root,cards)
|
|
|
|
monitors = MonitorManager().get_screensize(
|
|
False,
|
|
monitor_file,
|
|
drm_root=drm_root,
|
|
)
|
|
|
|
self.assertEqual(monitors.monitor_count, 3)
|
|
self.assertEqual(monitors.screen_aspect_ratio, 3*1920 / 1080)
|
|
x=0
|
|
for monitor in monitors.monitors:
|
|
self.assertEqual(monitor.width, 1920)
|
|
self.assertEqual(monitor.height, 1080)
|
|
self.assertEqual(monitor.x_coord, x)
|
|
x+=1920
|
|
|
|
def test_ignore_disconnected_and_disabled_connectors(self) -> None:
|
|
"""Verify disconnected or disabled displays are excluded from layouts."""
|
|
with TemporaryDirectory() as temporary_directory:
|
|
drm_root = Path(temporary_directory)
|
|
cards = ["card1-HDMI-A-1", "card1-HDMI-A-2", "card1-eDP-1"]
|
|
stati = ["enabled", "disabled", "disabled"]
|
|
connections = ["connected", "disconnected", "disconnected"]
|
|
|
|
create_drm_root(drm_root,cards,stati,connections)
|
|
|
|
drm_connectors = MonitorManager()._connected_drm_connectors(drm_root,"")
|
|
self.assertEqual(len(drm_connectors),1)
|
|
|
|
def test_laptop_monitor_respects_lid_state_open(self) -> None:
|
|
"""Verify the internal display is included only when the lid is open."""
|
|
with TemporaryDirectory() as temporary_directory:
|
|
drm_root = Path(temporary_directory)
|
|
cards = ["card1-HDMI-A-1", "card1-eDP-1"]
|
|
|
|
lid_state_path_str = temporary_directory + "/proc/acpi/button/lid/LID*/state"
|
|
create_drm_root(drm_root,cards,lid_state_path_str=lid_state_path_str)
|
|
drm_connectors = MonitorManager()._connected_drm_connectors(drm_root,lid_state_path_str)
|
|
self.assertEqual(len(drm_connectors),2)
|
|
|
|
def test_laptop_monitor_respects_lid_state_closed(self) -> None:
|
|
"""Verify the internal display is included only when the lid is open."""
|
|
with TemporaryDirectory() as temporary_directory:
|
|
drm_root = Path(temporary_directory)
|
|
cards = ["card1-HDMI-A-1", "card1-eDP-1"]
|
|
|
|
lid_state_path_str = temporary_directory + "/proc/acpi/button/lid/LID*/state"
|
|
create_drm_root(drm_root,cards,
|
|
lid_state_path_str=lid_state_path_str, lid_state="Closed")
|
|
|
|
drm_connectors = MonitorManager()._connected_drm_connectors(drm_root,lid_state_path_str)
|
|
self.assertEqual(len(drm_connectors),1)
|
|
|
|
def test_reject_no_enabled_monitors(self) -> None:
|
|
"""Verify no active displays raises an error."""
|
|
with TemporaryDirectory() as temporary_directory, \
|
|
self.assertRaisesRegex(RuntimeError, "No enabled monitors found"):
|
|
assets = Path(__file__).resolve().parents[4] / "testassets" / "wallpaper_changer"
|
|
monitor_file = assets / "monitors" / "monitors_all.xml"
|
|
drm_root = Path(temporary_directory)
|
|
|
|
cards = ["card1-HDMI-A-1", "card1-HDMI-A-2", "card1-eDP-1"]
|
|
stati = ["disabled", "disabled", "enabled"]
|
|
connections = ["disconnected", "disconnected", "connected"]
|
|
lid_state_path_str = temporary_directory + "/proc/acpi/button/lid/LID*/state"
|
|
create_drm_root(drm_root,cards,stati,connections,lid_state_path_str,"Closed")
|
|
MonitorManager().get_screensize(
|
|
False,
|
|
monitor_file,
|
|
drm_root=drm_root,
|
|
lid_state=lid_state_path_str,
|
|
)
|
|
|
|
def test_reject_unmatched_monitor_configuration(self) -> None:
|
|
"""Verify active displays without a matching XML layout raise an error."""
|
|
assets = Path(__file__).resolve().parents[4] / "testassets" / "wallpaper_changer"
|
|
monitor_file = assets / "monitors" / "monitors_3mon.xml"
|
|
with TemporaryDirectory() as temporary_directory, \
|
|
self.assertRaisesRegex(RuntimeError, "No matching monitor configuration found"):
|
|
drm_root = Path(temporary_directory)
|
|
cards = ["card1-HDMI-A-1","card1-eDP-1"]
|
|
create_drm_root(drm_root,cards)
|
|
MonitorManager().get_screensize(
|
|
False,
|
|
monitor_file,
|
|
drm_root=drm_root
|
|
)
|
|
|
|
def test_reject_malformed_monitor_configuration(self) -> None:
|
|
"""Verify malformed XML or missing mode values are reported."""
|
|
with TemporaryDirectory() as temporary_directory:
|
|
monitor_file = Path(temporary_directory) / "monitors.xml"
|
|
manager = MonitorManager()
|
|
|
|
monitor_file.write_text("<monitors><configuration>")
|
|
with self.subTest("malformed XML"), \
|
|
self.assertRaises(ET.ParseError):
|
|
manager.get_screensize(True, monitor_file)
|
|
|
|
monitor_file.write_text(
|
|
"<monitors><configuration><logicalmonitor><x>0</x>"
|
|
"<monitor><mode><height>1080</height></mode></monitor>"
|
|
"</logicalmonitor></configuration></monitors>"
|
|
)
|
|
with self.subTest("missing mode width"), \
|
|
self.assertRaisesRegex(ValueError, "Missing <width>"):
|
|
manager.get_screensize(True, monitor_file)
|
|
|
|
|
|
GNOME_DISPLAY_STATE = """\
|
|
(uint32 1, [
|
|
(('eDP-1', 'NCP', '1', '1'),
|
|
[('1920x1080@60.0', 1920, 1080, 60.0, 1.0, [1.0], {'is-current': <true>})],
|
|
{'display-name': <'Built-in display'>}),
|
|
(('HDMI-1', 'ACR', '2', '2'),
|
|
[('1920x1080@60.0', 1920, 1080, 60.0, 1.0, [1.0], {'is-current': <true>})],
|
|
{'display-name': <'HDMI-1'>}),
|
|
(('HDMI-2', 'DEL', '3', '3'),
|
|
[('2560x1440@60.0', 2560, 1440, 60.0, 1.0, [1.0], {}),
|
|
('1920x1080@60.0', 1920, 1080, 60.0, 1.0, [1.0], {'is-current': <true>})],
|
|
{'display-name': <'HDMI-2'>})
|
|
], [], {})"""
|
|
|
|
def create_faulty_xmls(
|
|
source_file: Path,
|
|
temp_dir: Path,
|
|
) -> list[Path]:
|
|
"""Generate XML files with exactly one faulty x/y/width/height value."""
|
|
|
|
values = {
|
|
"x": [-3840, -1920, -1080, -500, 500, 1080, 1920, 3840, 5760],
|
|
"y": [-2160, -1080, -500, 500, 1080, 2160],
|
|
"width": [1280, 1600, 1920, 2560, 3440, 3840, 5120],
|
|
"height": [720, 900, 1080, 1440, 2160],
|
|
}
|
|
|
|
generated_files = []
|
|
|
|
original_tree = ET.parse(source_file)
|
|
original_root = original_tree.getroot()
|
|
|
|
for tag, candidates in values.items():
|
|
elements = list(original_root.iter(tag))
|
|
|
|
for index, element in enumerate(elements):
|
|
original_value = (element.text or "").strip()
|
|
|
|
for fault_type in ("empty", "random"):
|
|
tree = ET.parse(source_file)
|
|
root = tree.getroot()
|
|
|
|
target = list(root.iter(tag))[index]
|
|
|
|
if fault_type == "empty":
|
|
target.text = ""
|
|
|
|
else:
|
|
available = [
|
|
value for value in candidates
|
|
if str(value) != original_value
|
|
]
|
|
target.text = str(random.choice(available))
|
|
|
|
output_file = temp_dir / (
|
|
f"{source_file.stem}_{tag}_{index}_{fault_type}.xml"
|
|
)
|
|
|
|
tree.write(
|
|
output_file,
|
|
encoding="utf-8",
|
|
xml_declaration=True,
|
|
)
|
|
|
|
generated_files.append(output_file)
|
|
|
|
return generated_files
|
|
|
|
def create_drm_root(
|
|
drm_root: Path,
|
|
cards: list[str],
|
|
stati: list[str] | None = None,
|
|
connections: list[str] | None = None,
|
|
lid_state_path_str: str | None = None,
|
|
lid_state: str = "Open",
|
|
):
|
|
if stati is None:
|
|
stati = ["enabled"] * len(cards)
|
|
if connections is None:
|
|
connections = ["connected"]*len(cards)
|
|
if lid_state_path_str is None:
|
|
lid_state_path_str = str(drm_root) + "/proc/acpi/button/lid/LID*/state"
|
|
(drm_root / "card1").mkdir()
|
|
|
|
for card, status, connected in zip(cards,stati,connections):
|
|
connector = drm_root / card
|
|
connector.mkdir()
|
|
(connector / "status").write_text(f"{connected}\n")
|
|
(connector / "enabled").write_text(f"{status}\n")
|
|
size_file = (
|
|
connector / "device/device/graphics/fb0/virtual_size"
|
|
)
|
|
size_file.parent.mkdir(parents=True)
|
|
size_file.write_text("1920,1080")
|
|
if lid_state_path_str:
|
|
lid_state_file_path = Path(lid_state_path_str.replace("*","0"))
|
|
lid_state_file_path.parent.mkdir(parents=True)
|
|
lid_state_file_path.write_text(f"state: {lid_state}\n") |