aboutsummaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2015-04-27 21:21:55 +0100
committerThomas Adam <thomas@xteddy.org>2015-04-27 21:21:55 +0100
commit94a8ef1caef855d1a43b6373dd08ce0bbf4aadd5 (patch)
tree052d89cf9193a324fb646fe25152df6aa4070534 /window.c
parent72e9ebf2ece28c986050162bf4f401a6a7679f53 (diff)
parent95195f52584565483bf9850840f6d81cd88bf9b2 (diff)
downloadrtmux-94a8ef1caef855d1a43b6373dd08ce0bbf4aadd5.tar.gz
rtmux-94a8ef1caef855d1a43b6373dd08ce0bbf4aadd5.tar.bz2
rtmux-94a8ef1caef855d1a43b6373dd08ce0bbf4aadd5.zip
Merge branch 'obsd-master'
Conflicts: Makefile tmux.1
Diffstat (limited to 'window.c')
-rw-r--r--window.c92
1 files changed, 51 insertions, 41 deletions
diff --git a/window.c b/window.c
index 762442d0..153ae945 100644
--- a/window.c
+++ b/window.c
@@ -48,8 +48,6 @@
* it reaches zero.
*/
-ARRAY_DECL(window_pane_list, struct window_pane *);
-
/* Global window list. */
struct windows windows;
@@ -63,7 +61,7 @@ void window_pane_timer_callback(int, short, void *);
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);
@@ -255,7 +253,7 @@ winlink_stack_remove(struct winlink_stack *stack, struct winlink *wl)
}
struct window *
-window_find_by_id_str(const char* s)
+window_find_by_id_str(const char *s)
{
const char *errstr;
u_int id;
@@ -1163,17 +1161,17 @@ window_pane_search(struct window_pane *wp, const char *searchstr,
/* 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;
}
@@ -1187,14 +1185,15 @@ window_pane_choose_best(struct window_pane_list *list)
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)
@@ -1217,12 +1216,14 @@ window_pane_find_up(struct window_pane *wp)
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);
}
@@ -1230,14 +1231,15 @@ window_pane_find_up(struct window_pane *wp)
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)
@@ -1260,12 +1262,14 @@ window_pane_find_down(struct window_pane *wp)
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);
}
@@ -1273,14 +1277,15 @@ window_pane_find_down(struct window_pane *wp)
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)
@@ -1303,12 +1308,14 @@ window_pane_find_left(struct window_pane *wp)
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);
}
@@ -1316,14 +1323,15 @@ window_pane_find_left(struct window_pane *wp)
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)
@@ -1346,12 +1354,14 @@ window_pane_find_right(struct window_pane *wp)
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);
}