From c3c63d3a1eaa102cac854cdab5661e9f908f7485 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 7 Nov 2024 09:31:26 +0530 Subject: [PATCH] Add a load event for watchers --- docs/launch.rst | 6 ++++++ kitty/launch.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/docs/launch.rst b/docs/launch.rst index 13bb8bd7a..fb11cdf89 100644 --- a/docs/launch.rst +++ b/docs/launch.rst @@ -128,6 +128,12 @@ create :file:`~/.config/kitty/mywatcher.py` and use :option:`launch --watcher` = from kitty.window import Window + def on_load(boss: Boss) -> None: + # This is a special function that is called just once when this watcher + # module is first loaded, can be used to perform any initializztion/one + # time setup. + ... + def on_resize(boss: Boss, window: Window, data: Dict[str, Any]) -> None: # Here data will contain old_geometry and new_geometry # Note that resize is also called the first time a window is created diff --git a/kitty/launch.py b/kitty/launch.py index 73d6a6972..a9a59604c 100644 --- a/kitty/launch.py +++ b/kitty/launch.py @@ -423,6 +423,7 @@ def load_watch_modules(watchers: Iterable[str]) -> Optional[Watchers]: return None import runpy ans = Watchers() + boss = get_boss() for path in watchers: path = resolve_custom_file(path) m = watcher_modules.get(path, None) @@ -436,6 +437,9 @@ def load_watch_modules(watchers: Iterable[str]) -> Optional[Watchers]: watcher_modules[path] = False continue watcher_modules[path] = m + w = m.get('on_load') + if callable(w): + w(boss) if m is False: continue w = m.get('on_close')