2000-04-26 08:03:38 +00:00
|
|
|
/*
|
|
|
|
|
windows.c : irssi
|
|
|
|
|
|
|
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
|
|
|
|
|
|
|
|
|
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 18:41:10 +00: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 08:03:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
|
#include "module-formats.h"
|
|
|
|
|
#include "modules.h"
|
|
|
|
|
#include "signals.h"
|
|
|
|
|
#include "commands.h"
|
2000-08-26 15:39:44 +00:00
|
|
|
#include "servers.h"
|
2000-05-04 10:32:42 +00:00
|
|
|
#include "misc.h"
|
2000-04-26 08:03:38 +00:00
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
|
|
#include "levels.h"
|
|
|
|
|
|
|
|
|
|
#include "printtext.h"
|
2000-11-17 16:27:14 +00:00
|
|
|
#include "fe-windows.h"
|
2000-04-26 08:03:38 +00:00
|
|
|
#include "window-items.h"
|
|
|
|
|
|
2000-05-04 10:32:42 +00:00
|
|
|
GSList *windows; /* first in the list is the active window,
|
|
|
|
|
next is the last active, etc. */
|
2000-04-26 08:03:38 +00:00
|
|
|
WINDOW_REC *active_win;
|
|
|
|
|
|
2000-05-15 08:25:45 +00:00
|
|
|
static int daytag;
|
2000-06-10 18:56:03 +00:00
|
|
|
static int daycheck; /* 0 = don't check, 1 = time is 00:00, check,
|
|
|
|
|
2 = time is 00:00, already checked */
|
2000-05-15 08:25:45 +00:00
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
static int window_get_new_refnum(void)
|
|
|
|
|
{
|
|
|
|
|
WINDOW_REC *win;
|
|
|
|
|
GSList *tmp;
|
|
|
|
|
int refnum;
|
|
|
|
|
|
|
|
|
|
refnum = 1;
|
|
|
|
|
tmp = windows;
|
|
|
|
|
while (tmp != NULL) {
|
|
|
|
|
win = tmp->data;
|
|
|
|
|
|
|
|
|
|
if (refnum != win->refnum) {
|
|
|
|
|
tmp = tmp->next;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
refnum++;
|
|
|
|
|
tmp = windows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return refnum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WINDOW_REC *window_create(WI_ITEM_REC *item, int automatic)
|
|
|
|
|
{
|
|
|
|
|
WINDOW_REC *rec;
|
|
|
|
|
|
|
|
|
|
rec = g_new0(WINDOW_REC, 1);
|
|
|
|
|
rec->refnum = window_get_new_refnum();
|
2002-12-28 17:54:13 +00:00
|
|
|
rec->level = settings_get_level("window_default_level");
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2000-05-04 10:32:42 +00:00
|
|
|
windows = g_slist_prepend(windows, rec);
|
2000-04-26 08:03:38 +00:00
|
|
|
signal_emit("window created", 2, rec, GINT_TO_POINTER(automatic));
|
|
|
|
|
|
2000-12-02 19:08:21 +00:00
|
|
|
if (item != NULL) window_item_add(rec, item, automatic);
|
2000-04-26 08:03:38 +00:00
|
|
|
if (windows->next == NULL || !automatic || settings_get_bool("window_auto_change")) {
|
|
|
|
|
if (automatic && windows->next != NULL)
|
|
|
|
|
signal_emit("window changed automatic", 1, rec);
|
|
|
|
|
window_set_active(rec);
|
|
|
|
|
}
|
|
|
|
|
return rec;
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-04 10:32:42 +00:00
|
|
|
/* removed_refnum was removed from the windows list, pack the windows so
|
|
|
|
|
there won't be any holes. If there is any holes after removed_refnum,
|
|
|
|
|
leave the windows behind it alone. */
|
|
|
|
|
static void windows_pack(int removed_refnum)
|
|
|
|
|
{
|
|
|
|
|
WINDOW_REC *window;
|
|
|
|
|
int refnum;
|
|
|
|
|
|
|
|
|
|
for (refnum = removed_refnum+1;; refnum++) {
|
|
|
|
|
window = window_find_refnum(refnum);
|
2001-01-01 18:30:23 +00:00
|
|
|
if (window == NULL || window->sticky_refnum)
|
|
|
|
|
break;
|
2000-05-04 10:32:42 +00:00
|
|
|
|
|
|
|
|
window_set_refnum(window, refnum-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
void window_destroy(WINDOW_REC *window)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail(window != NULL);
|
|
|
|
|
|
|
|
|
|
if (window->destroying) return;
|
|
|
|
|
window->destroying = TRUE;
|
2000-08-11 19:57:58 +00:00
|
|
|
windows = g_slist_remove(windows, window);
|
|
|
|
|
|
2002-05-04 19:44:25 +00:00
|
|
|
if (active_win == window) {
|
|
|
|
|
active_win = NULL; /* it's corrupted */
|
|
|
|
|
if (windows != NULL)
|
|
|
|
|
window_set_active(windows->data);
|
2000-08-11 19:57:58 +00:00
|
|
|
}
|
2000-04-26 08:03:38 +00:00
|
|
|
|
|
|
|
|
while (window->items != NULL)
|
2001-01-06 21:58:28 +00:00
|
|
|
window_item_destroy(window->items->data);
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2001-01-01 18:32:48 +00:00
|
|
|
if (settings_get_bool("windows_auto_renumber"))
|
|
|
|
|
windows_pack(window->refnum);
|
2000-09-27 00:08:03 +00:00
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
signal_emit("window destroyed", 1, window);
|
|
|
|
|
|
2001-02-10 09:12:53 +00:00
|
|
|
while (window->bound_items != NULL)
|
|
|
|
|
window_bind_destroy(window, window->bound_items->data);
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2001-03-17 02:34:42 +00:00
|
|
|
g_free_not_null(window->hilight_color);
|
2001-02-10 03:10:30 +00:00
|
|
|
g_free_not_null(window->servertag);
|
2000-08-01 01:02:46 +00:00
|
|
|
g_free_not_null(window->theme_name);
|
2000-04-26 08:03:38 +00:00
|
|
|
g_free_not_null(window->name);
|
|
|
|
|
g_free(window);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-03 22:03:00 +00:00
|
|
|
void window_auto_destroy(WINDOW_REC *window)
|
|
|
|
|
{
|
|
|
|
|
if (settings_get_bool("autoclose_windows") && windows->next != NULL &&
|
2001-06-27 21:31:26 +00:00
|
|
|
window->items == NULL && window->bound_items == NULL &&
|
2002-02-10 14:59:36 +00:00
|
|
|
window->level == 0 && !window->immortal)
|
2001-03-03 22:03:00 +00:00
|
|
|
window_destroy(window);
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
void window_set_active(WINDOW_REC *window)
|
|
|
|
|
{
|
2000-06-14 17:41:45 +00:00
|
|
|
WINDOW_REC *old_window;
|
|
|
|
|
|
2000-05-04 10:32:42 +00:00
|
|
|
if (window == active_win)
|
|
|
|
|
return;
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2000-06-14 17:41:45 +00:00
|
|
|
old_window = active_win;
|
2000-04-26 08:03:38 +00:00
|
|
|
active_win = window;
|
2000-10-22 12:33:47 +00:00
|
|
|
if (active_win != NULL) {
|
|
|
|
|
windows = g_slist_remove(windows, active_win);
|
|
|
|
|
windows = g_slist_prepend(windows, active_win);
|
|
|
|
|
}
|
2000-05-04 10:32:42 +00:00
|
|
|
|
2001-03-03 21:11:43 +00:00
|
|
|
if (active_win != NULL)
|
|
|
|
|
signal_emit("window changed", 2, active_win, old_window);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void window_change_server(WINDOW_REC *window, void *server)
|
|
|
|
|
{
|
2002-09-14 23:14:04 +00:00
|
|
|
SERVER_REC *active, *connect;
|
|
|
|
|
|
2002-04-12 19:41:51 +00:00
|
|
|
if (server != NULL && SERVER(server)->disconnected)
|
|
|
|
|
return;
|
|
|
|
|
|
2002-09-14 23:14:04 +00:00
|
|
|
if (server == NULL) {
|
|
|
|
|
active = connect = NULL;
|
2002-09-15 01:04:40 +00:00
|
|
|
} else if (g_slist_find(servers, server) != NULL) {
|
2002-09-14 23:14:04 +00:00
|
|
|
active = server;
|
|
|
|
|
connect = NULL;
|
|
|
|
|
} else {
|
|
|
|
|
active = NULL;
|
|
|
|
|
connect = server;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (window->connect_server != connect) {
|
|
|
|
|
window->connect_server = connect;
|
|
|
|
|
signal_emit("window connect changed", 2, window, connect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (window->active_server != active) {
|
|
|
|
|
window->active_server = active;
|
|
|
|
|
signal_emit("window server changed", 2, window, active);
|
2014-09-11 19:10:33 +02:00
|
|
|
}
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
2000-05-04 10:32:42 +00:00
|
|
|
void window_set_refnum(WINDOW_REC *window, int refnum)
|
|
|
|
|
{
|
|
|
|
|
GSList *tmp;
|
|
|
|
|
int old_refnum;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail(window != NULL);
|
|
|
|
|
g_return_if_fail(refnum >= 1);
|
|
|
|
|
if (window->refnum == refnum) return;
|
|
|
|
|
|
|
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
|
|
if (rec->refnum == refnum) {
|
|
|
|
|
rec->refnum = window->refnum;
|
|
|
|
|
signal_emit("window refnum changed", 2, rec, GINT_TO_POINTER(refnum));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
old_refnum = window->refnum;
|
|
|
|
|
window->refnum = refnum;
|
|
|
|
|
signal_emit("window refnum changed", 2, window, GINT_TO_POINTER(old_refnum));
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
void window_set_name(WINDOW_REC *window, const char *name)
|
|
|
|
|
{
|
|
|
|
|
g_free_not_null(window->name);
|
2002-05-04 23:07:43 +00:00
|
|
|
window->name = name == NULL || *name == '\0' ? NULL : g_strdup(name);
|
2000-04-26 08:03:38 +00:00
|
|
|
|
|
|
|
|
signal_emit("window name changed", 1, window);
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-20 13:29:20 +00:00
|
|
|
void window_set_history(WINDOW_REC *window, const char *name)
|
|
|
|
|
{
|
|
|
|
|
char *oldname;
|
|
|
|
|
oldname = window->history_name;
|
|
|
|
|
|
2001-12-20 21:52:16 +00:00
|
|
|
if (name == NULL || *name == '\0')
|
2001-12-20 13:29:20 +00:00
|
|
|
window->history_name = NULL;
|
|
|
|
|
else
|
|
|
|
|
window->history_name = g_strdup(name);
|
|
|
|
|
|
2015-12-15 01:52:44 +01:00
|
|
|
signal_emit("window history changed", 2, window, oldname);
|
2001-12-20 13:29:20 +00:00
|
|
|
|
|
|
|
|
g_free_not_null(oldname);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-15 01:52:44 +01:00
|
|
|
void window_clear_history(WINDOW_REC *window, const char *name)
|
|
|
|
|
{
|
|
|
|
|
signal_emit("window history cleared", 2, window, name);
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
void window_set_level(WINDOW_REC *window, int level)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail(window != NULL);
|
|
|
|
|
|
|
|
|
|
window->level = level;
|
|
|
|
|
signal_emit("window level changed", 1, window);
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-10 14:59:36 +00:00
|
|
|
void window_set_immortal(WINDOW_REC *window, int immortal)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail(window != NULL);
|
|
|
|
|
|
|
|
|
|
window->immortal = immortal;
|
|
|
|
|
signal_emit("window immortal changed", 1, window);
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-09 11:42:42 +00:00
|
|
|
/* return active item's name, or if none is active, window's name */
|
2002-05-16 00:34:37 +00:00
|
|
|
const char *window_get_active_name(WINDOW_REC *window)
|
2000-05-09 11:42:42 +00:00
|
|
|
{
|
|
|
|
|
g_return_val_if_fail(window != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (window->active != NULL)
|
2002-05-16 00:34:37 +00:00
|
|
|
return window->active->visible_name;
|
2000-05-09 11:42:42 +00:00
|
|
|
|
|
|
|
|
return window->name;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-22 13:04:07 +00:00
|
|
|
#define WINDOW_LEVEL_MATCH(window, server, level) \
|
|
|
|
|
(((window)->level & level) && \
|
|
|
|
|
(server == NULL || (window)->active_server == server))
|
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
WINDOW_REC *window_find_level(void *server, int level)
|
|
|
|
|
{
|
|
|
|
|
GSList *tmp;
|
2002-11-15 09:04:47 +00:00
|
|
|
WINDOW_REC *match;
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2002-11-15 09:04:47 +00:00
|
|
|
match = NULL;
|
2000-04-26 08:03:38 +00:00
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
2002-11-15 09:04:47 +00:00
|
|
|
if (WINDOW_LEVEL_MATCH(rec, server, level)) {
|
|
|
|
|
/* prefer windows without any items */
|
|
|
|
|
if (rec->items == NULL)
|
|
|
|
|
return rec;
|
|
|
|
|
|
|
|
|
|
if (match == NULL)
|
|
|
|
|
match = rec;
|
|
|
|
|
else if (active_win == rec) {
|
|
|
|
|
/* prefer active window over others */
|
|
|
|
|
match = rec;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
2002-11-15 09:04:47 +00:00
|
|
|
return match;
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WINDOW_REC *window_find_closest(void *server, const char *name, int level)
|
|
|
|
|
{
|
2002-02-15 14:54:00 +00:00
|
|
|
WINDOW_REC *window,*namewindow=NULL;
|
2000-04-26 08:03:38 +00:00
|
|
|
WI_ITEM_REC *item;
|
2002-11-15 09:04:47 +00:00
|
|
|
int i;
|
2000-04-26 08:03:38 +00:00
|
|
|
|
|
|
|
|
/* match by name */
|
|
|
|
|
item = name == NULL ? NULL :
|
|
|
|
|
window_item_find(server, name);
|
2002-02-15 14:54:00 +00:00
|
|
|
if (item != NULL) {
|
|
|
|
|
namewindow = window_item_window(item);
|
2002-11-15 09:04:47 +00:00
|
|
|
if (namewindow != NULL &&
|
|
|
|
|
((namewindow->level & level) != 0 ||
|
|
|
|
|
!settings_get_bool("window_check_level_first"))) {
|
|
|
|
|
/* match, but if multiple windows have the same level
|
|
|
|
|
we could be choosing a bad one here, eg.
|
|
|
|
|
name=nick1 would get nick2's query instead of
|
2003-01-30 16:28:31 +00:00
|
|
|
generic msgs window.
|
|
|
|
|
|
|
|
|
|
And check for prefixed !channel name --Borys */
|
2014-06-10 12:06:19 -04:00
|
|
|
if (g_ascii_strcasecmp(name, item->visible_name) == 0 ||
|
|
|
|
|
g_ascii_strcasecmp(name, (char *) window_item_get_target((WI_ITEM_REC *) item)) == 0)
|
2002-11-15 09:04:47 +00:00
|
|
|
return namewindow;
|
|
|
|
|
}
|
2002-02-15 14:54:00 +00:00
|
|
|
}
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2002-11-15 09:04:47 +00:00
|
|
|
/* prefer windows without items */
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
|
/* match by level */
|
|
|
|
|
if (level != MSGLEVEL_HILIGHT)
|
|
|
|
|
level &= ~(MSGLEVEL_HILIGHT | MSGLEVEL_NOHILIGHT);
|
|
|
|
|
window = window_find_level(server, level);
|
|
|
|
|
if (window != NULL && (i == 1 || window->items == NULL))
|
|
|
|
|
return window;
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2002-11-15 09:04:47 +00:00
|
|
|
/* match by level - ignore server */
|
|
|
|
|
window = window_find_level(NULL, level);
|
|
|
|
|
if (window != NULL && (i == 1 || window->items == NULL))
|
|
|
|
|
return window;
|
|
|
|
|
}
|
2000-05-29 00:32:48 +00:00
|
|
|
|
2002-02-15 14:54:00 +00:00
|
|
|
/* still return item's window if we didnt find anything */
|
|
|
|
|
if (namewindow != NULL) return namewindow;
|
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
/* fallback to active */
|
|
|
|
|
return active_win;
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-04 10:32:42 +00:00
|
|
|
WINDOW_REC *window_find_refnum(int refnum)
|
|
|
|
|
{
|
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
|
|
if (rec->refnum == refnum)
|
|
|
|
|
return rec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WINDOW_REC *window_find_name(const char *name)
|
2000-04-26 08:03:38 +00:00
|
|
|
{
|
2000-05-04 10:32:42 +00:00
|
|
|
GSList *tmp;
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2000-05-04 10:32:42 +00:00
|
|
|
g_return_val_if_fail(name != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
2014-06-10 12:06:19 -04:00
|
|
|
if (rec->name != NULL &&
|
|
|
|
|
g_ascii_strcasecmp(rec->name, name) == 0)
|
2000-05-04 10:32:42 +00:00
|
|
|
return rec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-02 19:08:21 +00:00
|
|
|
WINDOW_REC *window_find_item(SERVER_REC *server, const char *name)
|
2000-05-04 10:32:42 +00:00
|
|
|
{
|
|
|
|
|
WINDOW_REC *rec;
|
|
|
|
|
WI_ITEM_REC *item;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(name != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
rec = window_find_name(name);
|
|
|
|
|
if (rec != NULL) return rec;
|
|
|
|
|
|
2000-12-02 19:08:21 +00:00
|
|
|
item = server == NULL ? NULL :
|
|
|
|
|
window_item_find(server, name);
|
2002-04-26 13:01:06 +00:00
|
|
|
if (item == NULL) {
|
2000-04-26 08:03:38 +00:00
|
|
|
/* not found from the active server - any server? */
|
|
|
|
|
item = window_item_find(NULL, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item == NULL)
|
2007-08-04 12:49:57 +00:00
|
|
|
return NULL;
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2001-01-01 17:07:08 +00:00
|
|
|
return window_item_window(item);
|
2000-05-04 10:32:42 +00:00
|
|
|
}
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2000-06-12 22:57:53 +00:00
|
|
|
int window_refnum_prev(int refnum, int wrap)
|
2000-05-04 10:32:42 +00:00
|
|
|
{
|
2000-04-26 08:03:38 +00:00
|
|
|
GSList *tmp;
|
2000-05-15 08:25:45 +00:00
|
|
|
int prev, max;
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2000-05-15 08:25:45 +00:00
|
|
|
max = prev = -1;
|
2000-05-04 10:32:42 +00:00
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
2000-05-15 08:25:45 +00:00
|
|
|
if (rec->refnum < refnum && (prev == -1 || rec->refnum > prev))
|
|
|
|
|
prev = rec->refnum;
|
2000-06-12 22:57:53 +00:00
|
|
|
if (wrap && (max == -1 || rec->refnum > max))
|
2000-05-15 08:25:45 +00:00
|
|
|
max = rec->refnum;
|
2000-05-04 10:32:42 +00:00
|
|
|
}
|
2000-05-15 08:25:45 +00:00
|
|
|
|
|
|
|
|
return prev != -1 ? prev : max;
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-12 22:57:53 +00:00
|
|
|
int window_refnum_next(int refnum, int wrap)
|
2000-05-15 08:25:45 +00:00
|
|
|
{
|
|
|
|
|
GSList *tmp;
|
|
|
|
|
int min, next;
|
|
|
|
|
|
|
|
|
|
min = next = -1;
|
|
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
|
|
if (rec->refnum > refnum && (next == -1 || rec->refnum < next))
|
|
|
|
|
next = rec->refnum;
|
2000-06-12 22:57:53 +00:00
|
|
|
if (wrap && (min == -1 || rec->refnum < min))
|
2000-05-15 08:25:45 +00:00
|
|
|
min = rec->refnum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return next != -1 ? next : min;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int windows_refnum_last(void)
|
|
|
|
|
{
|
|
|
|
|
GSList *tmp;
|
|
|
|
|
int max;
|
|
|
|
|
|
|
|
|
|
max = -1;
|
|
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
|
|
if (rec->refnum > max)
|
|
|
|
|
max = rec->refnum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return max;
|
2000-05-04 10:32:42 +00:00
|
|
|
}
|
|
|
|
|
|
2001-08-03 22:54:08 +00:00
|
|
|
int window_refnum_cmp(WINDOW_REC *w1, WINDOW_REC *w2)
|
2001-01-01 14:57:55 +00:00
|
|
|
{
|
|
|
|
|
return w1->refnum < w2->refnum ? -1 : 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GSList *windows_get_sorted(void)
|
|
|
|
|
{
|
|
|
|
|
GSList *tmp, *sorted;
|
|
|
|
|
|
|
|
|
|
sorted = NULL;
|
|
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
|
|
sorted = g_slist_insert_sorted(sorted, rec, (GCompareFunc)
|
|
|
|
|
window_refnum_cmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sorted;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-08 16:08:47 +00:00
|
|
|
/* Add a new bind to window - if duplicate is found it's returned */
|
2001-02-10 09:12:53 +00:00
|
|
|
WINDOW_BIND_REC *window_bind_add(WINDOW_REC *window, const char *servertag,
|
|
|
|
|
const char *name)
|
|
|
|
|
{
|
|
|
|
|
WINDOW_BIND_REC *rec;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(window != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail(servertag != NULL, NULL);
|
2001-08-08 16:08:47 +00:00
|
|
|
g_return_val_if_fail(name != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
rec = window_bind_find(window, servertag, name);
|
|
|
|
|
if (rec != NULL)
|
|
|
|
|
return rec;
|
2001-02-10 09:12:53 +00:00
|
|
|
|
|
|
|
|
rec = g_new0(WINDOW_BIND_REC, 1);
|
|
|
|
|
rec->name = g_strdup(name);
|
|
|
|
|
rec->servertag = g_strdup(servertag);
|
|
|
|
|
|
|
|
|
|
window->bound_items = g_slist_append(window->bound_items, rec);
|
|
|
|
|
return rec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void window_bind_destroy(WINDOW_REC *window, WINDOW_BIND_REC *rec)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail(window != NULL);
|
|
|
|
|
g_return_if_fail(rec != NULL);
|
|
|
|
|
|
|
|
|
|
window->bound_items = g_slist_remove(window->bound_items, rec);
|
|
|
|
|
|
|
|
|
|
g_free(rec->servertag);
|
|
|
|
|
g_free(rec->name);
|
|
|
|
|
g_free(rec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WINDOW_BIND_REC *window_bind_find(WINDOW_REC *window, const char *servertag,
|
|
|
|
|
const char *name)
|
|
|
|
|
{
|
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(window != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail(servertag != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail(name != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
for (tmp = window->bound_items; tmp != NULL; tmp = tmp->next) {
|
|
|
|
|
WINDOW_BIND_REC *rec = tmp->data;
|
|
|
|
|
|
2014-06-10 12:06:19 -04:00
|
|
|
if (g_ascii_strcasecmp(rec->name, name) == 0 &&
|
|
|
|
|
g_ascii_strcasecmp(rec->servertag, servertag) == 0)
|
2001-02-10 09:12:53 +00:00
|
|
|
return rec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void window_bind_remove_unsticky(WINDOW_REC *window)
|
|
|
|
|
{
|
|
|
|
|
GSList *tmp, *next;
|
|
|
|
|
|
2001-02-19 02:26:32 +00:00
|
|
|
for (tmp = window->bound_items; tmp != NULL; tmp = next) {
|
2001-02-10 09:12:53 +00:00
|
|
|
WINDOW_BIND_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
|
|
next = tmp->next;
|
|
|
|
|
if (!rec->sticky)
|
|
|
|
|
window_bind_destroy(window, rec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-04 21:18:32 +00:00
|
|
|
static void sig_server_connected(SERVER_REC *server)
|
2000-04-26 08:03:38 +00:00
|
|
|
{
|
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail(server != NULL);
|
|
|
|
|
|
2000-09-30 00:11:56 +00:00
|
|
|
/* Try to keep some server assigned to windows..
|
|
|
|
|
Also change active window's server if the window is empty */
|
2000-04-26 08:03:38 +00:00
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
2001-02-10 03:10:30 +00:00
|
|
|
if ((rec->servertag == NULL ||
|
2014-06-10 12:06:19 -04:00
|
|
|
g_ascii_strcasecmp(rec->servertag, server->tag) == 0) &&
|
2001-02-10 03:10:30 +00:00
|
|
|
(rec->active_server == NULL ||
|
|
|
|
|
(rec == active_win && rec->items == NULL)))
|
2000-10-01 23:37:31 +00:00
|
|
|
window_change_server(rec, server);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-30 00:11:56 +00:00
|
|
|
static void sig_server_disconnected(SERVER_REC *server)
|
2000-04-26 08:03:38 +00:00
|
|
|
{
|
|
|
|
|
GSList *tmp;
|
2000-08-04 15:52:32 +00:00
|
|
|
SERVER_REC *new_server;
|
2000-04-26 08:03:38 +00:00
|
|
|
|
|
|
|
|
g_return_if_fail(server != NULL);
|
|
|
|
|
|
2000-08-04 15:52:32 +00:00
|
|
|
new_server = servers == NULL ? NULL : servers->data;
|
2000-04-26 08:03:38 +00:00
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
2002-09-14 23:14:04 +00:00
|
|
|
if (rec->active_server == server ||
|
|
|
|
|
rec->connect_server == server) {
|
2001-02-10 03:10:30 +00:00
|
|
|
window_change_server(rec, rec->servertag != NULL ?
|
|
|
|
|
NULL : new_server);
|
|
|
|
|
}
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-25 15:41:37 +00:00
|
|
|
static void window_print_daychange(WINDOW_REC *window, struct tm *tm)
|
|
|
|
|
{
|
|
|
|
|
THEME_REC *theme;
|
|
|
|
|
TEXT_DEST_REC dest;
|
|
|
|
|
char *format, str[256];
|
2007-02-25 17:42:54 +00:00
|
|
|
int ret;
|
2001-11-25 15:41:37 +00:00
|
|
|
|
|
|
|
|
theme = active_win->theme != NULL ? active_win->theme : current_theme;
|
|
|
|
|
format_create_dest(&dest, NULL, NULL, MSGLEVEL_NEVER, window);
|
|
|
|
|
format = format_get_text_theme(theme, MODULE_NAME, &dest,
|
|
|
|
|
TXT_DAYCHANGE);
|
2007-02-25 17:42:54 +00:00
|
|
|
ret = strftime(str, sizeof(str), format, tm);
|
2001-11-25 15:41:37 +00:00
|
|
|
g_free(format);
|
2007-02-25 17:42:54 +00:00
|
|
|
if (ret <= 0) return;
|
2001-11-25 15:41:37 +00:00
|
|
|
|
|
|
|
|
printtext_string_window(window, MSGLEVEL_NEVER, str);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-09 15:20:29 +01:00
|
|
|
short color_24bit_256 (const unsigned char rgb[])
|
|
|
|
|
{
|
|
|
|
|
static const int cstep_size = 40;
|
|
|
|
|
static const int cstep_start = 0x5f;
|
|
|
|
|
|
|
|
|
|
static const int gstep_size = 10;
|
|
|
|
|
static const int gstep_start = 0x08;
|
|
|
|
|
|
|
|
|
|
int dist[3] = {0};
|
|
|
|
|
int r[3], gr[3];
|
|
|
|
|
|
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 3; ++i) {
|
|
|
|
|
const int n = rgb[i];
|
|
|
|
|
gr[i] = -1;
|
|
|
|
|
if (n < cstep_start /2) {
|
|
|
|
|
r[i] = 0;
|
|
|
|
|
dist[i] = -cstep_size/2;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
r[i] = 1+((n-cstep_start + cstep_size /2)/cstep_size);
|
|
|
|
|
dist[i] = ((n-cstep_start + cstep_size /2)%cstep_size - cstep_size/2);
|
|
|
|
|
}
|
|
|
|
|
if (n < gstep_start /2) {
|
|
|
|
|
gr[i] = -1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
gr[i] = ((n-gstep_start + gstep_size /2)/gstep_size);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (r[0] == r[1] && r[1] == r[2] &&
|
|
|
|
|
4*abs(dist[0]) < gstep_size && 4*abs(dist[1]) < gstep_size && 4*abs(dist[2]) < gstep_size) {
|
|
|
|
|
/* skip gray detection */
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const int j = r[1] == r[2] ? 0 : 1;
|
|
|
|
|
if ((r[0] == r[1] || r[j] == r[2]) && abs(r[j]-r[(j+1)%3]) <= 1) {
|
|
|
|
|
const int k = gr[1] == gr[2] ? 0 : 1;
|
|
|
|
|
if ((gr[0] == gr[1] || gr[k] == gr[2]) && abs(gr[k]-gr[(k+1)%3]) <= 2) {
|
|
|
|
|
if (gr[k] < 0) {
|
|
|
|
|
r[0] = r[1] = r[2] = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (gr[k] > 23) {
|
|
|
|
|
r[0] = r[1] = r[2] = 5;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
r[0] = 6;
|
|
|
|
|
r[1] = (gr[k] / 6);
|
|
|
|
|
r[2] = gr[k]%6;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 16 + r[0]*36 + r[1] * 6 + r[2];
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-10 18:56:03 +00:00
|
|
|
static void sig_print_text(void)
|
2000-05-15 08:25:45 +00:00
|
|
|
{
|
|
|
|
|
GSList *tmp;
|
|
|
|
|
time_t t;
|
|
|
|
|
struct tm *tm;
|
|
|
|
|
|
|
|
|
|
t = time(NULL);
|
|
|
|
|
tm = localtime(&t);
|
2000-06-10 18:56:03 +00:00
|
|
|
if (tm->tm_hour != 0 || tm->tm_min != 0)
|
|
|
|
|
return;
|
2000-05-15 08:25:45 +00:00
|
|
|
|
2000-06-10 18:56:03 +00:00
|
|
|
daycheck = 2;
|
|
|
|
|
signal_remove("print text", (SIGNAL_FUNC) sig_print_text);
|
2000-05-15 08:25:45 +00:00
|
|
|
|
|
|
|
|
/* day changed, print notice about it to every window */
|
2007-04-16 19:10:46 +00:00
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next)
|
|
|
|
|
window_print_daychange(tmp->data, tm);
|
2000-06-10 18:56:03 +00:00
|
|
|
}
|
2000-05-15 08:25:45 +00:00
|
|
|
|
2000-06-10 18:56:03 +00:00
|
|
|
static int sig_check_daychange(void)
|
|
|
|
|
{
|
|
|
|
|
time_t t;
|
|
|
|
|
struct tm *tm;
|
|
|
|
|
|
|
|
|
|
t = time(NULL);
|
|
|
|
|
tm = localtime(&t);
|
|
|
|
|
|
|
|
|
|
if (daycheck == 1 && tm->tm_hour == 0 && tm->tm_min == 0) {
|
|
|
|
|
sig_print_text();
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tm->tm_hour != 23 || tm->tm_min != 59) {
|
|
|
|
|
daycheck = 0;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* time is 23:59 */
|
|
|
|
|
if (daycheck == 0) {
|
|
|
|
|
daycheck = 1;
|
|
|
|
|
signal_add("print text", (SIGNAL_FUNC) sig_print_text);
|
|
|
|
|
}
|
2000-05-15 08:25:45 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-10 18:56:03 +00:00
|
|
|
static void read_settings(void)
|
|
|
|
|
{
|
|
|
|
|
if (daytag != -1) {
|
|
|
|
|
g_source_remove(daytag);
|
|
|
|
|
daytag = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (settings_get_bool("timestamps"))
|
|
|
|
|
daytag = g_timeout_add(30000, (GSourceFunc) sig_check_daychange, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
void windows_init(void)
|
|
|
|
|
{
|
|
|
|
|
active_win = NULL;
|
2000-06-10 18:56:03 +00:00
|
|
|
daycheck = 0; daytag = -1;
|
2000-04-26 08:03:38 +00:00
|
|
|
settings_add_bool("lookandfeel", "window_auto_change", FALSE);
|
2001-01-01 18:32:48 +00:00
|
|
|
settings_add_bool("lookandfeel", "windows_auto_renumber", TRUE);
|
2002-02-15 14:54:00 +00:00
|
|
|
settings_add_bool("lookandfeel", "window_check_level_first", FALSE);
|
2002-12-28 17:54:13 +00:00
|
|
|
settings_add_level("lookandfeel", "window_default_level", "NONE");
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2000-06-10 18:56:03 +00:00
|
|
|
read_settings();
|
2002-09-14 23:14:04 +00:00
|
|
|
signal_add("server looking", (SIGNAL_FUNC) sig_server_connected);
|
2002-06-04 21:18:32 +00:00
|
|
|
signal_add("server connected", (SIGNAL_FUNC) sig_server_connected);
|
2000-04-26 08:03:38 +00:00
|
|
|
signal_add("server disconnected", (SIGNAL_FUNC) sig_server_disconnected);
|
|
|
|
|
signal_add("server connect failed", (SIGNAL_FUNC) sig_server_disconnected);
|
2000-06-10 18:56:03 +00:00
|
|
|
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void windows_deinit(void)
|
|
|
|
|
{
|
2000-06-10 18:56:03 +00:00
|
|
|
if (daytag != -1) g_source_remove(daytag);
|
|
|
|
|
if (daycheck == 1) signal_remove("print text", (SIGNAL_FUNC) sig_print_text);
|
2000-05-15 08:25:45 +00:00
|
|
|
|
2002-09-14 23:14:04 +00:00
|
|
|
signal_remove("server looking", (SIGNAL_FUNC) sig_server_connected);
|
2002-06-04 21:18:32 +00:00
|
|
|
signal_remove("server connected", (SIGNAL_FUNC) sig_server_connected);
|
2000-04-26 08:03:38 +00:00
|
|
|
signal_remove("server disconnected", (SIGNAL_FUNC) sig_server_disconnected);
|
|
|
|
|
signal_remove("server connect failed", (SIGNAL_FUNC) sig_server_disconnected);
|
2000-06-10 18:56:03 +00:00
|
|
|
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|