mirror of
https://github.com/tmate-io/tmate.git
synced 2025-08-15 08:12:46 +02:00
Add a base-index session option to specify the first index checked when looking
for an index for a new window.
This commit is contained in:
26
window.c
26
window.c
@ -122,16 +122,20 @@ winlink_find_by_index(struct winlinks *wwl, int idx)
|
||||
}
|
||||
|
||||
int
|
||||
winlink_next_index(struct winlinks *wwl)
|
||||
winlink_next_index(struct winlinks *wwl, int idx)
|
||||
{
|
||||
u_int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < INT_MAX; i++) {
|
||||
i = idx;
|
||||
do {
|
||||
if (winlink_find_by_index(wwl, i) == NULL)
|
||||
return (i);
|
||||
}
|
||||
|
||||
fatalx("no free indexes");
|
||||
if (i == INT_MAX)
|
||||
i = 0;
|
||||
else
|
||||
i++;
|
||||
} while (i != idx);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
u_int
|
||||
@ -152,14 +156,12 @@ winlink_add(struct winlinks *wwl, struct window *w, int idx)
|
||||
{
|
||||
struct winlink *wl;
|
||||
|
||||
if (idx == -1)
|
||||
idx = winlink_next_index(wwl);
|
||||
else if (winlink_find_by_index(wwl, idx) != NULL)
|
||||
if (idx < 0) {
|
||||
if ((idx = winlink_next_index(wwl, -idx - 1)) == -1)
|
||||
return (NULL);
|
||||
} else if (winlink_find_by_index(wwl, idx) != NULL)
|
||||
return (NULL);
|
||||
|
||||
if (idx < 0)
|
||||
fatalx("bad index");
|
||||
|
||||
wl = xcalloc(1, sizeof *wl);
|
||||
wl->idx = idx;
|
||||
wl->window = w;
|
||||
|
Reference in New Issue
Block a user