[modules/xrandr] Adapt to new API
This commit is contained in:
parent
932d362d30
commit
5851b104c5
4 changed files with 44 additions and 33 deletions
|
@ -65,7 +65,9 @@ class Module(core.input.Object):
|
||||||
def module_name(self):
|
def module_name(self):
|
||||||
return self.__module__.split('.')[-1]
|
return self.__module__.split('.')[-1]
|
||||||
|
|
||||||
def widgets(self):
|
def widgets(self, widgets=None):
|
||||||
|
if widgets:
|
||||||
|
self._widgets = widgets
|
||||||
return self._widgets
|
return self._widgets
|
||||||
|
|
||||||
def widget(self, name=None):
|
def widget(self, name=None):
|
||||||
|
|
|
@ -27,8 +27,18 @@ class Widget(util.store.Store, core.input.Object):
|
||||||
|
|
||||||
def state(self):
|
def state(self):
|
||||||
rv = []
|
rv = []
|
||||||
|
if self.get('state', None):
|
||||||
|
tmp = self.get('state')
|
||||||
|
if isinstance(tmp, list):
|
||||||
|
rv.extend(tmp)
|
||||||
|
else:
|
||||||
|
rv.append(tmp)
|
||||||
if self._module:
|
if self._module:
|
||||||
rv = self._module.state(self)
|
tmp = self._module.state(self)
|
||||||
|
if isinstance(tmp, list):
|
||||||
|
rv.extend(tmp)
|
||||||
|
else:
|
||||||
|
rv.append(tmp)
|
||||||
return rv if isinstance(rv, list) else [rv]
|
return rv if isinstance(rv, list) else [rv]
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
|
@ -31,3 +31,4 @@
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
- theme: load vs. __load vs. load_keywords
|
- theme: load vs. __load vs. load_keywords
|
||||||
|
- themes: use colors to improve theme readability
|
||||||
|
|
|
@ -20,22 +20,24 @@ import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import bumblebee.util
|
import core.module
|
||||||
import bumblebee.input
|
import core.widget
|
||||||
import bumblebee.output
|
import core.input
|
||||||
import bumblebee.engine
|
|
||||||
|
import util.cli
|
||||||
|
import util.format
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import i3
|
import i3
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
class Module(core.module.Module):
|
||||||
def __init__(self, engine, config):
|
def __init__(self, config=None):
|
||||||
widgets = []
|
widgets = []
|
||||||
self._engine = engine
|
super().__init__(config, widgets)
|
||||||
super(Module, self).__init__(engine, config, widgets)
|
|
||||||
self._autoupdate = bumblebee.util.asbool(self.parameter('autoupdate', True))
|
self._autoupdate = util.format.asbool(self.parameter('autoupdate', True))
|
||||||
self._needs_update = True
|
self._needs_update = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -46,7 +48,7 @@ class Module(bumblebee.engine.Module):
|
||||||
def _output_update(self, event, data, _):
|
def _output_update(self, event, data, _):
|
||||||
self._needs_update = True
|
self._needs_update = True
|
||||||
|
|
||||||
def update_widgets(self, widgets):
|
def update(self):
|
||||||
new_widgets = []
|
new_widgets = []
|
||||||
|
|
||||||
if self._autoupdate == False and self._needs_update == False:
|
if self._autoupdate == False and self._needs_update == False:
|
||||||
|
@ -54,7 +56,7 @@ class Module(bumblebee.engine.Module):
|
||||||
|
|
||||||
self._needs_update = False
|
self._needs_update = False
|
||||||
|
|
||||||
for line in bumblebee.util.execute('xrandr -q').split('\n'):
|
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]
|
||||||
|
@ -62,26 +64,22 @@ 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=1, cmd=self._toggle)
|
core.input.register(widget, button=1, cmd=self._toggle)
|
||||||
self._engine.input.register_callback(widget, button=3, cmd=self._toggle)
|
core.input.register(widget, button=3, cmd=self._toggle)
|
||||||
new_widgets.append(widget)
|
new_widgets.append(widget)
|
||||||
|
widget.module(self)
|
||||||
widget.set('state', 'on' if m else 'off')
|
widget.set('state', 'on' if m else 'off')
|
||||||
widget.set('pos', int(m.group(1)) if m else sys.maxsize)
|
widget.set('pos', int(m.group(1)) if m else sys.maxsize)
|
||||||
|
|
||||||
while len(widgets) > 0:
|
self.widgets(new_widgets)
|
||||||
del widgets[0]
|
|
||||||
for widget in new_widgets:
|
|
||||||
widgets.append(widget)
|
|
||||||
|
|
||||||
if self._autoupdate == False:
|
if self._autoupdate == False:
|
||||||
widget = bumblebee.output.Widget(full_text='')
|
widget = core.widget.Widget(full_text='')
|
||||||
|
widget.module(self)
|
||||||
widget.set('state', 'refresh')
|
widget.set('state', 'refresh')
|
||||||
self._engine.input.register_callback(widget, button=1, cmd=self._refresh)
|
core.input.register(widget, button=1, cmd=self._refresh)
|
||||||
widgets.append(widget)
|
self.widgets().append(widget)
|
||||||
|
|
||||||
def update(self, widgets):
|
|
||||||
self.update_widgets(widgets)
|
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
return widget.get('state', 'off')
|
return widget.get('state', 'off')
|
||||||
|
@ -90,10 +88,10 @@ class Module(bumblebee.engine.Module):
|
||||||
self._needs_update = True
|
self._needs_update = True
|
||||||
|
|
||||||
def _toggle(self, event):
|
def _toggle(self, event):
|
||||||
self._needs_update = True
|
self._refresh(self, event)
|
||||||
path = os.path.dirname(os.path.abspath(__file__))
|
path = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
if bumblebee.util.asbool(self.parameter('overwrite_i3config', False)) == True:
|
if util.format.asbool(self.parameter('overwrite_i3config', False)) == True:
|
||||||
toggle_cmd = '{}/../../bin/toggle-display.sh'.format(path)
|
toggle_cmd = '{}/../../bin/toggle-display.sh'.format(path)
|
||||||
else:
|
else:
|
||||||
toggle_cmd = 'xrandr'
|
toggle_cmd = 'xrandr'
|
||||||
|
@ -101,18 +99,18 @@ class Module(bumblebee.engine.Module):
|
||||||
widget = self.widget_by_id(event['instance'])
|
widget = self.widget_by_id(event['instance'])
|
||||||
|
|
||||||
if widget.get('state') == 'on':
|
if widget.get('state') == 'on':
|
||||||
bumblebee.util.execute('{} --output {} --off'.format(toggle_cmd, widget.name))
|
util.cli.execute('{} --output {} --off'.format(toggle_cmd, widget.name))
|
||||||
else:
|
else:
|
||||||
first_neighbor = next((widget for widget in self.widgets() if widget.get('state') == 'on'), None)
|
first_neighbor = next((widget for widget in self.widgets() if widget.get('state') == 'on'), None)
|
||||||
last_neighbor = next((widget for widget in reversed(self.widgets()) if widget.get('state') == 'on'), None)
|
last_neighbor = next((widget for widget in reversed(self.widgets()) if widget.get('state') == 'on'), None)
|
||||||
|
|
||||||
neighbor = first_neighbor if event['button'] == bumblebee.input.LEFT_MOUSE else last_neighbor
|
neighbor = first_neighbor if event['button'] == core.input.LEFT_MOUSE else last_neighbor
|
||||||
|
|
||||||
if neighbor is None:
|
if neighbor is None:
|
||||||
bumblebee.util.execute('{} --output {} --auto'.format(toggle_cmd, widget.name))
|
util.cli.execute('{} --output {} --auto'.format(toggle_cmd, widget.name))
|
||||||
else:
|
else:
|
||||||
bumblebee.util.execute('{} --output {} --auto --{}-of {}'.format(toggle_cmd, widget.name,
|
util.cli.execute('{} --output {} --auto --{}-of {}'.format(toggle_cmd, widget.name,
|
||||||
'left' if event.get('button') == bumblebee.input.LEFT_MOUSE else 'right',
|
'left' if event.get('button') == core.input.LEFT_MOUSE else 'right',
|
||||||
neighbor.name))
|
neighbor.name))
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue