1 1.1 christos /* $OpenBSD$ */ 2 1.1 christos 3 1.1 christos /* 4 1.1 christos * Copyright (c) 2018 Nicholas Marriott <nicholas.marriott (at) gmail.com> 5 1.1 christos * 6 1.1 christos * Permission to use, copy, modify, and distribute this software for any 7 1.1 christos * purpose with or without fee is hereby granted, provided that the above 8 1.1 christos * copyright notice and this permission notice appear in all copies. 9 1.1 christos * 10 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 1.1 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 1.1 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 1.1 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 1.1 christos * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 1.1 christos * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 1.1 christos */ 18 1.1 christos 19 1.1 christos #include <sys/types.h> 20 1.1 christos 21 1.1 christos #include <stdlib.h> 22 1.1 christos 23 1.1 christos #include "tmux.h" 24 1.1 christos 25 1.1 christos /* 26 1.1 christos * Increase or decrease window size. 27 1.1 christos */ 28 1.1 christos 29 1.1 christos static enum cmd_retval cmd_resize_window_exec(struct cmd *, 30 1.1 christos struct cmdq_item *); 31 1.1 christos 32 1.1 christos const struct cmd_entry cmd_resize_window_entry = { 33 1.1 christos .name = "resize-window", 34 1.1 christos .alias = "resizew", 35 1.1 christos 36 1.4 wiz .args = { "aADLRt:Ux:y:", 0, 1, NULL }, 37 1.1 christos .usage = "[-aADLRU] [-x width] [-y height] " CMD_TARGET_WINDOW_USAGE " " 38 1.1 christos "[adjustment]", 39 1.1 christos 40 1.1 christos .target = { 't', CMD_FIND_WINDOW, 0 }, 41 1.1 christos 42 1.1 christos .flags = CMD_AFTERHOOK, 43 1.1 christos .exec = cmd_resize_window_exec 44 1.1 christos }; 45 1.1 christos 46 1.1 christos static enum cmd_retval 47 1.1 christos cmd_resize_window_exec(struct cmd *self, struct cmdq_item *item) 48 1.1 christos { 49 1.3 christos struct args *args = cmd_get_args(self); 50 1.3 christos struct cmd_find_state *target = cmdq_get_target(item); 51 1.3 christos struct winlink *wl = target->wl; 52 1.1 christos struct window *w = wl->window; 53 1.3 christos struct session *s = target->s; 54 1.1 christos const char *errstr; 55 1.1 christos char *cause; 56 1.5 wiz u_int adjust, sx, sy, xpixel = 0, ypixel = 0; 57 1.1 christos 58 1.4 wiz if (args_count(args) == 0) 59 1.1 christos adjust = 1; 60 1.1 christos else { 61 1.4 wiz adjust = strtonum(args_string(args, 0), 1, INT_MAX, &errstr); 62 1.1 christos if (errstr != NULL) { 63 1.1 christos cmdq_error(item, "adjustment %s", errstr); 64 1.1 christos return (CMD_RETURN_ERROR); 65 1.1 christos } 66 1.1 christos } 67 1.1 christos 68 1.1 christos sx = w->sx; 69 1.1 christos sy = w->sy; 70 1.1 christos 71 1.1 christos if (args_has(args, 'x')) { 72 1.1 christos sx = args_strtonum(args, 'x', WINDOW_MINIMUM, WINDOW_MAXIMUM, 73 1.1 christos &cause); 74 1.1 christos if (cause != NULL) { 75 1.1 christos cmdq_error(item, "width %s", cause); 76 1.1 christos free(cause); 77 1.1 christos return (CMD_RETURN_ERROR); 78 1.1 christos } 79 1.1 christos } 80 1.1 christos if (args_has(args, 'y')) { 81 1.1 christos sy = args_strtonum(args, 'y', WINDOW_MINIMUM, WINDOW_MAXIMUM, 82 1.1 christos &cause); 83 1.1 christos if (cause != NULL) { 84 1.1 christos cmdq_error(item, "height %s", cause); 85 1.1 christos free(cause); 86 1.1 christos return (CMD_RETURN_ERROR); 87 1.1 christos } 88 1.1 christos } 89 1.1 christos 90 1.1 christos if (args_has(args, 'L')) { 91 1.1 christos if (sx >= adjust) 92 1.1 christos sx -= adjust; 93 1.1 christos } else if (args_has(args, 'R')) 94 1.1 christos sx += adjust; 95 1.1 christos else if (args_has(args, 'U')) { 96 1.1 christos if (sy >= adjust) 97 1.1 christos sy -= adjust; 98 1.1 christos } else if (args_has(args, 'D')) 99 1.1 christos sy += adjust; 100 1.1 christos 101 1.2 christos if (args_has(args, 'A')) { 102 1.2 christos default_window_size(NULL, s, w, &sx, &sy, &xpixel, &ypixel, 103 1.2 christos WINDOW_SIZE_LARGEST); 104 1.2 christos } else if (args_has(args, 'a')) { 105 1.2 christos default_window_size(NULL, s, w, &sx, &sy, &xpixel, &ypixel, 106 1.2 christos WINDOW_SIZE_SMALLEST); 107 1.2 christos } 108 1.1 christos 109 1.1 christos options_set_number(w->options, "window-size", WINDOW_SIZE_MANUAL); 110 1.4 wiz w->manual_sx = sx; 111 1.4 wiz w->manual_sy = sy; 112 1.4 wiz recalculate_size(w, 1); 113 1.1 christos 114 1.1 christos return (CMD_RETURN_NORMAL); 115 1.1 christos } 116