Display replicas, z-order for monitors

This commit is contained in:
Roberto Alsina 2020-01-31 16:29:04 -03:00
parent f67a4fe683
commit c134fb9ac0
2 changed files with 21 additions and 2 deletions

View File

@ -74,6 +74,7 @@ class Window(QObject):
monitor["res_x"],
monitor["res_y"],
name=name,
replica_of=monitor['replica_of'],
primary=monitor["primary"],
)
mon_item.setPos(monitor["pos_x"], monitor["pos_y"])
@ -116,6 +117,7 @@ class Window(QObject):
modes=[],
current_mode=None,
enabled=enabled,
replica_of=[],
)
elif line[0] == " ": # A mode
mode_name = line.strip().split()[0]
@ -124,6 +126,11 @@ class Window(QObject):
print(f"Current mode for {name}: {mode_name}")
self.xrandr_info[name]["current_mode"] = mode_name
for a in self.xrandr_info:
for b in self.xrandr_info:
if a !=b and is_replica_of(self.xrandr_info[a], self.xrandr_info[b]):
self.xrandr_info[a]['replica_of'].append(b)
def monitor_selected(self, name):
# Show modes
self.ui.modes.clear()
@ -145,7 +152,7 @@ class Window(QObject):
for mon in self.xrandr_info:
if mon != name:
self.ui.replicaOf.addItem(mon)
if is_replica_of(self.xrandr_info[mon], self.xrandr_info[name]):
if mon in self.xrandr_info[name]['replica_of']:
self.ui.replicaOf.setCurrentText(mon)
def updateScaleLabels(self):

View File

@ -4,11 +4,18 @@ from PySide2.QtGui import QBrush, QPen
class MonitorItem(QGraphicsRectItem):
z = 0
def __init__(self, *a, **kw):
primary = kw.pop('primary')
name = kw.pop('name')
replica_of=kw.pop('replica_of')
super().__init__(*a, **kw)
self.setAcceptedMouseButtons(Qt.LeftButton)
self.label = QGraphicsTextItem(kw["name"], self)
if replica_of:
label_text = f"{name} [{','.join(replica_of)}]"
else:
label_text = name
self.label = QGraphicsTextItem(label_text, self)
label_scale = min(
self.rect().width() / self.label.boundingRect().width(),
self.rect().height() / self.label.boundingRect().height(),
@ -16,6 +23,11 @@ class MonitorItem(QGraphicsRectItem):
self.label.setScale(label_scale)
if primary:
self.setBrush(QBrush('#eee8d5', Qt.SolidPattern))
self.setZValue(1)
else:
self.setBrush(QBrush('white', Qt.SolidPattern))
self.setZValue(self.z)
self.z -= 1
def mousePressEvent(self, event):
self.setCursor(Qt.ClosedHandCursor)