From 1a4cddb0b661bd5bc2f278419b45e2f5a4a5dc5a Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Sun, 11 Dec 2016 07:38:56 +0100 Subject: [PATCH] [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 --- bumblebee/input.py | 31 ++++++++++++++++++++----------- bumblebee/modules/battery.py | 1 + 2 files changed, 21 insertions(+), 11 deletions(-) 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: