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

Annotation of src/usr.bin/tmux/cmd-choose-window.c, Revision 1.1

1.1     ! nicm        1: /* $OpenBSD$ */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 2009 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 "tmux.h"
        !            22:
        !            23: /*
        !            24:  * Enter choice mode to choose a window.
        !            25:  */
        !            26:
        !            27: int    cmd_choose_window_exec(struct cmd *, struct cmd_ctx *);
        !            28:
        !            29: void   cmd_choose_window_callback(void *, int);
        !            30:
        !            31: const struct cmd_entry cmd_choose_window_entry = {
        !            32:        "choose-window", NULL,
        !            33:        CMD_TARGET_WINDOW_USAGE,
        !            34:        0,
        !            35:        cmd_target_init,
        !            36:        cmd_target_parse,
        !            37:        cmd_choose_window_exec,
        !            38:        cmd_target_send,
        !            39:        cmd_target_recv,
        !            40:        cmd_target_free,
        !            41:        cmd_target_print
        !            42: };
        !            43:
        !            44: struct cmd_choose_window_data {
        !            45:        u_int   session;
        !            46: };
        !            47:
        !            48: int
        !            49: cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
        !            50: {
        !            51:        struct cmd_target_data          *data = self->data;
        !            52:        struct cmd_choose_window_data   *cdata;
        !            53:        struct session                  *s;
        !            54:        struct winlink                  *wl, *wm;
        !            55:        struct window                   *w;
        !            56:        u_int                            idx, cur;
        !            57:
        !            58:        if (ctx->curclient == NULL) {
        !            59:                ctx->error(ctx, "must be run interactively");
        !            60:                return (-1);
        !            61:        }
        !            62:        s = ctx->curclient->session;
        !            63:
        !            64:        if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
        !            65:                return (-1);
        !            66:
        !            67:        if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
        !            68:                return (0);
        !            69:
        !            70:        cur = idx = 0;
        !            71:        RB_FOREACH(wm, winlinks, &s->windows) {
        !            72:                w = wm->window;
        !            73:
        !            74:                if (wm == s->curw)
        !            75:                        cur = idx;
        !            76:                idx++;
        !            77:
        !            78:                window_choose_add(wl->window->active,
        !            79:                    wm->idx, "%3d: %s [%ux%u %s] (%u panes)", wm->idx, w->name,
        !            80:                    w->sx, w->sy, layout_name(w), window_count_panes(w));
        !            81:        }
        !            82:
        !            83:        cdata = xmalloc(sizeof *cdata);
        !            84:        if (session_index(s, &cdata->session) != 0)
        !            85:                fatalx("session not found");
        !            86:
        !            87:        window_choose_ready(
        !            88:            wl->window->active, cur, cmd_choose_window_callback, cdata);
        !            89:
        !            90:        return (0);
        !            91: }
        !            92:
        !            93: void
        !            94: cmd_choose_window_callback(void *data, int idx)
        !            95: {
        !            96:        struct cmd_choose_window_data   *cdata = data;
        !            97:        struct session                  *s;
        !            98:
        !            99:        if (idx != -1 && cdata->session <= ARRAY_LENGTH(&sessions) - 1) {
        !           100:                s = ARRAY_ITEM(&sessions, cdata->session);
        !           101:                if (s != NULL && session_select(s, idx) == 0)
        !           102:                        server_redraw_session(s);
        !           103:                recalculate_sizes();
        !           104:        }
        !           105:        xfree(cdata);
        !           106: }