1 /* Id */ 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 <stdlib.h> 22 23 #include "tmux.h" 24 25 /* 26 * Increase or decrease pane size. 27 */ 28 29 void cmd_resize_pane_key_binding(struct cmd *, int); 30 enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_q *); 31 32 const struct cmd_entry cmd_resize_pane_entry = { 33 "resize-pane", "resizep", 34 "DLRt:Ux:y:Z", 0, 1, 35 "[-DLRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " [adjustment]", 36 0, 37 cmd_resize_pane_key_binding, 38 cmd_resize_pane_exec 39 }; 40 41 void 42 cmd_resize_pane_key_binding(struct cmd *self, int key) 43 { 44 switch (key) { 45 case KEYC_UP | KEYC_CTRL: 46 self->args = args_create(0); 47 args_set(self->args, 'U', NULL); 48 break; 49 case KEYC_DOWN | KEYC_CTRL: 50 self->args = args_create(0); 51 args_set(self->args, 'D', NULL); 52 break; 53 case KEYC_LEFT | KEYC_CTRL: 54 self->args = args_create(0); 55 args_set(self->args, 'L', NULL); 56 break; 57 case KEYC_RIGHT | KEYC_CTRL: 58 self->args = args_create(0); 59 args_set(self->args, 'R', NULL); 60 break; 61 case KEYC_UP | KEYC_ESCAPE: 62 self->args = args_create(1, "5"); 63 args_set(self->args, 'U', NULL); 64 break; 65 case KEYC_DOWN | KEYC_ESCAPE: 66 self->args = args_create(1, "5"); 67 args_set(self->args, 'D', NULL); 68 break; 69 case KEYC_LEFT | KEYC_ESCAPE: 70 self->args = args_create(1, "5"); 71 args_set(self->args, 'L', NULL); 72 break; 73 case KEYC_RIGHT | KEYC_ESCAPE: 74 self->args = args_create(1, "5"); 75 args_set(self->args, 'R', NULL); 76 break; 77 case 'z': 78 self->args = args_create(0); 79 args_set(self->args, 'Z', NULL); 80 break; 81 default: 82 self->args = args_create(0); 83 break; 84 } 85 } 86 87 enum cmd_retval 88 cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq) 89 { 90 struct args *args = self->args; 91 struct winlink *wl; 92 struct window *w; 93 const char *errstr; 94 char *cause; 95 struct window_pane *wp; 96 u_int adjust; 97 int x, y; 98 99 if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL) 100 return (CMD_RETURN_ERROR); 101 w = wl->window; 102 103 if (args_has(args, 'Z')) { 104 if (w->flags & WINDOW_ZOOMED) 105 window_unzoom(w); 106 else 107 window_zoom(wp); 108 server_redraw_window(w); 109 server_status_window(w); 110 return (CMD_RETURN_NORMAL); 111 } 112 server_unzoom_window(w); 113 114 if (args->argc == 0) 115 adjust = 1; 116 else { 117 adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr); 118 if (errstr != NULL) { 119 cmdq_error(cmdq, "adjustment %s", errstr); 120 return (CMD_RETURN_ERROR); 121 } 122 } 123 124 if (args_has(self->args, 'x')) { 125 x = args_strtonum(self->args, 'x', PANE_MINIMUM, INT_MAX, 126 &cause); 127 if (cause != NULL) { 128 cmdq_error(cmdq, "width %s", cause); 129 free(cause); 130 return (CMD_RETURN_ERROR); 131 } 132 layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x); 133 } 134 if (args_has(self->args, 'y')) { 135 y = args_strtonum(self->args, 'y', PANE_MINIMUM, INT_MAX, 136 &cause); 137 if (cause != NULL) { 138 cmdq_error(cmdq, "height %s", cause); 139 free(cause); 140 return (CMD_RETURN_ERROR); 141 } 142 layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y); 143 } 144 145 if (args_has(self->args, 'L')) 146 layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust); 147 else if (args_has(self->args, 'R')) 148 layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust); 149 else if (args_has(self->args, 'U')) 150 layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust); 151 else if (args_has(self->args, 'D')) 152 layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust); 153 server_redraw_window(wl->window); 154 155 return (CMD_RETURN_NORMAL); 156 } 157