mirror of
https://github.com/ralsina/xrandroll.git
synced 2024-12-04 15:50:33 +00:00
Working on making modes nicer
This commit is contained in:
parent
cb6d3932cd
commit
afc6067d2b
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@ -1,7 +1,7 @@
|
|||||||
name: CI
|
name: CI
|
||||||
|
|
||||||
on:
|
on:
|
||||||
[push, pull_request]
|
[push]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
2
TODO.md
Normal file
2
TODO.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
* Parse refresh rate for modes and use it
|
||||||
|
* Test using older xrandr
|
@ -20,6 +20,8 @@ def test_parse_modes(test_data):
|
|||||||
data = test_data.read("monitor_1.txt", deserialize=False).splitlines()
|
data = test_data.read("monitor_1.txt", deserialize=False).splitlines()
|
||||||
m = Monitor(data)
|
m = Monitor(data)
|
||||||
assert len(m.modes) == 9
|
assert len(m.modes) == 9
|
||||||
|
assert "0x56" in m.modes
|
||||||
|
assert str(m.modes["0x56"]) == "1920x1080 (0x56)"
|
||||||
assert m.enabled
|
assert m.enabled
|
||||||
assert m.primary
|
assert m.primary
|
||||||
assert m.orientation == "normal"
|
assert m.orientation == "normal"
|
||||||
|
@ -3,12 +3,13 @@ import shlex
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import parse
|
||||||
from PySide2.QtCore import QFile, QObject, QTimer
|
from PySide2.QtCore import QFile, QObject, QTimer
|
||||||
from PySide2.QtUiTools import QUiLoader
|
from PySide2.QtUiTools import QUiLoader
|
||||||
from PySide2.QtWidgets import QApplication, QGraphicsScene, QLabel
|
from PySide2.QtWidgets import QApplication, QGraphicsScene, QLabel
|
||||||
|
|
||||||
from .monitor_item import MonitorItem
|
|
||||||
from . import xrandr
|
from . import xrandr
|
||||||
|
from .monitor_item import MonitorItem
|
||||||
|
|
||||||
|
|
||||||
class Window(QObject):
|
class Window(QObject):
|
||||||
@ -44,7 +45,7 @@ class Window(QObject):
|
|||||||
monitor.enabled = enabled
|
monitor.enabled = enabled
|
||||||
if enabled and not monitor.get_current_mode():
|
if enabled and not monitor.get_current_mode():
|
||||||
# Choose a mode
|
# Choose a mode
|
||||||
self.ui.modes.setCurrentText(monitor.get_preferred_mode_name())
|
self.ui.modes.setCurrentText(str(monitor.get_preferred_mode()))
|
||||||
self.mode_changed()
|
self.mode_changed()
|
||||||
self.screen.update_replica_of()
|
self.screen.update_replica_of()
|
||||||
for mon in self.screen.monitors.values():
|
for mon in self.screen.monitors.values():
|
||||||
@ -183,7 +184,11 @@ class Window(QObject):
|
|||||||
|
|
||||||
for name, monitor in self.screen.monitors.items():
|
for name, monitor in self.screen.monitors.items():
|
||||||
self.ui.screenCombo.addItem(name)
|
self.ui.screenCombo.addItem(name)
|
||||||
mon_item = MonitorItem(data=monitor, window=self, name=name,)
|
mon_item = MonitorItem(
|
||||||
|
data=monitor,
|
||||||
|
window=self,
|
||||||
|
name=name,
|
||||||
|
)
|
||||||
self.scene.addItem(mon_item)
|
self.scene.addItem(mon_item)
|
||||||
monitor.item = mon_item
|
monitor.item = mon_item
|
||||||
self.ui.screenCombo.setCurrentText(self.screen.choose_a_monitor())
|
self.ui.screenCombo.setCurrentText(self.screen.choose_a_monitor())
|
||||||
@ -198,7 +203,7 @@ class Window(QObject):
|
|||||||
|
|
||||||
def mode_changed(self):
|
def mode_changed(self):
|
||||||
mon = self.ui.screenCombo.currentText()
|
mon = self.ui.screenCombo.currentText()
|
||||||
mode = self.ui.modes.currentText()
|
mode = parse.search("({mode_name})", self.ui.modes.currentText())["mode_name"]
|
||||||
if not mode:
|
if not mode:
|
||||||
return
|
return
|
||||||
print(f"Changing {mon} to {mode}")
|
print(f"Changing {mon} to {mode}")
|
||||||
@ -280,11 +285,11 @@ class Window(QObject):
|
|||||||
# Show modes
|
# Show modes
|
||||||
self.ui.modes.clear()
|
self.ui.modes.clear()
|
||||||
monitor = self.screen.monitors[name]
|
monitor = self.screen.monitors[name]
|
||||||
for mode in monitor.modes:
|
for name, mode in monitor.modes.items():
|
||||||
self.ui.modes.addItem(mode)
|
self.ui.modes.addItem(str(mode))
|
||||||
|
|
||||||
mode = monitor.get_current_mode()
|
mode = monitor.get_current_mode()
|
||||||
self.ui.modes.setCurrentText(mode.name)
|
self.ui.modes.setCurrentText(str(mode))
|
||||||
if monitor.orientation in ("normal", "inverted"):
|
if monitor.orientation in ("normal", "inverted"):
|
||||||
h_scale = monitor.res_x / mode.res_x
|
h_scale = monitor.res_x / mode.res_x
|
||||||
v_scale = monitor.res_y / mode.res_y
|
v_scale = monitor.res_y / mode.res_y
|
||||||
|
@ -10,10 +10,10 @@ def _split_by_lines_matching(pattern, lines):
|
|||||||
matching the pattern. The line matching the pattern is
|
matching the pattern. The line matching the pattern is
|
||||||
included in the SECOND group. Empty groups are removed."""
|
included in the SECOND group. Empty groups are removed."""
|
||||||
groups = [[]]
|
groups = [[]]
|
||||||
for l in lines:
|
for line in lines:
|
||||||
if re.match(pattern, l): # Start a new group
|
if re.match(pattern, line): # Start a new group
|
||||||
groups.append([])
|
groups.append([])
|
||||||
groups[-1].append(l)
|
groups[-1].append(line)
|
||||||
|
|
||||||
return [g for g in groups if g]
|
return [g for g in groups if g]
|
||||||
|
|
||||||
@ -52,6 +52,9 @@ class Mode:
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.header.strip()
|
return self.header.strip()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.res_x}x{self.res_y} ({self.name})"
|
||||||
|
|
||||||
|
|
||||||
class Monitor:
|
class Monitor:
|
||||||
"""Object representing a monitor according to xrandr."""
|
"""Object representing a monitor according to xrandr."""
|
||||||
@ -123,10 +126,10 @@ class Monitor:
|
|||||||
for k, v in self.modes.items():
|
for k, v in self.modes.items():
|
||||||
v.current = k == mode_name
|
v.current = k == mode_name
|
||||||
|
|
||||||
def get_preferred_mode_name(self):
|
def get_preferred_mode(self):
|
||||||
for k, v in self.modes.items():
|
for k, v in self.modes.items():
|
||||||
if v.preferred:
|
if v.preferred:
|
||||||
return k
|
return v
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def guess_scale_mode(self):
|
def guess_scale_mode(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user