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,19 +16,20 @@ def gen_xrandr_from_data(data):
cli = ["xrandr"] cli = ["xrandr"]
for name, mon in data.items(): for name, mon in data.items():
cli.append(f"--output {name}") cli.append(f"--output {name}")
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")]
if mon["orientation"] in (1, 3):
mod_x, mod_y = mod_y, mod_x
cli.append(f'--scale {mon["res_x"]/mod_x}x{mon["res_y"]/mod_y}')
cli.append(
f"--rotate {['normal', 'left', 'inverted', 'right'][mon['orientation']]}"
)
if mon["primary"]:
cli.append("--primary")
if not mon["enabled"]: if not mon["enabled"]:
cli.append("--off") 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")]
if mon["orientation"] in (1, 3):
mod_x, mod_y = mod_y, mod_x
cli.append(f'--scale {mon["res_x"]/mod_x}x{mon["res_y"]/mod_y}')
cli.append(
f"--rotate {['normal', 'left', 'inverted', 'right'][mon['orientation']]}"
)
if mon["primary"]:
cli.append("--primary")
return " ".join(cli) return " ".join(cli)
@ -104,11 +105,20 @@ class Window(QObject):
self.ui.cancelButton.clicked.connect(self.ui.reject) self.ui.cancelButton.clicked.connect(self.ui.reject)
self.ui.scaleModeCombo.currentTextChanged.connect(self.scale_mode_changed) self.ui.scaleModeCombo.currentTextChanged.connect(self.scale_mode_changed)
self.ui.primary.stateChanged.connect(self.primary_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 = QLabel(self.ui.sceneView)
self.pos_label.setText("FOOOOO") self.pos_label.setText("FOOOOO")
self.pos_label.move(5, 5) 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): def primary_changed(self):
mon = self.ui.screenCombo.currentText() mon = self.ui.screenCombo.currentText()
primary = self.ui.primary.isChecked() primary = self.ui.primary.isChecked()

View File

@ -41,13 +41,16 @@ class MonitorItem(QGraphicsRectItem, QObject):
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 data["primary"]: if data["enabled"]:
self.setBrush(QBrush("#eee8d5", Qt.SolidPattern)) if data["primary"]:
self.setZValue(1) self.setBrush(QBrush("#eee8d5", Qt.SolidPattern))
self.setZValue(1)
else:
self.setBrush(QBrush("white", Qt.SolidPattern))
self.setZValue(self.z)
self.z -= 1
else: else:
self.setBrush(QBrush("white", Qt.SolidPattern)) self.setBrush(QBrush("#010101", Qt.FDiagPattern))
self.setZValue(self.z)
self.z -= 1
def mousePressEvent(self, event): def mousePressEvent(self, event):
self.window.pos_label.show() self.window.pos_label.show()