diff --git a/bumblebee/input.py b/bumblebee/input.py index a501a85..ba41362 100644 --- a/bumblebee/input.py +++ b/bumblebee/input.py @@ -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): diff --git a/bumblebee/modules/battery.py b/bumblebee/modules/battery.py index 423d509..cf1251e 100644 --- a/bumblebee/modules/battery.py +++ b/bumblebee/modules/battery.py @@ -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: