[BACK]Return to cmd-switch-client.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/cmd-switch-client.c, Revision 1.42

1.42    ! nicm        1: /* $OpenBSD: cmd-switch-client.c,v 1.41 2015/12/23 00:12:57 nicm Exp $ */
1.1       nicm        2:
                      3: /*
1.42    ! nicm        4:  * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1       nicm        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:
1.17      nicm       30: enum cmd_retval         cmd_switch_client_exec(struct cmd *, struct cmd_q *);
1.1       nicm       31:
                     32: const struct cmd_entry cmd_switch_client_entry = {
1.39      nicm       33:        .name = "switch-client",
                     34:        .alias = "switchc",
                     35:
                     36:        .args = { "lc:Enpt:rT:", 0, 0 },
                     37:        .usage = "[-Elnpr] [-c target-client] [-t target-session] "
                     38:                 "[-T key-table]",
                     39:
1.40      nicm       40:        .cflag = CMD_CLIENT,
                     41:        .tflag = CMD_SESSION_WITHPANE,
                     42:
                     43:        .flags = CMD_READONLY,
1.39      nicm       44:        .exec = cmd_switch_client_exec
1.1       nicm       45: };
1.6       nicm       46:
1.15      nicm       47: enum cmd_retval
1.17      nicm       48: cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
1.1       nicm       49: {
1.19      nicm       50:        struct args             *args = self->args;
1.38      nicm       51:        struct cmd_state        *state = &cmdq->state;
                     52:        struct client           *c = state->c;
                     53:        struct session          *s = cmdq->state.tflag.s;
                     54:        struct window_pane      *wp;
                     55:        const char              *tablename, *update;
1.23      nicm       56:        struct key_table        *table;
1.13      nicm       57:
1.34      mmcc       58:        if (args_has(args, 'r'))
                     59:                c->flags ^= CLIENT_READONLY;
1.23      nicm       60:
                     61:        tablename = args_get(args, 'T');
                     62:        if (tablename != NULL) {
                     63:                table = key_bindings_get_table(tablename, 0);
                     64:                if (table == NULL) {
                     65:                        cmdq_error(cmdq, "table %s doesn't exist", tablename);
                     66:                        return (CMD_RETURN_ERROR);
                     67:                }
                     68:                table->references++;
                     69:                key_bindings_unref_table(c->keytable);
                     70:                c->keytable = table;
1.36      nicm       71:                return (CMD_RETURN_NORMAL);
1.13      nicm       72:        }
1.6       nicm       73:
1.11      nicm       74:        if (args_has(args, 'n')) {
1.6       nicm       75:                if ((s = session_next_session(c->session)) == NULL) {
1.17      nicm       76:                        cmdq_error(cmdq, "can't find next session");
1.15      nicm       77:                        return (CMD_RETURN_ERROR);
1.6       nicm       78:                }
1.11      nicm       79:        } else if (args_has(args, 'p')) {
1.6       nicm       80:                if ((s = session_previous_session(c->session)) == NULL) {
1.17      nicm       81:                        cmdq_error(cmdq, "can't find previous session");
1.15      nicm       82:                        return (CMD_RETURN_ERROR);
1.6       nicm       83:                }
1.11      nicm       84:        } else if (args_has(args, 'l')) {
1.9       nicm       85:                if (c->last_session != NULL && session_alive(c->last_session))
                     86:                        s = c->last_session;
1.38      nicm       87:                else
                     88:                        s = NULL;
1.8       nicm       89:                if (s == NULL) {
1.17      nicm       90:                        cmdq_error(cmdq, "can't find last session");
1.15      nicm       91:                        return (CMD_RETURN_ERROR);
1.8       nicm       92:                }
1.41      nicm       93:        } else {
1.19      nicm       94:                if (cmdq->client == NULL)
                     95:                        return (CMD_RETURN_NORMAL);
1.38      nicm       96:                if (state->tflag.wl != NULL) {
                     97:                        wp = state->tflag.wp;
1.19      nicm       98:                        if (wp != NULL)
                     99:                                window_set_active_pane(wp->window, wp);
1.38      nicm      100:                        session_set_current(s, state->tflag.wl);
1.19      nicm      101:                }
1.25      nicm      102:        }
                    103:
1.27      nicm      104:        if (c != NULL && !args_has(args, 'E')) {
1.32      nicm      105:                update = options_get_string(s->options, "update-environment");
1.33      nicm      106:                environ_update(update, c->environ, s->environ);
1.19      nicm      107:        }
1.8       nicm      108:
1.31      nicm      109:        if (c->session != NULL && c->session != s)
1.9       nicm      110:                c->last_session = c->session;
1.1       nicm      111:        c->session = s;
1.37      nicm      112:        server_client_set_key_table(c, NULL);
1.28      nicm      113:        status_timer_start(c);
1.29      nicm      114:        session_update_activity(s, NULL);
1.30      nicm      115:        gettimeofday(&s->last_attached_time, NULL);
1.1       nicm      116:
                    117:        recalculate_sizes();
1.7       nicm      118:        server_check_unattached();
1.1       nicm      119:        server_redraw_client(c);
1.14      nicm      120:        s->curw->flags &= ~WINLINK_ALERTFLAGS;
1.35      nicm      121:        alerts_check_session(s);
1.1       nicm      122:
1.15      nicm      123:        return (CMD_RETURN_NORMAL);
1.1       nicm      124: }