[modules/xrandr] Subscribe to i3 output events, if possible

If i3-py is available, use it to subscribe to output events to reload
the widget list whenever the outputs change.

fixes #359
This commit is contained in:
Tobias Witek 2019-02-09 11:00:12 +01:00
parent a198b8d9e3
commit 80892477f6

View file

@ -9,6 +9,9 @@ Parameters:
* xrandr.autoupdate: If set to 'false', does *not* invoke xrandr automatically. Instead, the * xrandr.autoupdate: If set to 'false', does *not* invoke xrandr automatically. Instead, the
module will only refresh when displays are enabled or disabled (defaults to false) module will only refresh when displays are enabled or disabled (defaults to false)
Requires the following python module:
* (optional) i3 - if present, the need for updating the widget list is auto-detected
Requires the following executable: Requires the following executable:
* xrandr * xrandr
""" """
@ -22,6 +25,11 @@ import bumblebee.input
import bumblebee.output import bumblebee.output
import bumblebee.engine import bumblebee.engine
try:
import i3
except:
pass
class Module(bumblebee.engine.Module): class Module(bumblebee.engine.Module):
def __init__(self, engine, config): def __init__(self, engine, config):
widgets = [] widgets = []
@ -30,6 +38,14 @@ class Module(bumblebee.engine.Module):
self._autoupdate = bumblebee.util.asbool(self.parameter("autoupdate", True)) self._autoupdate = bumblebee.util.asbool(self.parameter("autoupdate", True))
self._needs_update = True self._needs_update = True
try:
i3.Subscription(self._output_update, "output")
except:
pass
def _output_update(self, event, data, _):
self._needs_update = True
def update_widgets(self, widgets): def update_widgets(self, widgets):
new_widgets = [] new_widgets = []