Add a load event for watchers

This commit is contained in:
Kovid Goyal
2024-11-07 09:31:26 +05:30
parent 525dd56aae
commit c3c63d3a1e
2 changed files with 10 additions and 0 deletions

View File

@@ -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

View File

@@ -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')