2009-06-02 00:58:49 +02:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Swap two panes.
|
|
|
|
*/
|
|
|
|
|
2013-03-24 10:54:10 +01:00
|
|
|
enum cmd_retval cmd_swap_pane_exec(struct cmd *, struct cmd_q *);
|
2009-06-02 00:58:49 +02:00
|
|
|
|
|
|
|
const struct cmd_entry cmd_swap_pane_entry = {
|
|
|
|
"swap-pane", "swapp",
|
2011-01-04 01:42:46 +01:00
|
|
|
"dDs:t:U", 0, 0,
|
2009-07-30 15:45:56 +02:00
|
|
|
"[-dDU] " CMD_SRCDST_PANE_USAGE,
|
2011-01-04 01:42:46 +01:00
|
|
|
0,
|
|
|
|
cmd_swap_pane_exec
|
2009-06-02 00:58:49 +02:00
|
|
|
};
|
|
|
|
|
2012-07-11 09:10:15 +02:00
|
|
|
enum cmd_retval
|
2013-03-24 10:54:10 +01:00
|
|
|
cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
2009-06-02 00:58:49 +02:00
|
|
|
{
|
2011-01-04 01:42:46 +01:00
|
|
|
struct args *args = self->args;
|
2009-07-30 15:45:56 +02:00
|
|
|
struct winlink *src_wl, *dst_wl;
|
|
|
|
struct window *src_w, *dst_w;
|
|
|
|
struct window_pane *tmp_wp, *src_wp, *dst_wp;
|
|
|
|
struct layout_cell *src_lc, *dst_lc;
|
|
|
|
u_int sx, sy, xoff, yoff;
|
2009-06-02 00:58:49 +02:00
|
|
|
|
2013-03-24 10:54:10 +01:00
|
|
|
dst_wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &dst_wp);
|
2011-01-04 01:42:46 +01:00
|
|
|
if (dst_wl == NULL)
|
2012-07-11 09:10:15 +02:00
|
|
|
return (CMD_RETURN_ERROR);
|
2009-07-30 15:45:56 +02:00
|
|
|
dst_w = dst_wl->window;
|
2013-03-24 10:57:59 +01:00
|
|
|
server_unzoom_window(dst_w);
|
2009-07-30 15:45:56 +02:00
|
|
|
|
2011-01-04 01:42:46 +01:00
|
|
|
if (!args_has(args, 's')) {
|
2009-07-30 15:45:56 +02:00
|
|
|
src_w = dst_w;
|
2011-01-04 01:42:46 +01:00
|
|
|
if (args_has(self->args, 'D')) {
|
2009-07-30 15:45:56 +02:00
|
|
|
src_wp = TAILQ_NEXT(dst_wp, entry);
|
|
|
|
if (src_wp == NULL)
|
|
|
|
src_wp = TAILQ_FIRST(&dst_w->panes);
|
2011-01-04 01:42:46 +01:00
|
|
|
} else if (args_has(self->args, 'U')) {
|
2009-07-30 15:45:56 +02:00
|
|
|
src_wp = TAILQ_PREV(dst_wp, window_panes, entry);
|
|
|
|
if (src_wp == NULL)
|
|
|
|
src_wp = TAILQ_LAST(&dst_w->panes, window_panes);
|
2013-03-28 16:08:12 +01:00
|
|
|
} else {
|
2015-06-04 13:43:51 +02:00
|
|
|
src_wl = cmd_find_pane_marked(cmdq, NULL, NULL,
|
|
|
|
&src_wp);
|
2013-03-28 16:08:12 +01:00
|
|
|
if (src_wl == NULL)
|
|
|
|
return (CMD_RETURN_ERROR);
|
|
|
|
src_w = src_wl->window;
|
|
|
|
}
|
2009-07-30 15:45:56 +02:00
|
|
|
} else {
|
2015-06-04 13:43:51 +02:00
|
|
|
src_wl = cmd_find_pane_marked(cmdq, args_get(args, 's'), NULL,
|
|
|
|
&src_wp);
|
2009-07-30 15:45:56 +02:00
|
|
|
if (src_wl == NULL)
|
2012-07-11 09:10:15 +02:00
|
|
|
return (CMD_RETURN_ERROR);
|
2009-07-30 15:45:56 +02:00
|
|
|
src_w = src_wl->window;
|
2009-06-02 00:58:49 +02:00
|
|
|
}
|
2013-03-24 10:57:59 +01:00
|
|
|
server_unzoom_window(src_w);
|
2009-06-02 00:58:49 +02:00
|
|
|
|
|
|
|
if (src_wp == dst_wp)
|
2012-07-11 09:10:15 +02:00
|
|
|
return (CMD_RETURN_NORMAL);
|
2009-06-02 00:58:49 +02:00
|
|
|
|
|
|
|
tmp_wp = TAILQ_PREV(dst_wp, window_panes, entry);
|
2009-07-30 15:45:56 +02:00
|
|
|
TAILQ_REMOVE(&dst_w->panes, dst_wp, entry);
|
|
|
|
TAILQ_REPLACE(&src_w->panes, src_wp, dst_wp, entry);
|
2009-06-02 00:58:49 +02:00
|
|
|
if (tmp_wp == src_wp)
|
|
|
|
tmp_wp = dst_wp;
|
|
|
|
if (tmp_wp == NULL)
|
2009-07-30 15:45:56 +02:00
|
|
|
TAILQ_INSERT_HEAD(&dst_w->panes, src_wp, entry);
|
2009-06-02 00:58:49 +02:00
|
|
|
else
|
2009-07-30 15:45:56 +02:00
|
|
|
TAILQ_INSERT_AFTER(&dst_w->panes, tmp_wp, src_wp, entry);
|
|
|
|
|
|
|
|
src_lc = src_wp->layout_cell;
|
|
|
|
dst_lc = dst_wp->layout_cell;
|
|
|
|
src_lc->wp = dst_wp;
|
|
|
|
dst_wp->layout_cell = src_lc;
|
|
|
|
dst_lc->wp = src_wp;
|
|
|
|
src_wp->layout_cell = dst_lc;
|
2009-12-03 23:50:09 +01:00
|
|
|
|
2009-07-30 15:45:56 +02:00
|
|
|
src_wp->window = dst_w;
|
|
|
|
dst_wp->window = src_w;
|
2009-06-02 00:58:49 +02:00
|
|
|
|
2009-07-20 09:13:31 +02:00
|
|
|
sx = src_wp->sx; sy = src_wp->sy;
|
|
|
|
xoff = src_wp->xoff; yoff = src_wp->yoff;
|
|
|
|
src_wp->xoff = dst_wp->xoff; src_wp->yoff = dst_wp->yoff;
|
2009-06-02 00:58:49 +02:00
|
|
|
window_pane_resize(src_wp, dst_wp->sx, dst_wp->sy);
|
2009-07-20 09:13:31 +02:00
|
|
|
dst_wp->xoff = xoff; dst_wp->yoff = yoff;
|
|
|
|
window_pane_resize(dst_wp, sx, sy);
|
2009-06-02 00:58:49 +02:00
|
|
|
|
2011-01-04 01:42:46 +01:00
|
|
|
if (!args_has(self->args, 'd')) {
|
2009-07-30 15:45:56 +02:00
|
|
|
if (src_w != dst_w) {
|
|
|
|
window_set_active_pane(src_w, dst_wp);
|
|
|
|
window_set_active_pane(dst_w, src_wp);
|
|
|
|
} else {
|
|
|
|
tmp_wp = dst_wp;
|
|
|
|
if (!window_pane_visible(tmp_wp))
|
|
|
|
tmp_wp = src_wp;
|
|
|
|
window_set_active_pane(src_w, tmp_wp);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (src_w->active == src_wp)
|
|
|
|
window_set_active_pane(src_w, dst_wp);
|
|
|
|
if (dst_w->active == dst_wp)
|
|
|
|
window_set_active_pane(dst_w, src_wp);
|
2009-06-02 00:58:49 +02:00
|
|
|
}
|
2011-05-08 23:12:52 +02:00
|
|
|
if (src_w != dst_w) {
|
|
|
|
if (src_w->last == src_wp)
|
|
|
|
src_w->last = NULL;
|
|
|
|
if (dst_w->last == dst_wp)
|
|
|
|
dst_w->last = NULL;
|
|
|
|
}
|
2009-07-30 15:45:56 +02:00
|
|
|
server_redraw_window(src_w);
|
|
|
|
server_redraw_window(dst_w);
|
2009-06-02 00:58:49 +02:00
|
|
|
|
2012-07-11 09:10:15 +02:00
|
|
|
return (CMD_RETURN_NORMAL);
|
2009-06-02 00:58:49 +02:00
|
|
|
}
|