History wipe because Zed is very annoying...
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
from typing import override
|
||||
|
||||
from ..abstracts import AbstractDisplay
|
||||
from ..structs import Modeline, MonitorInfo
|
||||
from ._gnome_types import GNOMEDisplayConfig
|
||||
|
||||
# Half replaced implementation. More refactoring needs to be done in regards to setting the display.
|
||||
# Everything will be replaced with dorkbus Mutter stuff.
|
||||
|
||||
MODE_REGEX_PATTERN = re.compile(r"(\d+)x(\d+)@(\d+\.\d+)")
|
||||
|
||||
class Display(AbstractDisplay):
|
||||
@override
|
||||
def get_modes(self):
|
||||
mutter_display_state = GNOMEDisplayConfig()
|
||||
mutter_display_state.get_dbus_info()
|
||||
|
||||
primary_connectors = {
|
||||
m[0]
|
||||
for lm in mutter_display_state.logical_monitors
|
||||
if lm.is_primary
|
||||
for m in lm.monitors
|
||||
}
|
||||
|
||||
result = []
|
||||
for monitor in mutter_display_state.monitors:
|
||||
modes = [
|
||||
Modeline(
|
||||
mode.width,
|
||||
mode.height,
|
||||
mode.refresh_rate,
|
||||
)
|
||||
for mode in monitor.modes
|
||||
]
|
||||
|
||||
result.append(
|
||||
MonitorInfo(
|
||||
monitor.connector,
|
||||
monitor.connector in primary_connectors,
|
||||
modes
|
||||
)
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
@override
|
||||
def set_mode(self, modeline, requested_connector=None) -> None:
|
||||
subprocess.run(
|
||||
[
|
||||
"gdctl",
|
||||
"set",
|
||||
"--logical-monitor",
|
||||
"--primary",
|
||||
"--monitor",
|
||||
requested_connector,
|
||||
"--mode",
|
||||
str(modeline),
|
||||
]
|
||||
)
|
||||
|
||||
@override
|
||||
def save_current_mode(self, location):
|
||||
gdctl_output = subprocess.run(
|
||||
["gdctl", "show"], capture_output=True, text=True, check=True
|
||||
)
|
||||
match = MODE_REGEX_PATTERN.search(gdctl_output.stdout)
|
||||
w, h, r = match.groups()
|
||||
with open(location, "w") as file:
|
||||
file.write(f"{w}x{h}@{r}")
|
||||
|
||||
@override
|
||||
def read_saved_mode(self, location):
|
||||
with open(location, "r") as file:
|
||||
config_file_content = file.read()
|
||||
|
||||
match = MODE_REGEX_PATTERN.search(config_file_content)
|
||||
|
||||
w, h, r = match.groups()
|
||||
return Modeline(width=int(w), height=int(h), refresh_rate=float(r))
|
||||
|
||||
@staticmethod
|
||||
@override
|
||||
def detect():
|
||||
return "gnome" in os.environ.get("XDG_CURRENT_DESKTOP", "").lower()
|
||||
@@ -0,0 +1,104 @@
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
from gi.repository import Gio, GLib
|
||||
|
||||
# This is not going to be nice
|
||||
|
||||
@dataclass
|
||||
class _GNOMEDisplayMode:
|
||||
id: str
|
||||
width: int
|
||||
height: int
|
||||
refresh_rate: float
|
||||
preferred_scale: float
|
||||
supported_scales: list[float]
|
||||
|
||||
@dataclass
|
||||
class _GNOMEMonitor:
|
||||
connector: str
|
||||
vendor: str
|
||||
product: str
|
||||
serial: str
|
||||
modes: list[_GNOMEDisplayMode]
|
||||
properties: dict[str, Any]
|
||||
|
||||
@dataclass
|
||||
class _GNOMELogicalMonitor:
|
||||
x: int
|
||||
y: int
|
||||
scale: float
|
||||
transform: int
|
||||
is_primary: bool
|
||||
monitors: list[tuple[str, str, str, str]]
|
||||
properties: dict[str, Any]
|
||||
|
||||
@dataclass
|
||||
class GNOMEDisplayConfig:
|
||||
serial: int = 0
|
||||
monitors: list[_GNOMEMonitor] = field(default_factory=list)
|
||||
logical_monitors: list[_GNOMELogicalMonitor] = field(default_factory=list)
|
||||
global_properties: dict[str, Any] = field(default_factory=dict)
|
||||
|
||||
def get_dbus_info(self):
|
||||
bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
|
||||
|
||||
# Some beautiful dorkbus
|
||||
res = bus.call_sync(
|
||||
"org.gnome.Mutter.DisplayConfig",
|
||||
"/org/gnome/Mutter/DisplayConfig",
|
||||
"org.gnome.Mutter.DisplayConfig",
|
||||
"GetCurrentState",
|
||||
None,
|
||||
None,
|
||||
Gio.DBusCallFlags.NONE,
|
||||
-1,
|
||||
None
|
||||
)
|
||||
|
||||
# Serial, Monitors, Logical Monitors, Properties
|
||||
dbus_serial, monitors, logical_monitors, global_props = res.unpack()
|
||||
|
||||
self.serial = dbus_serial
|
||||
self.global_properties = global_props
|
||||
|
||||
self.logical_monitors = [
|
||||
_GNOMELogicalMonitor(
|
||||
x=lm[0],
|
||||
y=lm[1],
|
||||
scale=lm[2],
|
||||
transform=lm[3],
|
||||
is_primary=lm[4],
|
||||
monitors=lm[5],
|
||||
properties=lm[6],
|
||||
)
|
||||
for lm in logical_monitors
|
||||
]
|
||||
|
||||
self.monitors = []
|
||||
for info, modes_data, monitor_props in monitors:
|
||||
connector, vendor, product, monitor_serial = info
|
||||
|
||||
modes = [
|
||||
_GNOMEDisplayMode(
|
||||
id=m[0],
|
||||
width=m[1],
|
||||
height=m[2],
|
||||
refresh_rate=m[3],
|
||||
preferred_scale=m[4],
|
||||
supported_scales=m[5],
|
||||
)
|
||||
for m in modes_data
|
||||
]
|
||||
|
||||
monitor = _GNOMEMonitor(
|
||||
connector=connector,
|
||||
vendor=vendor,
|
||||
product=product,
|
||||
serial=monitor_serial,
|
||||
modes=modes,
|
||||
properties=monitor_props,
|
||||
)
|
||||
self.monitors.append(monitor)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user