summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2016-10-13 10:01:50 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2016-10-13 10:01:50 +0000
commit1ce190788f8a9771c0fdc87a578f903f52cb59d6 (patch)
tree8a3fe1b6a6f5829aa57bb7dfd8ed27631b9ec05b
parent2fdfe62035bfc1a16795dd53042323ff8bee7e82 (diff)
Some improvements and bug fixes for hooks:
- Prepare the state again before the "after" hooks are run, because the command may have killed or moved windows. - Use the hooks list from the newly prepared target, not the old hooks list (only matters for new-session really). - Correctly detect an invalid current state and ignore it in cmd_find_target ("killw; swapw"). - Change neww, new, killp, killw, splitw, swapp, swapw to update the current state (used if no explicit target is given) to something more useful after they have finished. For example, neww changes it to the newly created window. Hooks are still relatively new and primitive so there are likely to be more changes to come. Parts based on bug reports from Uwe Werler and Iblis Lin.
-rw-r--r--usr.bin/tmux/cmd-find.c24
-rw-r--r--usr.bin/tmux/cmd-join-pane.c9
-rw-r--r--usr.bin/tmux/cmd-new-session.c4
-rw-r--r--usr.bin/tmux/cmd-new-window.c4
-rw-r--r--usr.bin/tmux/cmd-queue.c46
-rw-r--r--usr.bin/tmux/cmd-split-window.c9
-rw-r--r--usr.bin/tmux/cmd-swap-pane.c9
-rw-r--r--usr.bin/tmux/cmd-swap-window.c9
-rw-r--r--usr.bin/tmux/cmd.c14
-rw-r--r--usr.bin/tmux/tmux.h3
10 files changed, 101 insertions, 30 deletions
diff --git a/usr.bin/tmux/cmd-find.c b/usr.bin/tmux/cmd-find.c
index 7db3e083bfb..4bc069ada42 100644
--- a/usr.bin/tmux/cmd-find.c
+++ b/usr.bin/tmux/cmd-find.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-find.c,v 1.33 2016/10/10 21:51:39 nicm Exp $ */
+/* $OpenBSD: cmd-find.c,v 1.34 2016/10/13 10:01:49 nicm Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -803,6 +803,15 @@ cmd_find_clear_state(struct cmd_find_state *fs, struct cmd_q *cmdq, int flags)
fs->idx = -1;
}
+/* Check if state is empty/ */
+int
+cmd_find_empty_state(struct cmd_find_state *fs)
+{
+ if (fs->s == NULL && fs->wl == NULL && fs->w == NULL && fs->wp == NULL)
+ return (1);
+ return (0);
+}
+
/* Check if a state if valid. */
int
cmd_find_valid_state(struct cmd_find_state *fs)
@@ -959,12 +968,19 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
cmd_find_clear_state(fs, cmdq, flags);
/* Find current state. */
- if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED))
+ if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED)) {
fs->current = &marked_pane;
- else if (cmd_find_valid_state(&cmdq->current))
+ log_debug(" current is marked pane");
+ } else if (cmd_find_valid_state(&cmdq->current)) {
fs->current = &cmdq->current;
- else
+ log_debug(" current is from queue");
+ } else {
fs->current = current;
+ log_debug(" current is from argument");
+ }
+ if (!cmd_find_empty_state(fs->current) &&
+ !cmd_find_valid_state(fs->current))
+ fatalx("invalid current find state");
/* An empty or NULL target is the current. */
if (target == NULL || *target == '\0')
diff --git a/usr.bin/tmux/cmd-join-pane.c b/usr.bin/tmux/cmd-join-pane.c
index b32d75e1a3d..30ff89dcb82 100644
--- a/usr.bin/tmux/cmd-join-pane.c
+++ b/usr.bin/tmux/cmd-join-pane.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-join-pane.c,v 1.26 2016/10/10 21:51:39 nicm Exp $ */
+/* $OpenBSD: cmd-join-pane.c,v 1.27 2016/10/13 10:01:49 nicm Exp $ */
/*
* Copyright (c) 2011 George Nachman <tmux@georgester.com>
@@ -156,5 +156,12 @@ cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq)
notify_window_layout_changed(src_w);
notify_window_layout_changed(dst_w);
+ cmd_find_clear_state(&cmdq->current, NULL, 0);
+ cmdq->current.s = dst_s;
+ cmdq->current.wl = dst_wl;
+ cmdq->current.w = dst_w;
+ cmdq->current.wp = dst_wp;
+ cmd_find_log_state(__func__, &cmdq->current);
+
return (CMD_RETURN_NORMAL);
}
diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c
index b4f406e7e6b..bc5b21b226b 100644
--- a/usr.bin/tmux/cmd-new-session.c
+++ b/usr.bin/tmux/cmd-new-session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-session.c,v 1.88 2016/10/10 21:51:39 nicm Exp $ */
+/* $OpenBSD: cmd-new-session.c,v 1.89 2016/10/13 10:01:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -310,6 +310,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
format_free(ft);
}
+ cmd_find_from_session(&cmdq->current, s);
+
if (!detached)
cmdq->client_exit = 0;
diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c
index eafb47a4f9a..6c5b2ae8cbe 100644
--- a/usr.bin/tmux/cmd-new-window.c
+++ b/usr.bin/tmux/cmd-new-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-window.c,v 1.60 2016/10/10 21:51:39 nicm Exp $ */
+/* $OpenBSD: cmd-new-window.c,v 1.61 2016/10/13 10:01:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -152,6 +152,8 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
format_free(ft);
}
+ cmd_find_from_winlink(&cmdq->current, s, wl);
+
if (to_free != NULL)
free((void *)to_free);
return (CMD_RETURN_NORMAL);
diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c
index 0824a425922..b976e984546 100644
--- a/usr.bin/tmux/cmd-queue.c
+++ b/usr.bin/tmux/cmd-queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-queue.c,v 1.38 2016/10/11 13:21:59 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.39 2016/10/13 10:01:49 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -182,13 +182,30 @@ cmdq_append(struct cmd_q *cmdq, struct cmd_list *cmdlist, struct mouse_event *m)
item->mouse.valid = 0;
}
+/* Find hooks list. */
+static struct hooks *
+cmdq_get_hooks(struct cmd_q *cmdq)
+{
+ struct session *s;
+
+ s = NULL;
+ if (cmdq->state.tflag.s != NULL)
+ s = cmdq->state.tflag.s;
+ else if (cmdq->state.sflag.s != NULL)
+ s = cmdq->state.sflag.s;
+ else if (cmdq->state.c != NULL)
+ s = cmdq->state.c->session;
+ if (s != NULL)
+ return (s->hooks);
+ return (global_hooks);
+}
+
/* Process one command. */
static enum cmd_retval
cmdq_continue_one(struct cmd_q *cmdq)
{
struct cmd *cmd = cmdq->cmd;
const char *name = cmd->entry->name;
- struct session *s;
struct hooks *hooks;
enum cmd_retval retval;
char *tmp;
@@ -208,18 +225,7 @@ cmdq_continue_one(struct cmd_q *cmdq)
goto error;
if (~cmdq->flags & CMD_Q_NOHOOKS) {
- s = NULL;
- if (cmdq->state.tflag.s != NULL)
- s = cmdq->state.tflag.s;
- else if (cmdq->state.sflag.s != NULL)
- s = cmdq->state.sflag.s;
- else if (cmdq->state.c != NULL)
- s = cmdq->state.c->session;
- if (s != NULL)
- hooks = s->hooks;
- else
- hooks = global_hooks;
-
+ hooks = cmdq_get_hooks(cmdq);
if (~cmdq->flags & CMD_Q_REENTRY) {
cmdq->flags |= CMD_Q_REENTRY;
if (hooks_wait(hooks, cmdq, NULL,
@@ -236,9 +242,13 @@ cmdq_continue_one(struct cmd_q *cmdq)
if (retval == CMD_RETURN_ERROR)
goto error;
- if (hooks != NULL && hooks_wait(hooks, cmdq, NULL,
- "after-%s", name) == 0)
- retval = CMD_RETURN_WAIT;
+ if (hooks != NULL) {
+ if (cmd_prepare_state(cmd, cmdq, cmdq->parent) != 0)
+ goto error;
+ hooks = cmdq_get_hooks(cmdq);
+ if (hooks_wait(hooks, cmdq, NULL, "after-%s", name) == 0)
+ retval = CMD_RETURN_WAIT;
+ }
cmdq_guard(cmdq, "end", flags);
return (retval);
@@ -261,6 +271,8 @@ cmdq_continue(struct cmd_q *cmdq)
cmdq->references++;
notify_disable();
+ cmd_find_clear_state(&cmdq->current, NULL, 0);
+
log_debug("continuing cmdq %p: flags %#x, client %p", cmdq, cmdq->flags,
c);
diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c
index 6da2a3cc4d5..f34586fcdbb 100644
--- a/usr.bin/tmux/cmd-split-window.c
+++ b/usr.bin/tmux/cmd-split-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-split-window.c,v 1.71 2016/10/10 21:51:39 nicm Exp $ */
+/* $OpenBSD: cmd-split-window.c,v 1.72 2016/10/13 10:01:49 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -178,6 +178,13 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
}
notify_window_layout_changed(w);
+ cmd_find_clear_state(&cmdq->current, NULL, 0);
+ cmdq->current.s = s;
+ cmdq->current.wl = wl;
+ cmdq->current.w = wl->window;
+ cmdq->current.wp = new_wp;
+ cmd_find_log_state(__func__, &cmdq->current);
+
if (to_free != NULL)
free((void *)to_free);
return (CMD_RETURN_NORMAL);
diff --git a/usr.bin/tmux/cmd-swap-pane.c b/usr.bin/tmux/cmd-swap-pane.c
index 8b2d0f2ddd8..56404a91700 100644
--- a/usr.bin/tmux/cmd-swap-pane.c
+++ b/usr.bin/tmux/cmd-swap-pane.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-swap-pane.c,v 1.27 2016/10/10 21:51:39 nicm Exp $ */
+/* $OpenBSD: cmd-swap-pane.c,v 1.28 2016/10/13 10:01:49 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -124,5 +124,12 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq)
server_redraw_window(src_w);
server_redraw_window(dst_w);
+ cmd_find_clear_state(&cmdq->current, NULL, 0);
+ cmdq->current.s = cmdq->state.tflag.s;
+ cmdq->current.wl = cmdq->state.tflag.wl;
+ cmdq->current.w = dst_w;
+ cmdq->current.wp = src_wp;
+ cmd_find_log_state(__func__, &cmdq->current);
+
return (CMD_RETURN_NORMAL);
}
diff --git a/usr.bin/tmux/cmd-swap-window.c b/usr.bin/tmux/cmd-swap-window.c
index 7b41584af54..255a5684914 100644
--- a/usr.bin/tmux/cmd-swap-window.c
+++ b/usr.bin/tmux/cmd-swap-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-swap-window.c,v 1.17 2016/10/10 21:51:39 nicm Exp $ */
+/* $OpenBSD: cmd-swap-window.c,v 1.18 2016/10/13 10:01:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -84,5 +84,12 @@ cmd_swap_window_exec(struct cmd *self, struct cmd_q *cmdq)
}
recalculate_sizes();
+ cmd_find_clear_state(&cmdq->current, NULL, 0);
+ cmdq->current.s = dst;
+ cmdq->current.wl = wl_dst;
+ cmdq->current.w = wl_dst->window;
+ cmdq->current.wp = cmdq->state.sflag.wp;
+ cmd_find_log_state(__func__, &cmdq->current);
+
return (CMD_RETURN_NORMAL);
}
diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c
index 730c96701cd..fb51e13e711 100644
--- a/usr.bin/tmux/cmd.c
+++ b/usr.bin/tmux/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.123 2016/10/05 12:32:13 nicm Exp $ */
+/* $OpenBSD: cmd.c,v 1.124 2016/10/13 10:01:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -456,12 +456,15 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
current = &parent->state.tflag;
else if (c == 's')
current = &parent->state.sflag;
- } else {
+ }
+ if (current == NULL || !cmd_find_valid_state(current)) {
error = cmd_find_current(&tmp, cmdq, targetflags);
if (error != 0 && ~targetflags & CMD_FIND_QUIET)
return (-1);
current = &tmp;
}
+ if (!cmd_find_empty_state(current) && !cmd_find_valid_state(current))
+ fatalx("invalid current state");
switch (flag) {
case CMD_NONE:
@@ -558,6 +561,13 @@ cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq, struct cmd_q *parent)
if (error != 0)
return (error);
+ if (!cmd_find_empty_state(&state->tflag) &&
+ !cmd_find_valid_state(&state->tflag))
+ fatalx("invalid -t state");
+ if (!cmd_find_empty_state(&state->sflag) &&
+ !cmd_find_valid_state(&state->sflag))
+ fatalx("invalid -s state");
+
return (0);
}
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index b5b50ab658b..f64ba7beff7 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.659 2016/10/12 15:26:37 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.660 2016/10/13 10:01:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1730,6 +1730,7 @@ int cmd_find_target(struct cmd_find_state *,
struct client *cmd_find_client(struct cmd_q *, const char *, int);
void cmd_find_clear_state(struct cmd_find_state *, struct cmd_q *,
int);
+int cmd_find_empty_state(struct cmd_find_state *);
int cmd_find_valid_state(struct cmd_find_state *);
void cmd_find_copy_state(struct cmd_find_state *,
struct cmd_find_state *);