[core] Fix callback registration ("shadowed" events)

Until now, as soon as a widget registered *any* callback, the default
callbacks (e.g. scroll up/down to go to next/previous workspace) didn't
work anymore, as there was a better match for the general registration
(even though not for the button).

To fix this, merge the callback registration into a flat registration,
where a key is calculated from the ID of the registrar and the
registered button.

see #23
This commit is contained in:
Tobi-wan Kenobi 2016-12-11 07:38:56 +01:00
parent d91294f010
commit 1a4cddb0b6
2 changed files with 21 additions and 11 deletions

View file

@ -79,30 +79,39 @@ class I3BarInput(object):
self._thread.join()
return self.clean_exit
def _uid(self, obj):
def _uuidstr(self, name, button):
return "{}::{}".format(name, button)
def _uid(self, obj, button):
uid = self.global_id
if obj:
uid = obj.id
return uid
return self._uuidstr(uid, button)
def deregister_callbacks(self, obj):
uid = self._uid(obj)
if uid in self._callbacks:
del self._callbacks[uid]
to_delete = []
uid = obj.id if obj else self.global_id
for key in self._callbacks:
if uid in key:
to_delete.append(key)
for key in to_delete:
del self._callbacks[key]
def register_callback(self, obj, button, cmd):
"""Register a callback function or system call"""
uid = self._uid(obj)
uid = self._uid(obj, button)
if uid not in self._callbacks:
self._callbacks[uid] = {}
self._callbacks[uid][button] = cmd
self._callbacks[uid] = cmd
def callback(self, event):
"""Execute callback action for an incoming event"""
cmd = self._callbacks.get(self.global_id, {})
cmd = self._callbacks.get(event["name"], cmd)
cmd = self._callbacks.get(event["instance"], cmd)
cmd = cmd.get(event["button"], None)
button = event["button"]
cmd = self._callbacks.get(self._uuidstr(self.global_id, button), None)
cmd = self._callbacks.get(self._uuidstr(event["name"], button), cmd)
cmd = self._callbacks.get(self._uuidstr(event["instance"], button), cmd)
if cmd is None:
return
if callable(cmd):

View file

@ -22,6 +22,7 @@ class Module(bumblebee.engine.Module):
battery = self.parameter("device", "BAT0")
self._path = "/sys/class/power_supply/{}".format(battery)
self._capacity = 100
self._ac = False
def capacity(self):
if self._ac: