Home | History | Annotate | Line # | Download | only in dist
      1   1.1.1.5  christos /* $OpenBSD$ */
      2       1.1      jmmv 
      3       1.1      jmmv /*
      4   1.1.1.6  christos  * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott (at) gmail.com>
      5       1.1      jmmv  *
      6       1.1      jmmv  * Permission to use, copy, modify, and distribute this software for any
      7       1.1      jmmv  * purpose with or without fee is hereby granted, provided that the above
      8       1.1      jmmv  * copyright notice and this permission notice appear in all copies.
      9       1.1      jmmv  *
     10       1.1      jmmv  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     11       1.1      jmmv  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     12       1.1      jmmv  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     13       1.1      jmmv  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     14       1.1      jmmv  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
     15       1.1      jmmv  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
     16       1.1      jmmv  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     17       1.1      jmmv  */
     18       1.1      jmmv 
     19       1.1      jmmv #include <sys/types.h>
     20       1.1      jmmv 
     21       1.1      jmmv #include <stdlib.h>
     22       1.1      jmmv 
     23       1.1      jmmv #include "tmux.h"
     24       1.1      jmmv 
     25       1.1      jmmv /*
     26       1.1      jmmv  * Move a window.
     27       1.1      jmmv  */
     28       1.1      jmmv 
     29   1.1.1.7  christos static enum cmd_retval	cmd_move_window_exec(struct cmd *, struct cmdq_item *);
     30       1.1      jmmv 
     31       1.1      jmmv const struct cmd_entry cmd_move_window_entry = {
     32   1.1.1.6  christos 	.name = "move-window",
     33   1.1.1.6  christos 	.alias = "movew",
     34   1.1.1.6  christos 
     35  1.1.1.10       wiz 	.args = { "abdkrs:t:", 0, 0, NULL },
     36   1.1.1.9  christos 	.usage = "[-abdkr] " CMD_SRCDST_WINDOW_USAGE,
     37   1.1.1.6  christos 
     38   1.1.1.8  christos 	.source = { 's', CMD_FIND_WINDOW, 0 },
     39   1.1.1.8  christos 	/* -t is special */
     40   1.1.1.6  christos 
     41   1.1.1.6  christos 	.flags = 0,
     42   1.1.1.6  christos 	.exec = cmd_move_window_exec
     43   1.1.1.5  christos };
     44   1.1.1.5  christos 
     45   1.1.1.5  christos const struct cmd_entry cmd_link_window_entry = {
     46   1.1.1.6  christos 	.name = "link-window",
     47   1.1.1.6  christos 	.alias = "linkw",
     48   1.1.1.6  christos 
     49  1.1.1.10       wiz 	.args = { "abdks:t:", 0, 0, NULL },
     50   1.1.1.9  christos 	.usage = "[-abdk] " CMD_SRCDST_WINDOW_USAGE,
     51   1.1.1.6  christos 
     52   1.1.1.8  christos 	.source = { 's', CMD_FIND_WINDOW, 0 },
     53   1.1.1.8  christos 	/* -t is special */
     54   1.1.1.6  christos 
     55   1.1.1.6  christos 	.flags = 0,
     56   1.1.1.6  christos 	.exec = cmd_move_window_exec
     57       1.1      jmmv };
     58       1.1      jmmv 
     59   1.1.1.7  christos static enum cmd_retval
     60   1.1.1.7  christos cmd_move_window_exec(struct cmd *self, struct cmdq_item *item)
     61       1.1      jmmv {
     62   1.1.1.9  christos 	struct args		*args = cmd_get_args(self);
     63   1.1.1.9  christos 	struct cmd_find_state	*source = cmdq_get_source(item);
     64   1.1.1.9  christos 	struct cmd_find_state	 target;
     65   1.1.1.9  christos 	const char		*tflag = args_get(args, 't');
     66   1.1.1.9  christos 	struct session		*src = source->s;
     67   1.1.1.9  christos 	struct session		*dst;
     68   1.1.1.9  christos 	struct winlink		*wl = source->wl;
     69   1.1.1.9  christos 	char			*cause;
     70   1.1.1.9  christos 	int			 idx, kflag, dflag, sflag, before;
     71   1.1.1.3  christos 
     72   1.1.1.6  christos 	if (args_has(args, 'r')) {
     73   1.1.1.9  christos 		if (cmd_find_target(&target, item, tflag, CMD_FIND_SESSION,
     74   1.1.1.9  christos 		    CMD_FIND_QUIET) != 0)
     75   1.1.1.8  christos 			return (CMD_RETURN_ERROR);
     76   1.1.1.8  christos 
     77   1.1.1.9  christos 		session_renumber_windows(target.s);
     78   1.1.1.3  christos 		recalculate_sizes();
     79   1.1.1.9  christos 		server_status_session(target.s);
     80   1.1.1.3  christos 
     81   1.1.1.3  christos 		return (CMD_RETURN_NORMAL);
     82   1.1.1.3  christos 	}
     83   1.1.1.9  christos 	if (cmd_find_target(&target, item, tflag, CMD_FIND_WINDOW,
     84   1.1.1.8  christos 	    CMD_FIND_WINDOW_INDEX) != 0)
     85   1.1.1.8  christos 		return (CMD_RETURN_ERROR);
     86   1.1.1.9  christos 	dst = target.s;
     87   1.1.1.9  christos 	idx = target.idx;
     88   1.1.1.5  christos 
     89   1.1.1.9  christos 	kflag = args_has(args, 'k');
     90   1.1.1.9  christos 	dflag = args_has(args, 'd');
     91   1.1.1.9  christos 	sflag = args_has(args, 's');
     92   1.1.1.9  christos 
     93   1.1.1.9  christos 	before = args_has(args, 'b');
     94   1.1.1.9  christos 	if (args_has(args, 'a') || before) {
     95   1.1.1.9  christos 		if (target.wl != NULL)
     96   1.1.1.9  christos 			idx = winlink_shuffle_up(dst, target.wl, before);
     97   1.1.1.9  christos 		else
     98   1.1.1.9  christos 			idx = winlink_shuffle_up(dst, dst->curw, before);
     99   1.1.1.9  christos 		if (idx == -1)
    100   1.1.1.5  christos 			return (CMD_RETURN_ERROR);
    101   1.1.1.5  christos 	}
    102   1.1.1.5  christos 
    103   1.1.1.9  christos 	if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
    104   1.1.1.9  christos 		cmdq_error(item, "%s", cause);
    105   1.1.1.3  christos 		free(cause);
    106   1.1.1.3  christos 		return (CMD_RETURN_ERROR);
    107       1.1      jmmv 	}
    108   1.1.1.9  christos 	if (cmd_get_entry(self) == &cmd_move_window_entry)
    109   1.1.1.5  christos 		server_unlink_window(src, wl);
    110   1.1.1.5  christos 
    111   1.1.1.5  christos 	/*
    112   1.1.1.5  christos 	 * Renumber the winlinks in the src session only, the destination
    113   1.1.1.5  christos 	 * session already has the correct winlink id to us, either
    114   1.1.1.5  christos 	 * automatically or specified by -s.
    115   1.1.1.5  christos 	 */
    116   1.1.1.6  christos 	if (!sflag && options_get_number(src->options, "renumber-windows"))
    117   1.1.1.5  christos 		session_renumber_windows(src);
    118   1.1.1.5  christos 
    119       1.1      jmmv 	recalculate_sizes();
    120       1.1      jmmv 
    121   1.1.1.3  christos 	return (CMD_RETURN_NORMAL);
    122       1.1      jmmv }
    123