mirror of
https://github.com/ralsina/xrandroll.git
synced 2024-11-24 20:12:21 +00:00
Organize monitors in screens
This commit is contained in:
parent
c40526118e
commit
6e18d870eb
@ -3,9 +3,9 @@ from xrandroll.xrandr import parse_data
|
|||||||
|
|
||||||
def test_parse_data(test_data):
|
def test_parse_data(test_data):
|
||||||
data = test_data.read("sample_1.txt", deserialize=False).splitlines()
|
data = test_data.read("sample_1.txt", deserialize=False).splitlines()
|
||||||
monitors = parse_data(data)
|
screen = parse_data(data)
|
||||||
assert len(monitors) == 2
|
assert len(screen.monitors) == 2
|
||||||
assert [m.output for m in monitors] == ["eDP", "HDMI-A-0"]
|
assert [m.output for m in screen.monitors.values()] == ["eDP", "HDMI-A-0"]
|
||||||
|
|
||||||
|
|
||||||
def test_parse_with_disconnected_monitors(test_data):
|
def test_parse_with_disconnected_monitors(test_data):
|
||||||
|
@ -9,6 +9,7 @@ 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 .monitor_item import MonitorItem
|
||||||
|
from . import xrandr
|
||||||
|
|
||||||
|
|
||||||
def parse_mode(mode):
|
def parse_mode(mode):
|
||||||
@ -377,6 +378,8 @@ class Window(QObject):
|
|||||||
self.ui.sceneView.scale(scale_factor, scale_factor)
|
self.ui.sceneView.scale(scale_factor, scale_factor)
|
||||||
|
|
||||||
def get_xrandr_info(self):
|
def get_xrandr_info(self):
|
||||||
|
self.monitors = xrandr.parse_data(xrandr.read_data())
|
||||||
|
|
||||||
data = subprocess.check_output(["xrandr"]).decode("utf-8").splitlines()
|
data = subprocess.check_output(["xrandr"]).decode("utf-8").splitlines()
|
||||||
name = None
|
name = None
|
||||||
for line in data:
|
for line in data:
|
||||||
|
@ -5,6 +5,16 @@ import subprocess
|
|||||||
from .monitor import Monitor, _split_by_lines_matching
|
from .monitor import Monitor, _split_by_lines_matching
|
||||||
|
|
||||||
|
|
||||||
|
class Screen:
|
||||||
|
"""A Screen is a collection of monitors."""
|
||||||
|
|
||||||
|
def __init__(self, data):
|
||||||
|
self.monitors = {}
|
||||||
|
for monitor_data in _split_by_lines_matching(r"^[^ \t].*", data[1:]):
|
||||||
|
m = Monitor(monitor_data)
|
||||||
|
self.monitors[m.output] = m
|
||||||
|
|
||||||
|
|
||||||
def read_data():
|
def read_data():
|
||||||
data = subprocess.check_output(
|
data = subprocess.check_output(
|
||||||
["xrandr", "--verbose"], encoding="utf-8"
|
["xrandr", "--verbose"], encoding="utf-8"
|
||||||
@ -14,9 +24,4 @@ def read_data():
|
|||||||
|
|
||||||
def parse_data(data):
|
def parse_data(data):
|
||||||
# Going to pretend there can only be one screen because life is short.
|
# Going to pretend there can only be one screen because life is short.
|
||||||
screen = _split_by_lines_matching("^Screen ", data)[0]
|
return Screen(_split_by_lines_matching("^Screen ", data)[0])
|
||||||
|
|
||||||
result = []
|
|
||||||
for monitor_data in _split_by_lines_matching(r"^[^ \t].*", screen[1:]):
|
|
||||||
result.append(Monitor(monitor_data))
|
|
||||||
return result
|
|
||||||
|
Loading…
Reference in New Issue
Block a user