The branch, hooks has been updated
via b2bfe4a2d482ca7c6eb737493c9e0f3d02eb54b1 (commit)
via 63ec2337e2b8a81b357eb40e881c74030da62bb7 (commit)
from 5abfa3ebc3e4e02484ea044a5cc7b2b163e39964 (commit)
- Log -----------------------------------------------------------------
commit b2bfe4a2d482ca7c6eb737493c9e0f3d02eb54b1
Author: Thomas Adam <[email protected]>
Commit: Thomas Adam <[email protected]>
notify: Support hooks
Let notifications also run hooks.
---
notify.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/notify.c b/notify.c
index 49c3f8b..6968a60 100644
--- a/notify.c
+++ b/notify.c
@@ -33,6 +33,22 @@ enum notify_type {
NOTIFY_SESSION_CLOSED
};
+struct notify_hooks {
+ const enum notify_type type;
+ const char *hook_name;
+};
+
+const struct notify_hooks notify_hooks_info[] = {
+ {NOTIFY_WINDOW_LAYOUT_CHANGED, "notify-window-layout-changed"},
+ {NOTIFY_WINDOW_UNLINKED, "notify-window-unlinked"},
+ {NOTIFY_WINDOW_LINKED, "notify-window-linked"},
+ {NOTIFY_WINDOW_RENAMED, "notify-window-renamed"},
+ {NOTIFY_ATTACHED_SESSION_CHANGED, "notify-attached-session-changed"},
+ {NOTIFY_SESSION_RENAMED, "notify-session-renamed"},
+ {NOTIFY_SESSION_CREATED, "notify-session-created"},
+ {NOTIFY_SESSION_CLOSED, "notify-session-closed"},
+};
+
struct notify_entry {
enum notify_type type;
@@ -48,6 +64,30 @@ int notify_disabled;
void notify_drain(void);
void notify_add(enum notify_type, struct client *, struct session *,
struct window *);
+void notify_run_hook(const struct notify_entry *);
+
+void
+notify_run_hook(const struct notify_entry *ne)
+{
+ struct hooks *hooks;
+ const char *hook_name = NULL;
+ u_int i;
+
+ for(i = 0; i < nitems(notify_hooks_info); i++) {
+ if (notify_hooks_info[i].type == ne->type) {
+ hook_name = notify_hooks_info[i].hook_name;
+ break;
+ }
+ }
+
+ if (hook_name == NULL)
+ return;
+
+ hooks = ne->session != NULL ? &ne->session->hooks : &global_hooks;
+
+ /* Run the hooked commands */
+ cmdq_hooks_run(hooks, NULL, hook_name, NULL);
+}
void
notify_enable(void)
@@ -131,6 +171,8 @@ notify_drain(void)
window_remove_ref(ne->window);
TAILQ_REMOVE(¬ify_queue, ne, entry);
+ notify_run_hook(ne);
+
free(ne);
}
}
commit 63ec2337e2b8a81b357eb40e881c74030da62bb7
Author: Thomas Adam <[email protected]>
Commit: Thomas Adam <[email protected]>
Make cmdq_run_hooks public
Make cmdq_run_hooks public, allowing hooks on notifies to use this. Stops
notifies needing to duplicate the hooks finding, etc. In making
cmdq_run_hooks
public, pass in both the prefix and the command, since notifies don't have a
prefix.
---
cmd-queue.c | 27 +++++++++++++++++----------
tmux.h | 2 ++
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/cmd-queue.c b/cmd-queue.c
index df9c872..721d674 100644
--- a/cmd-queue.c
+++ b/cmd-queue.c
@@ -25,7 +25,6 @@
#include "tmux.h"
-int cmdq_hooks_run(struct hooks *, const char *, struct cmd_q *);
void cmdq_hooks_emptyfn(struct cmd_q *);
enum cmd_retval cmdq_continue_one(struct cmd_q *);
@@ -158,14 +157,17 @@ cmdq_run(struct cmd_q *cmdq, struct cmd_list *cmdlist)
* running.
*/
int
-cmdq_hooks_run(struct hooks *hooks, const char *prefix, struct cmd_q *cmdq)
+cmdq_hooks_run(struct hooks *hooks, const char *prefix, const char *cmd_name,
+ struct cmd_q *cmdq)
{
- struct cmd *cmd = cmdq->cmd;
struct hook *hook;
struct cmd_q *hooks_cmdq;
char *s;
- xasprintf(&s, "%s-%s", prefix, cmd->entry->name);
+ if (prefix != NULL && cmd_name != NULL)
+ xasprintf(&s, "%s-%s", prefix, cmd_name);
+ else
+ xasprintf(&s, "%s", cmd_name);
hook = hooks_find(hooks, s);
if (hook == NULL) {
@@ -173,7 +175,7 @@ cmdq_hooks_run(struct hooks *hooks, const char *prefix,
struct cmd_q *cmdq)
return (0);
}
- hooks_cmdq = cmdq_new(cmdq->client);
+ hooks_cmdq = cmdq_new(cmdq != NULL ? cmdq->client : NULL);
hooks_cmdq->flags |= CMD_Q_NOHOOKS;
hooks_cmdq->emptyfn = cmdq_hooks_emptyfn;
@@ -182,7 +184,8 @@ cmdq_hooks_run(struct hooks *hooks, const char *prefix,
struct cmd_q *cmdq)
log_debug("entering hooks cmdq %p for %s", hooks_cmdq, s);
free(s);
- cmdq->references++;
+ if (cmdq != NULL)
+ cmdq->references++;
cmdq_run(hooks_cmdq, hook->cmdlist);
return (1);
@@ -196,10 +199,10 @@ cmdq_hooks_emptyfn(struct cmd_q *hooks_cmdq)
log_debug("exiting hooks cmdq %p", hooks_cmdq);
- if (hooks_cmdq->client_exit >= 0)
+ if (cmdq != NULL && hooks_cmdq->client_exit >= 0)
cmdq->client_exit = hooks_cmdq->client_exit;
- if (!cmdq_free(cmdq))
+ if (cmdq != NULL && !cmdq_free(cmdq))
cmdq_continue(cmdq);
cmdq_free(hooks_cmdq);
@@ -255,8 +258,10 @@ cmdq_continue_one(struct cmd_q *cmdq)
if (~cmdq->flags & CMD_Q_REENTRY) {
cmdq->flags |= CMD_Q_REENTRY;
- if (cmdq_hooks_run(hooks, "before", cmdq))
+ if (cmdq_hooks_run(hooks, "before",
+ cmdq->cmd->entry->name,cmdq)) {
return (CMD_RETURN_WAIT);
+ }
}
} else
hooks = NULL;
@@ -268,8 +273,10 @@ cmdq_continue_one(struct cmd_q *cmdq)
if (retval == CMD_RETURN_ERROR)
goto error;
- if (hooks != NULL && cmdq_hooks_run(hooks, "after", cmdq))
+ if (hooks != NULL && cmdq_hooks_run(hooks, "after",
+ cmdq->cmd->entry->name, cmdq)) {
retval = CMD_RETURN_WAIT;
+ }
cmdq_guard(cmdq, "end", flags);
return (retval);
diff --git a/tmux.h b/tmux.h
index 47b3665..062df70 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1903,6 +1903,8 @@ void cmdq_run(struct cmd_q *, struct
cmd_list *);
void cmdq_append(struct cmd_q *, struct cmd_list *);
int cmdq_continue(struct cmd_q *);
void cmdq_flush(struct cmd_q *);
+int cmdq_hooks_run(struct hooks *, const char *, const char *,
+ struct cmd_q *);
/* cmd-string.c */
int cmd_string_parse(const char *, struct cmd_list **, const char *,
-----------------------------------------------------------------------
Summary of changes:
cmd-queue.c | 27 +++++++++++++++++----------
notify.c | 42 ++++++++++++++++++++++++++++++++++++++++++
tmux.h | 2 ++
3 files changed, 61 insertions(+), 10 deletions(-)
hooks/post-receive
--
tmux
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
tmux-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-cvs