From 89cb92131be595adf56d7b950711dcfcf8792070 Mon Sep 17 00:00:00 2001 From: Sam Nystrom Date: Sat, 15 Jul 2023 20:35:55 -0400 Subject: statusbar: improve vol/brightness responsiveness If the volume or brightness just changed, then update the bar every twentieth of a second for two seconds instead of every second, since often the volume and brightness keys are pressed multiple times in quick succession. --- bin/statusbar | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'bin/statusbar') diff --git a/bin/statusbar b/bin/statusbar index d628578..7387bc5 100755 --- a/bin/statusbar +++ b/bin/statusbar @@ -62,14 +62,28 @@ def battery(): def clock(): return span('#7dc4e4', '', time.strftime("%b %d %H:%M")) +prev_vol = '' +prev_br = '' prev = '' +i = 0 while True: try: - status = ' | '.join([volume(), network(), brightness(), battery(), clock()]) + vol = volume() + br = brightness() + if vol != prev_vol or br != prev_br: + i = 20 + prev_vol = vol + prev_br = br + status = ' | '.join([vol, network(), br, battery(), clock()]) status = span('#cad3f5', status) if status != prev: subprocess.run(['somebar', '-c', 'status', status]) prev = status except Exception as e: print(''.join(traceback.format_exception(None, e, e.__traceback__))) - time.sleep(1 - time.time() % 1) + + if i > 0: + time.sleep(0.05) + i -= 1 + else: + time.sleep(0.5) -- cgit v1.2.3