mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-06 08:01:58 +02:00
Add a load event for watchers
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user