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 * 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 "DdegLlMmP:Rt:U", 0, 0, 32 "[-DdegLlMmRU] [-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 *w; 51 struct session *s; 52 struct window_pane *wp, *lastwp, *markedwp; 53 const char *style; 54 55 if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) { 56 wl = cmd_find_window(cmdq, args_get(args, 't'), NULL); 57 if (wl == NULL) 58 return (CMD_RETURN_ERROR); 59 w = wl->window; 60 61 if (w->last == NULL) { 62 cmdq_error(cmdq, "no last pane"); 63 return (CMD_RETURN_ERROR); 64 } 65 66 if (args_has(self->args, 'e')) 67 w->last->flags &= ~PANE_INPUTOFF; 68 else if (args_has(self->args, 'd')) 69 w->last->flags |= PANE_INPUTOFF; 70 else { 71 server_unzoom_window(w); 72 window_redraw_active_switch(w, w->last); 73 if (window_set_active_pane(w, w->last)) { 74 server_status_window(w); 75 server_redraw_window_borders(w); 76 } 77 } 78 79 return (CMD_RETURN_NORMAL); 80 } 81 82 if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL) 83 return (CMD_RETURN_ERROR); 84 w = wl->window; 85 86 if (args_has(args, 'm') || args_has(args, 'M')) { 87 if (args_has(args, 'm') && !window_pane_visible(wp)) 88 return (CMD_RETURN_NORMAL); 89 lastwp = marked_window_pane; 90 91 if (args_has(args, 'M') || server_is_marked(s, wl, wp)) 92 server_clear_marked(); 93 else 94 server_set_marked(s, wl, wp); 95 markedwp = marked_window_pane; 96 97 if (lastwp != NULL) { 98 server_redraw_window_borders(lastwp->window); 99 server_status_window(lastwp->window); 100 } 101 if (markedwp != NULL) { 102 server_redraw_window_borders(markedwp->window); 103 server_status_window(markedwp->window); 104 } 105 return (CMD_RETURN_NORMAL); 106 } 107 108 if (args_has(self->args, 'P') || args_has(self->args, 'g')) { 109 if (args_has(args, 'P')) { 110 style = args_get(args, 'P'); 111 if (style_parse(&grid_default_cell, &wp->colgc, 112 style) == -1) { 113 cmdq_error(cmdq, "bad style: %s", style); 114 return (CMD_RETURN_ERROR); 115 } 116 wp->flags |= PANE_REDRAW; 117 } 118 if (args_has(self->args, 'g')) 119 cmdq_print(cmdq, "%s", style_tostring(&wp->colgc)); 120 return (CMD_RETURN_NORMAL); 121 } 122 123 if (args_has(self->args, 'L')) 124 wp = window_pane_find_left(wp); 125 else if (args_has(self->args, 'R')) 126 wp = window_pane_find_right(wp); 127 else if (args_has(self->args, 'U')) 128 wp = window_pane_find_up(wp); 129 else if (args_has(self->args, 'D')) 130 wp = window_pane_find_down(wp); 131 if (wp == NULL) 132 return (CMD_RETURN_NORMAL); 133 134 if (args_has(self->args, 'e')) { 135 wp->flags &= ~PANE_INPUTOFF; 136 return (CMD_RETURN_NORMAL); 137 } 138 if (args_has(self->args, 'd')) { 139 wp->flags |= PANE_INPUTOFF; 140 return (CMD_RETURN_NORMAL); 141 } 142 143 if (wp == w->active) 144 return (CMD_RETURN_NORMAL); 145 server_unzoom_window(wp->window); 146 if (!window_pane_visible(wp)) { 147 cmdq_error(cmdq, "pane not visible"); 148 return (CMD_RETURN_ERROR); 149 } 150 window_redraw_active_switch(w, wp); 151 if (window_set_active_pane(w, wp)) { 152 server_status_window(w); 153 server_redraw_window_borders(w); 154 } 155 156 return (CMD_RETURN_NORMAL); 157 } 158