mirror of
https://github.com/ralsina/xrandroll.git
synced 2024-11-22 11:02:22 +00:00
Disconnect replicas when moved
This commit is contained in:
parent
c134fb9ac0
commit
55d8522c4b
20
main.py
20
main.py
@ -2,7 +2,7 @@ from copy import deepcopy
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from PySide2.QtCore import QFile, QObject
|
from PySide2.QtCore import QFile, QObject, Slot, SIGNAL
|
||||||
from PySide2.QtUiTools import QUiLoader
|
from PySide2.QtUiTools import QUiLoader
|
||||||
from PySide2.QtWidgets import QApplication, QGraphicsScene
|
from PySide2.QtWidgets import QApplication, QGraphicsScene
|
||||||
|
|
||||||
@ -73,15 +73,26 @@ class Window(QObject):
|
|||||||
0,
|
0,
|
||||||
monitor["res_x"],
|
monitor["res_x"],
|
||||||
monitor["res_y"],
|
monitor["res_y"],
|
||||||
|
data=monitor,
|
||||||
|
window=self,
|
||||||
name=name,
|
name=name,
|
||||||
replica_of=monitor['replica_of'],
|
|
||||||
primary=monitor["primary"],
|
|
||||||
)
|
)
|
||||||
mon_item.setPos(monitor["pos_x"], monitor["pos_y"])
|
mon_item.setPos(monitor["pos_x"], monitor["pos_y"])
|
||||||
self.scene.addItem(mon_item)
|
self.scene.addItem(mon_item)
|
||||||
monitor["item"] = mon_item
|
monitor["item"] = mon_item
|
||||||
self.adjust_view()
|
self.adjust_view()
|
||||||
|
|
||||||
|
@Slot()
|
||||||
|
def monitor_moved(self):
|
||||||
|
"Update xrandr_info with new monitor positions"
|
||||||
|
for _, mon in self.xrandr_info.items():
|
||||||
|
item = mon['item']
|
||||||
|
mon['pos_x'] = item.x()
|
||||||
|
mon['pos_y'] = item.y()
|
||||||
|
self.set_replica_of()
|
||||||
|
for _, mon in self.xrandr_info.items():
|
||||||
|
mon['item'].update_visuals(mon)
|
||||||
|
|
||||||
def adjust_view(self):
|
def adjust_view(self):
|
||||||
self.ui.sceneView.ensureVisible(self.scene.sceneRect(), 100, 100)
|
self.ui.sceneView.ensureVisible(self.scene.sceneRect(), 100, 100)
|
||||||
scale_factor = 0.7 * min(
|
scale_factor = 0.7 * min(
|
||||||
@ -125,8 +136,11 @@ class Window(QObject):
|
|||||||
if "*" in line:
|
if "*" in line:
|
||||||
print(f"Current mode for {name}: {mode_name}")
|
print(f"Current mode for {name}: {mode_name}")
|
||||||
self.xrandr_info[name]["current_mode"] = mode_name
|
self.xrandr_info[name]["current_mode"] = mode_name
|
||||||
|
self.set_replica_of()
|
||||||
|
|
||||||
|
def set_replica_of(self):
|
||||||
for a in self.xrandr_info:
|
for a in self.xrandr_info:
|
||||||
|
self.xrandr_info[a]['replica_of'] = []
|
||||||
for b 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]):
|
if a !=b and is_replica_of(self.xrandr_info[a], self.xrandr_info[b]):
|
||||||
self.xrandr_info[a]['replica_of'].append(b)
|
self.xrandr_info[a]['replica_of'].append(b)
|
||||||
|
@ -1,31 +1,37 @@
|
|||||||
from PySide2.QtCore import Qt
|
from PySide2.QtCore import Qt, Signal, QObject
|
||||||
from PySide2.QtWidgets import QGraphicsRectItem, QGraphicsTextItem
|
from PySide2.QtWidgets import QGraphicsRectItem, QGraphicsTextItem
|
||||||
from PySide2.QtGui import QBrush, QPen
|
from PySide2.QtGui import QBrush, QPen
|
||||||
|
|
||||||
|
|
||||||
class MonitorItem(QGraphicsRectItem):
|
class MonitorItem(QGraphicsRectItem, QObject):
|
||||||
z = 0
|
z = 0
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, *a, **kw):
|
def __init__(self, *a, **kw):
|
||||||
primary = kw.pop('primary')
|
data = kw.pop("data")
|
||||||
name = kw.pop('name')
|
self.name = kw.pop("name")
|
||||||
replica_of=kw.pop('replica_of')
|
self.window = kw.pop("window")
|
||||||
super().__init__(*a, **kw)
|
super().__init__(*a, **kw)
|
||||||
self.setAcceptedMouseButtons(Qt.LeftButton)
|
self.setAcceptedMouseButtons(Qt.LeftButton)
|
||||||
if replica_of:
|
self.label = QGraphicsTextItem("", self)
|
||||||
label_text = f"{name} [{','.join(replica_of)}]"
|
self.update_visuals(data)
|
||||||
|
|
||||||
|
def update_visuals(self, data):
|
||||||
|
if data['replica_of']:
|
||||||
|
label_text = f"{self.name} [{','.join(data['replica_of'])}]"
|
||||||
else:
|
else:
|
||||||
label_text = name
|
label_text = self.name
|
||||||
self.label = QGraphicsTextItem(label_text, self)
|
self.label.setPlainText(label_text)
|
||||||
label_scale = min(
|
label_scale = min(
|
||||||
self.rect().width() / self.label.boundingRect().width(),
|
self.rect().width() / self.label.boundingRect().width(),
|
||||||
self.rect().height() / self.label.boundingRect().height(),
|
self.rect().height() / self.label.boundingRect().height(),
|
||||||
)
|
)
|
||||||
self.label.setScale(label_scale)
|
self.label.setScale(label_scale)
|
||||||
if primary:
|
if data['primary']:
|
||||||
self.setBrush(QBrush('#eee8d5', Qt.SolidPattern))
|
self.setBrush(QBrush("#eee8d5", Qt.SolidPattern))
|
||||||
self.setZValue(1)
|
self.setZValue(1)
|
||||||
else:
|
else:
|
||||||
self.setBrush(QBrush('white', Qt.SolidPattern))
|
self.setBrush(QBrush("white", Qt.SolidPattern))
|
||||||
self.setZValue(self.z)
|
self.setZValue(self.z)
|
||||||
self.z -= 1
|
self.z -= 1
|
||||||
|
|
||||||
@ -35,6 +41,7 @@ class MonitorItem(QGraphicsRectItem):
|
|||||||
|
|
||||||
def mouseReleaseEvent(self, event):
|
def mouseReleaseEvent(self, event):
|
||||||
self.setCursor(Qt.OpenHandCursor)
|
self.setCursor(Qt.OpenHandCursor)
|
||||||
|
self.window.monitor_moved()
|
||||||
|
|
||||||
def mouseMoveEvent(self, event):
|
def mouseMoveEvent(self, event):
|
||||||
view = event.widget().parent()
|
view = event.widget().parent()
|
||||||
|
Loading…
Reference in New Issue
Block a user