[modules/rotation] create a widget per display once on refresh

* This module only updates some information on the screen when a new
display is added/removed, hence it makes sense to update it only when
the i3-bar is refreshed.
This commit is contained in:
Camilo Celis Guzman 2017-10-25 18:36:13 +09:00
parent 2bf89735fb
commit a84e568746

View file

@ -21,7 +21,6 @@ class Module(bumblebee.engine.Module):
self.update_widgets(widgets) self.update_widgets(widgets)
def update_widgets(self, widgets): def update_widgets(self, widgets):
new_widgets = []
for line in bumblebee.util.execute("xrandr -q").split("\n"): for line in bumblebee.util.execute("xrandr -q").split("\n"):
if not " connected" in line: if not " connected" in line:
continue continue
@ -37,16 +36,12 @@ class Module(bumblebee.engine.Module):
if not widget: if not widget:
widget = bumblebee.output.Widget(full_text=display, name=display) widget = bumblebee.output.Widget(full_text=display, name=display)
self._engine.input.register_callback(widget, button=bumblebee.input.LEFT_MOUSE, cmd=self._toggle) self._engine.input.register_callback(widget, button=bumblebee.input.LEFT_MOUSE, cmd=self._toggle)
new_widgets.append(widget)
widget.set("orientation", orientation) widget.set("orientation", orientation)
while len(widgets) > 0:
del widgets[0]
for widget in new_widgets:
widgets.append(widget) widgets.append(widget)
def update(self, widgets): def update(self, widgets):
self.update_widgets(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")