[modules/rotation] Update to latest API
This commit is contained in:
parent
0984c5502c
commit
369af17b56
1 changed files with 15 additions and 20 deletions
|
@ -6,22 +6,21 @@ Requires the following executable:
|
||||||
* xrandr
|
* xrandr
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import bumblebee.util
|
import core.module
|
||||||
import bumblebee.input
|
import core.widget
|
||||||
import bumblebee.output
|
import core.input
|
||||||
import bumblebee.engine
|
|
||||||
|
import util.cli
|
||||||
|
|
||||||
possible_orientations = ['normal', 'left', 'inverted', 'right']
|
possible_orientations = ['normal', 'left', 'inverted', 'right']
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
class Module(core.module.Module):
|
||||||
def __init__(self, engine, config):
|
def __init__(self, config):
|
||||||
widgets = []
|
super().__init__(config, [])
|
||||||
self._engine = engine
|
|
||||||
super(Module, self).__init__(engine, config, widgets)
|
|
||||||
self.update_widgets(widgets)
|
|
||||||
|
|
||||||
def update_widgets(self, widgets):
|
def update(self):
|
||||||
for line in bumblebee.util.execute('xrandr -q').split('\n'):
|
widgets = self.widgets()
|
||||||
|
for line in util.cli.execute('xrandr -q').split('\n'):
|
||||||
if not ' connected' in line:
|
if not ' connected' in line:
|
||||||
continue
|
continue
|
||||||
display = line.split(' ', 2)[0]
|
display = line.split(' ', 2)[0]
|
||||||
|
@ -34,19 +33,15 @@ class Module(bumblebee.engine.Module):
|
||||||
|
|
||||||
widget = self.widget(display)
|
widget = self.widget(display)
|
||||||
if not widget:
|
if not widget:
|
||||||
widget = bumblebee.output.Widget(full_text=display, name=display)
|
widget = core.widget.Widget(full_text=display, name=display)
|
||||||
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)
|
||||||
widget.set('orientation', orientation)
|
widget.set('orientation', orientation)
|
||||||
widgets.append(widget)
|
widgets.append(widget)
|
||||||
|
|
||||||
def update(self, widgets):
|
|
||||||
if len(widgets) <= 0:
|
|
||||||
self.update_widgets(widgets)
|
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
return widget.get('orientation', 'normal')
|
return widget.get('orientation', 'normal')
|
||||||
|
|
||||||
def _toggle(self, event):
|
def __toggle(self, event):
|
||||||
widget = self.widget_by_id(event['instance'])
|
widget = self.widget_by_id(event['instance'])
|
||||||
|
|
||||||
# compute new orientation based on current orientation
|
# compute new orientation based on current orientation
|
||||||
|
@ -56,6 +51,6 @@ class Module(bumblebee.engine.Module):
|
||||||
|
|
||||||
widget.set('orientation', new_orientation)
|
widget.set('orientation', new_orientation)
|
||||||
|
|
||||||
bumblebee.util.execute('xrandr --output {} --rotation {}'.format(widget.name, new_orientation))
|
util.cli.execute('xrandr --output {} --rotation {}'.format(widget.name, new_orientation))
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue