-/* $OpenBSD: window.c,v 1.125 2015/04/25 18:49:01 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.126 2015/04/25 18:56:05 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
* it reaches zero.
*/
-ARRAY_DECL(window_pane_list, struct window_pane *);
-
/* Global window list. */
struct windows windows;
void window_pane_read_callback(struct bufferevent *, void *);
void window_pane_error_callback(struct bufferevent *, short, void *);
-struct window_pane *window_pane_choose_best(struct window_pane_list *);
+struct window_pane *window_pane_choose_best(struct window_pane **, u_int);
RB_GENERATE(windows, window, entry, window_cmp);
/* Get MRU pane from a list. */
struct window_pane *
-window_pane_choose_best(struct window_pane_list *list)
+window_pane_choose_best(struct window_pane **list, u_int size)
{
struct window_pane *next, *best;
u_int i;
- if (ARRAY_LENGTH(list) == 0)
+ if (size == 0)
return (NULL);
- best = ARRAY_FIRST(list);
- for (i = 1; i < ARRAY_LENGTH(list); i++) {
- next = ARRAY_ITEM(list, i);
+ best = list[0];
+ for (i = 1; i < size; i++) {
+ next = list[i];
if (next->active_point > best->active_point)
best = next;
}
struct window_pane *
window_pane_find_up(struct window_pane *wp)
{
- struct window_pane *next, *best;
- u_int edge, left, right, end;
- struct window_pane_list list;
+ struct window_pane *next, *best, **list;
+ u_int edge, left, right, end, size;
int found;
if (wp == NULL || !window_pane_visible(wp))
return (NULL);
- ARRAY_INIT(&list);
+
+ list = NULL;
+ size = 0;
edge = wp->yoff;
if (edge == 0)
found = 1;
else if (end >= left && end <= right)
found = 1;
- if (found)
- ARRAY_ADD(&list, next);
+ if (!found)
+ continue;
+ list = xreallocarray(list, size + 1, sizeof *list);
+ list[size++] = next;
}
- best = window_pane_choose_best(&list);
- ARRAY_FREE(&list);
+ best = window_pane_choose_best(list, size);
+ free(list);
return (best);
}
struct window_pane *
window_pane_find_down(struct window_pane *wp)
{
- struct window_pane *next, *best;
- u_int edge, left, right, end;
- struct window_pane_list list;
+ struct window_pane *next, *best, **list;
+ u_int edge, left, right, end, size;
int found;
if (wp == NULL || !window_pane_visible(wp))
return (NULL);
- ARRAY_INIT(&list);
+
+ list = NULL;
+ size = 0;
edge = wp->yoff + wp->sy + 1;
if (edge >= wp->window->sy)
found = 1;
else if (end >= left && end <= right)
found = 1;
- if (found)
- ARRAY_ADD(&list, next);
+ if (!found)
+ continue;
+ list = xreallocarray(list, size + 1, sizeof *list);
+ list[size++] = next;
}
- best = window_pane_choose_best(&list);
- ARRAY_FREE(&list);
+ best = window_pane_choose_best(list, size);
+ free(list);
return (best);
}
struct window_pane *
window_pane_find_left(struct window_pane *wp)
{
- struct window_pane *next, *best;
- u_int edge, top, bottom, end;
- struct window_pane_list list;
+ struct window_pane *next, *best, **list;
+ u_int edge, top, bottom, end, size;
int found;
if (wp == NULL || !window_pane_visible(wp))
return (NULL);
- ARRAY_INIT(&list);
+
+ list = NULL;
+ size = 0;
edge = wp->xoff;
if (edge == 0)
found = 1;
else if (end >= top && end <= bottom)
found = 1;
- if (found)
- ARRAY_ADD(&list, next);
+ if (!found)
+ continue;
+ list = xreallocarray(list, size + 1, sizeof *list);
+ list[size++] = next;
}
- best = window_pane_choose_best(&list);
- ARRAY_FREE(&list);
+ best = window_pane_choose_best(list, size);
+ free(list);
return (best);
}
struct window_pane *
window_pane_find_right(struct window_pane *wp)
{
- struct window_pane *next, *best;
- u_int edge, top, bottom, end;
- struct window_pane_list list;
+ struct window_pane *next, *best, **list;
+ u_int edge, top, bottom, end, size;
int found;
if (wp == NULL || !window_pane_visible(wp))
return (NULL);
- ARRAY_INIT(&list);
+
+ list = NULL;
+ size = 0;
edge = wp->xoff + wp->sx + 1;
if (edge >= wp->window->sx)
found = 1;
else if (end >= top && end <= bottom)
found = 1;
- if (found)
- ARRAY_ADD(&list, next);
+ if (!found)
+ continue;
+ list = xreallocarray(list, size + 1, sizeof *list);
+ list[size++] = next;
}
- best = window_pane_choose_best(&list);
- ARRAY_FREE(&list);
+ best = window_pane_choose_best(list, size);
+ free(list);
return (best);
}