From 178cd0acfba6144924e88e6739d3c1999767585f Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Wed, 2 Sep 2009 21:22:37 +0000 Subject: [PATCH] Add active_window_ignore_refnum option With active_window_ignore_refnum = ON, the current behavior for the active_window key (meta-a by default) is preserved: windows are cycled in the order of most recent activity, highest activity first. With active_window_ignore_refnum = OFF, the old behavior is used: windows are cycled in the order of most recent activity, where ties of equally high activity are broken by refnums. Windows with lower refnums and equal activity will be chosen first. Submitted by Matt Sparks Bug #667 git-svn-id: file:///var/www/svn.irssi.org/SVN/irssi/trunk@5096 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/fe-common/core/window-commands.c | 35 +++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/fe-common/core/window-commands.c b/src/fe-common/core/window-commands.c index 3e262f4d..3f2797d5 100644 --- a/src/fe-common/core/window-commands.c +++ b/src/fe-common/core/window-commands.c @@ -24,6 +24,7 @@ #include "commands.h" #include "misc.h" #include "servers.h" +#include "settings.h" #include "levels.h" @@ -244,16 +245,23 @@ static void cmd_window_refnum(const char *data) window_set_active(window); } -/* return the first window number with the highest activity */ -static WINDOW_REC *window_highest_activity(WINDOW_REC *window) +/** + * return the window with the highest activity + * + * If ignore_refnum is true, the most recently active window with the highest + * activity will be returned. If ignore_refnum is false, the refnum will be used + * to break ties between windows with equally high activity. + */ +static WINDOW_REC *window_highest_activity(WINDOW_REC *window, + int ignore_refnum) { WINDOW_REC *rec, *max_win; GSList *tmp; - int max_act, through; + int max_act, max_ref, through; g_return_val_if_fail(window != NULL, NULL); - max_win = NULL; max_act = 0; through = FALSE; + max_win = NULL; max_act = 0; max_ref = 0; through = FALSE; tmp = g_slist_find(windows, window); for (;; tmp = tmp->next) { @@ -267,10 +275,22 @@ static WINDOW_REC *window_highest_activity(WINDOW_REC *window) rec = tmp->data; - if (rec->data_level > 0 && max_act < rec->data_level) { + /* ignore refnum */ + if (ignore_refnum && + rec->data_level > 0 && max_act < rec->data_level) { max_act = rec->data_level; max_win = rec; } + + /* windows with lower refnums break ties */ + else if (!ignore_refnum && + rec->data_level > 0 && + (rec->data_level > max_act || + (rec->data_level == max_act && rec->refnum < max_ref))) { + max_act = rec->data_level; + max_win = rec; + max_ref = rec->refnum; + } } return max_win; @@ -333,7 +353,8 @@ static void cmd_window_goto(const char *data) return; if (g_ascii_strcasecmp(target, "active") == 0) - window = window_highest_activity(active_win); + window = window_highest_activity(active_win, + settings_get_bool("active_window_ignore_refnum")); else { window = window_find_name(target); if (window == NULL && active_win->active_server != NULL) @@ -823,6 +844,8 @@ static void cmd_foreach_window(const char *data) void window_commands_init(void) { + settings_add_bool("lookandfeel", "active_window_ignore_refnum", TRUE); + command_bind("window", NULL, (SIGNAL_FUNC) cmd_window); command_bind("window new", NULL, (SIGNAL_FUNC) cmd_window_new); command_bind("window close", NULL, (SIGNAL_FUNC) cmd_window_close);