Apply clang-format to sidepanel related files

Formatted all sidepanel-related files according to irssi's .clang-format rules:
- src/fe-text/sidepanels.c (772 lines reformatted)
- src/fe-text/mainwindows.c (462 lines reformatted)
- src/fe-text/gui-readline.c (228 lines reformatted)
- src/fe-text/mainwindows-layout.c (83 lines reformatted)
- src/fe-text/irssi.c (37 lines reformatted)
- src/fe-text/mainwindows.h (29 lines reformatted)
- src/fe-text/module-formats.h (27 lines reformatted)

Key formatting changes applied:
- Indentation: spaces → tabs (IndentWidth: 8, UseTab: ForIndentation)
- Line breaking: ColumnLimit: 100, BreakBeforeBraces: Linux
- Alignment: AlignAfterOpenBracket: Align, AlignTrailingComments: true
- Spacing: proper spacing around operators and parentheses
- Pointer alignment: PointerAlignment: Right

Total: 905 insertions, 733 deletions across 7 files
Code functionality unchanged - purely cosmetic formatting
to match irssi project standards.

Timestamp: 2025-01-25 02:43
This commit is contained in:
kofany 2025-08-25 02:47:41 +02:00
commit 25f2b16544
7 changed files with 905 additions and 733 deletions

View file

