diff --git a/i3pystatus/clock.py b/i3pystatus/clock.py index dc03bee..a47684e 100644 --- a/i3pystatus/clock.py +++ b/i3pystatus/clock.py @@ -28,6 +28,8 @@ class Clock(IntervalModule): color = "#ffffff" interval = 1 current_format_id = 0 + on_scrollup = "next_format" + on_scrolldown = "next_format" def init(self): if self.format is None: @@ -78,8 +80,8 @@ class Clock(IntervalModule): if self.color != "i3Bar": self.output["color"] = self.color - def on_upscroll(self): + def next_format(self): self.current_format_id = (self.current_format_id + 1) % len(self.format) - def on_downscroll(self): + def previous_format(self): self.current_format_id = (self.current_format_id - 1) % len(self.format) diff --git a/i3pystatus/core/modules.py b/i3pystatus/core/modules.py index fc1e569..bf9438a 100644 --- a/i3pystatus/core/modules.py +++ b/i3pystatus/core/modules.py @@ -7,6 +7,22 @@ class Module(SettingsBase): output = None position = 0 + settings = ( + 'on_lclick', "Callback called on left click", + 'on_rclick', "Callback called on right click", + 'on_scrollup', "Callback called on scrolling up", + 'on_scrolldown', "Callback called on scrolling down", + ) + + # this allows for backward compatibility + on_lclick = None + on_rclick = None + on_scrollup = None + on_scrolldown = None + # on_rclick = "on_rightclick" + # on_scrollup = "on_upscroll" + # on_scrolldown = "on_downscroll" + def registered(self, status_handler): """Called when this module is registered with a status handler""" @@ -23,14 +39,22 @@ class Module(SettingsBase): pass def on_click(self, button): + cb = None if button == 1: # Left mouse button - self.on_leftclick() + cb = self.on_lclick or "on_leftclick" elif button == 3: # Right mouse button - self.on_rightclick() + cb = self.on_rclick or "on_rightclick" elif button == 4: # mouse wheel up - self.on_upscroll() + cb = self.on_scrollup or "on_upscroll" elif button == 5: # mouse wheel down - self.on_downscroll() + cb = self.on_scrolldown or "on_downscroll" + + if callable(cb): + return cb(self) + elif hasattr(self, cb): + return getattr(self, cb)() + else: + return run_through_shell(cb) def move(self, position): self.position = position