Open irssibot opened 12 years ago
irssi-active_window.diff
--- src/fe-common/core/window-commands.c.orig 2010-04-03 19:19:24.000000000 +0300
+++ src/fe-common/core/window-commands.c 2012-03-31 17:41:36.233839021 +0300
@@ -33,6 +33,7 @@
#include "window-items.h"
#include "windows-layout.h"
#include "printtext.h"
+#include <limits.h>
static void window_print_binds(WINDOW_REC *win)
{
@@ -246,23 +247,33 @@
}
/**
- * return the window with the highest activity
+ * return the window with the requested activity level.
*
- * 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
+ * If ignore_refnum is true, then:
+ *
+ * * If reverse_activity is true, windows with the lowest activity levels are returned first
+ * * If reverse_time is true, the oldest windows per activity level are returned first
+ *
+ * If ignore_refnum is false, then all other options are ignored and 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)
+static WINDOW_REC *window_target_activity(WINDOW_REC *window,
+ int ignore_refnum, int reverse_activity, int reverse_time)
{
- WINDOW_REC *rec, *max_win;
+ WINDOW_REC *rec, *target_win;
GSList *tmp;
- int max_act, max_ref, through;
+ int target_act, target_ref, through;
+ time_t target_time;
g_return_val_if_fail(window != NULL, NULL);
- max_win = NULL; max_act = 0; max_ref = 0; through = FALSE;
-
+ target_win = NULL;target_time=0; target_act = 0; target_ref = 0; through = FALSE;
+ if (reverse_activity)
+ /* C99 support ?! */
+ target_act = INT_MAX;
+ if (reverse_time)
+ target_time = time(NULL)+42;
tmp = g_slist_find(windows, window);
for (;; tmp = tmp->next) {
if (tmp == NULL) {
@@ -275,25 +286,48 @@
rec = tmp->data;
- /* ignore refnum */
- if (ignore_refnum &&
- rec->data_level > 0 && max_act < rec->data_level) {
- max_act = rec->data_level;
- max_win = rec;
+ /* Highest actvity level first then sort by time */
+ if (ignore_refnum && !reverse_activity &&
+ rec->data_level > 0 && target_act < rec->data_level &&
+ ( !reverse_time ||
+ (reverse_time && target_time > rec->last_line ))) {
+ target_act = rec->data_level;
+ target_win = rec;
+ }
+
+ /* Lowest activity level first then sort by time */
+ else if (ignore_refnum && reverse_activity &&
+ rec->data_level > 0 && target_act > rec->data_level &&
+ ( !reverse_time ||
+ (reverse_time && target_time > rec->last_line ))) {
+ target_act = rec->data_level;
+ target_win = rec;
+ }
+
+ /* Highest activity level first
+ * windows with lower refnums break ties */
+ else if (!ignore_refnum && !reverse_activity &&
+ rec->data_level > 0 &&
+ (rec->data_level > target_act ||
+ (rec->data_level == target_act && rec->refnum < target_ref))) {
+ target_act = rec->data_level;
+ target_win = rec;
+ target_ref = rec->refnum;
}
- /* windows with lower refnums break ties */
- else if (!ignore_refnum &&
+ /* Lowest activity levels first
+ * windows with lower refnums break ties */
+ else if (!ignore_refnum && reverse_activity &&
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;
+ (rec->data_level > target_act ||
+ (rec->data_level == target_act && rec->refnum > target_ref))) {
+ target_act = rec->data_level;
+ target_win = rec;
+ target_ref = rec->refnum;
}
}
- return max_win;
+ return target_win;
}
static inline int is_nearer(int r1, int r2)
@@ -353,8 +387,10 @@
return;
if (g_ascii_strcasecmp(target, "active") == 0)
- window = window_highest_activity(active_win,
- settings_get_bool("active_window_ignore_refnum"));
+ window = window_target_activity(active_win,
+ settings_get_bool("active_window_ignore_refnum"),
+ settings_get_bool("active_window_reverse_activity"),
+ settings_get_bool("active_window_reverse_time"));
else {
window = window_find_name(target);
if (window == NULL && active_win->active_server != NULL)
@@ -845,6 +881,8 @@
void window_commands_init(void)
{
settings_add_bool("lookandfeel", "active_window_ignore_refnum", TRUE);
+ settings_add_bool("lookandfeel", "active_window_reverse_activity", FALSE);
+ settings_add_bool("lookandfeel", "active_window_reverse_time", FALSE);
command_bind("window", NULL, (SIGNAL_FUNC) cmd_window);
command_bind("window new", NULL, (SIGNAL_FUNC) cmd_window_new);
User in #irssi.fi @ IRCNet asked if it's possible to open lowest activity windows first when using active_window.
Patch attached. Two new options: active_window_reverse_activity reverses activity sorting active_window_reverse_time reverses sorting by time inside activity levels.
Option active_window_reverse_activity is also usable when ignore_refnum = OFF.
I also renamed window_highest_activity() into window_target_activity() to have better name for this and future situations.
TODO: MAX_INT; target_act and better target_time