From ba24ba13db5e1122ad0788a6d4e263fb53de7bc6 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Sat, 2 May 2020 13:54:45 +0200 Subject: [PATCH] [core/input] add default workspace wrap bindings (mouse wheel up/down) --- bumblebee-status | 3 +++ core/event.py | 6 +++++- core/input.py | 9 +++++++-- doc/NOTES.md | 2 -- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/bumblebee-status b/bumblebee-status index e9cd545..a621165 100755 --- a/bumblebee-status +++ b/bumblebee-status @@ -83,6 +83,9 @@ def main(): output = core.output.i3(theme, config) modules = [] + core.input.register(None, core.input.WHEEL_UP, 'i3-msg workspace prev_on_output') + core.input.register(None, core.input.WHEEL_DOWN, 'i3-msg workspace next_on_output') + input_thread = threading.Thread(target=handle_input, args=(output,)) input_thread.daemon = True input_thread.start() diff --git a/core/event.py b/core/event.py index 2b0d0ee..a9a364c 100644 --- a/core/event.py +++ b/core/event.py @@ -12,10 +12,14 @@ def clear(): __callbacks.clear() def trigger(event, *args, **kwargs): - for callback in __callbacks.get(event, []): + cb = __callbacks.get(event, []) + if len(cb) == 0: return False + + for callback in cb: if len(args) + len(kwargs) == 0: callback() else: callback(*args, **kwargs) + return True # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/core/input.py b/core/input.py index 0065a10..308f7f7 100644 --- a/core/input.py +++ b/core/input.py @@ -34,7 +34,7 @@ def __execute(cmd): logging.error('failed to invoke callback: {}'.format(e)) def register(obj, button=None, cmd=None): - event_id = __event_id(obj.id, button) + event_id = __event_id(obj.id if obj is not None else '', button) logging.debug('registering callback {}'.format(event_id)) if callable(cmd): core.event.register(event_id, cmd) @@ -43,8 +43,13 @@ def register(obj, button=None, cmd=None): def trigger(event): if not 'button' in event: return + + triggered = False for field in ['instance', 'name']: if not field in event: continue - core.event.trigger(__event_id(event[field], event['button']), event) + if core.event.trigger(__event_id(event[field], event['button']), event): + triggered = True + if not triggered: + core.event.trigger(__event_id('', event['button']), event) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/doc/NOTES.md b/doc/NOTES.md index ce20c0d..194c1d7 100644 --- a/doc/NOTES.md +++ b/doc/NOTES.md @@ -12,7 +12,6 @@ ## Backwards-compatibility - alignment parameter -- default wheel handlers ## Improvements - API documentation @@ -22,5 +21,4 @@ - themes: use colors to improve theme readability - convert some stuff to simple attributes to reduce LOCs - theme.exclude (battery) -- configuration files - use add_widget() instead of core.widget.Widget()