diff options
| author | Sam Nystrom <sam@samnystrom.dev> | 2023-07-15 20:35:55 -0400 |
|---|---|---|
| committer | Sam Nystrom <sam@samnystrom.dev> | 2023-07-19 11:52:52 -0400 |
| commit | 89cb92131be595adf56d7b950711dcfcf8792070 (patch) | |
| tree | 413ce098e856ddfccbfb35629d4a1a25d1c7f438 /bin | |
| parent | 278d4f74df180279f2b17c1a03430a2dc2e0eae1 (diff) | |
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.
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/statusbar | 18 |
1 files changed, 16 insertions, 2 deletions
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) |
