Replace the notification system with events. Events can carry a payload of

additional payload (to reduce problems with lifetime of objects) and are
delivered to one or more event sinks. This is more powerful and reduces the
complex dependencies between control mode and hooks. Events are now used for
hooks, control mode notifications and for monitors (set-hook -B).

wait-for can now wait for an event to fire (-E flag, with -F to for filter),
with -v to print the payload, as well as listing (-l) waiting clients on an
event and forcing one to wake (-w).

A few additional hooks are also now available (pane-created, pane-resized, etc)
and some of the existing ones have additional format variables available.
This commit is contained in:
nicm
2026-07-10 13:38:45 +00:00
parent 1508bec957
commit d29aa12117
153 changed files with 2543 additions and 1787 deletions

49
spawn.c
View File

@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $OpenBSD: spawn.c,v 1.47 2026/07/10 13:38:45 nicm Exp $ */
/*
* Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -73,6 +73,45 @@ spawn_log(const char *from, struct spawn_context *sc)
log_debug("%s: s=$%u %s idx=%d", from, s->id, tmp, sc->idx);
}
static void
spawn_fire_pane_created(struct spawn_context *sc, struct window_pane *wp)
{
struct event_payload *ep;
struct cmd_find_state fs;
char *cmd = NULL;
const char *cwd = wp->cwd;
ep = event_payload_create();
cmd_find_from_winlink_pane(&fs, sc->wl, wp, 0);
event_payload_set_target(ep, &fs);
event_payload_set_session(ep, "session", sc->s);
event_payload_set_window(ep, "window", wp->window);
event_payload_set_int(ep, "window_index", sc->wl->idx);
event_payload_set_pane(ep, "pane", wp);
if (wp->argc != 0)
cmd = cmd_stringify_argv(wp->argc, wp->argv);
if (cmd != NULL && *cmd != '\0')
event_payload_set_string(ep, "pane_command", "%s", cmd);
else if (wp->shell != NULL)
event_payload_set_string(ep, "pane_command", "%s", wp->shell);
free(cmd);
if (cwd != NULL)
event_payload_set_string(ep, "pane_current_path", "%s", cwd);
if (sc->flags & SPAWN_EMPTY)
event_payload_set_int(ep, "created_empty", 1);
else
event_payload_set_int(ep, "created_empty", 0);
if (sc->flags & SPAWN_RESPAWN)
event_payload_set_int(ep, "created_respawn", 1);
else
event_payload_set_int(ep, "created_respawn", 0);
events_fire("pane-created", ep);
}
struct winlink *
spawn_window(struct spawn_context *sc, char **cause)
{
@@ -133,7 +172,7 @@ spawn_window(struct spawn_context *sc, char **cause)
* if this makes it empty.
*/
wl->flags &= ~WINLINK_ALERTFLAGS;
notify_session_window("window-unlinked", s, wl->window);
events_fire_winlink("window-unlinked", wl);
winlink_stack_remove(&s->lastw, wl);
winlink_remove(&s->windows, wl);
@@ -193,7 +232,7 @@ spawn_window(struct spawn_context *sc, char **cause)
/* Fire notification if new window. */
if (~sc->flags & SPAWN_RESPAWN)
notify_session_window("window-linked", s, w);
events_fire_winlink("window-linked", sc->wl);
session_group_synchronize_from(s);
return (sc->wl);
@@ -499,8 +538,8 @@ complete:
sigprocmask(SIG_SETMASK, &oldset, NULL);
window_pane_set_event(new_wp);
environ_free(child);
spawn_fire_pane_created(sc, new_wp);
if (sc->flags & SPAWN_RESPAWN)
return (new_wp);
@@ -511,7 +550,7 @@ complete:
window_set_active_pane(w, new_wp, 1);
}
if (~sc->flags & SPAWN_NONOTIFY)
notify_window("window-layout-changed", w);
events_fire_window("window-layout-changed", w);
return (new_wp);
}