2020-04-19 10:30:22 +02:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
|
|
|
"""Shows a widget for each connected screen and allows the user to loop through different orientations.
|
|
|
|
|
|
|
|
Requires the following executable:
|
|
|
|
* xrandr
|
|
|
|
"""
|
|
|
|
|
2020-04-19 10:33:29 +02:00
|
|
|
import core.module
|
|
|
|
import core.input
|
|
|
|
|
|
|
|
import util.cli
|
2020-04-19 10:30:22 +02:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
possible_orientations = ["normal", "left", "inverted", "right"]
|
|
|
|
|
2020-04-19 10:30:22 +02:00
|
|
|
|
2020-04-19 10:33:29 +02:00
|
|
|
class Module(core.module.Module):
|
2020-04-26 16:39:24 +02:00
|
|
|
def __init__(self, config, theme):
|
|
|
|
super().__init__(config, theme, [])
|
2020-04-19 10:30:22 +02:00
|
|
|
|
2020-04-19 10:33:29 +02:00
|
|
|
def update(self):
|
|
|
|
widgets = self.widgets()
|
2020-05-03 11:15:52 +02:00
|
|
|
for line in util.cli.execute("xrandr -q").split("\n"):
|
|
|
|
if not " connected" in line:
|
2020-04-19 10:30:22 +02:00
|
|
|
continue
|
2020-05-03 11:15:52 +02:00
|
|
|
display = line.split(" ", 2)[0]
|
2020-04-19 10:30:22 +02:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
orientation = "normal"
|
2020-04-19 10:30:22 +02:00
|
|
|
for curr_orient in possible_orientations:
|
2020-05-03 11:15:52 +02:00
|
|
|
if (line.split(" ")).count(curr_orient) > 1:
|
2020-04-19 10:30:22 +02:00
|
|
|
orientation = curr_orient
|
|
|
|
break
|
|
|
|
|
|
|
|
widget = self.widget(display)
|
|
|
|
if not widget:
|
2020-05-09 10:57:44 +02:00
|
|
|
widget = self.add_widget(full_text=display, name=display)
|
2020-05-03 11:15:52 +02:00
|
|
|
core.input.register(
|
|
|
|
widget, button=core.input.LEFT_MOUSE, cmd=self.__toggle
|
|
|
|
)
|
|
|
|
widget.set("orientation", orientation)
|
2020-04-19 10:30:22 +02:00
|
|
|
widgets.append(widget)
|
|
|
|
|
|
|
|
def state(self, widget):
|
2020-05-03 11:15:52 +02:00
|
|
|
return widget.get("orientation", "normal")
|
2020-04-19 10:30:22 +02:00
|
|
|
|
2020-04-19 10:33:29 +02:00
|
|
|
def __toggle(self, event):
|
2020-05-03 11:15:52 +02:00
|
|
|
widget = self.widget_by_id(event["instance"])
|
2020-04-19 10:30:22 +02:00
|
|
|
|
|
|
|
# compute new orientation based on current orientation
|
2020-05-03 11:15:52 +02:00
|
|
|
idx = possible_orientations.index(widget.get("orientation"))
|
2020-04-19 10:30:22 +02:00
|
|
|
idx = (idx + 1) % len(possible_orientations)
|
|
|
|
new_orientation = possible_orientations[idx]
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
widget.set("orientation", new_orientation)
|
|
|
|
|
|
|
|
util.cli.execute(
|
|
|
|
"xrandr --output {} --rotation {}".format(widget.name, new_orientation)
|
|
|
|
)
|
2020-04-19 10:30:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|