diff options
| author | Ultrabug <ultrabug@gentoo.org> | 2013-12-13 18:23:23 +0100 |
|---|---|---|
| committer | Ultrabug <ultrabug@gentoo.org> | 2013-12-13 18:23:23 +0100 |
| commit | 9ca0ee00a7cd12ce4a0ca7ea2b6ca8fcb55b47fa (patch) | |
| tree | a45bc8c3a5727fb14860baa1a7e7e4925074127a /py3status/__init__.py | |
| parent | 45872ecb1db0336531ea27605a7fd978583a46da (diff) | |
new generic click event handler using the special module file named i3bar_click_events.py which will be forwarded any orphan click event for action. this allows you to take action on clicks made on your i3status modules.
Diffstat (limited to 'py3status/__init__.py')
| -rwxr-xr-x | py3status/__init__.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/py3status/__init__.py b/py3status/__init__.py index 0a182dd..cb24d39 100755 --- a/py3status/__init__.py +++ b/py3status/__init__.py @@ -252,6 +252,22 @@ class Events(Thread): if self.config['debug']: syslog(LOG_INFO, 'dispatching default event {}'.format(event)) + def i3bar_click_events_module(self): + """ + Detect the presence of the special i3bar_click_events.py module. + + When py3status detects a module named 'i3bar_click_events.py', + it will dispatch i3status click events to this module so you can catch + them and trigger any function call based on the event. + """ + for module in self.modules: + if not module.click_events: + continue + if module.module_name == 'i3bar_click_events.py': + return module + else: + return False + def run(self): """ Wait for an i3bar JSON event, then find the right module to dispatch @@ -276,6 +292,7 @@ class Events(Thread): # setup default action on button 2 press default_event = False + dispatched = False if 'button' in event and event['button'] == 2: default_event = True @@ -291,10 +308,23 @@ class Events(Thread): if 'instance' in event: if event['instance'] == obj['instance']: self.dispatch(module, obj, event) + dispatched = True break else: self.dispatch(module, obj, event) + dispatched = True break + + # fall back to i3bar_click_events.py module if present + if not dispatched: + module = self.i3bar_click_events_module() + if module: + if self.config['debug']: + syslog( + LOG_INFO, + 'dispatching event to i3bar_click_events' + ) + self.dispatch(module, obj, event) except Exception: err = sys.exc_info()[1] syslog(LOG_WARNING, 'event failed ({})'.format(err)) |
