Support enabling / disabling monitors from the UI

This commit is contained in:
Roberto Alsina 2020-02-01 17:08:00 -03:00
parent 4373045db9
commit b3c03fe723
2 changed files with 30 additions and 17 deletions

View File

@ -16,6 +16,9 @@ def gen_xrandr_from_data(data):
cli = ["xrandr"]
for name, mon in data.items():
cli.append(f"--output {name}")
if not mon["enabled"]:
cli.append("--off")
else:
cli.append(f'--pos {int(mon["pos_x"])}x{int(mon["pos_y"])}')
cli.append(f'--mode {mon["current_mode"]}')
mod_x, mod_y = [int(n) for n in mon["current_mode"].split("x")]
@ -27,8 +30,6 @@ def gen_xrandr_from_data(data):
)
if mon["primary"]:
cli.append("--primary")
if not mon["enabled"]:
cli.append("--off")
return " ".join(cli)
@ -104,11 +105,20 @@ class Window(QObject):
self.ui.cancelButton.clicked.connect(self.ui.reject)
self.ui.scaleModeCombo.currentTextChanged.connect(self.scale_mode_changed)
self.ui.primary.stateChanged.connect(self.primary_changed)
self.ui.enabled.stateChanged.connect(self.enabled_changed)
self.pos_label = QLabel(self.ui.sceneView)
self.pos_label.setText("FOOOOO")
self.pos_label.move(5, 5)
def enabled_changed(self):
mon = self.ui.screenCombo.currentText()
enabled = self.ui.enabled.isChecked()
print(f'Setting {mon} enabled status to {enabled}')
monitor = self.xrandr_info[mon]
monitor['enabled'] = enabled
monitor["item"].update_visuals(monitor)
def primary_changed(self):
mon = self.ui.screenCombo.currentText()
primary = self.ui.primary.isChecked()

View File

@ -41,6 +41,7 @@ class MonitorItem(QGraphicsRectItem, QObject):
self.rect().height() / self.label.boundingRect().height(),
)
self.label.setScale(label_scale)
if data["enabled"]:
if data["primary"]:
self.setBrush(QBrush("#eee8d5", Qt.SolidPattern))
self.setZValue(1)
@ -48,6 +49,8 @@ class MonitorItem(QGraphicsRectItem, QObject):
self.setBrush(QBrush("white", Qt.SolidPattern))
self.setZValue(self.z)
self.z -= 1
else:
self.setBrush(QBrush("#010101", Qt.FDiagPattern))
def mousePressEvent(self, event):
self.window.pos_label.show()