[core/input] add default workspace wrap bindings (mouse wheel up/down)

This commit is contained in:
tobi-wan-kenobi 2020-05-02 13:54:45 +02:00
parent d0bb0f9b7a
commit ba24ba13db
4 changed files with 15 additions and 5 deletions

View file

@ -83,6 +83,9 @@ def main():
output = core.output.i3(theme, config) output = core.output.i3(theme, config)
modules = [] 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 = threading.Thread(target=handle_input, args=(output,))
input_thread.daemon = True input_thread.daemon = True
input_thread.start() input_thread.start()

View file

@ -12,10 +12,14 @@ def clear():
__callbacks.clear() __callbacks.clear()
def trigger(event, *args, **kwargs): 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: if len(args) + len(kwargs) == 0:
callback() callback()
else: else:
callback(*args, **kwargs) callback(*args, **kwargs)
return True
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -34,7 +34,7 @@ def __execute(cmd):
logging.error('failed to invoke callback: {}'.format(e)) logging.error('failed to invoke callback: {}'.format(e))
def register(obj, button=None, cmd=None): 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)) logging.debug('registering callback {}'.format(event_id))
if callable(cmd): if callable(cmd):
core.event.register(event_id, cmd) core.event.register(event_id, cmd)
@ -43,8 +43,13 @@ def register(obj, button=None, cmd=None):
def trigger(event): def trigger(event):
if not 'button' in event: return if not 'button' in event: return
triggered = False
for field in ['instance', 'name']: for field in ['instance', 'name']:
if not field in event: continue 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 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -12,7 +12,6 @@
## Backwards-compatibility ## Backwards-compatibility
- alignment parameter - alignment parameter
- default wheel handlers
## Improvements ## Improvements
- API documentation - API documentation
@ -22,5 +21,4 @@
- themes: use colors to improve theme readability - themes: use colors to improve theme readability
- convert some stuff to simple attributes to reduce LOCs - convert some stuff to simple attributes to reduce LOCs
- theme.exclude (battery) - theme.exclude (battery)
- configuration files
- use add_widget() instead of core.widget.Widget() - use add_widget() instead of core.widget.Widget()