fix wlrotation: migrated to new api

This commit is contained in:
Ludwig Behm 2023-11-08 21:52:08 +01:00
parent 27be30263f
commit 61123eb7a0
Signed by: l.behm
GPG key ID: D344835D63B89384

View file

@ -7,38 +7,33 @@ Requires the following executable:
* swaymsg * swaymsg
""" """
import bumblebee.util import core.module
import bumblebee.input import core.input
import bumblebee.output import util.cli
import bumblebee.engine
import json import json
from os import environ, path from os import environ, path
possible_orientations = ["normal", "90", "180", "270"] possible_orientations = ["normal", "90", "180", "270"]
class Module(bumblebee.engine.Module): class Module(core.module.Module):
def __init__(self, engine, config): def __init__(self, config, theme):
self.service = "sway-auto-rotate@%s" % path.basename(environ['SWAYSOCK']).replace('-', '\\\\x2d') super().__init__(config, theme, [])
widgets = []
self._engine = engine
super(Module, self).__init__(engine, config, widgets)
self.update_widgets(widgets)
def update_widgets(self, widgets): self.service = "sway-auto-rotate@%s" % path.basename(environ['SWAYSOCK']).replace('-', '\\\\x2d')
for display in json.loads(bumblebee.util.execute("/usr/bin/swaymsg -t get_outputs -r")): # self._widgets = []
self.update_widgets()
def update_widgets(self):
for display in json.loads(util.cli.execute("/usr/bin/swaymsg -t get_outputs -r")):
name = display['name'] name = display['name']
widget = self.widget(name) widget = self.widget(name)
if not widget: if not widget:
widget = bumblebee.output.Widget(name=name, full_text=""+name) widget = self.add_widget(name=name, full_text=""+name)
widget.set("auto", bumblebee.util.execute("systemctl --user show %s -p ActiveState" % self.service).split("\n")[0].split("=")[1]) widget.set("auto", util.cli.execute("systemctl --user show %s -p ActiveState" % self.service).split("\n")[0].split("=")[1])
self._engine.input.register_callback(widget, button=bumblebee.input.LEFT_MOUSE, cmd=self._toggle) core.input.register(widget, button=core.input.LEFT_MOUSE, cmd=self._toggle)
self._engine.input.register_callback(widget, button=bumblebee.input.RIGHT_MOUSE, cmd=self._toggle_auto) core.input.register(widget, button=core.input.RIGHT_MOUSE, cmd=self._toggle_auto)
widget.set("orientation", display['transform']) widget.set("orientation", display['transform'])
widgets.append(widget)
def update(self, widgets):
if len(widgets) <= 0:
self.update_widgets(widgets)
def state(self, widget): def state(self, widget):
curr = widget.get("auto", "inactive") curr = widget.get("auto", "inactive")
@ -47,23 +42,22 @@ class Module(bumblebee.engine.Module):
return [curr] return [curr]
def _toggle_auto(self, event): def _toggle_auto(self, event):
widget = self.widget_by_id(event["instance"]) widget = self.widget(widget_id=event["instance"])
if widget.get("auto") == "inactive": if widget.get("auto") == "inactive":
bumblebee.util.execute("systemctl --user start %s" % self.service) util.cli.execute("systemctl --user start %s" % self.service)
else: else:
bumblebee.util.execute("systemctl --user stop %s" % self.service) util.cli.execute("systemctl --user stop %s" % self.service)
widget.set("auto", bumblebee.util.execute("systemctl --user show %s -p ActiveState" % self.service).split("\n")[0].split("=")[1]) widget.set("auto", util.cli.execute("systemctl --user show %s -p ActiveState" % self.service).split("\n")[0].split("=")[1])
def _toggle(self, event): def _toggle(self, event):
widget = self.widget_by_id(event["instance"]) widget = self.widget(widget_id=event["instance"])
# compute new orientation based on current orientation # compute new orientation based on current orientation
idx = possible_orientations.index(widget.get("orientation")) idx = (possible_orientations.index(widget.get("orientation"))+ 1) % len(possible_orientations)
idx = (idx + 1) % len(possible_orientations)
new_orientation = possible_orientations[idx] new_orientation = possible_orientations[idx]
widget.set("orientation", new_orientation) widget.set("orientation", new_orientation)
bumblebee.util.execute("swaymsg 'output {} transform {}'".format(widget.name, new_orientation)) util.cli.execute("swaymsg 'output {} transform {}'".format(widget.name, new_orientation))
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4