@ -45,7 +45,8 @@
#define LINE_SPLIT_LIMIT 400 #define LINE_SPLIT_LIMIT 400
typedef void (*ENTRY_REDIRECT_KEY_FUNC)(int key, void *data, SERVER_REC *server, WI_ITEM_REC *item); typedef void (*ENTRY_REDIRECT_KEY_FUNC)(int key, void *data, SERVER_REC *server, WI_ITEM_REC *item);
typedef void (*ENTRY_REDIRECT_ENTRY_FUNC) (const char *line, void *data, SERVER_REC *server, WI_ITEM_REC *item); typedef void (*ENTRY_REDIRECT_ENTRY_FUNC)(const char *line, void *data, SERVER_REC *server,
WI_ITEM_REC *item);
typedef struct { typedef struct {
SIGNAL_FUNC func; SIGNAL_FUNC func;
@ -146,8 +147,7 @@ static void handle_entry_redirect(const char *line)
gui_entry_set_prompt(active_entry, ""); gui_entry_set_prompt(active_entry, "");
if (func != NULL) { if (func != NULL) {
func(line, data, active_win->active_server, func(line, data, active_win->active_server, active_win->active);
active_win->active);
} }
} }
@ -236,7 +236,8 @@ static void paste_buffer_join_lines(GArray *buf)
return; return;
/* now, enforce these to all subsequent lines */ /* now, enforce these to all subsequent lines */
count = indent; last_lf = TRUE; count = indent;
last_lf = TRUE;
for (; i < buf->len; i++) { for (; i < buf->len; i++) {
if (last_lf) { if (last_lf) {
if (isblank(arr[i])) if (isblank(arr[i]))
@ -254,13 +255,15 @@ static void paste_buffer_join_lines(GArray *buf)
/* all looks fine - now remove the whitespace, but don't let lines /* all looks fine - now remove the whitespace, but don't let lines
get longer than LINE_SPLIT_LIMIT chars */ get longer than LINE_SPLIT_LIMIT chars */
dest = arr; last_lf = TRUE; last_lf_pos = NULL; line_len = 0; dest = arr;
last_lf = TRUE;
last_lf_pos = NULL;
line_len = 0;
for (i = 0; i < buf->len; i++) { for (i = 0; i < buf->len; i++) {
if (last_lf && isblank(arr[i])) { if (last_lf && isblank(arr[i])) {
/* whitespace, ignore */ /* whitespace, ignore */
} else if (isnewline(arr[i])) { } else if (isnewline(arr[i])) {
if (!last_lf && i+1 != buf->len && if (!last_lf && i + 1 != buf->len && isblank(arr[i + 1])) {
isblank(arr[i+1])) {
last_lf_pos = dest; last_lf_pos = dest;
if (i != 0 && !isblank(arr[i - 1])) if (i != 0 && !isblank(arr[i - 1]))
*dest++ = ' '; *dest++ = ' ';
@ -275,7 +278,8 @@ static void paste_buffer_join_lines(GArray *buf)
if (++line_len >= LINE_SPLIT_LIMIT && last_lf_pos != NULL) { if (++line_len >= LINE_SPLIT_LIMIT && last_lf_pos != NULL) {
memmove(last_lf_pos + 1, last_lf_pos, memmove(last_lf_pos + 1, last_lf_pos,
(dest - last_lf_pos) * sizeof(unichar)); (dest - last_lf_pos) * sizeof(unichar));
*last_lf_pos = '\n'; last_lf_pos = NULL; *last_lf_pos = '\n';
last_lf_pos = NULL;
line_len = 0; line_len = 0;
dest++; dest++;
} }
@ -370,9 +374,9 @@ static void paste_flush(void (*send)(void))
g_array_set_size(paste_buffer_rest, 0); g_array_set_size(paste_buffer_rest, 0);
} }
gui_entry_set_prompt(active_entry, gui_entry_set_prompt(active_entry, paste_old_prompt == NULL ? "" : paste_old_prompt);
paste_old_prompt == NULL ? "" : paste_old_prompt); g_free(paste_old_prompt);
g_free(paste_old_prompt); paste_old_prompt = NULL; paste_old_prompt = NULL;
paste_prompt = FALSE; paste_prompt = FALSE;
paste_line_count = 0; paste_line_count = 0;
@ -514,21 +518,17 @@ static void insert_paste_prompt(void)
number of lines obtained from this. The number isn't entirely accurate; number of lines obtained from this. The number isn't entirely accurate;
we just choose the greater of the two since the exact value isn't we just choose the greater of the two since the exact value isn't
important */ important */
if (split_lines > paste_verify_line_count && if (split_lines > paste_verify_line_count && split_lines > paste_line_count) {
split_lines > paste_line_count) {
actual_line_count = split_lines; actual_line_count = split_lines;
} }
paste_prompt = TRUE; paste_prompt = TRUE;
paste_old_prompt = g_strdup(active_entry->prompt); paste_old_prompt = g_strdup(active_entry->prompt);
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_PASTE_WARNING, actual_line_count,
TXT_PASTE_WARNING,
actual_line_count,
active_win->active == NULL ? "window" : active_win->active == NULL ? "window" :
active_win->active->visible_name); active_win->active->visible_name);
str = format_get_text(MODULE_NAME, active_win, NULL, NULL, str = format_get_text(MODULE_NAME, active_win, NULL, NULL, TXT_PASTE_PROMPT, 0, 0);
TXT_PASTE_PROMPT, 0, 0);
gui_entry_set_prompt(active_entry, str); gui_entry_set_prompt(active_entry, str);
paste_entry = gui_entry_get_text(active_entry); paste_entry = gui_entry_get_text(active_entry);
paste_entry_pos = gui_entry_get_pos(active_entry); paste_entry_pos = gui_entry_get_pos(active_entry);
@ -640,9 +640,7 @@ static void key_send_line(void)
} }
if (redir == NULL) { if (redir == NULL) {
signal_emit("send command", 3, str, signal_emit("send command", 3, str, active_win->active_server, active_win->active);
active_win->active_server,
active_win->active);
} else { } else {
handle_entry_redirect(str); handle_entry_redirect(str);
} }
@ -654,9 +652,7 @@ static void key_send_line(void)
g_free(str); g_free(str);
} }
static void key_combo(void) static void key_combo(void) {}
{
}
static void key_backward_history(void) static void key_backward_history(void)
{ {
@ -801,7 +797,8 @@ static void key_yank_next_cutbuffer(void)
return; return;
rec = active_entry->kill_ring->data; rec = active_entry->kill_ring->data;
if (rec != NULL) length = rec->cutbuffer_len; if (rec != NULL)
length = rec->cutbuffer_len;
cutbuffer = gui_entry_get_next_cutbuffer(active_entry); cutbuffer = gui_entry_get_next_cutbuffer(active_entry);
if (cutbuffer != NULL) { if (cutbuffer != NULL) {
@ -957,12 +954,10 @@ static void paste_bracketed_middle(void)
for (i = 0; i <= len; i++, ptr++) { for (i = 0; i <= len; i++, ptr++) {
if (ptr[0] == bp_end[0] && memcmp(ptr, bp_end, sizeof(bp_end)) == 0) { if (ptr[0] == bp_end[0] && memcmp(ptr, bp_end, sizeof(bp_end)) == 0) {
/* if there are at least 6 bytes after the end, /* if there are at least 6 bytes after the end,
* check for another start marker right afterwards */ * check for another start marker right afterwards */
if (i <= (len - marklen) && if (i <= (len - marklen) &&
memcmp(ptr + marklen, bp_start, sizeof(bp_start)) == 0) { memcmp(ptr + marklen, bp_start, sizeof(bp_start)) == 0) {
/* remove both markers*/ /* remove both markers*/
g_array_remove_range(paste_buffer, i, marklen * 2); g_array_remove_range(paste_buffer, i, marklen * 2);
len -= marklen * 2; len -= marklen * 2;
@ -1005,7 +1000,8 @@ static void sig_input(void)
if (paste_bracketed_mode) { if (paste_bracketed_mode) {
paste_bracketed_middle(); paste_bracketed_middle();
} else if (!paste_use_bracketed_mode && paste_detect_time > 0 && paste_buffer->len >= 3) { } else if (!paste_use_bracketed_mode && paste_detect_time > 0 &&
paste_buffer->len >= 3) {
if (paste_timeout_id != -1) if (paste_timeout_id != -1)
g_source_remove(paste_timeout_id); g_source_remove(paste_timeout_id);
paste_timeout_id = g_timeout_add(paste_detect_time, paste_timeout, NULL); paste_timeout_id = g_timeout_add(paste_detect_time, paste_timeout, NULL);
@ -1017,7 +1013,8 @@ static void sig_input(void)
signal_emit("gui key pressed", 1, GINT_TO_POINTER(key)); signal_emit("gui key pressed", 1, GINT_TO_POINTER(key));
if (paste_bracketed_mode) { if (paste_bracketed_mode) {
/* just enabled by the signal, remove what was processed so far */ /* just enabled by the signal, remove what was processed so
* far */
g_array_remove_range(paste_buffer, 0, i + 1); g_array_remove_range(paste_buffer, 0, i + 1);
/* handle single-line / small pastes here */ /* handle single-line / small pastes here */
@ -1093,12 +1090,14 @@ static void key_scroll_forward(void)
static void key_scroll_start(void) static void key_scroll_start(void)
{ {
signal_emit("command scrollback home", 3, NULL, active_win->active_server, active_win->active); signal_emit("command scrollback home", 3, NULL, active_win->active_server,
active_win->active);
} }
static void key_scroll_end(void) static void key_scroll_end(void)
{ {
signal_emit("command scrollback end", 3, NULL, active_win->active_server, active_win->active); signal_emit("command scrollback end", 3, NULL, active_win->active_server,
active_win->active);
} }
static void key_change_window(const char *data) static void key_change_window(const char *data)
@ -1153,7 +1152,8 @@ static void key_check_replaces(void)
static void key_previous_window(void) static void key_previous_window(void)
{ {
signal_emit("command window previous", 3, "", active_win->active_server, active_win->active); signal_emit("command window previous", 3, "", active_win->active_server,
active_win->active);
} }
static void key_next_window(void) static void key_next_window(void)
@ -1183,7 +1183,8 @@ static void key_lower_window(void)
static void key_active_window(void) static void key_active_window(void)
{ {
signal_emit("command window goto", 3, "active", active_win->active_server, active_win->active); signal_emit("command window goto", 3, "active", active_win->active_server,
active_win->active);
} }
static SERVER_REC *get_prev_server(SERVER_REC *current) static SERVER_REC *get_prev_server(SERVER_REC *current)
@ -1192,8 +1193,8 @@ static SERVER_REC *get_prev_server(SERVER_REC *current)
if (current == NULL) { if (current == NULL) {
return servers != NULL ? g_slist_last(servers)->data : return servers != NULL ? g_slist_last(servers)->data :
lookup_servers != NULL ? lookup_servers != NULL ? g_slist_last(lookup_servers)->data :
g_slist_last(lookup_servers)->data : NULL; NULL;
} }
/* connect2 -> connect1 -> server2 -> server1 -> connect2 -> .. */ /* connect2 -> connect1 -> server2 -> server1 -> connect2 -> .. */
@ -1223,7 +1224,8 @@ static SERVER_REC *get_next_server(SERVER_REC *current)
if (current == NULL) { if (current == NULL) {
return servers != NULL ? servers->data : return servers != NULL ? servers->data :
lookup_servers != NULL ? lookup_servers->data : NULL; lookup_servers != NULL ? lookup_servers->data :
NULL;
} }
/* server1 -> server2 -> connect1 -> connect2 -> server1 -> .. */ /* server1 -> server2 -> connect1 -> connect2 -> server1 -> .. */
@ -1252,16 +1254,16 @@ static void key_previous_window_item(void)
SERVER_REC *server; SERVER_REC *server;
if (active_win->items != NULL) { if (active_win->items != NULL) {
signal_emit("command window item prev", 3, "", signal_emit("command window item prev", 3, "", active_win->active_server,
active_win->active_server, active_win->active); active_win->active);
} else if (servers != NULL || lookup_servers != NULL) { } else if (servers != NULL || lookup_servers != NULL) {
/* change server */ /* change server */
server = active_win->active_server; server = active_win->active_server;
if (server == NULL) if (server == NULL)
server = active_win->connect_server; server = active_win->connect_server;
server = get_prev_server(server); server = get_prev_server(server);
signal_emit("command window server", 3, server->tag, signal_emit("command window server", 3, server->tag, active_win->active_server,
active_win->active_server, active_win->active); active_win->active);
} }
} }
@ -1270,16 +1272,16 @@ static void key_next_window_item(void)
SERVER_REC *server; SERVER_REC *server;
if (active_win->items != NULL) { if (active_win->items != NULL) {
signal_emit("command window item next", 3, "", signal_emit("command window item next", 3, "", active_win->active_server,
active_win->active_server, active_win->active); active_win->active);
} else if (servers != NULL || lookup_servers != NULL) { } else if (servers != NULL || lookup_servers != NULL) {
/* change server */ /* change server */
server = active_win->active_server; server = active_win->active_server;
if (server == NULL) if (server == NULL)
server = active_win->connect_server; server = active_win->connect_server;
server = get_next_server(server); server = get_next_server(server);
signal_emit("command window server", 3, server->tag, signal_emit("command window server", 3, server->tag, active_win->active_server,
active_win->active_server, active_win->active); active_win->active);
} }
} }
@ -1292,8 +1294,8 @@ static void key_insert_text(const char *data)
{ {
char *str; char *str;
str = parse_special_string(data, active_win->active_server, str =
active_win->active, "", NULL, 0); parse_special_string(data, active_win->active_server, active_win->active, "", NULL, 0);
gui_entry_insert_text(active_entry, str); gui_entry_insert_text(active_entry, str);
g_free(str); g_free(str);
} }
@ -1316,8 +1318,7 @@ static void sig_window_auto_changed(void)
g_free(text); g_free(text);
} }
static void sig_gui_entry_redirect(SIGNAL_FUNC func, const char *entry, static void sig_gui_entry_redirect(SIGNAL_FUNC func, const char *entry, void *flags, void *data)
void *flags, void *data)
{ {
redir = g_new0(ENTRY_REDIRECT_REC, 1); redir = g_new0(ENTRY_REDIRECT_REC, 1);
redir->func = func; redir->func = func;
@ -1531,7 +1532,8 @@ void gui_readline_init(void)
for (n = 0; changekeys[n] != '\0'; n++) { for (n = 0; changekeys[n] != '\0'; n++) {
key = g_strdup_printf("meta-%c", changekeys[n]); key = g_strdup_printf("meta-%c", changekeys[n]);
ltoa(data, n + 1); ltoa(data, n + 1);
key_bind("change_window", "Change window", key, data, (SIGNAL_FUNC) key_change_window); key_bind("change_window", "Change window", key, data,
(SIGNAL_FUNC) key_change_window);
g_free(key); g_free(key);
} }

View file

@ -76,7 +76,6 @@ int quitting;
static int display_firsttimer = FALSE; static int display_firsttimer = FALSE;
static unsigned int user_settings_changed = 0; static unsigned int user_settings_changed = 0;
static void sig_exit(void) static void sig_exit(void)
{ {
quitting = TRUE; quitting = TRUE;
@ -285,10 +284,9 @@ static void check_files(void)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
static int version = 0; static int version = 0;
static GOptionEntry options[] = { static GOptionEntry options[] = { { "version", 'v', 0, G_OPTION_ARG_NONE, &version,
{ "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Display Irssi version", NULL }, "Display Irssi version", NULL },
{ NULL } { NULL } };
};
int loglev; int loglev;
core_register_options(); core_register_options();
@ -297,8 +295,8 @@ int main(int argc, char **argv)
args_execute(argc, argv); args_execute(argc, argv);
if (version) { if (version) {
printf(PACKAGE_TARNAME" " PACKAGE_VERSION" (%d %04d)\n", printf(PACKAGE_TARNAME " " PACKAGE_VERSION " (%d %04d)\n", IRSSI_VERSION_DATE,
IRSSI_VERSION_DATE, IRSSI_VERSION_TIME); IRSSI_VERSION_TIME);
return 0; return 0;
} }
@ -347,8 +345,7 @@ int main(int argc, char **argv)
if (settings_get_bool("quit_on_hup")) { if (settings_get_bool("quit_on_hup")) {
signal_emit("gui exit", 0); signal_emit("gui exit", 0);
} } else {
else {
signal_emit("command reload", 1, ""); signal_emit("command reload", 1, "");
} }
} }

View file

@ -69,7 +69,8 @@ static void sig_layout_window_restore(WINDOW_REC *window, CONFIG_NODE *node)
if (config_node_get_bool(node, "sticky", FALSE)) if (config_node_get_bool(node, "sticky", FALSE))
gui_window_set_sticky(window); gui_window_set_sticky(window);
textbuffer_view_set_hidden_level(gui->view, level2bits(config_node_get_str(node, "hidelevel", default_hidelevel), NULL)); textbuffer_view_set_hidden_level(
gui->view, level2bits(config_node_get_str(node, "hidelevel", default_hidelevel), NULL));
if (config_node_get_str(node, "scroll", NULL) != NULL) { if (config_node_get_str(node, "scroll", NULL) != NULL) {
gui->use_scroll = TRUE; gui->use_scroll = TRUE;
@ -104,15 +105,13 @@ static void sig_layout_save(void)
static int window_node_cmp(CONFIG_NODE *n1, CONFIG_NODE *n2) static int window_node_cmp(CONFIG_NODE *n1, CONFIG_NODE *n2)
{ {
return (config_node_get_int(n1, "first_line", 0) == return (config_node_get_int(n1, "first_line", 0) ==
config_node_get_int(n2, "first_line", 0) config_node_get_int(n2, "first_line", 0) &&
&&
config_node_get_int(n1, "first_column", 0) > config_node_get_int(n1, "first_column", 0) >
config_node_get_int(n2, "first_column", 0) config_node_get_int(n2, "first_column", 0)) ||
) ||
config_node_get_int(n1, "first_line", 0) > config_node_get_int(n1, "first_line", 0) >
config_node_get_int(n2, "first_line", 0) config_node_get_int(n2, "first_line", 0) ?
? -1 -1 :
: 1; 1;
} }
/* Returns list of mainwindow nodes sorted by first_line /* Returns list of mainwindow nodes sorted by first_line
@ -124,8 +123,7 @@ static GSList *get_sorted_windows_config(CONFIG_NODE *node)
output = NULL; output = NULL;
tmp = config_node_first(node->value); tmp = config_node_first(node->value);
for (; tmp != NULL; tmp = config_node_next(tmp)) { for (; tmp != NULL; tmp = config_node_next(tmp)) {
output = g_slist_insert_sorted(output, tmp->data, output = g_slist_insert_sorted(output, tmp->data, (GCompareFunc) window_node_cmp);
(GCompareFunc) window_node_cmp);
} }
return output; return output;
@ -172,17 +170,18 @@ static void sig_layout_restore(void)
int i, lower_size, lines_count, columns_count, diff; int i, lower_size, lines_count, columns_count, diff;
node = iconfig_node_traverse("mainwindows", FALSE); node = iconfig_node_traverse("mainwindows", FALSE);
if (node == NULL) return; if (node == NULL)
return;
sorted_config = get_sorted_windows_config(node); sorted_config = get_sorted_windows_config(node);
if (sorted_config == NULL) return; if (sorted_config == NULL)
return;
lines_config = get_windows_config_filter_line(sorted_config); lines_config = get_windows_config_filter_line(sorted_config);
lines_count = g_slist_length(lines_config); lines_count = g_slist_length(lines_config);
/* calculate the saved terminal height */ /* calculate the saved terminal height */
avail_height = term_height - avail_height = term_height - screen_reserved_top - screen_reserved_bottom;
screen_reserved_top - screen_reserved_bottom;
height = 0; height = 0;
heights = g_new0(int, lines_count); heights = g_new0(int, lines_count);
for (i = 0, tmp = lines_config; tmp != NULL; tmp = tmp->next, i++) { for (i = 0, tmp = lines_config; tmp != NULL; tmp = tmp->next, i++) {
@ -237,28 +236,35 @@ static void sig_layout_restore(void)
} }
/* create all the visible windows with correct size */ /* create all the visible windows with correct size */
lower_window = NULL; lower_size = 0; first = NULL; lower_window = NULL;
lower_size = 0;
first = NULL;
for (i = 0, tmp = lines_config; i < lines_count; tmp = tmp->next, i++) { for (i = 0, tmp = lines_config; i < lines_count; tmp = tmp->next, i++) {
GSList *tmp2, *columns_config, *line; GSList *tmp2, *columns_config, *line;
int j, l1, l2; int j, l1, l2;
CONFIG_NODE *node = tmp->data; CONFIG_NODE *node = tmp->data;
if (node->key == NULL) continue; if (node->key == NULL)
continue;
l1 = config_node_get_int(node, "first_line", -1); l1 = config_node_get_int(node, "first_line", -1);
l2 = l1 + config_node_get_int(node, "lines", 0) - 1; l2 = l1 + config_node_get_int(node, "lines", 0) - 1;
columns_config = get_windows_config_filter_column(sorted_config, l1, l2); columns_config = get_windows_config_filter_column(sorted_config, l1, l2);
window = NULL; columns_count = 0; window = NULL;
columns_count = 0;
widths = g_new0(int, max_wins_line); widths = g_new0(int, max_wins_line);
for (j = 0, tmp2 = columns_config; j < max_wins_line && tmp2 != NULL; tmp2 = tmp2->next, j++) { for (j = 0, tmp2 = columns_config; j < max_wins_line && tmp2 != NULL;
tmp2 = tmp2->next, j++) {
int width; int width;
WINDOW_REC *new_win; WINDOW_REC *new_win;
CONFIG_NODE *node2 = tmp2->data; CONFIG_NODE *node2 = tmp2->data;
if (node2->key == NULL) continue; if (node2->key == NULL)
continue;
/* create a new window + mainwindow */ /* create a new window + mainwindow */
signal_emit("gui window create override", 1, signal_emit("gui window create override", 1,
GINT_TO_POINTER(window == NULL ? MAIN_WINDOW_TYPE_SPLIT : MAIN_WINDOW_TYPE_RSPLIT)); GINT_TO_POINTER(window == NULL ? MAIN_WINDOW_TYPE_SPLIT :
MAIN_WINDOW_TYPE_RSPLIT));
new_win = window_create(NULL, TRUE); new_win = window_create(NULL, TRUE);
@ -279,7 +285,8 @@ static void sig_layout_restore(void)
continue; continue;
line = g_slist_reverse(mainwindows_get_line(WINDOW_MAIN(window))); line = g_slist_reverse(mainwindows_get_line(WINDOW_MAIN(window)));
for (j = g_slist_length(line), tmp2 = line; tmp2 != NULL; tmp2 = tmp2->next, j--) { for (j = g_slist_length(line), tmp2 = line; tmp2 != NULL; tmp2 = tmp2->next, j--) {
int width = MAX(NEW_WINDOW_WIDTH, widths[j-1] * term_width / columns_count); int width =
MAX(NEW_WINDOW_WIDTH, widths[j - 1] * term_width / columns_count);
MAIN_WINDOW_REC *rec = tmp2->data; MAIN_WINDOW_REC *rec = tmp2->data;
mainwindow_set_rsize(rec, width); mainwindow_set_rsize(rec, width);
} }

View file

@ -54,14 +54,14 @@ static int screen_collapsed = 0; /* see mainwindows_resize */
(window)->width - (window)->statusbar_columns, \ (window)->width - (window)->statusbar_columns, \
(window)->height - (window)->statusbar_lines); (window)->height - (window)->statusbar_lines);
static MAIN_WINDOW_REC *find_window_with_room() static MAIN_WINDOW_REC *find_window_with_room()
{ {
MAIN_WINDOW_REC *biggest_rec; MAIN_WINDOW_REC *biggest_rec;
GSList *tmp; GSList *tmp;
int space, biggest; int space, biggest;
biggest = 0; biggest_rec = NULL; biggest = 0;
biggest_rec = NULL;
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) { for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
MAIN_WINDOW_REC *rec = tmp->data; MAIN_WINDOW_REC *rec = tmp->data;
@ -81,7 +81,8 @@ static MAIN_WINDOW_REC *find_window_with_room_right(void)
GSList *tmp; GSList *tmp;
int space, biggest; int space, biggest;
biggest = 0; biggest_rec = NULL; biggest = 0;
biggest_rec = NULL;
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) { for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
MAIN_WINDOW_REC *rec = tmp->data; MAIN_WINDOW_REC *rec = tmp->data;
@ -110,8 +111,10 @@ static void mainwindow_resize_windows(MAIN_WINDOW_REC *window)
int sy = window->first_line + window->statusbar_lines_top; int sy = window->first_line + window->statusbar_lines_top;
int sw = window->width - window->statusbar_columns; int sw = window->width - window->statusbar_columns;
int sh = window->height - window->statusbar_lines; int sh = window->height - window->statusbar_lines;
if (sw < 1) sw = 1; if (sw < 1)
if (sh < 1) sh = 1; sw = 1;
if (sh < 1)
sh = 1;
term_window_move(window->screen_win, sx, sy, sw, sh); term_window_move(window->screen_win, sx, sy, sw, sh);
} }
@ -119,14 +122,15 @@ static void mainwindow_resize_windows(MAIN_WINDOW_REC *window)
for (tmp = windows; tmp != NULL; tmp = tmp->next) { for (tmp = windows; tmp != NULL; tmp = tmp->next) {
WINDOW_REC *rec = tmp->data; WINDOW_REC *rec = tmp->data;
if (rec->gui_data != NULL && if (rec->gui_data != NULL && WINDOW_GUI(rec)->parent == window &&
WINDOW_GUI(rec)->parent == window &&
!window_size_equals(rec, window)) { !window_size_equals(rec, window)) {
{ {
int tw = MAIN_WINDOW_TEXT_WIDTH(window); int tw = MAIN_WINDOW_TEXT_WIDTH(window);
int th = MAIN_WINDOW_TEXT_HEIGHT(window); int th = MAIN_WINDOW_TEXT_HEIGHT(window);
if (tw < 1) tw = 1; if (tw < 1)
if (th < 1) th = 1; tw = 1;
if (th < 1)
th = 1;
resized = TRUE; resized = TRUE;
gui_window_resize(rec, tw, th); gui_window_resize(rec, tw, th);
} }
@ -148,8 +152,8 @@ static void mainwindow_resize(MAIN_WINDOW_REC *window, int xdiff, int ydiff)
window->width = window->last_column - window->first_column + 1; window->width = window->last_column - window->first_column + 1;
window->height = window->last_line - window->first_line + 1; window->height = window->last_line - window->first_line + 1;
if (height != window->height || width != window->width) { if (height != window->height || width != window->width) {
g_warning("Resizing window %p W:%d expected:%d H:%d expected:%d", g_warning("Resizing window %p W:%d expected:%d H:%d expected:%d", window,
window, window->width, width, window->height, height); window->width, width, window->height, height);
} }
window->size_dirty = TRUE; window->size_dirty = TRUE;
} }
@ -163,16 +167,14 @@ static GSList *get_sticky_windows_sorted(MAIN_WINDOW_REC *mainwin)
WINDOW_REC *rec = tmp->data; WINDOW_REC *rec = tmp->data;
if (WINDOW_GUI(rec)->sticky && WINDOW_MAIN(rec) == mainwin) { if (WINDOW_GUI(rec)->sticky && WINDOW_MAIN(rec) == mainwin) {
list = g_slist_insert_sorted(list, rec, (GCompareFunc) list = g_slist_insert_sorted(list, rec, (GCompareFunc) window_refnum_cmp);
window_refnum_cmp);
} }
} }
return list; return list;
} }
void mainwindow_change_active(MAIN_WINDOW_REC *mainwin, void mainwindow_change_active(MAIN_WINDOW_REC *mainwin, WINDOW_REC *skip_window)
WINDOW_REC *skip_window)
{ {
WINDOW_REC *window, *other; WINDOW_REC *window, *other;
GSList *tmp; GSList *tmp;
@ -183,8 +185,7 @@ void mainwindow_change_active(MAIN_WINDOW_REC *mainwin,
tmp = get_sticky_windows_sorted(mainwin); tmp = get_sticky_windows_sorted(mainwin);
window = tmp->data; window = tmp->data;
if (window == skip_window) { if (window == skip_window) {
window = tmp->next == NULL ? NULL : window = tmp->next == NULL ? NULL : tmp->next->data;
tmp->next->data;
} }
g_slist_free(tmp); g_slist_free(tmp);
@ -218,8 +219,7 @@ void mainwindows_recreate(void)
rec->screen_win = mainwindow_create_screen(rec); rec->screen_win = mainwindow_create_screen(rec);
rec->dirty = TRUE; rec->dirty = TRUE;
textbuffer_view_set_window(WINDOW_GUI(rec->active)->view, textbuffer_view_set_window(WINDOW_GUI(rec->active)->view, rec->screen_win);
rec->screen_win);
} }
} }
@ -245,8 +245,7 @@ MAIN_WINDOW_REC *mainwindow_create(int right)
if (!right) { if (!right) {
GSList *tmp, *line; GSList *tmp, *line;
if (MAIN_WINDOW_TEXT_HEIGHT(parent) < if (MAIN_WINDOW_TEXT_HEIGHT(parent) < WINDOW_MIN_SIZE + NEW_WINDOW_SIZE)
WINDOW_MIN_SIZE+NEW_WINDOW_SIZE)
parent = find_window_with_room(); parent = find_window_with_room();
if (parent == NULL) { if (parent == NULL) {
g_free(rec); g_free(rec);
@ -347,8 +346,7 @@ static MAIN_WINDOW_REC *mainwindows_find_right(MAIN_WINDOW_REC *window, int find
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) { for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
MAIN_WINDOW_REC *rec = tmp->data; MAIN_WINDOW_REC *rec = tmp->data;
if (rec->first_line >= first_line && if (rec->first_line >= first_line && rec->last_line <= last_line &&
rec->last_line <= last_line &&
rec->first_column > last_column && rec->first_column > last_column &&
(best == NULL || rec->first_column < best->first_column)) (best == NULL || rec->first_column < best->first_column))
best = rec; best = rec;
@ -413,8 +411,7 @@ static MAIN_WINDOW_REC *mainwindows_find_left(MAIN_WINDOW_REC *window, int find_
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) { for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
MAIN_WINDOW_REC *rec = tmp->data; MAIN_WINDOW_REC *rec = tmp->data;
if (rec->first_line >= first_line && if (rec->first_line >= first_line && rec->last_line <= last_line &&
rec->last_line <= last_line &&
rec->last_column < first_column && rec->last_column < first_column &&
(best == NULL || rec->last_column > best->last_column)) (best == NULL || rec->last_column > best->last_column))
best = rec; best = rec;
@ -452,8 +449,7 @@ GSList *mainwindows_get_line(MAIN_WINDOW_REC *rec)
list = NULL; list = NULL;
for (win = mainwindows_find_left(rec, FALSE); for (win = mainwindows_find_left(rec, FALSE); win != NULL;
win != NULL;
win = mainwindows_find_left(win, FALSE)) { win = mainwindows_find_left(win, FALSE)) {
list = g_slist_append(list, win); list = g_slist_append(list, win);
} }
@ -461,8 +457,7 @@ GSList *mainwindows_get_line(MAIN_WINDOW_REC *rec)
if (rec != NULL) if (rec != NULL)
list = g_slist_append(list, rec); list = g_slist_append(list, rec);
for (win = mainwindows_find_right(rec, FALSE); for (win = mainwindows_find_right(rec, FALSE); win != NULL;
win != NULL;
win = mainwindows_find_right(win, FALSE)) { win = mainwindows_find_right(win, FALSE)) {
list = g_slist_append(list, win); list = g_slist_append(list, win);
} }
@ -563,7 +558,8 @@ static void mainwindow_destroy_full(MAIN_WINDOW_REC *window, int respace)
g_free(window); g_free(window);
if (active_mainwin == window) active_mainwin = NULL; if (active_mainwin == window)
active_mainwin = NULL;
} }
void mainwindow_destroy(MAIN_WINDOW_REC *window) void mainwindow_destroy(MAIN_WINDOW_REC *window)
@ -590,20 +586,20 @@ void mainwindows_redraw(void)
static int mainwindows_compare(MAIN_WINDOW_REC *w1, MAIN_WINDOW_REC *w2) static int mainwindows_compare(MAIN_WINDOW_REC *w1, MAIN_WINDOW_REC *w2)
{ {
return w1->first_line < w2->first_line ? -1 return w1->first_line < w2->first_line ? -1 :
: w1->first_line > w2->first_line ? 1 w1->first_line > w2->first_line ? 1 :
: w1->first_column < w2->first_column ? -1 w1->first_column < w2->first_column ? -1 :
: w1->first_column > w2->first_column ? 1 w1->first_column > w2->first_column ? 1 :
: 0; 0;
} }
static int mainwindows_compare_reverse(MAIN_WINDOW_REC *w1, MAIN_WINDOW_REC *w2) static int mainwindows_compare_reverse(MAIN_WINDOW_REC *w1, MAIN_WINDOW_REC *w2)
{ {
return w1->first_line < w2->first_line ? 1 return w1->first_line < w2->first_line ? 1 :
: w1->first_line > w2->first_line ? -1 w1->first_line > w2->first_line ? -1 :
: w1->first_column < w2->first_column ? 1 w1->first_column < w2->first_column ? 1 :
: w1->first_column > w2->first_column ? -1 w1->first_column > w2->first_column ? -1 :
: 0; 0;
} }
GSList *mainwindows_get_sorted(int reverse) GSList *mainwindows_get_sorted(int reverse)
@ -612,8 +608,9 @@ GSList *mainwindows_get_sorted(int reverse)
list = NULL; list = NULL;
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) { for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
list = g_slist_insert_sorted(list, tmp->data, (GCompareFunc) list = g_slist_insert_sorted(
(reverse ? mainwindows_compare_reverse : mainwindows_compare)); list, tmp->data,
(GCompareFunc) (reverse ? mainwindows_compare_reverse : mainwindows_compare));
} }
return list; return list;
@ -626,9 +623,7 @@ static void mainwindows_resize_smaller(int ydiff)
int space; int space;
sorted = NULL; sorted = NULL;
for (rec = mainwindows_find_lower(NULL); for (rec = mainwindows_find_lower(NULL); rec != NULL; rec = mainwindows_find_lower(rec)) {
rec != NULL;
rec = mainwindows_find_lower(rec)) {
sorted = g_slist_prepend(sorted, rec); sorted = g_slist_prepend(sorted, rec);
} }
if (sorted == NULL) if (sorted == NULL)
@ -718,7 +713,8 @@ static void mainwindows_resize_smaller(int ydiff)
signal_emit("mainwindow moved", 1, win); signal_emit("mainwindow moved", 1, win);
} }
} else { } else {
if (space > -ydiff) space = -ydiff; if (space > -ydiff)
space = -ydiff;
for (ltmp = line; ltmp != NULL; ltmp = ltmp->next) { for (ltmp = line; ltmp != NULL; ltmp = ltmp->next) {
MAIN_WINDOW_REC *win = ltmp->data; MAIN_WINDOW_REC *win = ltmp->data;
win->last_line += ydiff; win->last_line += ydiff;
@ -747,12 +743,15 @@ static void mainwindows_rresize_line(int xdiff, MAIN_WINDOW_REC *win)
/* Available text width on this line should respect globally reserved columns */ /* Available text width on this line should respect globally reserved columns */
new_avail = screen_width - screen_reserved_left - screen_reserved_right - windows + 1; new_avail = screen_width - screen_reserved_left - screen_reserved_right - windows + 1;
old_avail = (screen_width - xdiff) - screen_reserved_left - screen_reserved_right - windows + 1; old_avail =
(screen_width - xdiff) - screen_reserved_left - screen_reserved_right - windows + 1;
extra_width = new_avail; extra_width = new_avail;
for (tmp = line, i = 0; tmp != NULL; tmp = tmp->next, i++) { for (tmp = line, i = 0; tmp != NULL; tmp = tmp->next, i++) {
MAIN_WINDOW_REC *rec = tmp->data; MAIN_WINDOW_REC *rec = tmp->data;
/* Scale each window proportionally based on available text widths (excluding reserved columns) */ /* Scale each window proportionally based on available text widths (excluding
widths[i] = old_avail > 0 ? (MAIN_WINDOW_TEXT_WIDTH(rec) * new_avail) / old_avail : MAIN_WINDOW_TEXT_WIDTH(rec); * reserved columns) */
widths[i] = old_avail > 0 ? (MAIN_WINDOW_TEXT_WIDTH(rec) * new_avail) / old_avail :
MAIN_WINDOW_TEXT_WIDTH(rec);
extra_width -= widths[i] + rec->statusbar_columns; extra_width -= widths[i] + rec->statusbar_columns;
} }
shrunk = FALSE; shrunk = FALSE;
@ -769,8 +768,11 @@ static void mainwindows_rresize_line(int xdiff, MAIN_WINDOW_REC *win)
/* Distribute any leftover width across windows; base modulo on available width */ /* Distribute any leftover width across windows; base modulo on available width */
width_mod = new_avail % windows; width_mod = new_avail % windows;
#define extra ( (i >= width_mod && i < extra_width + width_mod) \ #define extra \
|| i + windows < extra_width + width_mod ? 1 : 0 ) ((i >= width_mod && i < extra_width + width_mod) || \
i + windows < extra_width + width_mod ? \
1 : \
0)
for (tmp = line, i = 0; tmp != NULL; tmp = tmp->next, i++) { for (tmp = line, i = 0; tmp != NULL; tmp = tmp->next, i++) {
MAIN_WINDOW_REC *rec = tmp->data; MAIN_WINDOW_REC *rec = tmp->data;
@ -779,13 +781,16 @@ static void mainwindows_rresize_line(int xdiff, MAIN_WINDOW_REC *win)
if (is_last) { if (is_last) {
/* Anchor rightmost window to reserved-right boundary to avoid gap/lag */ /* Anchor rightmost window to reserved-right boundary to avoid gap/lag */
rec->last_column = screen_width - 1 - screen_reserved_right; rec->last_column = screen_width - 1 - screen_reserved_right;
mainwindow_resize(rec, (rec->last_column - rec->first_column + 1) - rec->width, 0); mainwindow_resize(
rec, (rec->last_column - rec->first_column + 1) - rec->width, 0);
} else { } else {
rec->last_column = rec->first_column + widths[i] + rec->statusbar_columns + extra - 1; rec->last_column =
rec->first_column + widths[i] + rec->statusbar_columns + extra - 1;
/* Ensure we never write past the globally reserved right columns */ /* Ensure we never write past the globally reserved right columns */
if (rec->last_column > screen_width - 1 - screen_reserved_right) if (rec->last_column > screen_width - 1 - screen_reserved_right)
rec->last_column = screen_width - 1 - screen_reserved_right; rec->last_column = screen_width - 1 - screen_reserved_right;
mainwindow_resize(rec, widths[i] + rec->statusbar_columns + extra - rec->width, 0); mainwindow_resize(
rec, widths[i] + rec->statusbar_columns + extra - rec->width, 0);
} }
rec->size_dirty = TRUE; rec->size_dirty = TRUE;
next_column = rec->last_column + 2; next_column = rec->last_column + 2;
@ -811,7 +816,8 @@ void mainwindows_resize(int width, int height)
int avail_h = screen_height - screen_reserved_top - screen_reserved_bottom; int avail_h = screen_height - screen_reserved_top - screen_reserved_bottom;
if (avail_w <= 1 || avail_h <= 1) { if (avail_w <= 1 || avail_h <= 1) {
GSList *tmp; GSList *tmp;
if (!screen_collapsed) screen_collapsed = 1; if (!screen_collapsed)
screen_collapsed = 1;
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) { for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
MAIN_WINDOW_REC *rec = tmp->data; MAIN_WINDOW_REC *rec = tmp->data;
rec->first_column = screen_reserved_left; rec->first_column = screen_reserved_left;
@ -830,7 +836,8 @@ void mainwindows_resize(int width, int height)
/* Recover from collapsed state: reflow horizontally. */ /* Recover from collapsed state: reflow horizontally. */
MAIN_WINDOW_REC *win; MAIN_WINDOW_REC *win;
screen_collapsed = 0; screen_collapsed = 0;
for (win = mainwindows_find_lower(NULL); win != NULL; win = mainwindows_find_lower(win)) { for (win = mainwindows_find_lower(NULL); win != NULL;
win = mainwindows_find_lower(win)) {
mainwindows_rresize_line(0, win); mainwindows_rresize_line(0, win);
} }
irssi_set_dirty(); irssi_set_dirty();
@ -854,8 +861,7 @@ void mainwindows_resize(int width, int height)
/* algorithm: distribute new space on each line */ /* algorithm: distribute new space on each line */
MAIN_WINDOW_REC *win; MAIN_WINDOW_REC *win;
for (win = mainwindows_find_lower(NULL); for (win = mainwindows_find_lower(NULL); win != NULL;
win != NULL;
win = mainwindows_find_lower(win)) { win = mainwindows_find_lower(win)) {
mainwindows_rresize_line(xdiff, win); mainwindows_rresize_line(xdiff, win);
} }
@ -866,15 +872,16 @@ void mainwindows_resize(int width, int height)
destroy windows on the right if no room */ destroy windows on the right if no room */
MAIN_WINDOW_REC *win; MAIN_WINDOW_REC *win;
for (win = mainwindows_find_lower(NULL); for (win = mainwindows_find_lower(NULL); win != NULL;
win != NULL;
win = mainwindows_find_lower(win)) { win = mainwindows_find_lower(win)) {
int max_windows, i, last_column; int max_windows, i, last_column;
GSList *line, *tmp; GSList *line, *tmp;
line = mainwindows_get_line(win); line = mainwindows_get_line(win);
/* Respect globally reserved columns when computing capacity */ /* Respect globally reserved columns when computing capacity */
max_windows = (screen_width - screen_reserved_left - screen_reserved_right + 1) / (NEW_WINDOW_WIDTH + 1); max_windows =
(screen_width - screen_reserved_left - screen_reserved_right + 1) /
(NEW_WINDOW_WIDTH + 1);
if (max_windows < 1) if (max_windows < 1)
max_windows = 1; max_windows = 1;
last_column = screen_width - 1 - screen_reserved_right; last_column = screen_width - 1 - screen_reserved_right;
@ -888,7 +895,8 @@ void mainwindows_resize(int width, int height)
win = line->data; win = line->data;
g_slist_free(line); g_slist_free(line);
mainwindows_rresize_line(screen_width - screen_reserved_right - last_column + 1, win); mainwindows_rresize_line(
screen_width - screen_reserved_right - last_column + 1, win);
} }
} }
@ -950,8 +958,7 @@ int mainwindows_reserve_lines(int top, int bottom)
return ret; return ret;
} }
int mainwindow_set_statusbar_lines(MAIN_WINDOW_REC *window, int mainwindow_set_statusbar_lines(MAIN_WINDOW_REC *window, int top, int bottom)
int top, int bottom)
{ {
int ret; int ret;
@ -974,8 +981,7 @@ int mainwindow_set_statusbar_lines(MAIN_WINDOW_REC *window,
return ret; return ret;
} }
static void mainwindows_resize_two(GSList *grow_list, static void mainwindows_resize_two(GSList *grow_list, GSList *shrink_list, int count)
GSList *shrink_list, int count)
{ {
GSList *tmp; GSList *tmp;
MAIN_WINDOW_REC *win; MAIN_WINDOW_REC *win;
@ -1083,8 +1089,7 @@ static int try_shrink_upper(MAIN_WINDOW_REC *window, int count)
return FALSE; return FALSE;
} }
static int mainwindow_grow(MAIN_WINDOW_REC *window, int count, static int mainwindow_grow(MAIN_WINDOW_REC *window, int count, int resize_lower)
int resize_lower)
{ {
if (!resize_lower || !try_shrink_lower(window, count)) { if (!resize_lower || !try_shrink_lower(window, count)) {
if (!try_shrink_upper(window, count)) { if (!try_shrink_upper(window, count)) {
@ -1165,8 +1170,8 @@ static int mainwindow_shrink(MAIN_WINDOW_REC *window, int count, int resize_lowe
return TRUE; return TRUE;
} }
static void mainwindows_rresize_two(MAIN_WINDOW_REC *grow_win, static void mainwindows_rresize_two(MAIN_WINDOW_REC *grow_win, MAIN_WINDOW_REC *shrink_win,
MAIN_WINDOW_REC *shrink_win, int count) int count)
{ {
irssi_set_dirty(); irssi_set_dirty();
@ -1338,13 +1343,12 @@ static void window_balance_vertical(void)
MAIN_WINDOW_REC *win; MAIN_WINDOW_REC *win;
windows = g_slist_length(mainwindows); windows = g_slist_length(mainwindows);
if (windows == 1) return; if (windows == 1)
return;
sorted = NULL; sorted = NULL;
windows = 0; windows = 0;
for (win = mainwindows_find_lower(NULL); for (win = mainwindows_find_lower(NULL); win != NULL; win = mainwindows_find_lower(win)) {
win != NULL;
win = mainwindows_find_lower(win)) {
windows++; windows++;
sorted = g_slist_append(sorted, win); sorted = g_slist_append(sorted, win);
} }
@ -1388,8 +1392,7 @@ static void cmd_window_hide(const char *data)
WINDOW_REC *window; WINDOW_REC *window;
if (mainwindows->next == NULL) { if (mainwindows->next == NULL) {
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_CANT_HIDE_LAST);
TXT_CANT_HIDE_LAST);
return; return;
} }
@ -1398,8 +1401,8 @@ static void cmd_window_hide(const char *data)
else if (is_numeric(data, 0)) { else if (is_numeric(data, 0)) {
window = window_find_refnum(atoi(data)); window = window_find_refnum(atoi(data));
if (window == NULL) { if (window == NULL) {
printformat_window(active_win, MSGLEVEL_CLIENTERROR, printformat_window(active_win, MSGLEVEL_CLIENTERROR, TXT_REFNUM_NOT_FOUND,
TXT_REFNUM_NOT_FOUND, data); data);
} }
} else { } else {
window = window_find_item(active_win->active_server, data); window = window_find_item(active_win->active_server, data);
@ -1448,8 +1451,8 @@ static void cmd_window_show(const char *data)
if (is_numeric(args, '\0')) { if (is_numeric(args, '\0')) {
window = window_find_refnum(atoi(args)); window = window_find_refnum(atoi(args));
if (window == NULL) { if (window == NULL) {
printformat_window(active_win, MSGLEVEL_CLIENTERROR, printformat_window(active_win, MSGLEVEL_CLIENTERROR, TXT_REFNUM_NOT_FOUND,
TXT_REFNUM_NOT_FOUND, args); args);
} }
} else { } else {
window = window_find_item(active_win->active_server, args); window = window_find_item(active_win->active_server, args);
@ -1499,7 +1502,6 @@ static void mainwindow_grow_right_int(int count)
} }
} }
/* SYNTAX: WINDOW GROW [-right] [<lines>|<columns>] */ /* SYNTAX: WINDOW GROW [-right] [<lines>|<columns>] */
static void cmd_window_grow(const char *data) static void cmd_window_grow(const char *data)
{ {
@ -1536,7 +1538,8 @@ static void cmd_window_shrink(const char *data)
return; return;
count = *data == '\0' ? 1 : atoi(args); count = *data == '\0' ? 1 : atoi(args);
if (count < -INT_MAX) count = -INT_MAX; if (count < -INT_MAX)
count = -INT_MAX;
if (g_hash_table_lookup(optlist, "right") != NULL) { if (g_hash_table_lookup(optlist, "right") != NULL) {
mainwindow_grow_right_int(-count); mainwindow_grow_right_int(-count);
@ -1570,9 +1573,9 @@ static void cmd_window_size(const char *data)
mainwindow_grow_right_int(size); mainwindow_grow_right_int(size);
} else { } else {
size -= WINDOW_MAIN(active_win)->height - size -= WINDOW_MAIN(active_win)->height - WINDOW_MAIN(active_win)->statusbar_lines;
WINDOW_MAIN(active_win)->statusbar_lines; if (size < -INT_MAX)
if (size < -INT_MAX) size = -INT_MAX; size = -INT_MAX;
mainwindow_grow_int(size); mainwindow_grow_int(size);
} }
@ -1644,8 +1647,8 @@ static void cmd_window_up(const char *data)
GHashTable *optlist; GHashTable *optlist;
void *free_arg; void *free_arg;
if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, "window up",
"window up", &optlist)) &optlist))
return; return;
if (g_hash_table_lookup(optlist, "directional") != NULL) { if (g_hash_table_lookup(optlist, "directional") != NULL) {
@ -1670,8 +1673,8 @@ static void cmd_window_down(const char *data)
GHashTable *optlist; GHashTable *optlist;
void *free_arg; void *free_arg;
if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, "window down",
"window down", &optlist)) &optlist))
return; return;
if (g_hash_table_lookup(optlist, "directional") != NULL) { if (g_hash_table_lookup(optlist, "directional") != NULL) {
@ -1692,8 +1695,7 @@ static void cmd_window_down(const char *data)
#define WINDOW_STICKY_MATCH(window, sticky_parent) \ #define WINDOW_STICKY_MATCH(window, sticky_parent) \
((!WINDOW_GUI(window)->sticky && (sticky_parent) == NULL) || \ ((!WINDOW_GUI(window)->sticky && (sticky_parent) == NULL) || \
(WINDOW_GUI(window)->sticky && \ (WINDOW_GUI(window)->sticky && WINDOW_MAIN(window) == (sticky_parent)))
WINDOW_MAIN(window) == (sticky_parent)))
static int window_refnum_left(int refnum, int wrap) static int window_refnum_left(int refnum, int wrap)
{ {
@ -1704,8 +1706,7 @@ static int window_refnum_left(int refnum, int wrap)
window = window_find_refnum(refnum); window = window_find_refnum(refnum);
g_return_val_if_fail(window != NULL, -1); g_return_val_if_fail(window != NULL, -1);
find_sticky = WINDOW_MAIN(window)->sticky_windows ? find_sticky = WINDOW_MAIN(window)->sticky_windows ? WINDOW_MAIN(window) : NULL;
WINDOW_MAIN(window) : NULL;
do { do {
refnum = window_refnum_prev(refnum, wrap); refnum = window_refnum_prev(refnum, wrap);
@ -1727,8 +1728,7 @@ static int window_refnum_right(int refnum, int wrap)
window = window_find_refnum(refnum); window = window_find_refnum(refnum);
g_return_val_if_fail(window != NULL, -1); g_return_val_if_fail(window != NULL, -1);
find_sticky = WINDOW_MAIN(window)->sticky_windows ? find_sticky = WINDOW_MAIN(window)->sticky_windows ? WINDOW_MAIN(window) : NULL;
WINDOW_MAIN(window) : NULL;
do { do {
refnum = window_refnum_next(refnum, wrap); refnum = window_refnum_next(refnum, wrap);
@ -1747,8 +1747,8 @@ static void cmd_window_left(const char *data, SERVER_REC *server, void *item)
GHashTable *optlist; GHashTable *optlist;
void *free_arg; void *free_arg;
if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, "window left",
"window left", &optlist)) &optlist))
return; return;
if (g_hash_table_lookup(optlist, "directional") != NULL) { if (g_hash_table_lookup(optlist, "directional") != NULL) {
@ -1834,32 +1834,31 @@ static void cmd_window_stick(const char *data)
/* ref# specified */ /* ref# specified */
win = window_find_refnum(atoi(data)); win = window_find_refnum(atoi(data));
if (win == NULL) { if (win == NULL) {
printformat_window(active_win, MSGLEVEL_CLIENTERROR, printformat_window(active_win, MSGLEVEL_CLIENTERROR, TXT_REFNUM_NOT_FOUND,
TXT_REFNUM_NOT_FOUND, data); data);
return; return;
} }
while (*data != ' ' && *data != '\0') data++; while (*data != ' ' && *data != '\0')
while (*data == ' ') data++; data++;
while (*data == ' ')
data++;
} }
if (g_ascii_strncasecmp(data, "OF", 2) == 0 || i_toupper(*data) == 'N') { if (g_ascii_strncasecmp(data, "OF", 2) == 0 || i_toupper(*data) == 'N') {
/* unset sticky */ /* unset sticky */
if (!WINDOW_GUI(win)->sticky) { if (!WINDOW_GUI(win)->sticky) {
printformat_window(win, MSGLEVEL_CLIENTERROR, printformat_window(win, MSGLEVEL_CLIENTERROR, TXT_WINDOW_NOT_STICKY);
TXT_WINDOW_NOT_STICKY);
} else { } else {
gui_window_set_unsticky(win); gui_window_set_unsticky(win);
printformat_window(win, MSGLEVEL_CLIENTNOTICE, printformat_window(win, MSGLEVEL_CLIENTNOTICE, TXT_WINDOW_UNSET_STICKY);
TXT_WINDOW_UNSET_STICKY);
} }
} else { } else {
/* set sticky */ /* set sticky */
window_reparent(win, mainwin); window_reparent(win, mainwin);
gui_window_set_sticky(win); gui_window_set_sticky(win);
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_WINDOW_SET_STICKY);
TXT_WINDOW_SET_STICKY);
} }
} }
@ -1986,8 +1985,7 @@ static void windows_print_sticky(WINDOW_REC *win)
g_string_truncate(str, str->len - 2); g_string_truncate(str, str->len - 2);
g_slist_free(list); g_slist_free(list);
printformat_window(win, MSGLEVEL_CLIENTCRAP, printformat_window(win, MSGLEVEL_CLIENTCRAP, TXT_WINDOW_INFO_STICKY, str->str);
TXT_WINDOW_INFO_STICKY, str->str);
g_string_free(str, TRUE); g_string_free(str, TRUE);
} }
@ -1997,8 +1995,7 @@ static void sig_window_print_info(WINDOW_REC *win)
gui = WINDOW_GUI(win); gui = WINDOW_GUI(win);
if (gui->use_scroll) { if (gui->use_scroll) {
printformat_window(win, MSGLEVEL_CLIENTCRAP, printformat_window(win, MSGLEVEL_CLIENTCRAP, TXT_WINDOW_INFO_SCROLL,
TXT_WINDOW_INFO_SCROLL,
gui->scroll ? "yes" : "no"); gui->scroll ? "yes" : "no");
} }
@ -2106,8 +2103,7 @@ int mainwindows_reserve_columns(int left, int right)
return ret; return ret;
} }
int mainwindow_set_statusbar_columns(MAIN_WINDOW_REC *window, int mainwindow_set_statusbar_columns(MAIN_WINDOW_REC *window, int left, int right)
int left, int right)
{ {
int ret = -1; int ret = -1;
if (left != 0) { if (left != 0) {

View file

@ -7,11 +7,9 @@
#define WINDOW_MIN_SIZE 2 #define WINDOW_MIN_SIZE 2
#define NEW_WINDOW_WIDTH 20 /* must be >= MIN_SCREEN_WIDTH defined in term.c */ #define NEW_WINDOW_WIDTH 20 /* must be >= MIN_SCREEN_WIDTH defined in term.c */
#define MAIN_WINDOW_TEXT_HEIGHT(window) \ #define MAIN_WINDOW_TEXT_HEIGHT(window) ((window)->height - (window)->statusbar_lines)
((window)->height-(window)->statusbar_lines)
#define MAIN_WINDOW_TEXT_WIDTH(window) \ #define MAIN_WINDOW_TEXT_WIDTH(window) ((window)->width - (window)->statusbar_columns)
((window)->width-(window)->statusbar_columns)
typedef struct { typedef struct {
WINDOW_REC *active; WINDOW_REC *active;
@ -19,8 +17,10 @@ typedef struct {
TERM_WINDOW *screen_win; TERM_WINDOW *screen_win;
int sticky_windows; /* number of sticky windows */ int sticky_windows; /* number of sticky windows */
int first_line, last_line; /* first/last line used by this window (0..x) (includes statusbars) */ int first_line,
int first_column, last_column; /* first/last column used by this window (0..x) (includes statusbars) */ last_line; /* first/last line used by this window (0..x) (includes statusbars) */
int first_column,
last_column; /* first/last column used by this window (0..x) (includes statusbars) */
int width, height; /* width/height of the window (includes statusbars) */ int width, height; /* width/height of the window (includes statusbars) */
GSList *statusbars; GSList *statusbars;
@ -30,7 +30,8 @@ typedef struct {
int statusbar_columns; /* left+right */ int statusbar_columns; /* left+right */
unsigned int dirty : 1; /* This window needs a redraw */ unsigned int dirty : 1; /* This window needs a redraw */
unsigned int size_dirty:1; /* We'll need to resize the window, but haven't got around doing it just yet. */ unsigned int size_dirty : 1; /* We'll need to resize the window, but haven't got around
doing it just yet. */
} MAIN_WINDOW_REC; } MAIN_WINDOW_REC;
typedef struct { typedef struct {
@ -55,23 +56,19 @@ void mainwindows_recreate(void);
/* Change the window height - the height includes the lines needed for /* Change the window height - the height includes the lines needed for
statusbars. If resize_lower is TRUE, the lower window is first tried statusbars. If resize_lower is TRUE, the lower window is first tried
to be resized instead of upper window. */ to be resized instead of upper window. */
void mainwindow_set_size(MAIN_WINDOW_REC *window, int height, void mainwindow_set_size(MAIN_WINDOW_REC *window, int height, int resize_lower);
int resize_lower);
void mainwindow_set_rsize(MAIN_WINDOW_REC *window, int width); void mainwindow_set_rsize(MAIN_WINDOW_REC *window, int width);
void mainwindows_resize(int width, int height); void mainwindows_resize(int width, int height);
void mainwindow_change_active(MAIN_WINDOW_REC *mainwin, void mainwindow_change_active(MAIN_WINDOW_REC *mainwin, WINDOW_REC *skip_window);
WINDOW_REC *skip_window);
int mainwindows_reserve_lines(int top, int bottom); int mainwindows_reserve_lines(int top, int bottom);
int mainwindow_set_statusbar_lines(MAIN_WINDOW_REC *window, int mainwindow_set_statusbar_lines(MAIN_WINDOW_REC *window, int top, int bottom);
int top, int bottom);
void mainwindows_redraw_dirty(void); void mainwindows_redraw_dirty(void);
/* Reserve columns at left/right of a main window (for side panels). */ /* Reserve columns at left/right of a main window (for side panels). */
int mainwindows_reserve_columns(int left, int right); int mainwindows_reserve_columns(int left, int right);
int mainwindow_set_statusbar_columns(MAIN_WINDOW_REC *window, int mainwindow_set_statusbar_columns(MAIN_WINDOW_REC *window, int left, int right);
int left, int right);
GSList *mainwindows_get_sorted(int reverse); GSList *mainwindows_get_sorted(int reverse);
GSList *mainwindows_get_line(MAIN_WINDOW_REC *rec); GSList *mainwindows_get_line(MAIN_WINDOW_REC *rec);

View file

@ -83,7 +83,8 @@ enum {
#define TXT_SIDEPANEL_NICK_NORMAL format_find_tag(MODULE_NAME, "sidepanel_nick_normal") #define TXT_SIDEPANEL_NICK_NORMAL format_find_tag(MODULE_NAME, "sidepanel_nick_normal")
#define TXT_SIDEPANEL_NICK_OP_STATUS format_find_tag(MODULE_NAME, "sidepanel_nick_op_status") #define TXT_SIDEPANEL_NICK_OP_STATUS format_find_tag(MODULE_NAME, "sidepanel_nick_op_status")
#define TXT_SIDEPANEL_NICK_VOICE_STATUS format_find_tag(MODULE_NAME, "sidepanel_nick_voice_status") #define TXT_SIDEPANEL_NICK_VOICE_STATUS format_find_tag(MODULE_NAME, "sidepanel_nick_voice_status")
#define TXT_SIDEPANEL_NICK_NORMAL_STATUS format_find_tag(MODULE_NAME, "sidepanel_nick_normal_status") #define TXT_SIDEPANEL_NICK_NORMAL_STATUS \
format_find_tag(MODULE_NAME, "sidepanel_nick_normal_status")
extern FORMAT_REC gui_text_formats[TXT_COUNT + 1]; extern FORMAT_REC gui_text_formats[TXT_COUNT + 1];

View file

@ -22,7 +22,8 @@
#define DATA_LEVEL_EVENT 10 #define DATA_LEVEL_EVENT 10
/* UTF-8 character reading function based on textbuffer-view.c */ /* UTF-8 character reading function based on textbuffer-view.c */
static inline unichar read_unichar(const unsigned char *data, const unsigned char **next, int *width) static inline unichar read_unichar(const unsigned char *data, const unsigned char **next,
int *width)
{ {
unichar chr = g_utf8_get_char_validated((const char *) data, -1); unichar chr = g_utf8_get_char_validated((const char *) data, -1);
if (chr & 0x80000000) { if (chr & 0x80000000) {
@ -32,7 +33,8 @@ static inline unichar read_unichar(const unsigned char *data, const unsigned cha
} else { } else {
*next = (unsigned char *) g_utf8_next_char(data); *next = (unsigned char *) g_utf8_next_char(data);
*width = unichar_isprint(chr) ? i_wcwidth(chr) : 1; *width = unichar_isprint(chr) ? i_wcwidth(chr) : 1;
if (*width < 0) *width = 1; if (*width < 0)
*width = 1;
} }
return chr; return chr;
} }
@ -85,13 +87,19 @@ static gboolean esc_timeout_callback(gpointer data)
} }
static FILE *sp_log; static FILE *sp_log;
static void sp_log_open(void) { if (!sp_log) sp_log = fopen("/tmp/irssi_sidepanels.log", "a"); } static void sp_log_open(void)
{
if (!sp_log)
sp_log = fopen("/tmp/irssi_sidepanels.log", "a");
}
static void sp_logf(const char *fmt, ...) static void sp_logf(const char *fmt, ...)
{ {
va_list ap; va_list ap;
if (!sp_debug) return; if (!sp_debug)
return;
sp_log_open(); sp_log_open();
if (!sp_log) return; if (!sp_log)
return;
va_start(ap, fmt); va_start(ap, fmt);
vfprintf(sp_log, fmt, ap); vfprintf(sp_log, fmt, ap);
fprintf(sp_log, "\n"); fprintf(sp_log, "\n");
@ -115,7 +123,8 @@ static void read_settings(void)
apply_reservations_all(); apply_reservations_all();
apply_and_redraw(); apply_and_redraw();
if (!old_mouse) enable_mouse_tracking(); if (!old_mouse)
enable_mouse_tracking();
} }
static void apply_reservations_all(void) static void apply_reservations_all(void)
@ -150,8 +159,12 @@ typedef struct {
int right_selected_index; int right_selected_index;
int right_scroll_offset; int right_scroll_offset;
/* cached geometry for hit-test and drawing */ /* cached geometry for hit-test and drawing */
int left_x; int left_y; int left_h; int left_x;
int right_x; int right_y; int right_h; int left_y;
int left_h;
int right_x;
int right_y;
int right_h;
/* ordered nick pointers matching rendered order */ /* ordered nick pointers matching rendered order */
GSList *right_order; GSList *right_order;
} SP_MAINWIN_CTX; } SP_MAINWIN_CTX;
@ -171,10 +184,20 @@ static SP_MAINWIN_CTX *get_ctx(MAIN_WINDOW_REC *mw, gboolean create)
static void destroy_ctx(MAIN_WINDOW_REC *mw) static void destroy_ctx(MAIN_WINDOW_REC *mw)
{ {
SP_MAINWIN_CTX *ctx = g_hash_table_lookup(mw_to_ctx, mw); SP_MAINWIN_CTX *ctx = g_hash_table_lookup(mw_to_ctx, mw);
if (!ctx) return; if (!ctx)
if (ctx->left_tw) { term_window_destroy(ctx->left_tw); ctx->left_tw = NULL; } return;
if (ctx->right_tw) { term_window_destroy(ctx->right_tw); ctx->right_tw = NULL; } if (ctx->left_tw) {
if (ctx->right_order) { g_slist_free(ctx->right_order); ctx->right_order = NULL; } term_window_destroy(ctx->left_tw);
ctx->left_tw = NULL;
}
if (ctx->right_tw) {
term_window_destroy(ctx->right_tw);
ctx->right_tw = NULL;
}
if (ctx->right_order) {
g_slist_free(ctx->right_order);
ctx->right_order = NULL;
}
g_hash_table_remove(mw_to_ctx, mw); g_hash_table_remove(mw_to_ctx, mw);
g_free(ctx); g_free(ctx);
} }
@ -203,9 +226,10 @@ static void position_tw(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx)
/* Force statusbar redraw to fix input box positioning */ /* Force statusbar redraw to fix input box positioning */
signal_emit("mainwindow resized", 1, mw); signal_emit("mainwindow resized", 1, mw);
} }
ctx->left_x = x; ctx->left_y = y; ctx->left_h = h; ctx->left_x = x;
} ctx->left_y = y;
else if (ctx->left_tw) { ctx->left_h = h;
} else if (ctx->left_tw) {
/* Clear the left panel area before destroying */ /* Clear the left panel area before destroying */
clear_window_full(ctx->left_tw, ctx->left_w, ctx->left_h); clear_window_full(ctx->left_tw, ctx->left_w, ctx->left_h);
term_window_destroy(ctx->left_tw); term_window_destroy(ctx->left_tw);
@ -222,7 +246,8 @@ static void position_tw(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx)
show_right = sp_enable_right && ctx->right_w > 0; show_right = sp_enable_right && ctx->right_w > 0;
aw = mw->active; aw = mw->active;
if (sp_auto_hide_right) { if (sp_auto_hide_right) {
if (!aw || !aw->active || !aw->active->visible_name || !strchr(aw->active->visible_name, '#')) { if (!aw || !aw->active || !aw->active->visible_name ||
!strchr(aw->active->visible_name, '#')) {
show_right = FALSE; show_right = FALSE;
} }
} }
@ -241,9 +266,10 @@ static void position_tw(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx)
/* Force statusbar redraw to fix input box positioning */ /* Force statusbar redraw to fix input box positioning */
signal_emit("mainwindow resized", 1, mw); signal_emit("mainwindow resized", 1, mw);
} }
ctx->right_x = x; ctx->right_y = y; ctx->right_h = h; ctx->right_x = x;
} ctx->right_y = y;
else if (ctx->right_tw) { ctx->right_h = h;
} else if (ctx->right_tw) {
/* Clear the right panel area before destroying */ /* Clear the right panel area before destroying */
clear_window_full(ctx->right_tw, ctx->right_w, ctx->right_h); clear_window_full(ctx->right_tw, ctx->right_w, ctx->right_h);
term_window_destroy(ctx->right_tw); term_window_destroy(ctx->right_tw);
@ -260,19 +286,24 @@ static void position_tw(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx)
static void draw_border_vertical(TERM_WINDOW *tw, int width, int height, int left) static void draw_border_vertical(TERM_WINDOW *tw, int width, int height, int left)
{ {
(void)tw; (void)width; (void)height; (void)left; (void) tw;
(void) width;
(void) height;
(void) left;
} }
static void draw_main_window_borders(MAIN_WINDOW_REC *mw) static void draw_main_window_borders(MAIN_WINDOW_REC *mw)
{ {
SP_MAINWIN_CTX *ctx = get_ctx(mw, FALSE); SP_MAINWIN_CTX *ctx = get_ctx(mw, FALSE);
if (!ctx) return; if (!ctx)
return;
/* Draw left border (between left panel and main window) */ /* Draw left border (between left panel and main window) */
if (ctx->left_tw && ctx->left_h > 0) { if (ctx->left_tw && ctx->left_h > 0) {
int border_x = mw->first_column + mw->statusbar_columns_left - 1; int border_x = mw->first_column + mw->statusbar_columns_left - 1;
for (int y = 0; y < ctx->left_h; y++) { for (int y = 0; y < ctx->left_h; y++) {
gui_printtext_window_border(border_x, mw->first_line + mw->statusbar_lines_top + y); gui_printtext_window_border(border_x,
mw->first_line + mw->statusbar_lines_top + y);
} }
} }
@ -280,19 +311,20 @@ static void draw_main_window_borders(MAIN_WINDOW_REC *mw)
if (ctx->right_tw && ctx->right_h > 0) { if (ctx->right_tw && ctx->right_h > 0) {
int border_x = mw->last_column + 1; int border_x = mw->last_column + 1;
for (int y = 0; y < ctx->right_h; y++) { for (int y = 0; y < ctx->right_h; y++) {
gui_printtext_window_border(border_x, mw->first_line + mw->statusbar_lines_top + y); gui_printtext_window_border(border_x,
mw->first_line + mw->statusbar_lines_top + y);
} }
} }
} }
/* Get or create window priority state */ /* Get or create window priority state */
static window_priority_state *get_window_priority_state(WINDOW_REC *window) static window_priority_state *get_window_priority_state(WINDOW_REC *window)
{ {
window_priority_state *state; window_priority_state *state;
if (!window_priorities) if (!window_priorities)
window_priorities = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free); window_priorities =
g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
state = g_hash_table_lookup(window_priorities, window); state = g_hash_table_lookup(window_priorities, window);
if (!state) { if (!state) {
@ -345,16 +377,29 @@ static void handle_new_activity(WINDOW_REC *window, int data_level)
int new_priority; int new_priority;
const char *data_level_name; const char *data_level_name;
if (!window) return; if (!window)
return;
/* Debug: data level name */ /* Debug: data level name */
switch (data_level) { switch (data_level) {
case DATA_LEVEL_NONE: data_level_name = "NONE"; break; case DATA_LEVEL_NONE:
case DATA_LEVEL_TEXT: data_level_name = "TEXT"; break; data_level_name = "NONE";
case DATA_LEVEL_MSG: data_level_name = "MSG"; break; break;
case DATA_LEVEL_HILIGHT: data_level_name = "HILIGHT"; break; case DATA_LEVEL_TEXT:
case DATA_LEVEL_EVENT: data_level_name = "EVENT"; break; data_level_name = "TEXT";
default: data_level_name = "UNKNOWN"; break; break;
case DATA_LEVEL_MSG:
data_level_name = "MSG";
break;
case DATA_LEVEL_HILIGHT:
data_level_name = "HILIGHT";
break;
case DATA_LEVEL_EVENT:
data_level_name = "EVENT";
break;
default:
data_level_name = "UNKNOWN";
break;
} }
state = get_window_priority_state(window); state = get_window_priority_state(window);
@ -382,12 +427,14 @@ static void reset_window_priority(WINDOW_REC *window)
{ {
window_priority_state *state; window_priority_state *state;
if (!window) return; if (!window)
return;
state = get_window_priority_state(window); state = get_window_priority_state(window);
if (state->current_priority > 0) { if (state->current_priority > 0) {
/* Debug: Priority reset - tracks when user opens windows */ /* Debug: Priority reset - tracks when user opens windows */
sp_logf("RESET: Window %d priority reset from %d to 0 (opened)", window->refnum, state->current_priority); sp_logf("RESET: Window %d priority reset from %d to 0 (opened)", window->refnum,
state->current_priority);
state->current_priority = 0; state->current_priority = 0;
} else { } else {
/* Debug: Already reset - useful for detecting unnecessary resets */ /* Debug: Already reset - useful for detecting unnecessary resets */
@ -399,11 +446,13 @@ static void clear_window_full(TERM_WINDOW *tw, int width, int height)
{ {
int y; int y;
int x; int x;
if (!tw) return; if (!tw)
return;
term_set_color(tw, ATTR_RESET); term_set_color(tw, ATTR_RESET);
for (y = 0; y < height; y++) { for (y = 0; y < height; y++) {
term_move(tw, 0, y); term_move(tw, 0, y);
for (x = 0; x < width; x++) term_addch(tw, ' '); for (x = 0; x < width; x++)
term_addch(tw, ' ');
} }
} }
@ -411,7 +460,8 @@ static void clear_window_full(TERM_WINDOW *tw, int width, int height)
#define FGATTR (ATTR_NOCOLORS | ATTR_RESETFG | FG_MASK | ATTR_FGCOLOR24) #define FGATTR (ATTR_NOCOLORS | ATTR_RESETFG | FG_MASK | ATTR_FGCOLOR24)
#define BGATTR (ATTR_NOCOLORS | ATTR_RESETBG | BG_MASK | ATTR_BGCOLOR24) #define BGATTR (ATTR_NOCOLORS | ATTR_RESETBG | BG_MASK | ATTR_BGCOLOR24)
static void unformat_24bit_line_color(const unsigned char **ptr, int off, int *flags, unsigned int *fg, unsigned int *bg) static void unformat_24bit_line_color(const unsigned char **ptr, int off, int *flags,
unsigned int *fg, unsigned int *bg)
{ {
unsigned int color; unsigned int color;
unsigned char rgbx[4]; unsigned char rgbx[4];
@ -431,14 +481,14 @@ static void unformat_24bit_line_color(const unsigned char **ptr, int off, int *f
if (rgbx[3] & 0x1) { if (rgbx[3] & 0x1) {
*flags = (*flags & FGATTR) | ATTR_BGCOLOR24; *flags = (*flags & FGATTR) | ATTR_BGCOLOR24;
*bg = color; *bg = color;
} } else {
else {
*flags = (*flags & BGATTR) | ATTR_FGCOLOR24; *flags = (*flags & BGATTR) | ATTR_FGCOLOR24;
*fg = color; *fg = color;
} }
} }
static inline void unformat(const unsigned char **ptr, int *color, unsigned int *fg24, unsigned int *bg24) static inline void unformat(const unsigned char **ptr, int *color, unsigned int *fg24,
unsigned int *bg24)
{ {
switch (**ptr) { switch (**ptr) {
case FORMAT_STYLE_BLINK: case FORMAT_STYLE_BLINK:
@ -518,7 +568,8 @@ static inline void unformat(const unsigned char **ptr, int *color, unsigned int
return; return;
} }
static void draw_str_themed(TERM_WINDOW *tw, int x, int y, WINDOW_REC *wctx, int format_id, const char *text) static void draw_str_themed(TERM_WINDOW *tw, int x, int y, WINDOW_REC *wctx, int format_id,
const char *text)
{ {
TEXT_DEST_REC dest; TEXT_DEST_REC dest;
THEME_REC *theme; THEME_REC *theme;
@ -534,7 +585,8 @@ static void draw_str_themed(TERM_WINDOW *tw, int x, int y, WINDOW_REC *wctx, int
theme = window_get_theme(wctx); theme = window_get_theme(wctx);
out = format_get_text_theme(theme, MODULE_NAME, &dest, format_id, text); out = format_get_text_theme(theme, MODULE_NAME, &dest, format_id, text);
/* Debug: Uncomment to trace theme format rendering issues */ /* Debug: Uncomment to trace theme format rendering issues */
// sp_logf("THEME_DEBUG: format_id=%d text='%s' out='%s'", format_id, text ? text : "(null)", out ? out : "(null)"); // sp_logf("THEME_DEBUG: format_id=%d text='%s' out='%s'", format_id, text ? text :
// "(null)", out ? out : "(null)");
if (out != NULL && *out != '\0') { if (out != NULL && *out != '\0') {
/* Convert theme color codes and render with proper color handling */ /* Convert theme color codes and render with proper color handling */
@ -553,7 +605,8 @@ static void draw_str_themed(TERM_WINDOW *tw, int x, int y, WINDOW_REC *wctx, int
if (*ptr == 4) { if (*ptr == 4) {
/* Format code - process color change */ /* Format code - process color change */
ptr++; ptr++;
if (*ptr == '\0') break; if (*ptr == '\0')
break;
unformat(&ptr, &color, &fg24, &bg24); unformat(&ptr, &color, &fg24, &bg24);
term_set_color2(tw, color, fg24, bg24); term_set_color2(tw, color, fg24, bg24);
ptr++; ptr++;
@ -600,7 +653,8 @@ static void draw_str_themed(TERM_WINDOW *tw, int x, int y, WINDOW_REC *wctx, int
* sidepanel_nick_voice_status = "%C◆%N%c$1"; # nick instead of +nick * sidepanel_nick_voice_status = "%C◆%N%c$1"; # nick instead of +nick
* }; * };
*/ */
static void draw_str_themed_2params(TERM_WINDOW *tw, int x, int y, WINDOW_REC *wctx, int format_id, const char *param1, const char *param2) static void draw_str_themed_2params(TERM_WINDOW *tw, int x, int y, WINDOW_REC *wctx, int format_id,
const char *param1, const char *param2)
{ {
TEXT_DEST_REC dest; TEXT_DEST_REC dest;
THEME_REC *theme; THEME_REC *theme;
@ -624,7 +678,8 @@ static void draw_str_themed_2params(TERM_WINDOW *tw, int x, int y, WINDOW_REC *w
out = format_get_text_theme_charargs(theme, MODULE_NAME, &dest, format_id, args); out = format_get_text_theme_charargs(theme, MODULE_NAME, &dest, format_id, args);
/* Debug: Uncomment to trace 2-parameter theme format rendering */ /* Debug: Uncomment to trace 2-parameter theme format rendering */
// sp_logf("THEME_DEBUG_2P: format_id=%d param1='%s' param2='%s' out='%s'", // sp_logf("THEME_DEBUG_2P: format_id=%d param1='%s' param2='%s' out='%s'",
// format_id, param1 ? param1 : "(null)", param2 ? param2 : "(null)", out ? out : "(null)"); // format_id, param1 ? param1 : "(null)", param2 ? param2 : "(null)", out ? out :
// "(null)");
if (out != NULL && *out != '\0') { if (out != NULL && *out != '\0') {
/* Convert theme color codes and render with proper color handling */ /* Convert theme color codes and render with proper color handling */
@ -643,7 +698,8 @@ static void draw_str_themed_2params(TERM_WINDOW *tw, int x, int y, WINDOW_REC *w
if (*ptr == 4) { if (*ptr == 4) {
/* Format code - process color change */ /* Format code - process color change */
ptr++; ptr++;
if (*ptr == '\0') break; if (*ptr == '\0')
break;
unformat(&ptr, &color, &fg24, &bg24); unformat(&ptr, &color, &fg24, &bg24);
term_set_color2(tw, color, fg24, bg24); term_set_color2(tw, color, fg24, bg24);
ptr++; ptr++;
@ -669,14 +725,11 @@ static void draw_str_themed_2params(TERM_WINDOW *tw, int x, int y, WINDOW_REC *w
g_free(out); g_free(out);
} }
/* Renumber all windows according to sorted display order */ /* Renumber all windows according to sorted display order */
typedef struct { typedef struct {
WINDOW_REC *win; WINDOW_REC *win;
int sort_group; /* 0=Notices, 1=server, 2=channel, 3=query, 4=named_orphan, 5=unnamed_orphan */ int sort_group; /* 0=Notices, 1=server, 2=channel, 3=query, 4=named_orphan, 5=unnamed_orphan
*/
char *sort_key; /* For alphabetical sorting within group */ char *sort_key; /* For alphabetical sorting within group */
SERVER_REC *server; /* Server for grouping */ SERVER_REC *server; /* Server for grouping */
} WINDOW_SORT_REC; } WINDOW_SORT_REC;
@ -689,17 +742,22 @@ static gint compare_window_sort_items(gconstpointer a, gconstpointer b)
int server_cmp; int server_cmp;
/* 1. Notices always comes first */ /* 1. Notices always comes first */
if (w1->sort_group == 0) return -1; /* w1 is Notices */ if (w1->sort_group == 0)
if (w2->sort_group == 0) return 1; /* w2 is Notices */ return -1; /* w1 is Notices */
if (w2->sort_group == 0)
return 1; /* w2 is Notices */
/* 2. Sort by server (alphabetically) */ /* 2. Sort by server (alphabetically) */
if (w1->server && w2->server) { if (w1->server && w2->server) {
net1 = w1->server->connrec && w1->server->connrec->chatnet ? w1->server->connrec->chatnet : net1 = w1->server->connrec && w1->server->connrec->chatnet ?
w1->server->connrec->chatnet :
(w1->server->connrec ? w1->server->connrec->address : "server"); (w1->server->connrec ? w1->server->connrec->address : "server");
net2 = w2->server->connrec && w2->server->connrec->chatnet ? w2->server->connrec->chatnet : net2 = w2->server->connrec && w2->server->connrec->chatnet ?
w2->server->connrec->chatnet :
(w2->server->connrec ? w2->server->connrec->address : "server"); (w2->server->connrec ? w2->server->connrec->address : "server");
server_cmp = g_ascii_strcasecmp(net1 ? net1 : "", net2 ? net2 : ""); server_cmp = g_ascii_strcasecmp(net1 ? net1 : "", net2 ? net2 : "");
if (server_cmp != 0) return server_cmp; if (server_cmp != 0)
return server_cmp;
} else if (w1->server && !w2->server) { } else if (w1->server && !w2->server) {
return -1; /* Server windows come before non-server windows */ return -1; /* Server windows come before non-server windows */
} else if (!w1->server && w2->server) { } else if (!w1->server && w2->server) {
@ -712,7 +770,8 @@ static gint compare_window_sort_items(gconstpointer a, gconstpointer b)
} }
/* 4. Within same type, sort alphabetically by name */ /* 4. Within same type, sort alphabetically by name */
return g_ascii_strcasecmp(w1->sort_key ? w1->sort_key : "", w2->sort_key ? w2->sort_key : ""); return g_ascii_strcasecmp(w1->sort_key ? w1->sort_key : "",
w2->sort_key ? w2->sort_key : "");
} }
/* Build sorted list of windows according to user rules - shared by all functions */ /* Build sorted list of windows according to user rules - shared by all functions */
@ -748,7 +807,8 @@ static GSList *build_sorted_window_list(void)
sort_rec->sort_group = 1; sort_rec->sort_group = 1;
net = sort_rec->server->connrec && sort_rec->server->connrec->chatnet ? net = sort_rec->server->connrec && sort_rec->server->connrec->chatnet ?
sort_rec->server->connrec->chatnet : sort_rec->server->connrec->chatnet :
(sort_rec->server->connrec ? sort_rec->server->connrec->address : "server"); (sort_rec->server->connrec ? sort_rec->server->connrec->address :
"server");
sort_rec->sort_key = g_strdup(net ? net : "server"); sort_rec->sort_key = g_strdup(net ? net : "server");
} else if (win->active && win->active->server) { } else if (win->active && win->active->server) {
/* Windows with active channel/query items */ /* Windows with active channel/query items */
@ -821,13 +881,14 @@ static void renumber_windows_by_position(void)
free_sorted_window_list(sort_list); free_sorted_window_list(sort_list);
} }
static gint ci_nick_compare(gconstpointer a, gconstpointer b) static gint ci_nick_compare(gconstpointer a, gconstpointer b)
{ {
NICK_REC *n1 = (NICK_REC *) a; NICK_REC *n1 = (NICK_REC *) a;
NICK_REC *n2 = (NICK_REC *) b; NICK_REC *n2 = (NICK_REC *) b;
if (!n1 || !n1->nick) return 1; if (!n1 || !n1->nick)
if (!n2 || !n2->nick) return -1; return 1;
if (!n2 || !n2->nick)
return -1;
return g_ascii_strcasecmp(n1->nick, n2->nick); return g_ascii_strcasecmp(n1->nick, n2->nick);
} }
@ -840,9 +901,11 @@ static void draw_left_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx)
GSList *sort_list, *s; GSList *sort_list, *s;
int list_index; int list_index;
if (!ctx) return; if (!ctx)
return;
tw = ctx->left_tw; tw = ctx->left_tw;
if (!tw) return; if (!tw)
return;
clear_window_full(tw, ctx->left_w, ctx->left_h); clear_window_full(tw, ctx->left_w, ctx->left_h);
row = 0; row = 0;
@ -862,7 +925,8 @@ static void draw_left_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx)
int format; int format;
/* Skip items before our scroll offset */ /* Skip items before our scroll offset */
if (list_index++ < skip) continue; if (list_index++ < skip)
continue;
/* Determine format based on selection and activity */ /* Determine format based on selection and activity */
if (win->refnum - 1 == ctx->left_selected_index) { if (win->refnum - 1 == ctx->left_selected_index) {
@ -870,7 +934,8 @@ static void draw_left_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx)
} else if (sort_rec->sort_group == 0 || sort_rec->sort_group == 1) { } else if (sort_rec->sort_group == 0 || sort_rec->sort_group == 1) {
/* Notices and server status windows use header format unless selected */ /* Notices and server status windows use header format unless selected */
if (activity >= DATA_LEVEL_HILIGHT) { if (activity >= DATA_LEVEL_HILIGHT) {
/* Check if this is a nick mention (has hilight_color indicating nick mention) */ /* Check if this is a nick mention (has hilight_color indicating
* nick mention) */
if (win->hilight_color != NULL) { if (win->hilight_color != NULL) {
format = TXT_SIDEPANEL_ITEM_NICK_MENTION; format = TXT_SIDEPANEL_ITEM_NICK_MENTION;
} else { } else {
@ -888,7 +953,8 @@ static void draw_left_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx)
switch (current_priority) { switch (current_priority) {
case 4: /* PRIORITY 4: Nick mention OR Query messages (magenta) */ case 4: /* PRIORITY 4: Nick mention OR Query messages (magenta) */
/* Use QUERY_MSG only for query windows, NICK_MENTION for channel mentions */ /* Use QUERY_MSG only for query windows, NICK_MENTION for channel
* mentions */
if (win->active && IS_QUERY(win->active)) { if (win->active && IS_QUERY(win->active)) {
format = TXT_SIDEPANEL_ITEM_QUERY_MSG; format = TXT_SIDEPANEL_ITEM_QUERY_MSG;
} else { } else {
@ -912,7 +978,8 @@ static void draw_left_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx)
/* Draw the item */ /* Draw the item */
term_move(tw, 0, row); term_move(tw, 0, row);
draw_str_themed(tw, 0, row, mw->active, format, display_name ? display_name : "window"); draw_str_themed(tw, 0, row, mw->active, format,
display_name ? display_name : "window");
row++; row++;
} }
@ -935,18 +1002,25 @@ static void draw_right_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx)
int index; int index;
int row; int row;
GSList *nt; GSList *nt;
if (!ctx) return; if (!ctx)
return;
tw = ctx->right_tw; tw = ctx->right_tw;
if (!tw) return; if (!tw)
return;
clear_window_full(tw, ctx->right_w, ctx->right_h); clear_window_full(tw, ctx->right_w, ctx->right_h);
aw = mw->active; aw = mw->active;
height = ctx->right_h; height = ctx->right_h;
skip = ctx->right_scroll_offset; skip = ctx->right_scroll_offset;
index = 0; row = 0; index = 0;
if (ctx->right_order) { g_slist_free(ctx->right_order); ctx->right_order = NULL; } row = 0;
if (ctx->right_order) {
g_slist_free(ctx->right_order);
ctx->right_order = NULL;
}
/* If no channel active (no # in name), just draw border and return */ /* If no channel active (no # in name), just draw border and return */
if (!aw || !aw->active || !aw->active->visible_name || !strchr(aw->active->visible_name, '#')) { if (!aw || !aw->active || !aw->active->visible_name ||
!strchr(aw->active->visible_name, '#')) {
draw_border_vertical(tw, ctx->right_w, ctx->right_h, 0); draw_border_vertical(tw, ctx->right_w, ctx->right_h, 0);
irssi_set_dirty(); irssi_set_dirty();
return; return;
@ -959,10 +1033,14 @@ static void draw_right_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx)
/* Split nicks by status */ /* Split nicks by status */
for (nt = nicks; nt; nt = nt->next) { for (nt = nicks; nt; nt = nt->next) {
NICK_REC *nick = nt->data; NICK_REC *nick = nt->data;
if (!nick || !nick->nick) continue; if (!nick || !nick->nick)
if (nick->op) ops = g_slist_prepend(ops, nick); continue;
else if (nick->voice) voices = g_slist_prepend(voices, nick); if (nick->op)
else normal = g_slist_prepend(normal, nick); ops = g_slist_prepend(ops, nick);
else if (nick->voice)
voices = g_slist_prepend(voices, nick);
else
normal = g_slist_prepend(normal, nick);
} }
/* Sort each group alphabetically */ /* Sort each group alphabetically */
ops = g_slist_sort(ops, ci_nick_compare); ops = g_slist_sort(ops, ci_nick_compare);
@ -973,7 +1051,8 @@ static void draw_right_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx)
NICK_REC *nick = cur->data; NICK_REC *nick = cur->data;
int format; int format;
ctx->right_order = g_slist_append(ctx->right_order, nick); ctx->right_order = g_slist_append(ctx->right_order, nick);
if (index++ < skip) continue; if (index++ < skip)
continue;
term_move(tw, 1, row); term_move(tw, 1, row);
format = TXT_SIDEPANEL_NICK_OP_STATUS; format = TXT_SIDEPANEL_NICK_OP_STATUS;
draw_str_themed_2params(tw, 1, row, mw->active, format, "@", nick->nick); draw_str_themed_2params(tw, 1, row, mw->active, format, "@", nick->nick);
@ -983,7 +1062,8 @@ static void draw_right_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx)
NICK_REC *nick = cur->data; NICK_REC *nick = cur->data;
int format; int format;
ctx->right_order = g_slist_append(ctx->right_order, nick); ctx->right_order = g_slist_append(ctx->right_order, nick);
if (index++ < skip) continue; if (index++ < skip)
continue;
term_move(tw, 1, row); term_move(tw, 1, row);
format = TXT_SIDEPANEL_NICK_VOICE_STATUS; format = TXT_SIDEPANEL_NICK_VOICE_STATUS;
draw_str_themed_2params(tw, 1, row, mw->active, format, "+", nick->nick); draw_str_themed_2params(tw, 1, row, mw->active, format, "+", nick->nick);
@ -993,7 +1073,8 @@ static void draw_right_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx)
NICK_REC *nick = cur->data; NICK_REC *nick = cur->data;
int format; int format;
ctx->right_order = g_slist_append(ctx->right_order, nick); ctx->right_order = g_slist_append(ctx->right_order, nick);
if (index++ < skip) continue; if (index++ < skip)
continue;
term_move(tw, 1, row); term_move(tw, 1, row);
format = TXT_SIDEPANEL_NICK_NORMAL_STATUS; format = TXT_SIDEPANEL_NICK_NORMAL_STATUS;
draw_str_themed_2params(tw, 1, row, mw->active, format, "", nick->nick); draw_str_themed_2params(tw, 1, row, mw->active, format, "", nick->nick);
@ -1010,7 +1091,8 @@ static void draw_right_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx)
static void redraw_one(MAIN_WINDOW_REC *mw) static void redraw_one(MAIN_WINDOW_REC *mw)
{ {
SP_MAINWIN_CTX *ctx = get_ctx(mw, FALSE); SP_MAINWIN_CTX *ctx = get_ctx(mw, FALSE);
if (!ctx) return; if (!ctx)
return;
position_tw(mw, ctx); position_tw(mw, ctx);
draw_left_contents(mw, ctx); draw_left_contents(mw, ctx);
/* Only draw right contents if right panel is actually shown */ /* Only draw right contents if right panel is actually shown */
@ -1025,7 +1107,8 @@ static void redraw_one(MAIN_WINDOW_REC *mw)
static void redraw_all(void) static void redraw_all(void)
{ {
GSList *t; GSList *t;
for (t = mainwindows; t; t = t->next) redraw_one(t->data); for (t = mainwindows; t; t = t->next)
redraw_one(t->data);
} }
static void sig_mainwindow_resized(MAIN_WINDOW_REC *mw) static void sig_mainwindow_resized(MAIN_WINDOW_REC *mw)
@ -1051,7 +1134,10 @@ static void sig_window_changed(WINDOW_REC *w)
static void sig_window_item_changed(WINDOW_REC *w, WI_ITEM_REC *item) static void sig_window_item_changed(WINDOW_REC *w, WI_ITEM_REC *item)
{ {
const char *item_name = item ? item->visible_name : "NULL"; const char *item_name = item ? item->visible_name : "NULL";
const char *item_type = item ? (IS_QUERY(item) ? "QUERY" : IS_CHANNEL(item) ? "CHANNEL" : "OTHER") : "NONE"; const char *item_type = item ? (IS_QUERY(item) ? "QUERY" :
IS_CHANNEL(item) ? "CHANNEL" :
"OTHER") :
"NONE";
/* Debug: Window item changes - tracks channel/query switching */ /* Debug: Window item changes - tracks channel/query switching */
sp_logf("SIGNAL: window_item_changed Window %d item '%s' (%s) active_win=%d", sp_logf("SIGNAL: window_item_changed Window %d item '%s' (%s) active_win=%d",
@ -1101,14 +1187,17 @@ static void sig_channel_joined(CHANNEL_REC *channel)
static void sig_nicklist_changed(CHANNEL_REC *channel, NICK_REC *nick, const char *old_nick) static void sig_nicklist_changed(CHANNEL_REC *channel, NICK_REC *nick, const char *old_nick)
{ {
/* Nicklist changes don't trigger activity - just redraw */ /* Nicklist changes don't trigger activity - just redraw */
(void)channel; (void)nick; (void)old_nick; (void) channel;
(void) nick;
(void) old_nick;
redraw_all(); redraw_all();
} }
static void sig_nicklist_new(CHANNEL_REC *channel, NICK_REC *nick) static void sig_nicklist_new(CHANNEL_REC *channel, NICK_REC *nick)
{ {
/* Nicklist changes don't trigger activity - just redraw */ /* Nicklist changes don't trigger activity - just redraw */
(void)channel; (void)nick; (void) channel;
(void) nick;
redraw_all(); redraw_all();
} }
@ -1120,17 +1209,20 @@ static void sig_print_text(TEXT_DEST_REC *dest, const char *msg)
int data_level; int data_level;
const char *item_name, *item_type; const char *item_name, *item_type;
if (!dest || !dest->window) return; if (!dest || !dest->window)
return;
window = dest->window; window = dest->window;
/* Skip if this is the active window */ /* Skip if this is the active window */
if (window == active_win) return; if (window == active_win)
return;
/* Filter out message levels that are handled by dedicated signals to avoid duplicates */ /* Filter out message levels that are handled by dedicated signals to avoid duplicates */
if (dest->level & (MSGLEVEL_JOINS | MSGLEVEL_PARTS | MSGLEVEL_QUITS | MSGLEVEL_KICKS | if (dest->level & (MSGLEVEL_JOINS | MSGLEVEL_PARTS | MSGLEVEL_QUITS | MSGLEVEL_KICKS |
MSGLEVEL_MODES | MSGLEVEL_TOPICS | MSGLEVEL_NICKS | MSGLEVEL_ACTIONS)) { MSGLEVEL_MODES | MSGLEVEL_TOPICS | MSGLEVEL_NICKS | MSGLEVEL_ACTIONS)) {
/* These are handled by message_join/part/quit/nick signals - skip to avoid duplicates */ /* These are handled by message_join/part/quit/nick signals - skip to avoid
* duplicates */
return; return;
} }
@ -1154,7 +1246,10 @@ static void sig_print_text(TEXT_DEST_REC *dest, const char *msg)
/* Debug logging */ /* Debug logging */
item = window->active; item = window->active;
item_name = item ? item->visible_name : "NULL"; item_name = item ? item->visible_name : "NULL";
item_type = item ? (IS_QUERY(item) ? "QUERY" : IS_CHANNEL(item) ? "CHANNEL" : "OTHER") : "NONE"; item_type = item ? (IS_QUERY(item) ? "QUERY" :
IS_CHANNEL(item) ? "CHANNEL" :
"OTHER") :
"NONE";
/* Debug: Text messages - essential for activity classification debugging */ /* Debug: Text messages - essential for activity classification debugging */
sp_logf("SIGNAL: print_text Window %d '%s' (%s) msg_level=0x%x data_level=%d active_win=%d", sp_logf("SIGNAL: print_text Window %d '%s' (%s) msg_level=0x%x data_level=%d active_win=%d",
@ -1165,34 +1260,35 @@ static void sig_print_text(TEXT_DEST_REC *dest, const char *msg)
redraw_all(); redraw_all();
} }
/* Event signal handlers for join/part/quit/nick - priority 1 events */ /* Event signal handlers for join/part/quit/nick - priority 1 events */
static void sig_message_join(SERVER_REC *server, const char *channel, const char *nick, const char *address, const char *account, const char *realname) static void sig_message_join(SERVER_REC *server, const char *channel, const char *nick,
const char *address, const char *account, const char *realname)
{ {
WINDOW_REC *window = window_find_item(server, channel); WINDOW_REC *window = window_find_item(server, channel);
if (window) { if (window) {
/* Debug: Join events - tracks channel join activity */ /* Debug: Join events - tracks channel join activity */
sp_logf("SIGNAL: message_join %s on %s (Window %d) active_win=%d", sp_logf("SIGNAL: message_join %s on %s (Window %d) active_win=%d", nick, channel,
nick, channel, window->refnum, active_win ? active_win->refnum : -1); window->refnum, active_win ? active_win->refnum : -1);
handle_new_activity(window, DATA_LEVEL_EVENT); handle_new_activity(window, DATA_LEVEL_EVENT);
} }
redraw_all(); redraw_all();
} }
static void sig_message_part(SERVER_REC *server, const char *channel, const char *nick, const char *address, const char *reason) static void sig_message_part(SERVER_REC *server, const char *channel, const char *nick,
const char *address, const char *reason)
{ {
WINDOW_REC *window = window_find_item(server, channel); WINDOW_REC *window = window_find_item(server, channel);
if (window) { if (window) {
/* Debug: Part events - tracks channel part activity */ /* Debug: Part events - tracks channel part activity */
sp_logf("SIGNAL: message_part %s from %s (Window %d) active_win=%d", sp_logf("SIGNAL: message_part %s from %s (Window %d) active_win=%d", nick, channel,
nick, channel, window->refnum, active_win ? active_win->refnum : -1); window->refnum, active_win ? active_win->refnum : -1);
handle_new_activity(window, DATA_LEVEL_EVENT); handle_new_activity(window, DATA_LEVEL_EVENT);
} }
redraw_all(); redraw_all();
} }
static void sig_message_quit(SERVER_REC *server, const char *nick, const char *address, const char *reason) static void sig_message_quit(SERVER_REC *server, const char *nick, const char *address,
const char *reason)
{ {
/* Handle quit for all windows where this nick was present */ /* Handle quit for all windows where this nick was present */
GSList *tmp; GSList *tmp;
@ -1205,7 +1301,8 @@ static void sig_message_quit(SERVER_REC *server, const char *nick, const char *a
redraw_all(); redraw_all();
} }
static void sig_message_nick(SERVER_REC *server, const char *newnick, const char *oldnick, const char *address) static void sig_message_nick(SERVER_REC *server, const char *newnick, const char *oldnick,
const char *address)
{ {
/* Handle nick change for all windows on this server */ /* Handle nick change for all windows on this server */
GSList *tmp; GSList *tmp;
@ -1218,9 +1315,6 @@ static void sig_message_nick(SERVER_REC *server, const char *newnick, const char
redraw_all(); redraw_all();
} }
static void setup_ctx_for(MAIN_WINDOW_REC *mw) static void setup_ctx_for(MAIN_WINDOW_REC *mw)
{ {
SP_MAINWIN_CTX *ctx; SP_MAINWIN_CTX *ctx;
@ -1239,7 +1333,8 @@ static void update_left_selection_to_active(void)
SP_MAINWIN_CTX *ctx = get_ctx(mw, FALSE); SP_MAINWIN_CTX *ctx = get_ctx(mw, FALSE);
WINDOW_REC *aw = mw->active; WINDOW_REC *aw = mw->active;
if (!ctx || !aw) continue; if (!ctx || !aw)
continue;
/* Simple: selection index = active window refnum - 1 (0-based indexing) */ /* Simple: selection index = active window refnum - 1 (0-based indexing) */
ctx->left_selected_index = aw->refnum - 1; ctx->left_selected_index = aw->refnum - 1;
@ -1270,7 +1365,8 @@ static gboolean handle_click_at(int x, int y, int button)
for (mt = mainwindows; mt; mt = mt->next) { for (mt = mainwindows; mt; mt = mt->next) {
MAIN_WINDOW_REC *mw = mt->data; MAIN_WINDOW_REC *mw = mt->data;
SP_MAINWIN_CTX *ctx = get_ctx(mw, FALSE); SP_MAINWIN_CTX *ctx = get_ctx(mw, FALSE);
if (!ctx) continue; if (!ctx)
continue;
if (ctx->left_tw) { if (ctx->left_tw) {
int px = ctx->left_x, py = ctx->left_y, pw = ctx->left_w, ph = ctx->left_h; int px = ctx->left_x, py = ctx->left_y, pw = ctx->left_w, ph = ctx->left_h;
if (x >= px && x < px + pw && y >= py && y < py + ph) { if (x >= px && x < px + pw && y >= py && y < py + ph) {
@ -1288,11 +1384,15 @@ static gboolean handle_click_at(int x, int y, int button)
WINDOW_SORT_REC *sort_rec = s->data; WINDOW_SORT_REC *sort_rec = s->data;
WINDOW_REC *win = sort_rec->win; WINDOW_REC *win = sort_rec->win;
/* Debug: Window switches via mouse - tracks click navigation */ /* Debug: Window switches via mouse - tracks click
sp_logf("MOUSE_CLICK: switching to window %d (was %d)", * navigation */
win ? win->refnum : -1, active_win ? active_win->refnum : -1); sp_logf(
"MOUSE_CLICK: switching to window %d (was %d)",
win ? win->refnum : -1,
active_win ? active_win->refnum : -1);
ctx->left_selected_index = target_index; ctx->left_selected_index = target_index;
if (win) window_set_active(win); if (win)
window_set_active(win);
redraw_one(mw); redraw_one(mw);
irssi_set_dirty(); irssi_set_dirty();
free_sorted_window_list(sort_list); free_sorted_window_list(sort_list);
@ -1304,7 +1404,8 @@ static gboolean handle_click_at(int x, int y, int button)
} }
} }
if (ctx->right_tw) { if (ctx->right_tw) {
int px = ctx->right_x, py = ctx->right_y, pw = ctx->right_w, ph = ctx->right_h; int px = ctx->right_x, py = ctx->right_y, pw = ctx->right_w,
ph = ctx->right_h;
if (x >= px && x < px + pw && y >= py && y < py + ph) { if (x >= px && x < px + pw && y >= py && y < py + ph) {
int row = y - py; int row = y - py;
WINDOW_REC *aw = mw->active; WINDOW_REC *aw = mw->active;
@ -1313,10 +1414,12 @@ static gboolean handle_click_at(int x, int y, int button)
int target_index = ctx->right_scroll_offset + row; int target_index = ctx->right_scroll_offset + row;
int count = g_slist_length(ctx->right_order); int count = g_slist_length(ctx->right_order);
if (target_index >= 0 && target_index < count) { if (target_index >= 0 && target_index < count) {
NICK_REC *nick = g_slist_nth_data(ctx->right_order, target_index); NICK_REC *nick = g_slist_nth_data(ctx->right_order,
target_index);
ctx->right_selected_index = target_index; ctx->right_selected_index = target_index;
if (nick && nick->nick) if (nick && nick->nick)
signal_emit("command query", 3, nick->nick, ch->server, ch); signal_emit("command query", 3, nick->nick,
ch->server, ch);
redraw_one(mw); redraw_one(mw);
irssi_set_dirty(); irssi_set_dirty();
return TRUE; return TRUE;
@ -1341,15 +1444,18 @@ gboolean sidepanels_try_parse_mouse_key(unichar key)
gboolean press; gboolean press;
GSList *mt; GSList *mt;
if (!sp_enable_mouse) return FALSE; if (!sp_enable_mouse)
if (reemit_guard) return FALSE; /* Don't process re-emitted keys */ return FALSE;
if (reemit_guard)
return FALSE; /* Don't process re-emitted keys */
if (mouse_state == 0) { if (mouse_state == 0) {
if (key == 0x1b) { if (key == 0x1b) {
mouse_state = 1; mouse_state = 1;
mouse_len = 0; mouse_len = 0;
esc_pending = 1; esc_pending = 1;
/* Start timeout to distinguish fast mouse ESC from user ESC+key */ /* Start timeout to distinguish fast mouse ESC from user ESC+key */
if (esc_timeout_tag != -1) g_source_remove(esc_timeout_tag); if (esc_timeout_tag != -1)
g_source_remove(esc_timeout_tag);
esc_timeout_tag = g_timeout_add(50, esc_timeout_callback, NULL); esc_timeout_tag = g_timeout_add(50, esc_timeout_callback, NULL);
return TRUE; return TRUE;
} }
@ -1357,28 +1463,48 @@ gboolean sidepanels_try_parse_mouse_key(unichar key)
} else if (mouse_state == 1) { } else if (mouse_state == 1) {
if (key == '[') { if (key == '[') {
/* Cancel timeout - might be mouse sequence or arrow keys */ /* Cancel timeout - might be mouse sequence or arrow keys */
if (esc_timeout_tag != -1) { g_source_remove(esc_timeout_tag); esc_timeout_tag = -1; } if (esc_timeout_tag != -1) {
g_source_remove(esc_timeout_tag);
esc_timeout_tag = -1;
}
mouse_state = 2; mouse_state = 2;
esc_pending = 0; /* clear pending since we'll handle this */ esc_pending = 0; /* clear pending since we'll handle this */
return TRUE; return TRUE;
} }
if (key == 'O') { if (key == 'O') {
/* This is ESC O - application mode arrow keys, re-emit immediately */ /* This is ESC O - application mode arrow keys, re-emit immediately */
if (esc_timeout_tag != -1) { g_source_remove(esc_timeout_tag); esc_timeout_tag = -1; } if (esc_timeout_tag != -1) {
g_source_remove(esc_timeout_tag);
esc_timeout_tag = -1;
}
mouse_state = 3; /* special state for ESC O sequences */ mouse_state = 3; /* special state for ESC O sequences */
esc_pending = 0; /* clear pending since we'll handle this immediately */ esc_pending = 0; /* clear pending since we'll handle this immediately */
return TRUE; return TRUE;
} }
/* Not SGR - cancel timeout and re-emit ESC */ /* Not SGR - cancel timeout and re-emit ESC */
if (esc_timeout_tag != -1) { g_source_remove(esc_timeout_tag); esc_timeout_tag = -1; } if (esc_timeout_tag != -1) {
mouse_state = 0; mouse_len = 0; g_source_remove(esc_timeout_tag);
if (esc_pending && !reemit_guard) { reemit_guard = 1; signal_emit("gui key pressed", 1, GINT_TO_POINTER(0x1b)); reemit_guard = 0; esc_pending = 0; } esc_timeout_tag = -1;
}
mouse_state = 0;
mouse_len = 0;
if (esc_pending && !reemit_guard) {
reemit_guard = 1;
signal_emit("gui key pressed", 1, GINT_TO_POINTER(0x1b));
reemit_guard = 0;
esc_pending = 0;
}
return FALSE; return FALSE;
} else if (mouse_state == 3) { } else if (mouse_state == 3) {
/* ESC O sequence - re-emit ESC O and current key */ /* ESC O sequence - re-emit ESC O and current key */
mouse_state = 0; mouse_len = 0; esc_pending = 0; mouse_state = 0;
mouse_len = 0;
esc_pending = 0;
/* Cancel any pending timeout */ /* Cancel any pending timeout */
if (esc_timeout_tag != -1) { g_source_remove(esc_timeout_tag); esc_timeout_tag = -1; } if (esc_timeout_tag != -1) {
g_source_remove(esc_timeout_tag);
esc_timeout_tag = -1;
}
if (!reemit_guard) { if (!reemit_guard) {
reemit_guard = 1; reemit_guard = 1;
signal_emit("gui key pressed", 1, GINT_TO_POINTER(0x1b)); signal_emit("gui key pressed", 1, GINT_TO_POINTER(0x1b));
@ -1388,7 +1514,8 @@ gboolean sidepanels_try_parse_mouse_key(unichar key)
} }
return TRUE; return TRUE;
} else if (mouse_state >= 2) { } else if (mouse_state >= 2) {
if (mouse_len < (int)sizeof(mouse_buf)-1) mouse_buf[mouse_len++] = (char)key; if (mouse_len < (int) sizeof(mouse_buf) - 1)
mouse_buf[mouse_len++] = (char) key;
mouse_buf[mouse_len] = '\0'; mouse_buf[mouse_len] = '\0';
s = mouse_buf; s = mouse_buf;
/* Check if this is arrow keys (A/B/C/D) or other ESC sequences */ /* Check if this is arrow keys (A/B/C/D) or other ESC sequences */
@ -1396,8 +1523,13 @@ gboolean sidepanels_try_parse_mouse_key(unichar key)
key == 'H' || key == 'F' || key == '1' || key == '2' || key == 'H' || key == 'F' || key == '1' || key == '2' ||
key == '3' || key == '4' || key == '5' || key == '6')) { key == '3' || key == '4' || key == '5' || key == '6')) {
/* This is arrow key or function key - re-emit ESC[ and current key */ /* This is arrow key or function key - re-emit ESC[ and current key */
mouse_state = 0; mouse_len = 0; esc_pending = 0; mouse_state = 0;
if (esc_timeout_tag != -1) { g_source_remove(esc_timeout_tag); esc_timeout_tag = -1; } mouse_len = 0;
esc_pending = 0;
if (esc_timeout_tag != -1) {
g_source_remove(esc_timeout_tag);
esc_timeout_tag = -1;
}
if (!reemit_guard) { if (!reemit_guard) {
reemit_guard = 1; reemit_guard = 1;
signal_emit("gui key pressed", 1, GINT_TO_POINTER(0x1b)); signal_emit("gui key pressed", 1, GINT_TO_POINTER(0x1b));
@ -1408,23 +1540,41 @@ gboolean sidepanels_try_parse_mouse_key(unichar key)
return TRUE; return TRUE;
} }
if (*s != '<') { /* not SGR mouse - cancel */ if (*s != '<') { /* not SGR mouse - cancel */
mouse_state = 0; mouse_len = 0; esc_pending = 0; mouse_state = 0;
if (esc_timeout_tag != -1) { g_source_remove(esc_timeout_tag); esc_timeout_tag = -1; } mouse_len = 0;
esc_pending = 0;
if (esc_timeout_tag != -1) {
g_source_remove(esc_timeout_tag);
esc_timeout_tag = -1;
}
return TRUE; return TRUE;
} }
sc1 = strchr(s, ';'); if (!sc1) return TRUE; sc1 = strchr(s, ';');
sc2 = strchr(sc1+1, ';'); if (!sc2) return TRUE; if (!sc1)
end = sc2+1; if (*end == '\0') return TRUE; return TRUE;
sc2 = strchr(sc1 + 1, ';');
if (!sc2)
return TRUE;
end = sc2 + 1;
if (*end == '\0')
return TRUE;
last = end[(int) strlen(end) - 1]; last = end[(int) strlen(end) - 1];
if (last != 'M' && last != 'm') return TRUE; if (last != 'M' && last != 'm')
return TRUE;
braw = atoi(s + 1); braw = atoi(s + 1);
x = atoi(sc1 + 1); x = atoi(sc1 + 1);
y = atoi(sc2 + 1); y = atoi(sc2 + 1);
x -= 1; y -= 1; x -= 1;
y -= 1;
press = (last == 'M'); press = (last == 'M');
mouse_state = 0; mouse_len = 0; esc_pending = 0; mouse_state = 0;
mouse_len = 0;
esc_pending = 0;
/* Cancel timeout if still active */ /* Cancel timeout if still active */
if (esc_timeout_tag != -1) { g_source_remove(esc_timeout_tag); esc_timeout_tag = -1; } if (esc_timeout_tag != -1) {
g_source_remove(esc_timeout_tag);
esc_timeout_tag = -1;
}
if ((braw & 64) && press) { if ((braw & 64) && press) {
int dir; int dir;
int delta; int delta;
@ -1434,20 +1584,29 @@ gboolean sidepanels_try_parse_mouse_key(unichar key)
for (mt = mainwindows; mt; mt = mt->next) { for (mt = mainwindows; mt; mt = mt->next) {
MAIN_WINDOW_REC *mw = mt->data; MAIN_WINDOW_REC *mw = mt->data;
SP_MAINWIN_CTX *ctx = get_ctx(mw, FALSE); SP_MAINWIN_CTX *ctx = get_ctx(mw, FALSE);
if (!ctx) continue; if (!ctx)
continue;
if (ctx->left_tw) { if (ctx->left_tw) {
px = ctx->left_x; py = ctx->left_y; pw = ctx->left_w; ph = ctx->left_h; px = ctx->left_x;
py = ctx->left_y;
pw = ctx->left_w;
ph = ctx->left_h;
if (x >= px && x < px + pw && y >= py && y < py + ph) { if (x >= px && x < px + pw && y >= py && y < py + ph) {
ctx->left_scroll_offset = MAX(0, ctx->left_scroll_offset + delta); ctx->left_scroll_offset =
MAX(0, ctx->left_scroll_offset + delta);
redraw_one(mw); redraw_one(mw);
irssi_set_dirty(); irssi_set_dirty();
return TRUE; return TRUE;
} }
} }
if (ctx->right_tw) { if (ctx->right_tw) {
px = ctx->right_x; py = ctx->right_y; pw = ctx->right_w; ph = ctx->right_h; px = ctx->right_x;
py = ctx->right_y;
pw = ctx->right_w;
ph = ctx->right_h;
if (x >= px && x < px + pw && y >= py && y < py + ph) { if (x >= px && x < px + pw && y >= py && y < py + ph) {
ctx->right_scroll_offset = MAX(0, ctx->right_scroll_offset + delta); ctx->right_scroll_offset =
MAX(0, ctx->right_scroll_offset + delta);
redraw_one(mw); redraw_one(mw);
irssi_set_dirty(); irssi_set_dirty();
return TRUE; return TRUE;
@ -1511,7 +1670,8 @@ void sidepanels_init(void)
/* Apply reservations but don't redraw yet - wait for irssi init finished */ /* Apply reservations but don't redraw yet - wait for irssi init finished */
apply_reservations_all(); apply_reservations_all();
enable_mouse_tracking(); enable_mouse_tracking();
esc_pending = 0; reemit_guard = 0; esc_pending = 0;
reemit_guard = 0;
signal_add("irssi init finished", (SIGNAL_FUNC) sig_irssi_init_finished); signal_add("irssi init finished", (SIGNAL_FUNC) sig_irssi_init_finished);
signal_add("mainwindow created", (SIGNAL_FUNC) sig_mainwindow_created); signal_add("mainwindow created", (SIGNAL_FUNC) sig_mainwindow_created);
signal_add("setup changed", (SIGNAL_FUNC) read_settings); signal_add("setup changed", (SIGNAL_FUNC) read_settings);
@ -1592,10 +1752,22 @@ void sidepanels_deinit(void)
if (mw->statusbar_columns_right) if (mw->statusbar_columns_right)
mainwindow_set_statusbar_columns(mw, 0, -mw->statusbar_columns_right); mainwindow_set_statusbar_columns(mw, 0, -mw->statusbar_columns_right);
} }
if (mw_to_ctx) { g_hash_table_destroy(mw_to_ctx); mw_to_ctx = NULL; } if (mw_to_ctx) {
if (window_priorities) { g_hash_table_destroy(window_priorities); window_priorities = NULL; } g_hash_table_destroy(mw_to_ctx);
mw_to_ctx = NULL;
}
if (window_priorities) {
g_hash_table_destroy(window_priorities);
window_priorities = NULL;
}
disable_mouse_tracking(); disable_mouse_tracking();
/* Clean up timeout */ /* Clean up timeout */
if (esc_timeout_tag != -1) { g_source_remove(esc_timeout_tag); esc_timeout_tag = -1; } if (esc_timeout_tag != -1) {
if (sp_log) { fclose(sp_log); sp_log = NULL; } g_source_remove(esc_timeout_tag);
esc_timeout_tag = -1;
}
if (sp_log) {
fclose(sp_log);
sp_log = NULL;
}
} }