[core/output] Start implementation of a partial update

Add a "patch()" method that eventually will only update affected
modules.
This commit is contained in:
Tobias Witek 2020-02-08 14:22:43 +01:00
parent cc0139e517
commit 5810a12944
2 changed files with 15 additions and 11 deletions

View file

@ -11,13 +11,14 @@ import core.output
import core.module
import core.input
def handle_input():
def handle_input(output):
poll = select.poll()
poll.register(sys.stdin.fileno(), select.POLLIN)
while True:
events = poll.poll()
modules = {}
for fileno, event in events:
line = '['
while line.startswith('['):
@ -26,8 +27,11 @@ def handle_input():
try:
event = json.loads(line)
core.input.trigger(event)
if 'name' in event:
modules[event['name']] = True
except ValueError:
pass
output.draw('patch', modules.keys())
poll.unregister(sys.stdin.fileno())
@ -42,7 +46,7 @@ def main():
output = core.output.i3()
modules = []
input_thread = threading.Thread(target=handle_input)
input_thread = threading.Thread(target=handle_input, args=(output,))
input_thread.daemon = True
input_thread.start()
@ -51,7 +55,6 @@ def main():
output.modules(modules)
output.draw('start')
while True:
output.clear()
for module in modules:
module.update()
output.draw('statusline')

View file

@ -5,15 +5,16 @@ import time
class i3(object):
def __init__(self):
self._modules = []
self.clear()
self._status = []
def modules(self, modules=None):
if not modules:
return self._modules
self._modules = modules if isinstance(modules, list) else [ modules ]
def draw(self, what):
data = getattr(self, what)()
def draw(self, what, args=None):
cb = getattr(self, what)
data = cb(args) if args else cb()
if 'data' in data:
sys.stdout.write(json.dumps(data['data']))
if 'suffix' in data:
@ -30,20 +31,20 @@ class i3(object):
def stop(self):
return { 'suffix': '\n]' }
def clear(self):
self._statusline = []
def patch(self, affected_modules):
pass # TODO
def statusline(self):
status = []
self._status = []
for module in self._modules:
for widget in module.widgets():
status.append({
self._status.append({
'full_text': widget.full_text(),
'instance': widget.id(),
'name': module.id(),
})
return {
'data': status,
'data': self._status,
'suffix': ','
}