2000-04-26 04:03:38 -04:00
|
|
|
/*
|
2001-03-12 05:33:13 -05:00
|
|
|
statusbar-items.c : irssi
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-03-12 05:33:13 -05:00
|
|
|
Copyright (C) 1999-2001 Timo Sirainen
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2007-05-08 14:41:10 -04:00
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2000-04-26 04:03:38 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
2019-05-01 10:33:47 -04:00
|
|
|
#include <irssi/src/core/signals.h>
|
|
|
|
#include <irssi/src/core/settings.h>
|
|
|
|
#include <irssi/src/core/servers.h>
|
|
|
|
|
|
|
|
#include <irssi/src/fe-common/core/themes.h>
|
|
|
|
#include <irssi/src/fe-text/statusbar.h>
|
|
|
|
#include <irssi/src/fe-text/gui-entry.h>
|
|
|
|
#include <irssi/src/fe-text/gui-windows.h>
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:42:37 -04:00
|
|
|
/* how often to redraw lagging time (seconds) */
|
2000-04-26 04:03:38 -04:00
|
|
|
#define LAG_REFRESH_TIME 10
|
2000-06-10 20:42:37 -04:00
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
static GList *activity_list;
|
2007-07-26 09:53:22 -04:00
|
|
|
static guint8 actlist_sort;
|
2022-01-19 12:01:30 -05:00
|
|
|
static char *actlist_separator;
|
2001-11-25 11:35:11 -05:00
|
|
|
static GSList *more_visible; /* list of MAIN_WINDOW_RECs which have --more-- */
|
2001-10-13 12:11:13 -04:00
|
|
|
static GHashTable *input_entries;
|
2001-11-19 17:21:57 -05:00
|
|
|
static int last_lag, last_lag_unknown, lag_timeout_tag;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
static void item_window_active(SBAR_ITEM_REC *item, int get_size_only)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
WINDOW_REC *window;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
window = active_win;
|
|
|
|
if (item->bar->parent_window != NULL)
|
|
|
|
window = item->bar->parent_window->active;
|
2001-03-12 05:33:13 -05:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
if (window != NULL && window->active != NULL) {
|
|
|
|
statusbar_item_default_handler(item, get_size_only,
|
|
|
|
NULL, "", TRUE);
|
|
|
|
} else if (get_size_only) {
|
|
|
|
item->min_size = item->max_size = 0;
|
2001-03-12 05:33:13 -05:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
static void item_window_empty(SBAR_ITEM_REC *item, int get_size_only)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
WINDOW_REC *window;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
window = active_win;
|
|
|
|
if (item->bar->parent_window != NULL)
|
|
|
|
window = item->bar->parent_window->active;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
if (window != NULL && window->active == NULL) {
|
|
|
|
statusbar_item_default_handler(item, get_size_only,
|
|
|
|
NULL, "", TRUE);
|
|
|
|
} else if (get_size_only) {
|
|
|
|
item->min_size = item->max_size = 0;
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-10-23 17:26:03 -04:00
|
|
|
static char *get_activity_list(MAIN_WINDOW_REC *window, int normal, int hilight)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-23 17:26:03 -04:00
|
|
|
THEME_REC *theme;
|
2001-03-12 05:33:13 -05:00
|
|
|
GString *str;
|
2008-05-15 12:54:01 -04:00
|
|
|
GString *format;
|
2001-03-12 05:33:13 -05:00
|
|
|
GList *tmp;
|
2022-01-19 12:01:30 -05:00
|
|
|
char *ret, *name, *value;
|
2019-04-08 06:32:58 -04:00
|
|
|
int is_det;
|
2008-06-10 06:21:00 -04:00
|
|
|
int add_name = settings_get_bool("actlist_names");
|
2019-04-08 06:32:58 -04:00
|
|
|
int pref_name = settings_get_bool("actlist_prefer_window_name");
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-03-12 05:33:13 -05:00
|
|
|
str = g_string_new(NULL);
|
2008-05-15 12:54:01 -04:00
|
|
|
format = g_string_new(NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-23 17:26:03 -04:00
|
|
|
theme = window != NULL && window->active != NULL &&
|
|
|
|
window->active->theme != NULL ?
|
|
|
|
window->active->theme : current_theme;
|
|
|
|
|
2001-03-12 05:33:13 -05:00
|
|
|
for (tmp = activity_list; tmp != NULL; tmp = tmp->next) {
|
|
|
|
WINDOW_REC *window = tmp->data;
|
|
|
|
|
|
|
|
is_det = window->data_level >= DATA_LEVEL_HILIGHT;
|
|
|
|
if ((!is_det && !normal) || (is_det && !hilight))
|
|
|
|
continue;
|
|
|
|
|
2001-10-23 17:26:03 -04:00
|
|
|
/* comma separator */
|
|
|
|
if (str->len > 0) {
|
2022-02-06 03:50:38 -05:00
|
|
|
g_string_printf(format, "{sb_act_sep %s}", actlist_separator);
|
2022-01-19 07:09:49 -05:00
|
|
|
value = theme_format_expand(theme, format->str);
|
2001-10-23 17:26:03 -04:00
|
|
|
g_string_append(str, value);
|
|
|
|
g_free(value);
|
|
|
|
}
|
2001-03-12 05:33:13 -05:00
|
|
|
|
|
|
|
switch (window->data_level) {
|
|
|
|
case DATA_LEVEL_NONE:
|
|
|
|
case DATA_LEVEL_TEXT:
|
2008-06-10 06:21:00 -04:00
|
|
|
name = "{sb_act_text %d";
|
2001-03-12 05:33:13 -05:00
|
|
|
break;
|
|
|
|
case DATA_LEVEL_MSG:
|
2008-06-10 06:21:00 -04:00
|
|
|
name = "{sb_act_msg %d";
|
2001-03-12 05:33:13 -05:00
|
|
|
break;
|
|
|
|
default:
|
2001-10-23 17:26:03 -04:00
|
|
|
if (window->hilight_color == NULL)
|
2008-06-10 06:21:00 -04:00
|
|
|
name = "{sb_act_hilight %d";
|
2001-10-23 17:26:03 -04:00
|
|
|
else
|
|
|
|
name = NULL;
|
2001-03-12 05:33:13 -05:00
|
|
|
break;
|
|
|
|
}
|
2001-03-16 20:52:43 -05:00
|
|
|
|
2001-10-23 17:26:03 -04:00
|
|
|
if (name != NULL)
|
2008-05-15 12:54:01 -04:00
|
|
|
g_string_printf(format, name, window->refnum);
|
2001-10-23 17:26:03 -04:00
|
|
|
else
|
2008-06-10 06:21:00 -04:00
|
|
|
g_string_printf(format, "{sb_act_hilight_color %s %d",
|
2001-10-23 17:26:03 -04:00
|
|
|
window->hilight_color,
|
|
|
|
window->refnum);
|
2019-04-02 03:39:03 -04:00
|
|
|
|
2008-06-10 06:21:00 -04:00
|
|
|
if (add_name && window->active != NULL)
|
2019-03-22 14:10:10 -04:00
|
|
|
g_string_append_printf(format, ":%s",
|
2019-04-02 03:39:03 -04:00
|
|
|
pref_name == 1 && window->name != NULL ?
|
|
|
|
window->name : window->active->visible_name);
|
2008-06-10 06:21:00 -04:00
|
|
|
g_string_append_c(format, '}');
|
2001-10-23 17:26:03 -04:00
|
|
|
|
2008-05-15 12:54:01 -04:00
|
|
|
value = theme_format_expand(theme, format->str);
|
2001-10-23 17:26:03 -04:00
|
|
|
g_string_append(str, value);
|
|
|
|
g_free(value);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
2001-01-31 06:23:29 -05:00
|
|
|
|
2001-03-12 05:33:13 -05:00
|
|
|
ret = str->len == 0 ? NULL : str->str;
|
|
|
|
g_string_free(str, ret == NULL);
|
2008-05-15 12:54:01 -04:00
|
|
|
g_string_free(format, TRUE);
|
2001-03-12 05:33:13 -05:00
|
|
|
return ret;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-31 06:23:29 -05:00
|
|
|
/* redraw activity, FIXME: if we didn't get enough size, this gets buggy.
|
|
|
|
At least "Det:" isn't printed properly. also we should rearrange the
|
|
|
|
act list so that the highest priority items comes first. */
|
2001-10-13 12:11:13 -04:00
|
|
|
static void item_act(SBAR_ITEM_REC *item, int get_size_only)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
char *actlist;
|
2016-12-12 21:04:01 -05:00
|
|
|
int max_size;
|
|
|
|
|
|
|
|
if (get_size_only) {
|
|
|
|
if (activity_list == NULL)
|
|
|
|
item->min_size = item->max_size = 0;
|
|
|
|
/* Skip activity calculation on regular trigger, only
|
|
|
|
set dirty */
|
|
|
|
return;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-23 17:26:03 -04:00
|
|
|
actlist = get_activity_list(item->bar->parent_window, TRUE, TRUE);
|
2001-10-13 12:11:13 -04:00
|
|
|
if (actlist == NULL) {
|
2001-03-12 05:33:13 -05:00
|
|
|
return;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2016-12-12 21:04:01 -05:00
|
|
|
max_size = item->max_size;
|
|
|
|
statusbar_item_default_handler(item, TRUE,
|
|
|
|
NULL, actlist, FALSE);
|
|
|
|
statusbar_item_default_handler(item, FALSE,
|
2001-10-13 12:11:13 -04:00
|
|
|
NULL, actlist, FALSE);
|
2016-12-12 21:04:01 -05:00
|
|
|
if (max_size != item->max_size) {
|
|
|
|
/* Due to above hack of skipping the calculation, we
|
|
|
|
need to manually trigger the redraw process now or
|
|
|
|
we won't see the item */
|
|
|
|
item->bar->dirty = item->dirty = TRUE;
|
|
|
|
statusbar_redraw(item->bar, TRUE);
|
|
|
|
statusbar_redraw_dirty();
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-03-14 21:26:12 -05:00
|
|
|
g_free_not_null(actlist);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2008-05-15 06:54:03 -04:00
|
|
|
static int window_level_recent_cmp(WINDOW_REC *w1, WINDOW_REC *w2)
|
2007-07-26 09:53:22 -04:00
|
|
|
{
|
2008-04-05 10:09:01 -04:00
|
|
|
if (w1->data_level >= w2->data_level)
|
2007-07-26 09:53:22 -04:00
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-05-15 06:54:03 -04:00
|
|
|
static int window_level_cmp(WINDOW_REC *w1, WINDOW_REC *w2)
|
|
|
|
{
|
|
|
|
if (w1->data_level > w2->data_level ||
|
|
|
|
(w1->data_level == w2->data_level && w1->refnum < w2->refnum))
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
static void sig_statusbar_activity_hilight(WINDOW_REC *window, gpointer oldlevel)
|
|
|
|
{
|
2007-05-30 17:17:59 -04:00
|
|
|
GList *node;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-03-12 05:33:13 -05:00
|
|
|
g_return_if_fail(window != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2007-05-30 17:17:59 -04:00
|
|
|
node = g_list_find(activity_list, window);
|
|
|
|
|
2007-07-26 09:53:22 -04:00
|
|
|
if (actlist_sort == 1) {
|
2001-03-12 05:33:13 -05:00
|
|
|
/* Move the window to the first in the activity list */
|
2007-05-30 17:17:59 -04:00
|
|
|
if (node != NULL)
|
|
|
|
activity_list = g_list_delete_link(activity_list, node);
|
2001-03-12 05:33:13 -05:00
|
|
|
if (window->data_level != 0)
|
|
|
|
activity_list = g_list_prepend(activity_list, window);
|
2001-10-20 15:52:07 -04:00
|
|
|
statusbar_items_redraw("act");
|
2001-03-12 05:33:13 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-07-26 09:53:22 -04:00
|
|
|
if (actlist_sort == 2) {
|
|
|
|
if (node != NULL) {
|
2008-05-15 06:54:03 -04:00
|
|
|
if (window->data_level == GPOINTER_TO_INT(oldlevel)) {
|
|
|
|
if (window->hilight_color != 0)
|
|
|
|
statusbar_items_redraw("act");
|
|
|
|
return;
|
|
|
|
}
|
2007-07-26 09:53:22 -04:00
|
|
|
activity_list = g_list_delete_link(activity_list, node);
|
|
|
|
}
|
|
|
|
if (window->data_level != 0)
|
|
|
|
activity_list = g_list_insert_sorted(activity_list, window, (GCompareFunc)
|
|
|
|
window_level_cmp);
|
|
|
|
statusbar_items_redraw("act");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-15 06:54:03 -04:00
|
|
|
if (actlist_sort == 3) {
|
|
|
|
if (node != NULL)
|
|
|
|
activity_list = g_list_delete_link(activity_list, node);
|
|
|
|
if (window->data_level != 0)
|
|
|
|
activity_list = g_list_insert_sorted(activity_list, window, (GCompareFunc)
|
|
|
|
window_level_recent_cmp);
|
|
|
|
statusbar_items_redraw("act");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-30 17:17:59 -04:00
|
|
|
if (node != NULL) {
|
2001-03-12 05:33:13 -05:00
|
|
|
/* already in activity list */
|
|
|
|
if (window->data_level == 0) {
|
|
|
|
/* remove from activity list */
|
2007-05-30 17:17:59 -04:00
|
|
|
activity_list = g_list_delete_link(activity_list, node);
|
2001-10-20 15:52:07 -04:00
|
|
|
statusbar_items_redraw("act");
|
2001-03-12 05:33:13 -05:00
|
|
|
} else if (window->data_level != GPOINTER_TO_INT(oldlevel) ||
|
|
|
|
window->hilight_color != 0) {
|
|
|
|
/* different level as last time (or maybe different
|
|
|
|
hilight color?), just redraw it. */
|
2001-10-20 15:52:07 -04:00
|
|
|
statusbar_items_redraw("act");
|
2001-03-12 05:33:13 -05:00
|
|
|
}
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
2001-03-12 05:33:13 -05:00
|
|
|
|
|
|
|
if (window->data_level == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* add window to activity list .. */
|
2007-05-30 17:17:59 -04:00
|
|
|
activity_list = g_list_insert_sorted(activity_list, window, (GCompareFunc)
|
|
|
|
window_refnum_cmp);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-20 15:52:07 -04:00
|
|
|
statusbar_items_redraw("act");
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_statusbar_activity_window_destroyed(WINDOW_REC *window)
|
|
|
|
{
|
2008-04-06 15:19:46 -04:00
|
|
|
GList *node;
|
|
|
|
|
2000-09-26 20:08:03 -04:00
|
|
|
g_return_if_fail(window != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2008-04-06 15:19:46 -04:00
|
|
|
node = g_list_find(activity_list, window);
|
|
|
|
if (node != NULL)
|
|
|
|
activity_list = g_list_delete_link(activity_list, node);
|
2001-10-20 15:52:07 -04:00
|
|
|
statusbar_items_redraw("act");
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-09-26 20:11:06 -04:00
|
|
|
static void sig_statusbar_activity_updated(void)
|
|
|
|
{
|
2001-10-20 15:52:07 -04:00
|
|
|
statusbar_items_redraw("act");
|
2000-09-26 20:11:06 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
static void item_more(SBAR_ITEM_REC *item, int get_size_only)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-11-25 11:35:11 -05:00
|
|
|
MAIN_WINDOW_REC *mainwin;
|
|
|
|
int visible;
|
|
|
|
|
2001-11-29 18:50:47 -05:00
|
|
|
if (active_win == NULL) {
|
|
|
|
mainwin = NULL;
|
|
|
|
visible = FALSE;
|
|
|
|
} else {
|
|
|
|
mainwin = WINDOW_MAIN(active_win);
|
|
|
|
visible = WINDOW_GUI(active_win)->view->more_text;
|
|
|
|
}
|
|
|
|
|
2001-11-25 11:35:11 -05:00
|
|
|
if (!visible) {
|
2001-11-29 18:50:47 -05:00
|
|
|
if (mainwin != NULL)
|
|
|
|
more_visible = g_slist_remove(more_visible, mainwin);
|
2001-11-18 17:17:31 -05:00
|
|
|
if (get_size_only)
|
|
|
|
item->min_size = item->max_size = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-11-25 11:35:11 -05:00
|
|
|
more_visible = g_slist_prepend(more_visible, mainwin);
|
2001-11-18 17:17:31 -05:00
|
|
|
statusbar_item_default_handler(item, get_size_only, NULL, "", FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_statusbar_more_updated(void)
|
|
|
|
{
|
2001-11-25 11:35:11 -05:00
|
|
|
int visible;
|
|
|
|
|
2016-06-25 10:06:50 -04:00
|
|
|
/* no active window, for example during /window hide */
|
|
|
|
if (active_win == NULL)
|
|
|
|
return;
|
|
|
|
|
2001-11-25 11:35:11 -05:00
|
|
|
visible = g_slist_find(more_visible, WINDOW_MAIN(active_win)) != NULL;
|
|
|
|
if (WINDOW_GUI(active_win)->view->more_text != visible)
|
2001-11-18 17:17:31 -05:00
|
|
|
statusbar_items_redraw("more");
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-11-19 17:21:57 -05:00
|
|
|
/* Returns the lag in milliseconds. If we haven't been able to ask the lag
|
|
|
|
for a while, unknown is set to TRUE. */
|
|
|
|
static int get_lag(SERVER_REC *server, int *unknown)
|
|
|
|
{
|
|
|
|
long lag;
|
|
|
|
|
|
|
|
*unknown = FALSE;
|
|
|
|
|
|
|
|
if (server == NULL || server->lag_last_check == 0) {
|
|
|
|
/* lag has not been asked even once yet */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-06 04:56:25 -05:00
|
|
|
if (server->lag_sent == 0) {
|
2001-11-19 17:21:57 -05:00
|
|
|
/* no lag queries going on currently */
|
|
|
|
return server->lag;
|
|
|
|
}
|
|
|
|
|
2019-12-06 04:56:25 -05:00
|
|
|
/* we're not sure about our current lag.. */
|
2001-11-19 17:21:57 -05:00
|
|
|
*unknown = TRUE;
|
|
|
|
|
2019-12-06 04:56:25 -05:00
|
|
|
lag = (long) (time(NULL) - (server->lag_sent / G_TIME_SPAN_SECOND));
|
2001-11-19 17:21:57 -05:00
|
|
|
if (server->lag/1000 > lag) {
|
|
|
|
/* we've been waiting the lag reply less time than
|
|
|
|
what last known lag was -> use the last known lag */
|
|
|
|
return server->lag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return how long we have been waiting for lag reply */
|
|
|
|
return lag*1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void item_lag(SBAR_ITEM_REC *item, int get_size_only)
|
|
|
|
{
|
|
|
|
SERVER_REC *server;
|
|
|
|
char str[MAX_INT_STRLEN+10];
|
|
|
|
int lag, lag_unknown;
|
|
|
|
|
|
|
|
server = active_win == NULL ? NULL : active_win->active_server;
|
2002-12-28 12:54:13 -05:00
|
|
|
lag = get_lag(server, &lag_unknown);
|
2001-11-19 17:21:57 -05:00
|
|
|
|
2002-12-28 12:54:13 -05:00
|
|
|
if (lag <= 0 || lag < settings_get_time("lag_min_show")) {
|
2001-11-19 17:21:57 -05:00
|
|
|
/* don't print the lag item */
|
|
|
|
if (get_size_only)
|
|
|
|
item->min_size = item->max_size = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-12-28 12:54:13 -05:00
|
|
|
lag /= 10;
|
2001-11-19 17:21:57 -05:00
|
|
|
last_lag = lag;
|
|
|
|
last_lag_unknown = lag_unknown;
|
|
|
|
|
|
|
|
if (lag_unknown) {
|
2017-11-30 05:15:47 -05:00
|
|
|
/* "??)" in C becomes ']'
|
|
|
|
See: https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C */
|
2015-09-20 15:45:33 -04:00
|
|
|
g_snprintf(str, sizeof(str), "%d (?""?)", lag / 100);
|
2001-11-19 17:21:57 -05:00
|
|
|
} else {
|
2015-09-20 15:45:33 -04:00
|
|
|
if (lag % 100 == 0)
|
|
|
|
g_snprintf(str, sizeof(str), "%d", lag / 100);
|
|
|
|
else
|
|
|
|
g_snprintf(str, sizeof(str), "%d.%02d", lag / 100, lag % 100);
|
2001-11-19 17:21:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
statusbar_item_default_handler(item, get_size_only,
|
|
|
|
NULL, str, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lag_check_update(void)
|
|
|
|
{
|
|
|
|
SERVER_REC *server;
|
|
|
|
int lag, lag_unknown;
|
|
|
|
|
|
|
|
server = active_win == NULL ? NULL : active_win->active_server;
|
|
|
|
lag = get_lag(server, &lag_unknown)/10;
|
|
|
|
|
2002-12-28 12:54:13 -05:00
|
|
|
if (lag < settings_get_time("lag_min_show"))
|
|
|
|
lag = 0;
|
|
|
|
else
|
|
|
|
lag /= 10;
|
2001-11-19 17:21:57 -05:00
|
|
|
|
|
|
|
if (lag != last_lag || (lag > 0 && lag_unknown != last_lag_unknown))
|
|
|
|
statusbar_items_redraw("lag");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_server_lag_updated(SERVER_REC *server)
|
|
|
|
{
|
|
|
|
if (active_win != NULL && active_win->active_server == server)
|
|
|
|
lag_check_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sig_lag_timeout(void)
|
|
|
|
{
|
|
|
|
lag_check_update();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
static void item_input(SBAR_ITEM_REC *item, int get_size_only)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
GUI_ENTRY_REC *rec;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2002-03-24 14:06:47 -05:00
|
|
|
rec = g_hash_table_lookup(input_entries, item->bar->config->name);
|
2001-10-13 12:11:13 -04:00
|
|
|
if (rec == NULL) {
|
2017-04-24 18:42:53 -04:00
|
|
|
rec = gui_entry_create(ITEM_WINDOW_REAL_XPOS(item), item->bar->real_ypos,
|
2002-02-15 08:38:24 -05:00
|
|
|
item->size, term_type == TERM_TYPE_UTF8);
|
2001-10-24 09:47:13 -04:00
|
|
|
gui_entry_set_active(rec);
|
2002-03-24 14:06:47 -05:00
|
|
|
g_hash_table_insert(input_entries,
|
|
|
|
g_strdup(item->bar->config->name), rec);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
2001-10-28 13:40:12 -05:00
|
|
|
|
|
|
|
if (get_size_only) {
|
2017-04-24 18:42:53 -04:00
|
|
|
int max_width;
|
|
|
|
WINDOW_REC *window;
|
|
|
|
|
|
|
|
window = item->bar->parent_window != NULL
|
|
|
|
? item->bar->parent_window->active
|
|
|
|
: NULL;
|
|
|
|
|
|
|
|
max_width = window != NULL ? window->width : term_width;
|
|
|
|
|
|
|
|
item->min_size = 2+max_width/10;
|
|
|
|
item->max_size = max_width;
|
|
|
|
return;
|
2001-10-28 13:40:12 -05:00
|
|
|
}
|
|
|
|
|
2017-04-24 18:42:53 -04:00
|
|
|
gui_entry_move(rec, ITEM_WINDOW_REAL_XPOS(item), item->bar->real_ypos,
|
2001-10-28 13:40:12 -05:00
|
|
|
item->size);
|
|
|
|
gui_entry_redraw(rec); /* FIXME: this is only necessary with ^L.. */
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
2002-01-28 22:13:06 -05:00
|
|
|
static void read_settings(void)
|
|
|
|
{
|
2022-01-31 04:36:57 -05:00
|
|
|
const char *sep;
|
2002-02-15 08:38:24 -05:00
|
|
|
if (active_entry != NULL)
|
|
|
|
gui_entry_set_utf8(active_entry, term_type == TERM_TYPE_UTF8);
|
2007-07-26 09:53:22 -04:00
|
|
|
|
2020-05-24 12:43:46 -04:00
|
|
|
actlist_sort = settings_get_choice("actlist_sort");
|
2022-01-19 12:01:30 -05:00
|
|
|
|
2022-01-31 04:36:57 -05:00
|
|
|
sep = settings_get_str("actlist_separator");
|
2022-02-05 20:27:36 -05:00
|
|
|
if (g_strcmp0(actlist_separator, sep) != 0) {
|
2022-01-31 04:36:57 -05:00
|
|
|
g_free(actlist_separator);
|
|
|
|
actlist_separator = g_strdup(sep);
|
2022-01-19 12:01:30 -05:00
|
|
|
statusbar_items_redraw("act");
|
|
|
|
}
|
2002-01-28 22:13:06 -05:00
|
|
|
}
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
void statusbar_items_init(void)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2002-12-31 07:36:56 -05:00
|
|
|
settings_add_time("misc", "lag_min_show", "1sec");
|
2020-05-24 12:43:46 -04:00
|
|
|
settings_add_choice("lookandfeel", "actlist_sort", 0, "refnum;recent;level;level,recent");
|
2008-06-10 06:21:00 -04:00
|
|
|
settings_add_bool("lookandfeel", "actlist_names", FALSE);
|
2022-01-19 07:09:49 -05:00
|
|
|
settings_add_str("lookandfeel", "actlist_separator", ",");
|
2019-03-22 14:10:10 -04:00
|
|
|
settings_add_bool("lookandfeel", "actlist_prefer_window_name", FALSE);
|
2001-10-13 12:11:13 -04:00
|
|
|
|
|
|
|
statusbar_item_register("window", NULL, item_window_active);
|
|
|
|
statusbar_item_register("window_empty", NULL, item_window_empty);
|
|
|
|
statusbar_item_register("prompt", NULL, item_window_active);
|
|
|
|
statusbar_item_register("prompt_empty", NULL, item_window_empty);
|
2002-03-10 09:02:33 -05:00
|
|
|
statusbar_item_register("topic", NULL, item_window_active);
|
|
|
|
statusbar_item_register("topic_empty", NULL, item_window_empty);
|
2001-10-13 12:11:13 -04:00
|
|
|
statusbar_item_register("lag", NULL, item_lag);
|
|
|
|
statusbar_item_register("act", NULL, item_act);
|
|
|
|
statusbar_item_register("more", NULL, item_more);
|
|
|
|
statusbar_item_register("input", NULL, item_input);
|
|
|
|
|
2001-11-19 17:21:57 -05:00
|
|
|
/* activity */
|
2000-04-26 04:03:38 -04:00
|
|
|
activity_list = NULL;
|
|
|
|
signal_add("window activity", (SIGNAL_FUNC) sig_statusbar_activity_hilight);
|
|
|
|
signal_add("window destroyed", (SIGNAL_FUNC) sig_statusbar_activity_window_destroyed);
|
2000-09-26 20:11:06 -04:00
|
|
|
signal_add("window refnum changed", (SIGNAL_FUNC) sig_statusbar_activity_updated);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-11-19 17:21:57 -05:00
|
|
|
/* more */
|
2001-11-25 11:35:11 -05:00
|
|
|
more_visible = NULL;
|
2001-11-18 17:17:31 -05:00
|
|
|
signal_add("gui page scrolled", (SIGNAL_FUNC) sig_statusbar_more_updated);
|
|
|
|
signal_add("window changed", (SIGNAL_FUNC) sig_statusbar_more_updated);
|
|
|
|
signal_add_last("gui print text finished", (SIGNAL_FUNC) sig_statusbar_more_updated);
|
|
|
|
signal_add_last("command clear", (SIGNAL_FUNC) sig_statusbar_more_updated);
|
|
|
|
signal_add_last("command scrollback", (SIGNAL_FUNC) sig_statusbar_more_updated);
|
|
|
|
|
2001-11-19 17:21:57 -05:00
|
|
|
/* lag */
|
|
|
|
last_lag = 0; last_lag_unknown = FALSE;
|
|
|
|
signal_add("server lag", (SIGNAL_FUNC) sig_server_lag_updated);
|
|
|
|
signal_add("window changed", (SIGNAL_FUNC) lag_check_update);
|
|
|
|
signal_add("window server changed", (SIGNAL_FUNC) lag_check_update);
|
|
|
|
lag_timeout_tag = g_timeout_add(5000, (GSourceFunc) sig_lag_timeout, NULL);
|
|
|
|
|
|
|
|
/* input */
|
2002-03-24 14:06:47 -05:00
|
|
|
input_entries = g_hash_table_new((GHashFunc) g_str_hash,
|
|
|
|
(GCompareFunc) g_str_equal);
|
2002-01-28 22:13:06 -05:00
|
|
|
|
|
|
|
read_settings();
|
2002-02-15 13:39:32 -05:00
|
|
|
signal_add_last("setup changed", (SIGNAL_FUNC) read_settings);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
void statusbar_items_deinit(void)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-11-19 17:21:57 -05:00
|
|
|
/* activity */
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_remove("window activity", (SIGNAL_FUNC) sig_statusbar_activity_hilight);
|
|
|
|
signal_remove("window destroyed", (SIGNAL_FUNC) sig_statusbar_activity_window_destroyed);
|
2000-09-26 20:11:06 -04:00
|
|
|
signal_remove("window refnum changed", (SIGNAL_FUNC) sig_statusbar_activity_updated);
|
2001-11-19 17:21:57 -05:00
|
|
|
g_list_free(activity_list);
|
|
|
|
activity_list = NULL;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-11-19 17:21:57 -05:00
|
|
|
/* more */
|
2001-11-25 11:35:11 -05:00
|
|
|
g_slist_free(more_visible);
|
2001-11-18 17:17:31 -05:00
|
|
|
signal_remove("gui page scrolled", (SIGNAL_FUNC) sig_statusbar_more_updated);
|
|
|
|
signal_remove("window changed", (SIGNAL_FUNC) sig_statusbar_more_updated);
|
|
|
|
signal_remove("gui print text finished", (SIGNAL_FUNC) sig_statusbar_more_updated);
|
|
|
|
signal_remove("command clear", (SIGNAL_FUNC) sig_statusbar_more_updated);
|
|
|
|
signal_remove("command scrollback", (SIGNAL_FUNC) sig_statusbar_more_updated);
|
|
|
|
|
2001-11-19 17:21:57 -05:00
|
|
|
/* lag */
|
|
|
|
signal_remove("server lag", (SIGNAL_FUNC) sig_server_lag_updated);
|
|
|
|
signal_remove("window changed", (SIGNAL_FUNC) lag_check_update);
|
|
|
|
signal_remove("window server changed", (SIGNAL_FUNC) lag_check_update);
|
|
|
|
g_source_remove(lag_timeout_tag);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-11-19 17:21:57 -05:00
|
|
|
/* input */
|
2002-03-24 14:06:47 -05:00
|
|
|
g_hash_table_foreach(input_entries, (GHFunc) g_free, NULL);
|
|
|
|
g_hash_table_destroy(input_entries);
|
2002-01-28 22:13:06 -05:00
|
|
|
|
|
|
|
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|