[core/input] Separate module/widget update and retrieval

To make it easier to update individual modules, separate the call to
update() and the call to actually drawing the status.

Additionally, this avoids the "side effect" of updating when drawing the
status line.
This commit is contained in:
Tobias Witek 2020-02-09 13:25:34 +01:00
parent 5810a12944
commit 4e2a645bd3
3 changed files with 15 additions and 14 deletions

View file

@ -5,7 +5,7 @@ import time
class i3(object):
def __init__(self):
self._modules = []
self._status = []
self._status = {}
def modules(self, modules=None):
if not modules:
@ -31,20 +31,23 @@ class i3(object):
def stop(self):
return { 'suffix': '\n]' }
def patch(self, affected_modules):
pass # TODO
def statusline(self):
self._status = []
def update(self, affected_modules=None):
for module in self._modules:
module.update()
self._status[module] = []
for widget in module.widgets():
self._status.append({
self._status[module].append({
'full_text': widget.full_text(),
'instance': widget.id(),
'name': module.id(),
})
def statusline(self):
widgets = []
for module in self._modules:
widgets += self._status[module]
return {
'data': self._status,
'data': widgets,
'suffix': ','
}