Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 115 lines (99 sloc) 2.962 kb
0f2e336 @orebokech Import upstream snapshot from SVN r2670
orebokech authored
1 /* $Id: cmd-switch-client.c 2665 2012-01-21 19:30:07Z tcunha $ */
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
2
3 /*
4 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
5 *
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.
9 *
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.
17 */
18
19 #include <sys/types.h>
20
21 #include <stdlib.h>
22 #include <string.h>
23
24 #include "tmux.h"
25
26 /*
27 * Switch client to a different session.
28 */
29
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
30 void cmd_switch_client_key_binding(struct cmd *, int);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
31 int cmd_switch_client_exec(struct cmd *, struct cmd_ctx *);
32
33 const struct cmd_entry cmd_switch_client_entry = {
34 "switch-client", "switchc",
b016948 @orebokech Import upstream snapshot from SVN r2608
orebokech authored
35 "lc:npt:r", 0, 0,
36 "[-lnpr] [-c target-client] [-t target-session]",
37 CMD_READONLY,
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
38 cmd_switch_client_key_binding,
39 NULL,
40 cmd_switch_client_exec
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
41 };
42
77c63de @orebokech Import upstream version 1.4
orebokech authored
43 void
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
44 cmd_switch_client_key_binding(struct cmd *self, int key)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
45 {
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
46 self->args = args_create(0);
77c63de @orebokech Import upstream version 1.4
orebokech authored
47 switch (key) {
48 case '(':
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
49 args_set(self->args, 'p', NULL);
77c63de @orebokech Import upstream version 1.4
orebokech authored
50 break;
51 case ')':
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
52 args_set(self->args, 'n', NULL);
77c63de @orebokech Import upstream version 1.4
orebokech authored
53 break;
54 case 'L':
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
55 args_set(self->args, 'l', NULL);
77c63de @orebokech Import upstream version 1.4
orebokech authored
56 break;
57 }
58 }
59
60 int
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
61 cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx)
62 {
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
63 struct args *args = self->args;
64 struct client *c;
65 struct session *s;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
66
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
67 if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
68 return (-1);
77c63de @orebokech Import upstream version 1.4
orebokech authored
69
b016948 @orebokech Import upstream snapshot from SVN r2608
orebokech authored
70 if (args_has(args, 'r')) {
71 if (c->flags & CLIENT_READONLY) {
72 c->flags &= ~CLIENT_READONLY;
73 ctx->info(ctx, "made client writable");
74 } else {
75 c->flags |= CLIENT_READONLY;
76 ctx->info(ctx, "made client read-only");
77 }
78 }
79
77c63de @orebokech Import upstream version 1.4
orebokech authored
80 s = NULL;
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
81 if (args_has(args, 'n')) {
77c63de @orebokech Import upstream version 1.4
orebokech authored
82 if ((s = session_next_session(c->session)) == NULL) {
83 ctx->error(ctx, "can't find next session");
84 return (-1);
85 }
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
86 } else if (args_has(args, 'p')) {
77c63de @orebokech Import upstream version 1.4
orebokech authored
87 if ((s = session_previous_session(c->session)) == NULL) {
88 ctx->error(ctx, "can't find previous session");
89 return (-1);
90 }
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
91 } else if (args_has(args, 'l')) {
77c63de @orebokech Import upstream version 1.4
orebokech authored
92 if (c->last_session != NULL && session_alive(c->last_session))
93 s = c->last_session;
94 if (s == NULL) {
95 ctx->error(ctx, "can't find last session");
96 return (-1);
97 }
98 } else
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
99 s = cmd_find_session(ctx, args_get(args, 't'), 0);
77c63de @orebokech Import upstream version 1.4
orebokech authored
100 if (s == NULL)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
101 return (-1);
102
77c63de @orebokech Import upstream version 1.4
orebokech authored
103 if (c->session != NULL)
104 c->last_session = c->session;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
105 c->session = s;
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
106 session_update_activity(s);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
107
108 recalculate_sizes();
77c63de @orebokech Import upstream version 1.4
orebokech authored
109 server_check_unattached();
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
110 server_redraw_client(c);
0f2e336 @orebokech Import upstream snapshot from SVN r2670
orebokech authored
111 s->curw->flags &= ~WINLINK_ALERTFLAGS;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
112
113 return (0);
114 }
Something went wrong with that request. Please try again.