[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:
parent
d91294f010
commit
1a4cddb0b6
2 changed files with 21 additions and 11 deletions
|
@ -79,30 +79,39 @@ class I3BarInput(object):
|
||||||
self._thread.join()
|
self._thread.join()
|
||||||
return self.clean_exit
|
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
|
uid = self.global_id
|
||||||
if obj:
|
if obj:
|
||||||
uid = obj.id
|
uid = obj.id
|
||||||
return uid
|
return self._uuidstr(uid, button)
|
||||||
|
|
||||||
def deregister_callbacks(self, obj):
|
def deregister_callbacks(self, obj):
|
||||||
uid = self._uid(obj)
|
to_delete = []
|
||||||
if uid in self._callbacks:
|
uid = obj.id if obj else self.global_id
|
||||||
del self._callbacks[uid]
|
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):
|
def register_callback(self, obj, button, cmd):
|
||||||
"""Register a callback function or system call"""
|
"""Register a callback function or system call"""
|
||||||
uid = self._uid(obj)
|
uid = self._uid(obj, button)
|
||||||
if uid not in self._callbacks:
|
if uid not in self._callbacks:
|
||||||
self._callbacks[uid] = {}
|
self._callbacks[uid] = {}
|
||||||
self._callbacks[uid][button] = cmd
|
self._callbacks[uid] = cmd
|
||||||
|
|
||||||
def callback(self, event):
|
def callback(self, event):
|
||||||
"""Execute callback action for an incoming event"""
|
"""Execute callback action for an incoming event"""
|
||||||
cmd = self._callbacks.get(self.global_id, {})
|
button = event["button"]
|
||||||
cmd = self._callbacks.get(event["name"], cmd)
|
|
||||||
cmd = self._callbacks.get(event["instance"], cmd)
|
cmd = self._callbacks.get(self._uuidstr(self.global_id, button), None)
|
||||||
cmd = cmd.get(event["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:
|
if cmd is None:
|
||||||
return
|
return
|
||||||
if callable(cmd):
|
if callable(cmd):
|
||||||
|
|
|
@ -22,6 +22,7 @@ class Module(bumblebee.engine.Module):
|
||||||
battery = self.parameter("device", "BAT0")
|
battery = self.parameter("device", "BAT0")
|
||||||
self._path = "/sys/class/power_supply/{}".format(battery)
|
self._path = "/sys/class/power_supply/{}".format(battery)
|
||||||
self._capacity = 100
|
self._capacity = 100
|
||||||
|
self._ac = False
|
||||||
|
|
||||||
def capacity(self):
|
def capacity(self):
|
||||||
if self._ac:
|
if self._ac:
|
||||||
|
|
Loading…
Reference in a new issue