1 /* $OpenBSD: cmd-select-pane.c,v 1.23 2015/04/29 16:26:17 nicm Exp $ */ 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 * Select pane. 25 */ 26 27 enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_q *); 28 29 const struct cmd_entry cmd_select_pane_entry = { 30 "select-pane", "selectp", 31 "DdegLlP:Rt:U", 0, 0, 32 "[-DdegLlRU] [-P style] " CMD_TARGET_PANE_USAGE, 33 0, 34 cmd_select_pane_exec 35 }; 36 37 const struct cmd_entry cmd_last_pane_entry = { 38 "last-pane", "lastp", 39 "det:", 0, 0, 40 "[-de] " CMD_TARGET_WINDOW_USAGE, 41 0, 42 cmd_select_pane_exec 43 }; 44 45 enum cmd_retval 46 cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq) 47 { 48 struct args *args = self->args; 49 struct winlink *wl; 50 struct window_pane *wp; 51 const char *style; 52 53 if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) { 54 wl = cmd_find_window(cmdq, args_get(args, 't'), NULL); 55 if (wl == NULL) 56 return (CMD_RETURN_ERROR); 57 58 if (wl->window->last == NULL) { 59 cmdq_error(cmdq, "no last pane"); 60 return (CMD_RETURN_ERROR); 61 } 62 63 if (args_has(self->args, 'e')) 64 wl->window->last->flags &= ~PANE_INPUTOFF; 65 else if (args_has(self->args, 'd')) 66 wl->window->last->flags |= PANE_INPUTOFF; 67 else { 68 server_unzoom_window(wl->window); 69 window_set_active_pane(wl->window, wl->window->last); 70 server_status_window(wl->window); 71 server_redraw_window_borders(wl->window); 72 } 73 74 return (CMD_RETURN_NORMAL); 75 } 76 77 if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL) 78 return (CMD_RETURN_ERROR); 79 80 if (args_has(self->args, 'P') || args_has(self->args, 'g')) { 81 if (args_has(args, 'P')) { 82 style = args_get(args, 'P'); 83 if (style_parse(&grid_default_cell, &wp->colgc, 84 style) == -1) { 85 cmdq_error(cmdq, "bad style: %s", style); 86 return (CMD_RETURN_ERROR); 87 } 88 wp->flags |= PANE_REDRAW; 89 } 90 if (args_has(self->args, 'g')) 91 cmdq_print(cmdq, "%s", style_tostring(&wp->colgc)); 92 return (CMD_RETURN_NORMAL); 93 } 94 95 if (args_has(self->args, 'L')) 96 wp = window_pane_find_left(wp); 97 else if (args_has(self->args, 'R')) 98 wp = window_pane_find_right(wp); 99 else if (args_has(self->args, 'U')) 100 wp = window_pane_find_up(wp); 101 else if (args_has(self->args, 'D')) 102 wp = window_pane_find_down(wp); 103 if (wp == NULL) 104 return (CMD_RETURN_NORMAL); 105 106 if (args_has(self->args, 'e')) { 107 wp->flags &= ~PANE_INPUTOFF; 108 return (CMD_RETURN_NORMAL); 109 } 110 if (args_has(self->args, 'd')) { 111 wp->flags |= PANE_INPUTOFF; 112 return (CMD_RETURN_NORMAL); 113 } 114 115 if (wp == wl->window->active) 116 return (CMD_RETURN_NORMAL); 117 server_unzoom_window(wp->window); 118 if (!window_pane_visible(wp)) { 119 cmdq_error(cmdq, "pane not visible"); 120 return (CMD_RETURN_ERROR); 121 } 122 if (window_set_active_pane(wl->window, wp)) { 123 server_status_window(wl->window); 124 server_redraw_window_borders(wl->window); 125 } 126 127 return (CMD_RETURN_NORMAL); 128 } 129