Unzoom window at start of destroy so it doesn't happen later (when
[tmux-openbsd.git] / cmd-detach-client.c
blob661293aeadc75d8cada25d56e1242f31fa8b7705
1 /* $OpenBSD$ */
3 /*
4 * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
21 #include <string.h>
23 #include "tmux.h"
26 * Detach a client.
29 static enum cmd_retval cmd_detach_client_exec(struct cmd *,
30 struct cmdq_item *);
32 const struct cmd_entry cmd_detach_client_entry = {
33 .name = "detach-client",
34 .alias = "detach",
36 .args = { "aE:s:t:P", 0, 0, NULL },
37 .usage = "[-aP] [-E shell-command] "
38 "[-s target-session] " CMD_TARGET_CLIENT_USAGE,
40 .source = { 's', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
42 .flags = CMD_READONLY|CMD_CLIENT_TFLAG,
43 .exec = cmd_detach_client_exec
46 const struct cmd_entry cmd_suspend_client_entry = {
47 .name = "suspend-client",
48 .alias = "suspendc",
50 .args = { "t:", 0, 0, NULL },
51 .usage = CMD_TARGET_CLIENT_USAGE,
53 .flags = CMD_CLIENT_TFLAG,
54 .exec = cmd_detach_client_exec
57 static enum cmd_retval
58 cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
60 struct args *args = cmd_get_args(self);
61 struct cmd_find_state *source = cmdq_get_source(item);
62 struct client *tc = cmdq_get_target_client(item), *loop;
63 struct session *s;
64 enum msgtype msgtype;
65 const char *cmd = args_get(args, 'E');
67 if (cmd_get_entry(self) == &cmd_suspend_client_entry) {
68 server_client_suspend(tc);
69 return (CMD_RETURN_NORMAL);
72 if (args_has(args, 'P'))
73 msgtype = MSG_DETACHKILL;
74 else
75 msgtype = MSG_DETACH;
77 if (args_has(args, 's')) {
78 s = source->s;
79 if (s == NULL)
80 return (CMD_RETURN_NORMAL);
81 TAILQ_FOREACH(loop, &clients, entry) {
82 if (loop->session == s) {
83 if (cmd != NULL)
84 server_client_exec(loop, cmd);
85 else
86 server_client_detach(loop, msgtype);
89 return (CMD_RETURN_STOP);
92 if (args_has(args, 'a')) {
93 TAILQ_FOREACH(loop, &clients, entry) {
94 if (loop->session != NULL && loop != tc) {
95 if (cmd != NULL)
96 server_client_exec(loop, cmd);
97 else
98 server_client_detach(loop, msgtype);
101 return (CMD_RETURN_NORMAL);
104 if (cmd != NULL)
105 server_client_exec(tc, cmd);
106 else
107 server_client_detach(tc, msgtype);
108 return (CMD_RETURN_STOP);