From 4d96d7e4df69b54259c848cbf20958dda39988d6 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 22 Feb 2002 13:04:07 +0000 Subject: [PATCH] Window level matching code was a bit messy. Also, now the active window is preferred if there's multiple matches by the same level. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2525 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/fe-common/core/fe-windows.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/fe-common/core/fe-windows.c b/src/fe-common/core/fe-windows.c index 985d05c4..fe76427b 100644 --- a/src/fe-common/core/fe-windows.c +++ b/src/fe-common/core/fe-windows.c @@ -238,24 +238,26 @@ char *window_get_active_name(WINDOW_REC *window) return window->name; } +#define WINDOW_LEVEL_MATCH(window, server, level) \ + (((window)->level & level) && \ + (server == NULL || (window)->active_server == server)) + WINDOW_REC *window_find_level(void *server, int level) { - WINDOW_REC *match; GSList *tmp; - match = NULL; + /* prefer active window if possible */ + if (WINDOW_LEVEL_MATCH(active_win, server, level)) + return active_win; + for (tmp = windows; tmp != NULL; tmp = tmp->next) { WINDOW_REC *rec = tmp->data; - if ((server == NULL || rec->active_server == server) && - (rec->level & level)) { - if (server == NULL || rec->active_server == server) - return rec; - match = rec; - } + if (WINDOW_LEVEL_MATCH(rec, server, level)) + return rec; } - return match; + return NULL; } WINDOW_REC *window_find_closest(void *server, const char *name, int level)