From b99c454a5a5ab5a1b610f7adb03cafb097b27363 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Fri, 4 Nov 2016 19:11:10 +0100 Subject: [PATCH] [main] Redraw on click Whenever a module in the bar is clicked, immediately redraw the line, to make for a snappier user experience (especially when muting/unmuting). --- bumblebee/output.py | 8 +++++++- bumblebee/outputs/i3.py | 5 +++-- i3bumblebee | 7 +++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/bumblebee/output.py b/bumblebee/output.py index af542e6..4d51caf 100644 --- a/bumblebee/output.py +++ b/bumblebee/output.py @@ -1,9 +1,15 @@ class Output(object): - def __init__(self, theme): + def __init__(self, refresh, theme): self._theme = theme + self._refresh = refresh self._callbacks = {} + def redraw(self): + self._refresh.acquire() + self._refresh.notify() + self._refresh.release() + def add_callback(self, cmd, button, module=None): if module: module = module.replace("bumblebee.modules.", "") diff --git a/bumblebee/outputs/i3.py b/bumblebee/outputs/i3.py index 6940579..691f30b 100644 --- a/bumblebee/outputs/i3.py +++ b/bumblebee/outputs/i3.py @@ -25,10 +25,11 @@ def read_input(output): button = event.get("button", -1) ) subprocess.Popen(shlex.split(cb), stdout=DEVNULL, stderr=DEVNULL) + output.redraw() class i3bar(bumblebee.output.Output): - def __init__(self, theme): - super(i3bar, self).__init__(theme) + def __init__(self, refresh, theme): + super(i3bar, self).__init__(refresh, theme) self._data = [] self.add_callback("i3-msg workspace prev_on_output", 4) diff --git a/i3bumblebee b/i3bumblebee index d5e12da..ff1631f 100755 --- a/i3bumblebee +++ b/i3bumblebee @@ -7,6 +7,7 @@ import glob import pkgutil import argparse import textwrap +import threading import importlib import bumblebee.theme import bumblebee.modules @@ -83,8 +84,9 @@ def main(): print_theme_list() sys.exit(0) + refresh = threading.Condition() theme = bumblebee.theme.Theme(args.theme) if args.theme else bumblebee.theme.Theme() - output = bumblebee.outputs.i3.i3bar(theme) + output = bumblebee.outputs.i3.i3bar(refresh, theme) modules = [] for m in args.modules: @@ -96,6 +98,7 @@ def main(): print output.start() sys.stdout.flush() + refresh.acquire() while True: theme.reset() for m in modules: @@ -103,7 +106,7 @@ def main(): theme.next() print output.get() sys.stdout.flush() - time.sleep(args.interval) + refresh.wait(args.interval) print output.stop()