summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/window.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2015-06-17 16:50:29 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2015-06-17 16:50:29 +0000
commitd599f43b521fb4c67be15bf2a2e218eb959f711d (patch)
tree5fa8300b7be0d0f7f8e3ef91afdaffbf259dbb02 /usr.bin/tmux/window.c
parent6ce537927c04b37a29c1663e0c5aa82be57bca95 (diff)
Move the shuffle code from new-window -a into a function and add a -a
flag for move-window too. From Thomas Adam.
Diffstat (limited to 'usr.bin/tmux/window.c')
-rw-r--r--usr.bin/tmux/window.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index 14f14fea6a9..bd25c6f827c 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.133 2015/06/15 10:58:01 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.134 2015/06/17 16:50:28 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1378,3 +1378,28 @@ winlink_clear_flags(struct winlink *wl)
}
}
}
+
+int
+winlink_shuffle_up(struct session *s, struct winlink *wl)
+{
+ int idx, last;
+
+ idx = wl->idx + 1;
+
+ /* Find the next free index. */
+ for (last = idx; last < INT_MAX; last++) {
+ if (winlink_find_by_index(&s->windows, last) == NULL)
+ break;
+ }
+ if (last == INT_MAX)
+ return (-1);
+
+ /* Move everything from last - 1 to idx up a bit. */
+ for (; last > idx; last--) {
+ wl = winlink_find_by_index(&s->windows, last - 1);
+ server_link_window(s, wl, s, last, 0, 0, NULL);
+ server_unlink_window(s, wl);
+ }
+
+ return (idx);
+}