Mark bottom edge of screen in red

This commit is contained in:
Roberto Alsina 2020-01-31 20:42:38 -03:00
parent b659da5757
commit a5bc4bab91
2 changed files with 39 additions and 9 deletions

13
main.py
View File

@ -19,6 +19,7 @@ def gen_xrandr_from_data(data):
cli.append(f'--mode {mon["current_mode"]}') cli.append(f'--mode {mon["current_mode"]}')
mod_x, mod_y = [int(n) for n in mon["current_mode"].split("x")] mod_x, mod_y = [int(n) for n in mon["current_mode"].split("x")]
cli.append(f'--scale {mon["res_x"]/mod_x}x{mon["res_y"]/mod_y}') 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"]: if mon["primary"]:
cli.append("--primary") cli.append("--primary")
if not mon["enabled"]: if not mon["enabled"]:
@ -132,12 +133,20 @@ class Window(QObject):
self.xrandr_info[mon]["current_mode"] = mode self.xrandr_info[mon]["current_mode"] = mode
mode_x, mode_y = mode.split("x") mode_x, mode_y = mode.split("x")
# use resolution via scaling # use resolution via scaling
if self.xrandr_info[mon]["orientation"] in (0,2):
self.xrandr_info[mon]["res_x"] = int( self.xrandr_info[mon]["res_x"] = int(
int(mode_x) * self.ui.horizontalScale.value() / 100 int(mode_x) * self.ui.horizontalScale.value() / 100
) )
self.xrandr_info[mon]["res_y"] = int( self.xrandr_info[mon]["res_y"] = int(
int(mode_y) * self.ui.verticalScale.value() / 100 int(mode_y) * self.ui.verticalScale.value() / 100
) )
else:
self.xrandr_info[mon]["res_x"] = int(
int(mode_y) * self.ui.horizontalScale.value() / 100
)
self.xrandr_info[mon]["res_y"] = int(
int(mode_x) * self.ui.verticalScale.value() / 100
)
self.xrandr_info[mon]["item"].update_visuals(self.xrandr_info[mon]) self.xrandr_info[mon]["item"].update_visuals(self.xrandr_info[mon])
def monitor_moved(self): def monitor_moved(self):
@ -219,8 +228,12 @@ class Window(QObject):
mod_x, mod_y = [ mod_x, mod_y = [
int(x) for x in self.xrandr_info[name]["current_mode"].split("x") int(x) for x in self.xrandr_info[name]["current_mode"].split("x")
] ]
if self.xrandr_info[name]["orientation"] in (0,2):
h_scale = self.xrandr_info[name]["res_x"] / mod_x h_scale = self.xrandr_info[name]["res_x"] / mod_x
v_scale = self.xrandr_info[name]["res_y"] / mod_y v_scale = self.xrandr_info[name]["res_y"] / mod_y
else:
h_scale = self.xrandr_info[name]["res_y"] / mod_x
v_scale = self.xrandr_info[name]["res_x"] / mod_y
self.ui.horizontalScale.setValue(h_scale * 100) self.ui.horizontalScale.setValue(h_scale * 100)
self.ui.verticalScale.setValue(v_scale * 100) self.ui.verticalScale.setValue(v_scale * 100)
self.ui.primary.setChecked(self.xrandr_info[name]["primary"]) self.ui.primary.setChecked(self.xrandr_info[name]["primary"])

View File

@ -13,6 +13,8 @@ class MonitorItem(QGraphicsRectItem, QObject):
super().__init__(0, 0, 0, 0) super().__init__(0, 0, 0, 0)
self.setAcceptedMouseButtons(Qt.LeftButton) self.setAcceptedMouseButtons(Qt.LeftButton)
self.label = QGraphicsTextItem("", self) self.label = QGraphicsTextItem("", self)
self.bottom_edge = QGraphicsRectItem(0, 0, 0, 0, self)
self.bottom_edge.setBrush(QBrush("red", Qt.SolidPattern))
self.update_visuals(data) self.update_visuals(data)
def update_visuals(self, data): def update_visuals(self, data):
@ -20,7 +22,22 @@ class MonitorItem(QGraphicsRectItem, QObject):
label_text = f"{self.name} [{','.join(data['replica_of'])}]" label_text = f"{self.name} [{','.join(data['replica_of'])}]"
else: else:
label_text = self.name label_text = self.name
if data["orientation"] in (0, 2):
self.setRect(0, 0, data["res_x"], data["res_y"]) self.setRect(0, 0, data["res_x"], data["res_y"])
if data["orientation"] == 0:
self.bottom_edge.setRect(
0, data["res_y"] - 50, data["res_x"], 50
)
if data["orientation"] == 2:
self.bottom_edge.setRect(0, 0, data["res_x"], 50)
else:
self.setRect(0, 0, data["res_y"], data["res_x"])
if data["orientation"] == 1:
self.bottom_edge.setRect(
data["res_y"] - 50, 0, 50, data["res_x"]
)
if data["orientation"] == 3:
self.bottom_edge.setRect(0, 0, 50, data["res_x"])
self.setPos(data["pos_x"], data["pos_y"]) self.setPos(data["pos_x"], data["pos_y"])
self.label.setPlainText(label_text) self.label.setPlainText(label_text)
label_scale = min( label_scale = min(