diff options
author | Thomas Adam <thomas@xteddy.org> | 2016-10-17 00:01:11 +0100 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2016-10-17 00:01:11 +0100 |
commit | d54e990c4ffb576aa3d82306b970dc64bdd4cda6 (patch) | |
tree | 14657ab6804e8dcb4ee696afd823e19e46e0631f /notify.c | |
parent | 1a6e696b08113ca17ee8e881844167cf94276846 (diff) | |
parent | fe106842c879c8f2d0419afba4f90ce0c62c5e80 (diff) | |
download | rtmux-d54e990c4ffb576aa3d82306b970dc64bdd4cda6.tar.gz rtmux-d54e990c4ffb576aa3d82306b970dc64bdd4cda6.tar.bz2 rtmux-d54e990c4ffb576aa3d82306b970dc64bdd4cda6.zip |
Merge branch 'obsd-master'
Diffstat (limited to 'notify.c')
-rw-r--r-- | notify.c | 159 |
1 files changed, 75 insertions, 84 deletions
@@ -19,72 +19,43 @@ #include <sys/types.h> #include <stdlib.h> +#include <string.h> #include "tmux.h" -enum notify_type { - NOTIFY_WINDOW_LAYOUT_CHANGED, - NOTIFY_WINDOW_UNLINKED, - NOTIFY_WINDOW_LINKED, - NOTIFY_WINDOW_RENAMED, - NOTIFY_ATTACHED_SESSION_CHANGED, - NOTIFY_SESSION_RENAMED, - NOTIFY_SESSION_CREATED, - NOTIFY_SESSION_CLOSED -}; - -static const char *notify_hooks[] = { - "window-layout-changed", - NULL, /* "window-unlinked", */ - NULL, /* "window-linked", */ - "window-renamed", - NULL, /* "attached-session-changed", */ - "session-renamed", - "session-created", - "session-closed" -}; - struct notify_entry { - enum notify_type type; + const char *name; struct client *client; struct session *session; struct window *window; + int pane; + + struct cmd_find_state fs; }; static void notify_hook(struct cmdq_item *item, struct notify_entry *ne) { - const char *name; struct cmd_find_state fs; struct hook *hook; struct cmdq_item *new_item; struct session *s = ne->session; struct window *w = ne->window; - name = notify_hooks[ne->type]; - if (name == NULL) - return; - cmd_find_clear_state(&fs, NULL, 0); - if (s != NULL && w != NULL) - cmd_find_from_session_window(&fs, s, w); - else if (w != NULL) - cmd_find_from_window(&fs, w); - else if (s != NULL && session_alive(s)) - cmd_find_from_session(&fs, s); - else + if (cmd_find_empty_state(&ne->fs) || !cmd_find_valid_state(&ne->fs)) cmd_find_current(&fs, item, CMD_FIND_QUIET); - if (cmd_find_empty_state(&fs) || !cmd_find_valid_state(&fs)) - return; + else + cmd_find_copy_state(&fs, &ne->fs); - hook = hooks_find(fs.s->hooks, name); + hook = hooks_find(hooks_get(fs.s), ne->name); if (hook == NULL) return; - log_debug("notify hook %s", name); + log_debug("notify hook %s", ne->name); new_item = cmdq_get_command(hook->cmdlist, &fs, NULL, CMDQ_NOHOOKS); - cmdq_format(new_item, "hook", "%s", name); + cmdq_format(new_item, "hook", "%s", ne->name); if (s != NULL) { cmdq_format(new_item, "hook_session", "$%u", s->id); @@ -94,6 +65,8 @@ notify_hook(struct cmdq_item *item, struct notify_entry *ne) cmdq_format(new_item, "hook_window", "@%u", w->id); cmdq_format(new_item, "hook_window_name", "%s", w->name); } + if (ne->pane != -1) + cmdq_format(new_item, "hook_pane", "%%%d", ne->pane); cmdq_insert_after(item, new_item); } @@ -103,32 +76,23 @@ notify_callback(struct cmdq_item *item, void *data) { struct notify_entry *ne = data; - switch (ne->type) { - case NOTIFY_WINDOW_LAYOUT_CHANGED: + if (strcmp(ne->name, "window-layout-changed") == 0) control_notify_window_layout_changed(ne->window); - break; - case NOTIFY_WINDOW_UNLINKED: + if (strcmp(ne->name, "window-unlinked") == 0) control_notify_window_unlinked(ne->session, ne->window); - break; - case NOTIFY_WINDOW_LINKED: + if (strcmp(ne->name, "window-linked") == 0) control_notify_window_linked(ne->session, ne->window); - break; - case NOTIFY_WINDOW_RENAMED: + if (strcmp(ne->name, "window-renamed") == 0) control_notify_window_renamed(ne->window); - break; - case NOTIFY_ATTACHED_SESSION_CHANGED: - control_notify_attached_session_changed(ne->client); - break; - case NOTIFY_SESSION_RENAMED: + if (strcmp(ne->name, "client-session-changed") == 0) + control_notify_client_session_changed(ne->client); + if (strcmp(ne->name, "session-renamed") == 0) control_notify_session_renamed(ne->session); - break; - case NOTIFY_SESSION_CREATED: + if (strcmp(ne->name, "session-created") == 0) control_notify_session_created(ne->session); - break; - case NOTIFY_SESSION_CLOSED: + if (strcmp(ne->name, "session-closed") == 0) control_notify_session_closed(ne->session); - break; - } + notify_hook(item, ne); if (ne->client != NULL) @@ -137,24 +101,35 @@ notify_callback(struct cmdq_item *item, void *data) session_unref(ne->session); if (ne->window != NULL) window_remove_ref(ne->window); + + if (ne->fs.s != NULL) + session_unref(ne->fs.s); + + free((void *)ne->name); free(ne); return (CMD_RETURN_NORMAL); } static void -notify_add(enum notify_type type, struct client *c, struct session *s, - struct window *w) +notify_add(const char *name, struct cmd_find_state *fs, struct client *c, + struct session *s, struct window *w, struct window_pane *wp) { struct notify_entry *ne; struct cmdq_item *new_item; ne = xcalloc(1, sizeof *ne); - ne->type = type; + ne->name = xstrdup(name); + ne->client = c; ne->session = s; ne->window = w; + if (wp != NULL) + ne->pane = wp->id; + else + ne->pane = -1; + if (c != NULL) c->references++; if (s != NULL) @@ -162,6 +137,10 @@ notify_add(enum notify_type type, struct client *c, struct session *s, if (w != NULL) w->references++; + cmd_find_copy_state(&ne->fs, fs); + if (ne->fs.s != NULL) + ne->fs.s->references++; /* cmd_find_valid_state need session */ + new_item = cmdq_get_callback(notify_callback, ne); cmdq_append(NULL, new_item); } @@ -178,49 +157,61 @@ notify_input(struct window_pane *wp, struct evbuffer *input) } void -notify_window_layout_changed(struct window *w) +notify_client(const char *name, struct client *c) { - notify_add(NOTIFY_WINDOW_LAYOUT_CHANGED, NULL, NULL, w); -} + struct cmd_find_state fs; -void -notify_window_unlinked(struct session *s, struct window *w) -{ - notify_add(NOTIFY_WINDOW_UNLINKED, NULL, s, w); + if (c->session != NULL) + cmd_find_from_session(&fs, c->session); + else + cmd_find_current(&fs, NULL, CMD_FIND_QUIET); + notify_add(name, &fs, c, NULL, NULL, NULL); } void -notify_window_linked(struct session *s, struct window *w) +notify_session(const char *name, struct session *s) { - notify_add(NOTIFY_WINDOW_LINKED, NULL, s, w); -} + struct cmd_find_state fs; -void -notify_window_renamed(struct window *w) -{ - notify_add(NOTIFY_WINDOW_RENAMED, NULL, NULL, w); + if (session_alive(s)) + cmd_find_from_session(&fs, s); + else + cmd_find_current(&fs, NULL, CMD_FIND_QUIET); + notify_add(name, &fs, NULL, s, NULL, NULL); } void -notify_attached_session_changed(struct client *c) +notify_winlink(const char *name, struct session *s, struct winlink *wl) { - notify_add(NOTIFY_ATTACHED_SESSION_CHANGED, c, NULL, NULL); + struct cmd_find_state fs; + + cmd_find_from_winlink(&fs, s, wl); + notify_add(name, &fs, NULL, s, wl->window, NULL); } void -notify_session_renamed(struct session *s) +notify_session_window(const char *name, struct session *s, struct window *w) { - notify_add(NOTIFY_SESSION_RENAMED, NULL, s, NULL); + struct cmd_find_state fs; + + cmd_find_from_session_window(&fs, s, w); + notify_add(name, &fs, NULL, s, w, NULL); } void -notify_session_created(struct session *s) +notify_window(const char *name, struct window *w) { - notify_add(NOTIFY_SESSION_CREATED, NULL, s, NULL); + struct cmd_find_state fs; + + cmd_find_from_window(&fs, w); + notify_add(name, &fs, NULL, NULL, w, NULL); } void -notify_session_closed(struct session *s) +notify_pane(const char *name, struct window_pane *wp) { - notify_add(NOTIFY_SESSION_CLOSED, NULL, s, NULL); + struct cmd_find_state fs; + + cmd_find_from_pane(&fs, wp); + notify_add(name, &fs, NULL, NULL, NULL, wp); } |