From f42a88d3305380a8355ea5b02f8697d97ead77ee Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Mon, 10 Jun 2024 20:40:22 -0500 Subject: fix(i3blocks): fix title blocklet clearing --- i3blocks/.local/lib/i3blocks/i3blocks-title | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'i3blocks') diff --git a/i3blocks/.local/lib/i3blocks/i3blocks-title b/i3blocks/.local/lib/i3blocks/i3blocks-title index 1247253..a2f8ca5 100755 --- a/i3blocks/.local/lib/i3blocks/i3blocks-title +++ b/i3blocks/.local/lib/i3blocks/i3blocks-title @@ -33,11 +33,15 @@ class Printer: class Blocklet: - EVENTS = [ + SET_EVENTS = [ i3ipc.Event.WINDOW_FOCUS, i3ipc.Event.WINDOW_TITLE, i3ipc.Event.WINDOW_NEW, + ] + + CLEAR_EVENTS = [ i3ipc.Event.WINDOW_CLOSE, + i3ipc.Event.WORKSPACE_FOCUS, ] def __init__(self, task_group: TaskGroup): @@ -50,27 +54,29 @@ class Blocklet: self = cls(task_group) self.i3 = await Connection().connect() - for event in Blocklet.EVENTS: - self.i3.on(event, lambda _, event: self.update_focus(event.container.name)) + for event in Blocklet.SET_EVENTS: + self.i3.on(event, lambda _, e: self.set(e.container.name)) - self.i3.on( - i3ipc.Event.WORKSPACE_FOCUS, - lambda _, event: self.update_focus(), - ) + for event in Blocklet.CLEAR_EVENTS: + self.i3.on(event, lambda _, e: self.clear()) return self async def main(self): if focused := (await self.i3.get_tree()).find_focused(): - self.update_focus(focused.name) + self.set(focused.name) await self.i3.main() - def update_focus(self, title: str = None): + def set(self, title: str = None): if self.printer_task is not None: self.printer_task.cancel() - self.printer_task = self.task_group.create_task(Printer(title).print()) + def clear(self): + if self.printer_task is not None: + self.printer_task.cancel() + print(flush=True) + async def main(): try: -- cgit v1.2.3-70-g09d2