From f26a9f9d1d9bf910fd97a8512ee2b516f6db875b Mon Sep 17 00:00:00 2001 From: Mathis FELARDOS Date: Fri, 25 Mar 2016 22:18:14 +0100 Subject: [PATCH] core: Improve the support of other button * This commit fix #259 * Change 'unhandled' callback by 'other' * Add the an optional parameter 'button_id' for all callbacks Signed-off-by: Mathis FELARDOS --- i3pystatus/core/__init__.py | 10 ++++++---- i3pystatus/core/modules.py | 30 ++++++++++++++++-------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/i3pystatus/core/__init__.py b/i3pystatus/core/__init__.py index f0c7173..4bd54a6 100644 --- a/i3pystatus/core/__init__.py +++ b/i3pystatus/core/__init__.py @@ -32,14 +32,16 @@ class CommandEndpoint: for cmd in self.io_handler_factory().read(): target_module = self.modules.get(cmd["instance"]) + button = cmd["button"] + kwargs = {"button_id": button} try: - pos = {"pos_x": int(cmd["x"]), - "pos_y": int(cmd["y"])} + kwargs.update({"pos_x": cmd["x"], + "pos_y": cmd["y"]}) except Exception: - pos = {} + continue if target_module: - target_module.on_click(cmd["button"], **pos) + target_module.on_click(button, **kwargs) target_module.run() self.io.async_refresh() diff --git a/i3pystatus/core/modules.py b/i3pystatus/core/modules.py index cb29164..41a5936 100644 --- a/i3pystatus/core/modules.py +++ b/i3pystatus/core/modules.py @@ -36,8 +36,8 @@ class Module(SettingsBase): ('on_doublerightclick', "Callback called on double right click (see :ref:`callbacks`)"), ('on_doubleupscroll', "Callback called on double scroll up (see :ref:`callbacks`)"), ('on_doubledownscroll', "Callback called on double scroll down (see :ref:`callbacks`)"), - ('on_unhandledclick', "Callback called on unhandled click (see :ref:`callbacks`)"), - ('on_doubleunhandledclick', "Callback called on double unhandled click (see :ref:`callbacks`)"), + ('on_otherclick', "Callback called on other click (see :ref:`callbacks`)"), + ('on_doubleotherclick', "Callback called on double other click (see :ref:`callbacks`)"), ('multi_click_timeout', "Time (in seconds) before a single click is executed."), ('hints', "Additional output blocks for module output (see :ref:`hints`)"), ) @@ -53,8 +53,8 @@ class Module(SettingsBase): on_doubleupscroll = None on_doubledownscroll = None - on_unhandledclick = None - on_doubleunhandledclick = None + on_otherclick = None + on_doubleotherclick = None multi_click_timeout = 0.25 @@ -171,14 +171,16 @@ class Module(SettingsBase): Currently implemented events are: - =========== ================ ========= - Event Callback setting Button ID - =========== ================ ========= - Left click on_leftclick 1 - Right click on_rightclick 3 - Scroll up on_upscroll 4 - Scroll down on_downscroll 5 - =========== ================ ========= + ============ ================ ========= + Event Callback setting Button ID + ============ ================ ========= + Left click on_leftclick 1 + Middle click on_middleclick 2 + Right click on_rightclick 3 + Scroll up on_upscroll 4 + Scroll down on_downscroll 5 + Others on_otherclick > 5 + ============ ================ ========= The action is determined by the nature (type and value) of the callback setting in the following order: @@ -206,8 +208,8 @@ class Module(SettingsBase): try: action = actions[button - 1] except (TypeError, IndexError): - self.__log_button_event(button, None, None, "Unhandled button") - action = "unhandled" + self.__log_button_event(button, None, None, "Other button") + action = "otherclick" m_click = self.__multi_click