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

Annotation of src/usr.bin/tmux/cmd-select-window.c, Revision 1.5

1.5     ! nicm        1: /* $OpenBSD: cmd-select-window.c,v 1.4 2009/11/13 19:53:29 nicm Exp $ */
1.1       nicm        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:
                     23: #include "tmux.h"
                     24:
                     25: /*
                     26:  * Select window by index.
                     27:  */
                     28:
1.5     ! nicm       29: void   cmd_select_window_key_binding(struct cmd *, int);
1.1       nicm       30: int    cmd_select_window_exec(struct cmd *, struct cmd_ctx *);
                     31:
                     32: const struct cmd_entry cmd_select_window_entry = {
                     33:        "select-window", "selectw",
1.5     ! nicm       34:        "t:", 0, 0,
1.1       nicm       35:        CMD_TARGET_WINDOW_USAGE,
1.5     ! nicm       36:        0,
        !            37:        cmd_select_window_key_binding,
        !            38:        NULL,
        !            39:        cmd_select_window_exec
1.1       nicm       40: };
                     41:
                     42: void
1.5     ! nicm       43: cmd_select_window_key_binding(struct cmd *self, int key)
1.1       nicm       44: {
1.5     ! nicm       45:        char    tmp[16];
1.1       nicm       46:
1.5     ! nicm       47:        xsnprintf(tmp, sizeof tmp, ":%d", key - '0');
1.1       nicm       48:
1.5     ! nicm       49:        self->args = args_create(0);
        !            50:        args_set(self->args, 't', tmp);
1.1       nicm       51: }
                     52:
                     53: int
                     54: cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
                     55: {
1.5     ! nicm       56:        struct args     *args = self->args;
        !            57:        struct winlink  *wl;
        !            58:        struct session  *s;
1.1       nicm       59:
1.5     ! nicm       60:        if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
1.1       nicm       61:                return (-1);
                     62:
                     63:        if (session_select(s, wl->idx) == 0)
                     64:                server_redraw_session(s);
                     65:        recalculate_sizes();
                     66:
                     67:        return (0);
                     68: }