From 25f2b165445b4d8157a0735b5cfdbdc167684394 Mon Sep 17 00:00:00 2001 From: kofany Date: Mon, 25 Aug 2025 02:47:41 +0200 Subject: [PATCH] Apply clang-format to sidepanel related files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/fe-text/gui-readline.c | 226 ++++----- src/fe-text/irssi.c | 37 +- src/fe-text/mainwindows-layout.c | 83 ++-- src/fe-text/mainwindows.c | 460 +++++++++--------- src/fe-text/mainwindows.h | 29 +- src/fe-text/module-formats.h | 27 +- src/fe-text/sidepanels.c | 772 +++++++++++++++++++------------ 7 files changed, 903 insertions(+), 731 deletions(-) diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c index 56639aa7..5f74cd06 100644 --- a/src/fe-text/gui-readline.c +++ b/src/fe-text/gui-readline.c @@ -44,12 +44,13 @@ /* After LINE_SPLIT_LIMIT characters, the message will be split into multiple lines */ #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_ENTRY_FUNC) (const char *line, 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 struct { SIGNAL_FUNC func; - int flags; + int flags; void *data; } ENTRY_REDIRECT_REC; @@ -81,7 +82,7 @@ static int previous_yank_preceded; * bracketed paste mode active. Fror more details see * https://cirw.in/blog/bracketed-paste */ static const unichar bp_start[] = { 0x1b, '[', '2', '0', '0', '~' }; -static const unichar bp_end[] = { 0x1b, '[', '2', '0', '1', '~' }; +static const unichar bp_end[] = { 0x1b, '[', '2', '0', '1', '~' }; #define BRACKETED_PASTE_TIMEOUT (5 * 1000) // ms @@ -114,7 +115,7 @@ void input_listen_init(int handle) void input_listen_deinit(void) { g_source_remove(readtag); - readtag = -1; + readtag = -1; } static void handle_key_redirect(int key) @@ -137,7 +138,7 @@ static void handle_entry_redirect(const char *line) ENTRY_REDIRECT_ENTRY_FUNC func; void *data; - gui_entry_set_hidden(active_entry, FALSE); + gui_entry_set_hidden(active_entry, FALSE); func = (ENTRY_REDIRECT_ENTRY_FUNC) redir->func; data = redir->data; @@ -146,8 +147,7 @@ static void handle_entry_redirect(const char *line) gui_entry_set_prompt(active_entry, ""); if (func != NULL) { - func(line, data, active_win->active_server, - active_win->active); + func(line, data, active_win->active_server, active_win->active); } } @@ -161,14 +161,14 @@ static int get_scroll_count(void) if (count == 0) count = 1; else if (count < 0) - count = active_mainwin->height-active_mainwin->statusbar_lines+count; + count = active_mainwin->height - active_mainwin->statusbar_lines + count; else if (count < 1) - count = 1.0/count; + count = 1.0 / count; if (*str == '/' || *str == '.') { - count = (active_mainwin->height-active_mainwin->statusbar_lines)/count; + count = (active_mainwin->height - active_mainwin->statusbar_lines) / count; } - return (int)count; + return (int) count; } static void window_prev_page(void) @@ -213,7 +213,7 @@ static void paste_buffer_join_lines(GArray *buf) if (buf->len == 0) return; - arr = (unichar *)buf->data; + arr = (unichar *) buf->data; /* first line */ if (isblank(arr[0])) @@ -221,7 +221,7 @@ static void paste_buffer_join_lines(GArray *buf) /* find the first beginning of indented line */ for (i = 1; i < buf->len; i++) { - if (isnewline(arr[i-1]) && isblank(arr[i])) + if (isnewline(arr[i - 1]) && isblank(arr[i])) break; } if (i == buf->len) @@ -236,7 +236,8 @@ static void paste_buffer_join_lines(GArray *buf) return; /* now, enforce these to all subsequent lines */ - count = indent; last_lf = TRUE; + count = indent; + last_lf = TRUE; for (; i < buf->len; i++) { if (last_lf) { if (isblank(arr[i])) @@ -254,15 +255,17 @@ static void paste_buffer_join_lines(GArray *buf) /* all looks fine - now remove the whitespace, but don't let lines 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++) { if (last_lf && isblank(arr[i])) { /* whitespace, ignore */ } else if (isnewline(arr[i])) { - if (!last_lf && i+1 != buf->len && - isblank(arr[i+1])) { + if (!last_lf && i + 1 != buf->len && isblank(arr[i + 1])) { last_lf_pos = dest; - if (i != 0 && !isblank(arr[i-1])) + if (i != 0 && !isblank(arr[i - 1])) *dest++ = ' '; } else { *dest++ = '\n'; /* double-LF */ @@ -273,9 +276,10 @@ static void paste_buffer_join_lines(GArray *buf) } else { last_lf = FALSE; if (++line_len >= LINE_SPLIT_LIMIT && last_lf_pos != NULL) { - memmove(last_lf_pos+1, last_lf_pos, - (dest - last_lf_pos) * sizeof(unichar)); - *last_lf_pos = '\n'; last_lf_pos = NULL; + memmove(last_lf_pos + 1, last_lf_pos, + (dest - last_lf_pos) * sizeof(unichar)); + *last_lf_pos = '\n'; + last_lf_pos = NULL; line_len = 0; dest++; } @@ -370,9 +374,9 @@ static void paste_flush(void (*send)(void)) g_array_set_size(paste_buffer_rest, 0); } - gui_entry_set_prompt(active_entry, - paste_old_prompt == NULL ? "" : paste_old_prompt); - g_free(paste_old_prompt); paste_old_prompt = NULL; + gui_entry_set_prompt(active_entry, paste_old_prompt == NULL ? "" : paste_old_prompt); + g_free(paste_old_prompt); + paste_old_prompt = NULL; paste_prompt = FALSE; 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; we just choose the greater of the two since the exact value isn't important */ - if (split_lines > paste_verify_line_count && - split_lines > paste_line_count) { + if (split_lines > paste_verify_line_count && split_lines > paste_line_count) { actual_line_count = split_lines; } paste_prompt = TRUE; paste_old_prompt = g_strdup(active_entry->prompt); - printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, - TXT_PASTE_WARNING, - actual_line_count, - active_win->active == NULL ? "window" : - active_win->active->visible_name); + printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_PASTE_WARNING, actual_line_count, + active_win->active == NULL ? "window" : + active_win->active->visible_name); - str = format_get_text(MODULE_NAME, active_win, NULL, NULL, - TXT_PASTE_PROMPT, 0, 0); + str = format_get_text(MODULE_NAME, active_win, NULL, NULL, TXT_PASTE_PROMPT, 0, 0); gui_entry_set_prompt(active_entry, str); paste_entry = gui_entry_get_text(active_entry); paste_entry_pos = gui_entry_get_pos(active_entry); @@ -559,16 +559,16 @@ static void sig_gui_key_pressed(gpointer keyp) if (key < 32) { /* control key */ - str[0] = '^'; - str[1] = (char)key+'@'; - str[2] = '\0'; + str[0] = '^'; + str[1] = (char) key + '@'; + str[2] = '\0'; } else if (key == 127) { - str[0] = '^'; + str[0] = '^'; str[1] = '?'; - str[2] = '\0'; + str[2] = '\0'; } else if (!active_entry->utf8) { if (key <= 0xff) { - str[0] = (char)key; + str[0] = (char) key; str[1] = '\0'; } else { str[0] = (char) (key >> 8); @@ -576,7 +576,7 @@ static void sig_gui_key_pressed(gpointer keyp) str[2] = '\0'; } } else { - /* need to convert to utf8 */ + /* need to convert to utf8 */ str[g_unichar_to_utf8(key, str)] = '\0'; } @@ -640,9 +640,7 @@ static void key_send_line(void) } if (redir == NULL) { - signal_emit("send command", 3, str, - active_win->active_server, - active_win->active); + signal_emit("send command", 3, str, active_win->active_server, active_win->active); } else { handle_entry_redirect(str); } @@ -651,22 +649,20 @@ static void key_send_line(void) gui_entry_set_text(active_entry, ""); command_history_clear_pos(active_win); - g_free(str); + g_free(str); } -static void key_combo(void) -{ -} +static void key_combo(void) {} static void key_backward_history(void) { const char *text; - char *line; + char *line; line = gui_entry_get_text(active_entry); text = command_history_prev(active_win, line); gui_entry_set_text(active_entry, text); - g_free(line); + g_free(line); } static void key_forward_history(void) @@ -677,7 +673,7 @@ static void key_forward_history(void) line = gui_entry_get_text(active_entry); text = command_history_next(active_win, line); gui_entry_set_text(active_entry, text); - g_free(line); + g_free(line); } static void key_backward_global_history(void) @@ -715,7 +711,7 @@ static void key_erase_history_entry(void) static void key_beginning_of_line(void) { - gui_entry_set_pos(active_entry, 0); + gui_entry_set_pos(active_entry, 0); } static void key_end_of_line(void) @@ -780,7 +776,7 @@ static void key_yank_from_cutbuffer(void) { char *cutbuffer; - cutbuffer = gui_entry_get_cutbuffer(active_entry); + cutbuffer = gui_entry_get_cutbuffer(active_entry); if (cutbuffer != NULL) { gui_entry_insert_text(active_entry, cutbuffer); active_entry->yank_preceded = TRUE; @@ -801,7 +797,8 @@ static void key_yank_next_cutbuffer(void) return; 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); if (cutbuffer != NULL) { @@ -902,9 +899,9 @@ static gboolean paste_timeout(gpointer data) } g_array_set_size(paste_buffer, 0); } else if (paste_verify_line_count > 0 && - (paste_line_count >= paste_verify_line_count || - split_lines > paste_verify_line_count) && - active_win->active != NULL) + (paste_line_count >= paste_verify_line_count || + split_lines > paste_verify_line_count) && + active_win->active != NULL) insert_paste_prompt(); else paste_flush(paste_send); @@ -957,12 +954,10 @@ static void paste_bracketed_middle(void) for (i = 0; i <= len; i++, ptr++) { if (ptr[0] == bp_end[0] && memcmp(ptr, bp_end, sizeof(bp_end)) == 0) { - /* if there are at least 6 bytes after the end, * check for another start marker right afterwards */ if (i <= (len - marklen) && memcmp(ptr + marklen, bp_start, sizeof(bp_start)) == 0) { - /* remove both markers*/ g_array_remove_range(paste_buffer, i, marklen * 2); len -= marklen * 2; @@ -981,7 +976,7 @@ static void paste_bracketed_middle(void) static void sig_input(void) { if (!active_entry) { - /* no active entry yet - wait until we have it */ + /* no active entry yet - wait until we have it */ return; } @@ -1005,7 +1000,8 @@ static void sig_input(void) if (paste_bracketed_mode) { 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) g_source_remove(paste_timeout_id); 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)); 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); /* handle single-line / small pastes here */ @@ -1093,12 +1090,14 @@ static void key_scroll_forward(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) { - 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) @@ -1111,7 +1110,7 @@ static void key_completion(int erase, int backward) char *text, *line; int pos; - text = gui_entry_get_text_and_pos(active_entry, &pos); + text = gui_entry_get_text_and_pos(active_entry, &pos); line = word_complete(active_win, text, &pos, erase, backward); g_free(text); @@ -1123,17 +1122,17 @@ static void key_completion(int erase, int backward) static void key_word_completion_backward(void) { - key_completion(FALSE, TRUE); + key_completion(FALSE, TRUE); } static void key_word_completion(void) { - key_completion(FALSE, FALSE); + key_completion(FALSE, FALSE); } static void key_erase_completion(void) { - key_completion(TRUE, FALSE); + key_completion(TRUE, FALSE); } static void key_check_replaces(void) @@ -1141,7 +1140,7 @@ static void key_check_replaces(void) char *text, *line; int pos; - text = gui_entry_get_text_and_pos(active_entry, &pos); + text = gui_entry_get_text_and_pos(active_entry, &pos); line = auto_word_complete(text, &pos); g_free(text); @@ -1153,7 +1152,8 @@ static void key_check_replaces(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) @@ -1183,7 +1183,8 @@ static void key_lower_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) @@ -1191,9 +1192,9 @@ static SERVER_REC *get_prev_server(SERVER_REC *current) int pos; if (current == NULL) { - return servers != NULL ? g_slist_last(servers)->data : - lookup_servers != NULL ? - g_slist_last(lookup_servers)->data : NULL; + return servers != NULL ? g_slist_last(servers)->data : + lookup_servers != NULL ? g_slist_last(lookup_servers)->data : + NULL; } /* connect2 -> connect1 -> server2 -> server1 -> connect2 -> .. */ @@ -1201,7 +1202,7 @@ static SERVER_REC *get_prev_server(SERVER_REC *current) pos = g_slist_index(servers, current); if (pos != -1) { if (pos > 0) - return g_slist_nth(servers, pos-1)->data; + return g_slist_nth(servers, pos - 1)->data; if (lookup_servers != NULL) return g_slist_last(lookup_servers)->data; return g_slist_last(servers)->data; @@ -1211,7 +1212,7 @@ static SERVER_REC *get_prev_server(SERVER_REC *current) g_assert(pos >= 0); if (pos > 0) - return g_slist_nth(lookup_servers, pos-1)->data; + return g_slist_nth(lookup_servers, pos - 1)->data; if (servers != NULL) return g_slist_last(servers)->data; return g_slist_last(lookup_servers)->data; @@ -1222,8 +1223,9 @@ static SERVER_REC *get_next_server(SERVER_REC *current) GSList *pos; if (current == NULL) { - return servers != NULL ? servers->data : - lookup_servers != NULL ? lookup_servers->data : NULL; + return servers != NULL ? servers->data : + lookup_servers != NULL ? lookup_servers->data : + NULL; } /* server1 -> server2 -> connect1 -> connect2 -> server1 -> .. */ @@ -1252,16 +1254,16 @@ static void key_previous_window_item(void) SERVER_REC *server; if (active_win->items != NULL) { - signal_emit("command window item prev", 3, "", - active_win->active_server, active_win->active); + signal_emit("command window item prev", 3, "", active_win->active_server, + active_win->active); } else if (servers != NULL || lookup_servers != NULL) { /* change server */ server = active_win->active_server; if (server == NULL) server = active_win->connect_server; server = get_prev_server(server); - signal_emit("command window server", 3, server->tag, - active_win->active_server, active_win->active); + signal_emit("command window server", 3, server->tag, active_win->active_server, + active_win->active); } } @@ -1270,37 +1272,37 @@ static void key_next_window_item(void) SERVER_REC *server; if (active_win->items != NULL) { - signal_emit("command window item next", 3, "", - active_win->active_server, active_win->active); + signal_emit("command window item next", 3, "", active_win->active_server, + active_win->active); } else if (servers != NULL || lookup_servers != NULL) { /* change server */ server = active_win->active_server; if (server == NULL) server = active_win->connect_server; server = get_next_server(server); - signal_emit("command window server", 3, server->tag, - active_win->active_server, active_win->active); + signal_emit("command window server", 3, server->tag, active_win->active_server, + active_win->active); } } static void key_escape(void) { - escape_next_key = TRUE; + escape_next_key = TRUE; } static void key_insert_text(const char *data) { char *str; - str = parse_special_string(data, active_win->active_server, - active_win->active, "", NULL, 0); + str = + parse_special_string(data, active_win->active_server, active_win->active, "", NULL, 0); gui_entry_insert_text(active_entry, str); - g_free(str); + g_free(str); } static void key_sig_stop(void) { - term_stop(); + term_stop(); } static void sig_window_auto_changed(void) @@ -1310,14 +1312,13 @@ static void sig_window_auto_changed(void) if (active_entry == NULL) return; - text = gui_entry_get_text(active_entry); + text = gui_entry_get_text(active_entry); command_history_next(active_win, text); gui_entry_set_text(active_entry, ""); - g_free(text); + g_free(text); } -static void sig_gui_entry_redirect(SIGNAL_FUNC func, const char *entry, - void *flags, void *data) +static void sig_gui_entry_redirect(SIGNAL_FUNC func, const char *entry, void *flags, void *data) { redir = g_new0(ENTRY_REDIRECT_REC, 1); redir->func = func; @@ -1351,13 +1352,13 @@ void gui_readline_init(void) char *key, data[MAX_INT_STRLEN]; int n; - escape_next_key = FALSE; + escape_next_key = FALSE; redir = NULL; paste_entry = NULL; paste_entry_pos = 0; paste_buffer = g_array_new(FALSE, FALSE, sizeof(unichar)); paste_buffer_rest = g_array_new(FALSE, FALSE, sizeof(unichar)); - paste_old_prompt = NULL; + paste_old_prompt = NULL; paste_timeout_id = -1; paste_bracketed_mode = FALSE; last_keypress = g_get_real_time(); @@ -1375,7 +1376,7 @@ void gui_readline_init(void) setup_changed(); keyboard = keyboard_create(NULL); - key_configure_freeze(); + key_configure_freeze(); key_bind("key", NULL, " ", "space", (SIGNAL_FUNC) key_combo); key_bind("key", NULL, "^M", "return", (SIGNAL_FUNC) key_combo); @@ -1385,13 +1386,13 @@ void gui_readline_init(void) key_bind("key", NULL, "^I", "tab", (SIGNAL_FUNC) key_combo); key_bind("key", NULL, "meta2-Z", "stab", (SIGNAL_FUNC) key_combo); - /* meta */ + /* meta */ key_bind("key", NULL, "^[", "meta", (SIGNAL_FUNC) key_combo); key_bind("key", NULL, "meta-[", "meta2", (SIGNAL_FUNC) key_combo); key_bind("key", NULL, "meta-O", "meta2", (SIGNAL_FUNC) key_combo); key_bind("key", NULL, "meta-[O", "meta2", (SIGNAL_FUNC) key_combo); - /* arrow keys */ + /* arrow keys */ key_bind("key", NULL, "meta2-A", "up", (SIGNAL_FUNC) key_combo); key_bind("key", NULL, "meta2-B", "down", (SIGNAL_FUNC) key_combo); key_bind("key", NULL, "meta2-C", "right", (SIGNAL_FUNC) key_combo); @@ -1527,18 +1528,19 @@ void gui_readline_init(void) key_bind("multi", NULL, "return", "check_replaces;send_line", NULL); key_bind("multi", NULL, "space", "check_replaces;insert_text ", NULL); - /* moving between windows */ + /* moving between windows */ for (n = 0; changekeys[n] != '\0'; n++) { key = g_strdup_printf("meta-%c", changekeys[n]); - ltoa(data, n+1); - key_bind("change_window", "Change window", key, data, (SIGNAL_FUNC) key_change_window); + ltoa(data, n + 1); + key_bind("change_window", "Change window", key, data, + (SIGNAL_FUNC) key_change_window); g_free(key); } - /* misc */ + /* misc */ key_bind("stop_irc", "Send SIGSTOP to client", "^Z", NULL, (SIGNAL_FUNC) key_sig_stop); - key_configure_thaw(); + key_configure_thaw(); signal_add("window changed automatic", (SIGNAL_FUNC) sig_window_auto_changed); signal_add("gui entry redirect", (SIGNAL_FUNC) sig_gui_entry_redirect); @@ -1548,9 +1550,9 @@ void gui_readline_init(void) void gui_readline_deinit(void) { - input_listen_deinit(); + input_listen_deinit(); - key_configure_freeze(); + key_configure_freeze(); key_unbind("paste_start", (SIGNAL_FUNC) key_paste_start); key_unbind("paste_cancel", (SIGNAL_FUNC) key_paste_cancel); @@ -1561,9 +1563,9 @@ void gui_readline_deinit(void) key_unbind("backward_character", (SIGNAL_FUNC) key_backward_character); key_unbind("forward_character", (SIGNAL_FUNC) key_forward_character); - key_unbind("backward_word", (SIGNAL_FUNC) key_backward_word); + key_unbind("backward_word", (SIGNAL_FUNC) key_backward_word); key_unbind("forward_word", (SIGNAL_FUNC) key_forward_word); - key_unbind("backward_to_space", (SIGNAL_FUNC) key_backward_to_space); + key_unbind("backward_to_space", (SIGNAL_FUNC) key_backward_to_space); key_unbind("forward_to_space", (SIGNAL_FUNC) key_forward_to_space); key_unbind("beginning_of_line", (SIGNAL_FUNC) key_beginning_of_line); key_unbind("end_of_line", (SIGNAL_FUNC) key_end_of_line); @@ -1620,10 +1622,10 @@ void gui_readline_deinit(void) key_unbind("change_window", (SIGNAL_FUNC) key_change_window); key_unbind("stop_irc", (SIGNAL_FUNC) key_sig_stop); keyboard_destroy(keyboard); - g_array_free(paste_buffer, TRUE); - g_array_free(paste_buffer_rest, TRUE); + g_array_free(paste_buffer, TRUE); + g_array_free(paste_buffer_rest, TRUE); - key_configure_thaw(); + key_configure_thaw(); signal_remove("window changed automatic", (SIGNAL_FUNC) sig_window_auto_changed); signal_remove("gui entry redirect", (SIGNAL_FUNC) sig_gui_entry_redirect); diff --git a/src/fe-text/irssi.c b/src/fe-text/irssi.c index 42c4a121..19e705e2 100644 --- a/src/fe-text/irssi.c +++ b/src/fe-text/irssi.c @@ -76,10 +76,9 @@ int quitting; static int display_firsttimer = FALSE; static unsigned int user_settings_changed = 0; - static void sig_exit(void) { - quitting = TRUE; + quitting = TRUE; } static void sig_settings_userinfo_changed(gpointer changedp) @@ -106,12 +105,12 @@ static void sig_autoload_modules(void) void irssi_redraw(void) { dirty = TRUE; - full_redraw = TRUE; + full_redraw = TRUE; } void irssi_set_dirty(void) { - dirty = TRUE; + dirty = TRUE; } static void dirty_check(void) @@ -119,10 +118,10 @@ static void dirty_check(void) if (!dirty) return; - term_resize_dirty(); + term_resize_dirty(); if (full_redraw) { - full_redraw = FALSE; + full_redraw = FALSE; /* first clear the screen so curses will be forced to redraw the screen */ @@ -134,10 +133,10 @@ static void dirty_check(void) } mainwindows_redraw_dirty(); - statusbar_redraw_dirty(); + statusbar_redraw_dirty(); term_refresh(NULL); - dirty = FALSE; + dirty = FALSE; } static void textui_init(void) @@ -212,11 +211,11 @@ static void textui_finish_init(void) statusbar_redraw(NULL, TRUE); if (servers == NULL && lookup_servers == NULL) { - printformat(NULL, NULL, MSGLEVEL_CRAP|MSGLEVEL_NO_ACT, TXT_IRSSI_BANNER); + printformat(NULL, NULL, MSGLEVEL_CRAP | MSGLEVEL_NO_ACT, TXT_IRSSI_BANNER); } if (display_firsttimer) { - printformat(NULL, NULL, MSGLEVEL_CRAP|MSGLEVEL_NO_ACT, TXT_WELCOME_FIRSTTIME); + printformat(NULL, NULL, MSGLEVEL_CRAP | MSGLEVEL_NO_ACT, TXT_WELCOME_FIRSTTIME); } /* see irc-servers-setup.c:init_userinfo */ @@ -238,7 +237,7 @@ static void textui_deinit(void) { signal(SIGINT, SIG_DFL); - term_refresh_freeze(); + term_refresh_freeze(); while (modules != NULL) module_unload(modules->data); @@ -285,10 +284,9 @@ static void check_files(void) int main(int argc, char **argv) { static int version = 0; - static GOptionEntry options[] = { - { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Display Irssi version", NULL }, - { NULL } - }; + static GOptionEntry options[] = { { "version", 'v', 0, G_OPTION_ARG_NONE, &version, + "Display Irssi version", NULL }, + { NULL } }; int loglev; core_register_options(); @@ -296,9 +294,9 @@ int main(int argc, char **argv) args_register(options); args_execute(argc, argv); - if (version) { - printf(PACKAGE_TARNAME" " PACKAGE_VERSION" (%d %04d)\n", - IRSSI_VERSION_DATE, IRSSI_VERSION_TIME); + if (version) { + printf(PACKAGE_TARNAME " " PACKAGE_VERSION " (%d %04d)\n", IRSSI_VERSION_DATE, + IRSSI_VERSION_TIME); return 0; } @@ -347,8 +345,7 @@ int main(int argc, char **argv) if (settings_get_bool("quit_on_hup")) { signal_emit("gui exit", 0); - } - else { + } else { signal_emit("command reload", 1, ""); } } diff --git a/src/fe-text/mainwindows-layout.c b/src/fe-text/mainwindows-layout.c index 7cbf2e66..df02f0a3 100644 --- a/src/fe-text/mainwindows-layout.c +++ b/src/fe-text/mainwindows-layout.c @@ -32,9 +32,9 @@ static void sig_layout_window_save(WINDOW_REC *window, CONFIG_NODE *node) { WINDOW_REC *active; - GUI_WINDOW_REC *gui; + GUI_WINDOW_REC *gui; - gui = WINDOW_GUI(window); + gui = WINDOW_GUI(window); if (gui->sticky) { iconfig_node_set_bool(node, "sticky", TRUE); active = gui->parent->active; @@ -51,7 +51,7 @@ static void sig_layout_window_save(WINDOW_REC *window, CONFIG_NODE *node) } if (gui->use_scroll) - iconfig_node_set_bool(node, "scroll", gui->scroll); + iconfig_node_set_bool(node, "scroll", gui->scroll); } static void sig_layout_window_restore(WINDOW_REC *window, CONFIG_NODE *node) @@ -69,7 +69,8 @@ static void sig_layout_window_restore(WINDOW_REC *window, CONFIG_NODE *node) if (config_node_get_bool(node, "sticky", FALSE)) 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) { gui->use_scroll = TRUE; @@ -80,9 +81,9 @@ static void sig_layout_window_restore(WINDOW_REC *window, CONFIG_NODE *node) static void main_window_save(MAIN_WINDOW_REC *window, CONFIG_NODE *node) { - char num[MAX_INT_STRLEN]; + char num[MAX_INT_STRLEN]; - ltoa(num, window->active->refnum); + ltoa(num, window->active->refnum); node = iconfig_node_section(node, num, NODE_TYPE_BLOCK); iconfig_node_set_int(node, "first_line", window->first_line); @@ -104,15 +105,13 @@ static void sig_layout_save(void) static int window_node_cmp(CONFIG_NODE *n1, CONFIG_NODE *n2) { return (config_node_get_int(n1, "first_line", 0) == - config_node_get_int(n2, "first_line", 0) - && - config_node_get_int(n1, "first_column", 0) > - config_node_get_int(n2, "first_column", 0) - ) || - config_node_get_int(n1, "first_line", 0) > - config_node_get_int(n2, "first_line", 0) - ? -1 - : 1; + config_node_get_int(n2, "first_line", 0) && + config_node_get_int(n1, "first_column", 0) > + config_node_get_int(n2, "first_column", 0)) || + config_node_get_int(n1, "first_line", 0) > + config_node_get_int(n2, "first_line", 0) ? + -1 : + 1; } /* Returns list of mainwindow nodes sorted by first_line @@ -121,14 +120,13 @@ static GSList *get_sorted_windows_config(CONFIG_NODE *node) { GSList *tmp, *output; - output = NULL; + output = NULL; tmp = config_node_first(node->value); for (; tmp != NULL; tmp = config_node_next(tmp)) { - output = g_slist_insert_sorted(output, tmp->data, - (GCompareFunc) window_node_cmp); + output = g_slist_insert_sorted(output, tmp->data, (GCompareFunc) window_node_cmp); } - return output; + return output; } static GSList *get_windows_config_filter_line(GSList *in) @@ -172,17 +170,18 @@ static void sig_layout_restore(void) int i, lower_size, lines_count, columns_count, diff; node = iconfig_node_traverse("mainwindows", FALSE); - if (node == NULL) return; + if (node == NULL) + return; 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_count = g_slist_length(lines_config); /* calculate the saved terminal height */ - avail_height = term_height - - screen_reserved_top - screen_reserved_bottom; + avail_height = term_height - screen_reserved_top - screen_reserved_bottom; height = 0; heights = g_new0(int, lines_count); for (i = 0, tmp = lines_config; tmp != NULL; tmp = tmp->next, i++) { @@ -196,7 +195,7 @@ static void sig_layout_restore(void) if (max_wins_line < 1) max_wins_line = 1; - if (avail_height <= (WINDOW_MIN_SIZE*2)+1) { + if (avail_height <= (WINDOW_MIN_SIZE * 2) + 1) { /* we can fit only one window to screen - give it all the height we can */ lines_count = 1; @@ -205,7 +204,7 @@ static void sig_layout_restore(void) /* Terminal's height is different from the saved one. Resize the windows so they fit to screen. */ while (height > avail_height && - lines_count*(WINDOW_MIN_SIZE+1) > avail_height) { + lines_count * (WINDOW_MIN_SIZE + 1) > avail_height) { /* all windows can't fit into screen, remove the lowest ones */ lines_count--; @@ -213,9 +212,9 @@ static void sig_layout_restore(void) /* try to keep the windows' size about the same in percents */ for (i = 0; i < lines_count; i++) { - int size = avail_height*heights[i]/height; - if (size < WINDOW_MIN_SIZE+1) - size = WINDOW_MIN_SIZE+1; + int size = avail_height * heights[i] / height; + if (size < WINDOW_MIN_SIZE + 1) + size = WINDOW_MIN_SIZE + 1; heights[i] = size; } @@ -229,7 +228,7 @@ static void sig_layout_restore(void) if (i == lines_count) i = 0; - if (heights[i] > WINDOW_MIN_SIZE+1) { + if (heights[i] > WINDOW_MIN_SIZE + 1) { height += diff; heights[i] += diff; } @@ -237,28 +236,35 @@ static void sig_layout_restore(void) } /* 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++) { GSList *tmp2, *columns_config, *line; int j, l1, l2; CONFIG_NODE *node = tmp->data; - if (node->key == NULL) continue; + if (node->key == NULL) + continue; l1 = config_node_get_int(node, "first_line", -1); l2 = l1 + config_node_get_int(node, "lines", 0) - 1; 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); - 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; WINDOW_REC *new_win; CONFIG_NODE *node2 = tmp2->data; - if (node2->key == NULL) continue; + if (node2->key == NULL) + continue; /* create a new window + mainwindow */ 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); @@ -279,7 +285,8 @@ static void sig_layout_restore(void) continue; line = g_slist_reverse(mainwindows_get_line(WINDOW_MAIN(window))); 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; mainwindow_set_rsize(rec, width); } @@ -291,8 +298,8 @@ static void sig_layout_restore(void) lower_window = WINDOW_MAIN(window); lower_size = heights[i]; - if (lower_size < WINDOW_MIN_SIZE+1) - lower_size = WINDOW_MIN_SIZE+1; + if (lower_size < WINDOW_MIN_SIZE + 1) + lower_size = WINDOW_MIN_SIZE + 1; } g_slist_free(sorted_config); g_free(heights); diff --git a/src/fe-text/mainwindows.c b/src/fe-text/mainwindows.c index 31c5d759..f34caad2 100644 --- a/src/fe-text/mainwindows.c +++ b/src/fe-text/mainwindows.c @@ -41,19 +41,18 @@ int screen_reserved_left, screen_reserved_right; static int screen_width, screen_height; static int screen_collapsed = 0; /* see mainwindows_resize */ -#define mainwindow_create_screen(window) \ - term_window_create((window)->first_column + (window)->statusbar_columns_left, \ - (window)->first_line + (window)->statusbar_lines_top, \ - (window)->width - (window)->statusbar_columns, \ - (window)->height - (window)->statusbar_lines) - -#define mainwindow_set_screen_size(window) \ - term_window_move((window)->screen_win, \ - (window)->first_column + (window)->statusbar_columns_left, \ - (window)->first_line + (window)->statusbar_lines_top, \ - (window)->width - (window)->statusbar_columns, \ - (window)->height - (window)->statusbar_lines); +#define mainwindow_create_screen(window) \ + term_window_create((window)->first_column + (window)->statusbar_columns_left, \ + (window)->first_line + (window)->statusbar_lines_top, \ + (window)->width - (window)->statusbar_columns, \ + (window)->height - (window)->statusbar_lines) +#define mainwindow_set_screen_size(window) \ + term_window_move((window)->screen_win, \ + (window)->first_column + (window)->statusbar_columns_left, \ + (window)->first_line + (window)->statusbar_lines_top, \ + (window)->width - (window)->statusbar_columns, \ + (window)->height - (window)->statusbar_lines); static MAIN_WINDOW_REC *find_window_with_room() { @@ -61,12 +60,13 @@ static MAIN_WINDOW_REC *find_window_with_room() GSList *tmp; int space, biggest; - biggest = 0; biggest_rec = NULL; + biggest = 0; + biggest_rec = NULL; for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) { MAIN_WINDOW_REC *rec = tmp->data; space = MAIN_WINDOW_TEXT_HEIGHT(rec); - if (space >= WINDOW_MIN_SIZE+NEW_WINDOW_SIZE && space > biggest) { + if (space >= WINDOW_MIN_SIZE + NEW_WINDOW_SIZE && space > biggest) { biggest = space; biggest_rec = rec; } @@ -81,7 +81,8 @@ static MAIN_WINDOW_REC *find_window_with_room_right(void) GSList *tmp; int space, biggest; - biggest = 0; biggest_rec = NULL; + biggest = 0; + biggest_rec = NULL; for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) { MAIN_WINDOW_REC *rec = tmp->data; @@ -95,8 +96,8 @@ static MAIN_WINDOW_REC *find_window_with_room_right(void) return biggest_rec; } -#define window_size_equals(window, mainwin) \ - ((window)->width == MAIN_WINDOW_TEXT_WIDTH(mainwin) && \ +#define window_size_equals(window, mainwin) \ + ((window)->width == MAIN_WINDOW_TEXT_WIDTH(mainwin) && \ (window)->height == MAIN_WINDOW_TEXT_HEIGHT(mainwin)) static void mainwindow_resize_windows(MAIN_WINDOW_REC *window) @@ -110,8 +111,10 @@ static void mainwindow_resize_windows(MAIN_WINDOW_REC *window) int sy = window->first_line + window->statusbar_lines_top; int sw = window->width - window->statusbar_columns; int sh = window->height - window->statusbar_lines; - if (sw < 1) sw = 1; - if (sh < 1) sh = 1; + if (sw < 1) + sw = 1; + if (sh < 1) + sh = 1; 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) { WINDOW_REC *rec = tmp->data; - if (rec->gui_data != NULL && - WINDOW_GUI(rec)->parent == window && + if (rec->gui_data != NULL && WINDOW_GUI(rec)->parent == window && !window_size_equals(rec, window)) { { int tw = MAIN_WINDOW_TEXT_WIDTH(window); int th = MAIN_WINDOW_TEXT_HEIGHT(window); - if (tw < 1) tw = 1; - if (th < 1) th = 1; + if (tw < 1) + tw = 1; + if (th < 1) + th = 1; resized = TRUE; gui_window_resize(rec, tw, th); } @@ -145,11 +149,11 @@ static void mainwindow_resize(MAIN_WINDOW_REC *window, int xdiff, int ydiff) height = window->height + ydiff; width = window->width + xdiff; - window->width = window->last_column-window->first_column+1; - window->height = window->last_line-window->first_line+1; + window->width = window->last_column - window->first_column + 1; + window->height = window->last_line - window->first_line + 1; if (height != window->height || width != window->width) { - g_warning("Resizing window %p W:%d expected:%d H:%d expected:%d", - window, window->width, width, window->height, height); + g_warning("Resizing window %p W:%d expected:%d H:%d expected:%d", window, + window->width, width, window->height, height); } window->size_dirty = TRUE; } @@ -158,35 +162,32 @@ static GSList *get_sticky_windows_sorted(MAIN_WINDOW_REC *mainwin) { GSList *tmp, *list; - list = NULL; + list = NULL; for (tmp = windows; tmp != NULL; tmp = tmp->next) { WINDOW_REC *rec = tmp->data; if (WINDOW_GUI(rec)->sticky && WINDOW_MAIN(rec) == mainwin) { - list = g_slist_insert_sorted(list, rec, (GCompareFunc) - window_refnum_cmp); + list = g_slist_insert_sorted(list, rec, (GCompareFunc) window_refnum_cmp); } } - return list; + return list; } -void mainwindow_change_active(MAIN_WINDOW_REC *mainwin, - WINDOW_REC *skip_window) +void mainwindow_change_active(MAIN_WINDOW_REC *mainwin, WINDOW_REC *skip_window) { - WINDOW_REC *window, *other; + WINDOW_REC *window, *other; GSList *tmp; - mainwin->active = NULL; + mainwin->active = NULL; if (mainwin->sticky_windows) { /* sticky window */ - tmp = get_sticky_windows_sorted(mainwin); - window = tmp->data; + tmp = get_sticky_windows_sorted(mainwin); + window = tmp->data; if (window == skip_window) { - window = tmp->next == NULL ? NULL : - tmp->next->data; + window = tmp->next == NULL ? NULL : tmp->next->data; } - g_slist_free(tmp); + g_slist_free(tmp); if (window != NULL) { window_set_active(window); @@ -194,7 +195,7 @@ void mainwindow_change_active(MAIN_WINDOW_REC *mainwin, } } - other = NULL; + other = NULL; for (tmp = windows; tmp != NULL; tmp = tmp->next) { WINDOW_REC *rec = tmp->data; @@ -217,9 +218,8 @@ void mainwindows_recreate(void) MAIN_WINDOW_REC *rec = tmp->data; rec->screen_win = mainwindow_create_screen(rec); - rec->dirty = TRUE; - textbuffer_view_set_window(WINDOW_GUI(rec->active)->view, - rec->screen_win); + rec->dirty = TRUE; + textbuffer_view_set_window(WINDOW_GUI(rec->active)->view, rec->screen_win); } } @@ -235,18 +235,17 @@ MAIN_WINDOW_REC *mainwindow_create(int right) active_mainwin = rec; rec->first_line = screen_reserved_top; - rec->last_line = term_height-1 - screen_reserved_bottom; - rec->height = rec->last_line-rec->first_line+1; + rec->last_line = term_height - 1 - screen_reserved_bottom; + rec->height = rec->last_line - rec->first_line + 1; rec->first_column = screen_reserved_left; - rec->last_column = screen_width-1 - screen_reserved_right; - rec->width = rec->last_column-rec->first_column+1; + rec->last_column = screen_width - 1 - screen_reserved_right; + rec->width = rec->last_column - rec->first_column + 1; } else { parent = WINDOW_MAIN(active_win); if (!right) { GSList *tmp, *line; - if (MAIN_WINDOW_TEXT_HEIGHT(parent) < - WINDOW_MIN_SIZE+NEW_WINDOW_SIZE) + if (MAIN_WINDOW_TEXT_HEIGHT(parent) < WINDOW_MIN_SIZE + NEW_WINDOW_SIZE) parent = find_window_with_room(); if (parent == NULL) { g_free(rec); @@ -256,16 +255,16 @@ MAIN_WINDOW_REC *mainwindow_create(int right) space = parent->height / 2; rec->first_line = parent->first_line; rec->last_line = rec->first_line + space; - rec->height = rec->last_line-rec->first_line+1; + rec->height = rec->last_line - rec->first_line + 1; rec->first_column = screen_reserved_left; - rec->last_column = screen_width-1 - screen_reserved_right; - rec->width = rec->last_column-rec->first_column+1; + rec->last_column = screen_width - 1 - screen_reserved_right; + rec->width = rec->last_column - rec->first_column + 1; line = mainwindows_get_line(parent); for (tmp = line; tmp != NULL; tmp = tmp->next) { MAIN_WINDOW_REC *rec = tmp->data; - rec->first_line += space+1; - mainwindow_resize(rec, 0, -space-1); + rec->first_line += space + 1; + mainwindow_resize(rec, 0, -space - 1); } g_slist_free(line); } else { @@ -283,10 +282,10 @@ MAIN_WINDOW_REC *mainwindow_create(int right) rec->height = parent->height; rec->first_column = parent->last_column - space + 1; rec->last_column = parent->last_column; - rec->width = rec->last_column-rec->first_column+1; + rec->width = rec->last_column - rec->first_column + 1; - parent->last_column -= space+1; - mainwindow_resize(parent, -space-1, 0); + parent->last_column -= space + 1; + mainwindow_resize(parent, -space - 1, 0); } } @@ -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) { MAIN_WINDOW_REC *rec = tmp->data; - if (rec->first_line >= first_line && - rec->last_line <= last_line && + if (rec->first_line >= first_line && rec->last_line <= last_line && rec->first_column > last_column && (best == NULL || rec->first_column < best->first_column)) 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) { MAIN_WINDOW_REC *rec = tmp->data; - if (rec->first_line >= first_line && - rec->last_line <= last_line && + if (rec->first_line >= first_line && rec->last_line <= last_line && rec->last_column < first_column && (best == NULL || rec->last_column > best->last_column)) best = rec; @@ -452,8 +449,7 @@ GSList *mainwindows_get_line(MAIN_WINDOW_REC *rec) list = NULL; - for (win = mainwindows_find_left(rec, FALSE); - win != NULL; + for (win = mainwindows_find_left(rec, FALSE); win != NULL; win = mainwindows_find_left(win, FALSE)) { list = g_slist_append(list, win); } @@ -461,8 +457,7 @@ GSList *mainwindows_get_line(MAIN_WINDOW_REC *rec) if (rec != NULL) list = g_slist_append(list, rec); - for (win = mainwindows_find_right(rec, FALSE); - win != NULL; + for (win = mainwindows_find_right(rec, FALSE); win != NULL; win = mainwindows_find_right(win, FALSE)) { list = g_slist_append(list, win); } @@ -482,22 +477,22 @@ static void mainwindows_add_space(MAIN_WINDOW_REC *destroy_win) if (destroy_win->last_column < destroy_win->first_column) return; - rsize = destroy_win->last_column-destroy_win->first_column+1; + rsize = destroy_win->last_column - destroy_win->first_column + 1; rec = mainwindows_find_left(destroy_win, FALSE); if (rec != NULL) { rec->last_column = destroy_win->last_column; - mainwindow_resize(rec, rsize+1, 0); + mainwindow_resize(rec, rsize + 1, 0); return; } rec = mainwindows_find_right(destroy_win, FALSE); if (rec != NULL) { rec->first_column = destroy_win->first_column; - mainwindow_resize(rec, rsize+1, 0); + mainwindow_resize(rec, rsize + 1, 0); return; } - size = destroy_win->last_line-destroy_win->first_line+1; + size = destroy_win->last_line - destroy_win->first_line + 1; rec = mainwindows_find_lower(destroy_win); if (rec != NULL) { @@ -532,15 +527,15 @@ static void mainwindows_add_space(MAIN_WINDOW_REC *destroy_win) static void gui_windows_remove_parent(MAIN_WINDOW_REC *window) { - MAIN_WINDOW_REC *new_parent; + MAIN_WINDOW_REC *new_parent; GSList *tmp; - new_parent = mainwindows->data; + new_parent = mainwindows->data; for (tmp = windows; tmp != NULL; tmp = tmp->next) { WINDOW_REC *rec = tmp->data; if (rec->gui_data != NULL && WINDOW_MAIN(rec) == window) - gui_window_reparent(rec, new_parent); + gui_window_reparent(rec, new_parent); } } @@ -551,7 +546,7 @@ static void mainwindow_destroy_full(MAIN_WINDOW_REC *window, int respace) mainwindows = g_slist_remove(mainwindows, window); signal_emit("mainwindow destroyed", 1, window); - term_window_destroy(window->screen_win); + term_window_destroy(window->screen_win); if (mainwindows != NULL) { gui_windows_remove_parent(window); @@ -563,7 +558,8 @@ static void mainwindow_destroy_full(MAIN_WINDOW_REC *window, int respace) g_free(window); - if (active_mainwin == window) active_mainwin = NULL; + if (active_mainwin == window) + active_mainwin = NULL; } void mainwindow_destroy(MAIN_WINDOW_REC *window) @@ -578,32 +574,32 @@ void mainwindow_destroy_half(MAIN_WINDOW_REC *window) void mainwindows_redraw(void) { - GSList *tmp; + GSList *tmp; - irssi_set_dirty(); + irssi_set_dirty(); for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) { MAIN_WINDOW_REC *rec = tmp->data; - rec->dirty = TRUE; + rec->dirty = TRUE; } } static int mainwindows_compare(MAIN_WINDOW_REC *w1, MAIN_WINDOW_REC *w2) { - return 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 - : 0; + return 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 : + 0; } static int mainwindows_compare_reverse(MAIN_WINDOW_REC *w1, MAIN_WINDOW_REC *w2) { - return 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 - : 0; + return 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 : + 0; } GSList *mainwindows_get_sorted(int reverse) @@ -612,8 +608,9 @@ GSList *mainwindows_get_sorted(int reverse) list = NULL; for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) { - list = g_slist_insert_sorted(list, tmp->data, (GCompareFunc) - (reverse ? mainwindows_compare_reverse : mainwindows_compare)); + list = g_slist_insert_sorted( + list, tmp->data, + (GCompareFunc) (reverse ? mainwindows_compare_reverse : mainwindows_compare)); } return list; @@ -626,9 +623,7 @@ static void mainwindows_resize_smaller(int ydiff) int space; sorted = NULL; - for (rec = mainwindows_find_lower(NULL); - rec != NULL; - rec = mainwindows_find_lower(rec)) { + for (rec = mainwindows_find_lower(NULL); rec != NULL; rec = mainwindows_find_lower(rec)) { sorted = g_slist_prepend(sorted, rec); } if (sorted == NULL) @@ -650,7 +645,7 @@ static void mainwindows_resize_smaller(int ydiff) if (win == active_mainwin && tmp == sorted) skip_active = TRUE; - lmin = MAIN_WINDOW_TEXT_HEIGHT(win)-WINDOW_MIN_SIZE; + lmin = MAIN_WINDOW_TEXT_HEIGHT(win) - WINDOW_MIN_SIZE; if (lmin < min) min = lmin; } @@ -701,7 +696,7 @@ static void mainwindows_resize_smaller(int ydiff) for (ltmp = line; ltmp != NULL; ltmp = ltmp->next) { int lmin; MAIN_WINDOW_REC *win = ltmp->data; - lmin = MAIN_WINDOW_TEXT_HEIGHT(win)-WINDOW_MIN_SIZE; + lmin = MAIN_WINDOW_TEXT_HEIGHT(win) - WINDOW_MIN_SIZE; if (lmin < min) min = lmin; } @@ -718,7 +713,8 @@ static void mainwindows_resize_smaller(int ydiff) signal_emit("mainwindow moved", 1, win); } } else { - if (space > -ydiff) space = -ydiff; + if (space > -ydiff) + space = -ydiff; for (ltmp = line; ltmp != NULL; ltmp = ltmp->next) { MAIN_WINDOW_REC *win = ltmp->data; win->last_line += ydiff; @@ -747,18 +743,21 @@ static void mainwindows_rresize_line(int xdiff, MAIN_WINDOW_REC *win) /* Available text width on this line should respect globally reserved columns */ 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; for (tmp = line, i = 0; tmp != NULL; tmp = tmp->next, i++) { MAIN_WINDOW_REC *rec = tmp->data; - /* Scale each window proportionally based on available text widths (excluding reserved columns) */ - widths[i] = old_avail > 0 ? (MAIN_WINDOW_TEXT_WIDTH(rec) * new_avail) / old_avail : MAIN_WINDOW_TEXT_WIDTH(rec); + /* Scale each window proportionally based on available text widths (excluding + * 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; } shrunk = FALSE; for (i = windows; extra_width < 0; i = i > 1 ? i - 1 : windows) { - if (widths[i-1] > NEW_WINDOW_WIDTH || (i == 1 && !shrunk)) { - widths[i-1]--; + if (widths[i - 1] > NEW_WINDOW_WIDTH || (i == 1 && !shrunk)) { + widths[i - 1]--; extra_width++; shrunk = i == 1; } @@ -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 */ width_mod = new_avail % windows; -#define extra ( (i >= width_mod && i < extra_width + width_mod) \ - || i + windows < extra_width + width_mod ? 1 : 0 ) +#define extra \ + ((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++) { MAIN_WINDOW_REC *rec = tmp->data; @@ -779,13 +781,16 @@ static void mainwindows_rresize_line(int xdiff, MAIN_WINDOW_REC *win) if (is_last) { /* Anchor rightmost window to reserved-right boundary to avoid gap/lag */ 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 { - 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 */ if (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; next_column = rec->last_column + 2; @@ -800,8 +805,8 @@ void mainwindows_resize(int width, int height) { int xdiff, ydiff; - xdiff = width-screen_width; - ydiff = height-screen_height; + xdiff = width - screen_width; + ydiff = height - screen_height; screen_width = width; screen_height = height; @@ -811,7 +816,8 @@ void mainwindows_resize(int width, int height) int avail_h = screen_height - screen_reserved_top - screen_reserved_bottom; if (avail_w <= 1 || avail_h <= 1) { GSList *tmp; - if (!screen_collapsed) screen_collapsed = 1; + if (!screen_collapsed) + screen_collapsed = 1; for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) { MAIN_WINDOW_REC *rec = tmp->data; rec->first_column = screen_reserved_left; @@ -830,7 +836,8 @@ void mainwindows_resize(int width, int height) /* Recover from collapsed state: reflow horizontally. */ MAIN_WINDOW_REC *win; 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); } irssi_set_dirty(); @@ -854,8 +861,7 @@ void mainwindows_resize(int width, int height) /* algorithm: distribute new space on each line */ MAIN_WINDOW_REC *win; - for (win = mainwindows_find_lower(NULL); - win != NULL; + for (win = mainwindows_find_lower(NULL); win != NULL; win = mainwindows_find_lower(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 */ MAIN_WINDOW_REC *win; - for (win = mainwindows_find_lower(NULL); - win != NULL; + for (win = mainwindows_find_lower(NULL); win != NULL; win = mainwindows_find_lower(win)) { int max_windows, i, last_column; GSList *line, *tmp; line = mainwindows_get_line(win); /* 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) max_windows = 1; last_column = screen_width - 1 - screen_reserved_right; @@ -888,7 +895,8 @@ void mainwindows_resize(int width, int height) win = line->data; 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,32 +958,30 @@ int mainwindows_reserve_lines(int top, int bottom) return ret; } -int mainwindow_set_statusbar_lines(MAIN_WINDOW_REC *window, - int top, int bottom) +int mainwindow_set_statusbar_lines(MAIN_WINDOW_REC *window, int top, int bottom) { int ret; - ret = -1; + ret = -1; if (top != 0) { - ret = window->statusbar_lines_top; + ret = window->statusbar_lines_top; window->statusbar_lines_top += top; - window->statusbar_lines += top; + window->statusbar_lines += top; } if (bottom != 0) { - ret = window->statusbar_lines_bottom; - window->statusbar_lines_bottom += bottom; - window->statusbar_lines += bottom; + ret = window->statusbar_lines_bottom; + window->statusbar_lines_bottom += bottom; + window->statusbar_lines += bottom; } - if (top+bottom != 0) - window->size_dirty = TRUE; + if (top + bottom != 0) + window->size_dirty = TRUE; - return ret; + return ret; } -static void mainwindows_resize_two(GSList *grow_list, - GSList *shrink_list, int count) +static void mainwindows_resize_two(GSList *grow_list, GSList *shrink_list, int count) { GSList *tmp; MAIN_WINDOW_REC *win; @@ -1011,7 +1017,7 @@ static int try_shrink_lower(MAIN_WINDOW_REC *window, int count) for (tmp = shrink_list; tmp != NULL; tmp = tmp->next) { win = tmp->data; - if (MAIN_WINDOW_TEXT_HEIGHT(win)-count < WINDOW_MIN_SIZE) { + if (MAIN_WINDOW_TEXT_HEIGHT(win) - count < WINDOW_MIN_SIZE) { ok = FALSE; break; } @@ -1057,7 +1063,7 @@ static int try_shrink_upper(MAIN_WINDOW_REC *window, int count) for (tmp = shrink_list; tmp != NULL; tmp = tmp->next) { win = tmp->data; - if (MAIN_WINDOW_TEXT_HEIGHT(win)-count < WINDOW_MIN_SIZE) { + if (MAIN_WINDOW_TEXT_HEIGHT(win) - count < WINDOW_MIN_SIZE) { ok = FALSE; break; } @@ -1083,17 +1089,16 @@ static int try_shrink_upper(MAIN_WINDOW_REC *window, int count) return FALSE; } -static int mainwindow_grow(MAIN_WINDOW_REC *window, int count, - int resize_lower) +static int mainwindow_grow(MAIN_WINDOW_REC *window, int count, int resize_lower) { if (!resize_lower || !try_shrink_lower(window, count)) { if (!try_shrink_upper(window, count)) { - if (resize_lower || !try_shrink_lower(window, count)) + if (resize_lower || !try_shrink_lower(window, count)) return FALSE; } } - return TRUE; + return TRUE; } static int try_grow_lower(MAIN_WINDOW_REC *window, int count) @@ -1152,21 +1157,21 @@ static int mainwindow_shrink(MAIN_WINDOW_REC *window, int count, int resize_lowe { g_return_val_if_fail(count >= 0, FALSE); - if (MAIN_WINDOW_TEXT_HEIGHT(window)-count < WINDOW_MIN_SIZE) - return FALSE; + if (MAIN_WINDOW_TEXT_HEIGHT(window) - count < WINDOW_MIN_SIZE) + return FALSE; if (!resize_lower || !try_grow_lower(window, count)) { if (!try_grow_upper(window, count)) { - if (resize_lower || !try_grow_lower(window, count)) + if (resize_lower || !try_grow_lower(window, count)) return FALSE; } } - return TRUE; + return TRUE; } -static void mainwindows_rresize_two(MAIN_WINDOW_REC *grow_win, - MAIN_WINDOW_REC *shrink_win, int count) +static void mainwindows_rresize_two(MAIN_WINDOW_REC *grow_win, MAIN_WINDOW_REC *shrink_win, + int count) { irssi_set_dirty(); @@ -1184,7 +1189,7 @@ static int try_shrink_right(MAIN_WINDOW_REC *window, int count) shrink_win = mainwindows_find_right(window, FALSE); if (shrink_win != NULL) { - if (MAIN_WINDOW_TEXT_WIDTH(shrink_win)-count < NEW_WINDOW_WIDTH) { + if (MAIN_WINDOW_TEXT_WIDTH(shrink_win) - count < NEW_WINDOW_WIDTH) { return FALSE; } @@ -1206,7 +1211,7 @@ static int try_shrink_left(MAIN_WINDOW_REC *window, int count) shrink_win = mainwindows_find_left(window, FALSE); if (shrink_win != NULL) { - if (MAIN_WINDOW_TEXT_WIDTH(shrink_win)-count < NEW_WINDOW_WIDTH) { + if (MAIN_WINDOW_TEXT_WIDTH(shrink_win) - count < NEW_WINDOW_WIDTH) { return FALSE; } window->first_column -= count; @@ -1263,7 +1268,7 @@ static int mainwindow_shrink_right(MAIN_WINDOW_REC *window, int count) { g_return_val_if_fail(count >= 0, FALSE); - if (MAIN_WINDOW_TEXT_WIDTH(window)-count < NEW_WINDOW_WIDTH) + if (MAIN_WINDOW_TEXT_WIDTH(window) - count < NEW_WINDOW_WIDTH) return FALSE; if (!try_grow_right(window, count)) { @@ -1279,7 +1284,7 @@ static int mainwindow_shrink_right(MAIN_WINDOW_REC *window, int count) to be resized instead of upper window. */ void mainwindow_set_size(MAIN_WINDOW_REC *window, int height, int resize_lower) { - height -= window->height; + height -= window->height; if (height < 0) mainwindow_shrink(window, -height, resize_lower); else @@ -1303,11 +1308,11 @@ void mainwindows_redraw_dirty(void) MAIN_WINDOW_REC *rec = tmp->data; if (rec->size_dirty) { - rec->size_dirty = FALSE; + rec->size_dirty = FALSE; mainwindow_resize_windows(rec); } if (rec->dirty) { - rec->dirty = FALSE; + rec->dirty = FALSE; gui_window_redraw(rec->active); } else if (WINDOW_GUI(rec->active)->view->dirty) { gui_window_redraw(rec->active); @@ -1338,20 +1343,19 @@ static void window_balance_vertical(void) MAIN_WINDOW_REC *win; windows = g_slist_length(mainwindows); - if (windows == 1) return; + if (windows == 1) + return; sorted = NULL; windows = 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)) { windows++; sorted = g_slist_append(sorted, win); } - avail_size = term_height - screen_reserved_top-screen_reserved_bottom; - unit_size = avail_size/windows; - bigger_units = avail_size%windows; + avail_size = term_height - screen_reserved_top - screen_reserved_bottom; + unit_size = avail_size / windows; + bigger_units = avail_size % windows; last_line = screen_reserved_top; for (stmp = sorted; stmp != NULL; stmp = stmp->next) { @@ -1362,7 +1366,7 @@ static void window_balance_vertical(void) MAIN_WINDOW_REC *rec = ltmp->data; old_size = rec->height; rec->first_line = last_line; - rec->last_line = rec->first_line + unit_size-1; + rec->last_line = rec->first_line + unit_size - 1; if (bigger_units > 0) { rec->last_line++; @@ -1373,7 +1377,7 @@ static void window_balance_vertical(void) if (line != NULL && bigger_units > 0) { bigger_units--; } - last_line = win->last_line+1; + last_line = win->last_line + 1; g_slist_free(line); } @@ -1388,8 +1392,7 @@ static void cmd_window_hide(const char *data) WINDOW_REC *window; if (mainwindows->next == NULL) { - printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, - TXT_CANT_HIDE_LAST); + printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_CANT_HIDE_LAST); return; } @@ -1398,8 +1401,8 @@ static void cmd_window_hide(const char *data) else if (is_numeric(data, 0)) { window = window_find_refnum(atoi(data)); if (window == NULL) { - printformat_window(active_win, MSGLEVEL_CLIENTERROR, - TXT_REFNUM_NOT_FOUND, data); + printformat_window(active_win, MSGLEVEL_CLIENTERROR, TXT_REFNUM_NOT_FOUND, + data); } } else { window = window_find_item(active_win->active_server, data); @@ -1411,7 +1414,7 @@ static void cmd_window_hide(const char *data) if (WINDOW_MAIN(window)->sticky_windows) { if (!settings_get_bool("autounstick_windows")) { printformat_window(active_win, MSGLEVEL_CLIENTERROR, - TXT_CANT_HIDE_STICKY_WINDOWS); + TXT_CANT_HIDE_STICKY_WINDOWS); return; } } @@ -1435,7 +1438,7 @@ static void cmd_window_show(const char *data) int right; if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, - "window show", &optlist, &args)) + "window show", &optlist, &args)) return; right = g_hash_table_lookup(optlist, "right") != NULL; @@ -1448,8 +1451,8 @@ static void cmd_window_show(const char *data) if (is_numeric(args, '\0')) { window = window_find_refnum(atoi(args)); if (window == NULL) { - printformat_window(active_win, MSGLEVEL_CLIENTERROR, - TXT_REFNUM_NOT_FOUND, args); + printformat_window(active_win, MSGLEVEL_CLIENTERROR, TXT_REFNUM_NOT_FOUND, + args); } } else { window = window_find_item(active_win->active_server, args); @@ -1463,7 +1466,7 @@ static void cmd_window_show(const char *data) if (WINDOW_GUI(window)->sticky) { if (!settings_get_bool("autounstick_windows")) { printformat_window(active_win, MSGLEVEL_CLIENTERROR, - TXT_CANT_SHOW_STICKY_WINDOWS); + TXT_CANT_SHOW_STICKY_WINDOWS); return; } } @@ -1499,7 +1502,6 @@ static void mainwindow_grow_right_int(int count) } } - /* SYNTAX: WINDOW GROW [-right] [|] */ static void cmd_window_grow(const char *data) { @@ -1509,7 +1511,7 @@ static void cmd_window_grow(const char *data) int count; if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, - "window grow", &optlist, &args)) + "window grow", &optlist, &args)) return; count = *data == '\0' ? 1 : atoi(args); @@ -1532,11 +1534,12 @@ static void cmd_window_shrink(const char *data) int count; if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, - "window shrink", &optlist, &args)) + "window shrink", &optlist, &args)) return; 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) { mainwindow_grow_right_int(-count); @@ -1556,7 +1559,7 @@ static void cmd_window_size(const char *data) int size; if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, - "window size", &optlist, &args)) + "window size", &optlist, &args)) return; if (!is_numeric(args, 0)) { @@ -1570,9 +1573,9 @@ static void cmd_window_size(const char *data) mainwindow_grow_right_int(size); } else { - size -= WINDOW_MAIN(active_win)->height - - WINDOW_MAIN(active_win)->statusbar_lines; - if (size < -INT_MAX) size = -INT_MAX; + size -= WINDOW_MAIN(active_win)->height - WINDOW_MAIN(active_win)->statusbar_lines; + if (size < -INT_MAX) + size = -INT_MAX; mainwindow_grow_int(size); } @@ -1594,16 +1597,16 @@ static void window_balance_horizontal(void) return; } - avail_width = term_width - screen_reserved_left-screen_reserved_right - windows + 1; - unit_width = avail_width/windows; - bigger_units = avail_width%windows; + avail_width = term_width - screen_reserved_left - screen_reserved_right - windows + 1; + unit_width = avail_width / windows; + bigger_units = avail_width % windows; last_column = screen_reserved_left; for (ltmp = line; ltmp != NULL; ltmp = ltmp->next) { win = ltmp->data; old_width = win->width; win->first_column = last_column; - win->last_column = win->first_column + unit_width-1; + win->last_column = win->first_column + unit_width - 1; if (bigger_units > 0) { win->last_column++; @@ -1611,7 +1614,7 @@ static void window_balance_horizontal(void) } mainwindow_resize(win, win->last_column - win->first_column + 1 - old_width, 0); - last_column = win->last_column+2; + last_column = win->last_column + 2; } g_slist_free(line); @@ -1625,7 +1628,7 @@ static void cmd_window_balance(const char *data) void *free_arg; if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, - "window balance", &optlist)) + "window balance", &optlist)) return; if (g_hash_table_lookup(optlist, "right") != NULL) { @@ -1644,8 +1647,8 @@ static void cmd_window_up(const char *data) GHashTable *optlist; void *free_arg; - if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, - "window up", &optlist)) + if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, "window up", + &optlist)) return; if (g_hash_table_lookup(optlist, "directional") != NULL) { @@ -1670,8 +1673,8 @@ static void cmd_window_down(const char *data) GHashTable *optlist; void *free_arg; - if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, - "window down", &optlist)) + if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, "window down", + &optlist)) return; if (g_hash_table_lookup(optlist, "directional") != NULL) { @@ -1690,22 +1693,20 @@ static void cmd_window_down(const char *data) cmd_params_free(free_arg); } -#define WINDOW_STICKY_MATCH(window, sticky_parent) \ - ((!WINDOW_GUI(window)->sticky && (sticky_parent) == NULL) || \ - (WINDOW_GUI(window)->sticky && \ - WINDOW_MAIN(window) == (sticky_parent))) +#define WINDOW_STICKY_MATCH(window, sticky_parent) \ + ((!WINDOW_GUI(window)->sticky && (sticky_parent) == NULL) || \ + (WINDOW_GUI(window)->sticky && WINDOW_MAIN(window) == (sticky_parent))) static int window_refnum_left(int refnum, int wrap) { - MAIN_WINDOW_REC *find_sticky; + MAIN_WINDOW_REC *find_sticky; WINDOW_REC *window; int start_refnum = refnum; window = window_find_refnum(refnum); g_return_val_if_fail(window != NULL, -1); - find_sticky = WINDOW_MAIN(window)->sticky_windows ? - WINDOW_MAIN(window) : NULL; + find_sticky = WINDOW_MAIN(window)->sticky_windows ? WINDOW_MAIN(window) : NULL; do { refnum = window_refnum_prev(refnum, wrap); @@ -1720,15 +1721,14 @@ static int window_refnum_left(int refnum, int wrap) static int window_refnum_right(int refnum, int wrap) { - MAIN_WINDOW_REC *find_sticky; + MAIN_WINDOW_REC *find_sticky; WINDOW_REC *window; int start_refnum = refnum; window = window_find_refnum(refnum); g_return_val_if_fail(window != NULL, -1); - find_sticky = WINDOW_MAIN(window)->sticky_windows ? - WINDOW_MAIN(window) : NULL; + find_sticky = WINDOW_MAIN(window)->sticky_windows ? WINDOW_MAIN(window) : NULL; do { 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; void *free_arg; - if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, - "window left", &optlist)) + if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, "window left", + &optlist)) return; if (g_hash_table_lookup(optlist, "directional") != NULL) { @@ -1777,7 +1777,7 @@ static void cmd_window_right(const char *data) void *free_arg; if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, - "window right", &optlist)) + "window right", &optlist)) return; if (g_hash_table_lookup(optlist, "directional") != NULL) { @@ -1824,42 +1824,41 @@ static void window_reparent(WINDOW_REC *win, MAIN_WINDOW_REC *mainwin) /* SYNTAX: WINDOW STICK [] [ON|OFF] */ static void cmd_window_stick(const char *data) { - MAIN_WINDOW_REC *mainwin; - WINDOW_REC *win; + MAIN_WINDOW_REC *mainwin; + WINDOW_REC *win; - mainwin = active_mainwin; - win = active_mainwin->active; + mainwin = active_mainwin; + win = active_mainwin->active; if (is_numeric(data, ' ')) { /* ref# specified */ win = window_find_refnum(atoi(data)); if (win == NULL) { - printformat_window(active_win, MSGLEVEL_CLIENTERROR, - TXT_REFNUM_NOT_FOUND, data); + printformat_window(active_win, MSGLEVEL_CLIENTERROR, TXT_REFNUM_NOT_FOUND, + data); return; } - while (*data != ' ' && *data != '\0') data++; - while (*data == ' ') data++; + while (*data != ' ' && *data != '\0') + data++; + while (*data == ' ') + data++; } if (g_ascii_strncasecmp(data, "OF", 2) == 0 || i_toupper(*data) == 'N') { /* unset sticky */ if (!WINDOW_GUI(win)->sticky) { - printformat_window(win, MSGLEVEL_CLIENTERROR, - TXT_WINDOW_NOT_STICKY); + printformat_window(win, MSGLEVEL_CLIENTERROR, TXT_WINDOW_NOT_STICKY); } else { - gui_window_set_unsticky(win); - printformat_window(win, MSGLEVEL_CLIENTNOTICE, - TXT_WINDOW_UNSET_STICKY); + gui_window_set_unsticky(win); + printformat_window(win, MSGLEVEL_CLIENTNOTICE, TXT_WINDOW_UNSET_STICKY); } } else { /* set sticky */ window_reparent(win, mainwin); - gui_window_set_sticky(win); + gui_window_set_sticky(win); - printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, - TXT_WINDOW_SET_STICKY); + printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_WINDOW_SET_STICKY); } } @@ -1870,7 +1869,7 @@ static void cmd_window_move_left(const char *data) void *free_arg; if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, - "window move left", &optlist)) + "window move left", &optlist)) return; if (g_hash_table_lookup(optlist, "directional") != NULL) { @@ -1899,7 +1898,7 @@ static void cmd_window_move_right(const char *data) void *free_arg; if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, - "window move right", &optlist)) + "window move right", &optlist)) return; if (g_hash_table_lookup(optlist, "directional") != NULL) { @@ -1929,7 +1928,7 @@ static void cmd_window_move_up(const char *data) void *free_arg; if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, - "window move up", &optlist)) + "window move up", &optlist)) return; if (g_hash_table_lookup(optlist, "directional") != NULL) { @@ -1952,7 +1951,7 @@ static void cmd_window_move_down(const char *data) void *free_arg; if (!cmd_get_params(data, &free_arg, PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, - "window move down", &optlist)) + "window move down", &optlist)) return; if (g_hash_table_lookup(optlist, "directional") != NULL) { @@ -1969,13 +1968,13 @@ static void cmd_window_move_down(const char *data) static void windows_print_sticky(WINDOW_REC *win) { - MAIN_WINDOW_REC *mainwin; - GSList *tmp, *list; + MAIN_WINDOW_REC *mainwin; + GSList *tmp, *list; GString *str; - mainwin = WINDOW_MAIN(win); + mainwin = WINDOW_MAIN(win); - /* convert to string */ + /* convert to string */ str = g_string_new(NULL); list = get_sticky_windows_sorted(mainwin); for (tmp = list; tmp != NULL; tmp = tmp->next) { @@ -1983,12 +1982,11 @@ static void windows_print_sticky(WINDOW_REC *win) g_string_append_printf(str, "#%d, ", rec->refnum); } - g_string_truncate(str, str->len-2); - g_slist_free(list); + g_string_truncate(str, str->len - 2); + g_slist_free(list); - printformat_window(win, MSGLEVEL_CLIENTCRAP, - TXT_WINDOW_INFO_STICKY, str->str); - g_string_free(str, TRUE); + printformat_window(win, MSGLEVEL_CLIENTCRAP, TXT_WINDOW_INFO_STICKY, str->str); + g_string_free(str, TRUE); } static void sig_window_print_info(WINDOW_REC *win) @@ -1997,13 +1995,12 @@ static void sig_window_print_info(WINDOW_REC *win) gui = WINDOW_GUI(win); if (gui->use_scroll) { - printformat_window(win, MSGLEVEL_CLIENTCRAP, - TXT_WINDOW_INFO_SCROLL, - gui->scroll ? "yes" : "no"); + printformat_window(win, MSGLEVEL_CLIENTCRAP, TXT_WINDOW_INFO_SCROLL, + gui->scroll ? "yes" : "no"); } if (WINDOW_MAIN(win)->sticky_windows) - windows_print_sticky(win); + windows_print_sticky(win); } void mainwindows_init(void) @@ -2106,8 +2103,7 @@ int mainwindows_reserve_columns(int left, int right) return ret; } -int mainwindow_set_statusbar_columns(MAIN_WINDOW_REC *window, - int left, int right) +int mainwindow_set_statusbar_columns(MAIN_WINDOW_REC *window, int left, int right) { int ret = -1; if (left != 0) { @@ -2120,7 +2116,7 @@ int mainwindow_set_statusbar_columns(MAIN_WINDOW_REC *window, window->statusbar_columns_right += right; window->statusbar_columns += right; } - if (left+right != 0) + if (left + right != 0) window->size_dirty = TRUE; return ret; } diff --git a/src/fe-text/mainwindows.h b/src/fe-text/mainwindows.h index a1448838..3f377771 100644 --- a/src/fe-text/mainwindows.h +++ b/src/fe-text/mainwindows.h @@ -7,11 +7,9 @@ #define WINDOW_MIN_SIZE 2 #define NEW_WINDOW_WIDTH 20 /* must be >= MIN_SCREEN_WIDTH defined in term.c */ -#define MAIN_WINDOW_TEXT_HEIGHT(window) \ - ((window)->height-(window)->statusbar_lines) +#define MAIN_WINDOW_TEXT_HEIGHT(window) ((window)->height - (window)->statusbar_lines) -#define MAIN_WINDOW_TEXT_WIDTH(window) \ - ((window)->width-(window)->statusbar_columns) +#define MAIN_WINDOW_TEXT_WIDTH(window) ((window)->width - (window)->statusbar_columns) typedef struct { WINDOW_REC *active; @@ -19,8 +17,10 @@ typedef struct { TERM_WINDOW *screen_win; 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_column, last_column; /* first/last column used by this window (0..x) (includes statusbars) */ + int first_line, + 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) */ GSList *statusbars; @@ -29,8 +29,9 @@ typedef struct { int statusbar_columns_left, statusbar_columns_right; int statusbar_columns; /* left+right */ - 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 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. */ } MAIN_WINDOW_REC; typedef struct { @@ -55,23 +56,19 @@ void mainwindows_recreate(void); /* Change the window height - the height includes the lines needed for statusbars. If resize_lower is TRUE, the lower window is first tried to be resized instead of upper window. */ -void mainwindow_set_size(MAIN_WINDOW_REC *window, int height, - int resize_lower); +void mainwindow_set_size(MAIN_WINDOW_REC *window, int height, int resize_lower); void mainwindow_set_rsize(MAIN_WINDOW_REC *window, int width); void mainwindows_resize(int width, int height); -void mainwindow_change_active(MAIN_WINDOW_REC *mainwin, - WINDOW_REC *skip_window); +void mainwindow_change_active(MAIN_WINDOW_REC *mainwin, WINDOW_REC *skip_window); int mainwindows_reserve_lines(int top, int bottom); -int mainwindow_set_statusbar_lines(MAIN_WINDOW_REC *window, - int top, int bottom); +int mainwindow_set_statusbar_lines(MAIN_WINDOW_REC *window, int top, int bottom); void mainwindows_redraw_dirty(void); /* Reserve columns at left/right of a main window (for side panels). */ int mainwindows_reserve_columns(int left, int right); -int mainwindow_set_statusbar_columns(MAIN_WINDOW_REC *window, - int left, int right); +int mainwindow_set_statusbar_columns(MAIN_WINDOW_REC *window, int left, int right); GSList *mainwindows_get_sorted(int reverse); GSList *mainwindows_get_line(MAIN_WINDOW_REC *rec); diff --git a/src/fe-text/module-formats.h b/src/fe-text/module-formats.h index 990afaf1..f8f4d7b5 100644 --- a/src/fe-text/module-formats.h +++ b/src/fe-text/module-formats.h @@ -70,21 +70,22 @@ enum { }; /* Sidepanel format indices appended at the end of gui_text_formats: we declare explicit macros. */ -#define TXT_SIDEPANEL_HEADER format_find_tag(MODULE_NAME, "sidepanel_header") -#define TXT_SIDEPANEL_ITEM format_find_tag(MODULE_NAME, "sidepanel_item") -#define TXT_SIDEPANEL_ITEM_SELECTED format_find_tag(MODULE_NAME, "sidepanel_item_selected") -#define TXT_SIDEPANEL_ITEM_ACTIVITY format_find_tag(MODULE_NAME, "sidepanel_item_activity") +#define TXT_SIDEPANEL_HEADER format_find_tag(MODULE_NAME, "sidepanel_header") +#define TXT_SIDEPANEL_ITEM format_find_tag(MODULE_NAME, "sidepanel_item") +#define TXT_SIDEPANEL_ITEM_SELECTED format_find_tag(MODULE_NAME, "sidepanel_item_selected") +#define TXT_SIDEPANEL_ITEM_ACTIVITY format_find_tag(MODULE_NAME, "sidepanel_item_activity") #define TXT_SIDEPANEL_ITEM_NICK_MENTION format_find_tag(MODULE_NAME, "sidepanel_item_nick_mention") -#define TXT_SIDEPANEL_ITEM_QUERY_MSG format_find_tag(MODULE_NAME, "sidepanel_item_query_msg") -#define TXT_SIDEPANEL_ITEM_EVENTS format_find_tag(MODULE_NAME, "sidepanel_item_events") -#define TXT_SIDEPANEL_ITEM_HIGHLIGHT format_find_tag(MODULE_NAME, "sidepanel_item_highlight") -#define TXT_SIDEPANEL_NICK_OP format_find_tag(MODULE_NAME, "sidepanel_nick_op") -#define TXT_SIDEPANEL_NICK_VOICE format_find_tag(MODULE_NAME, "sidepanel_nick_voice") -#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_ITEM_QUERY_MSG format_find_tag(MODULE_NAME, "sidepanel_item_query_msg") +#define TXT_SIDEPANEL_ITEM_EVENTS format_find_tag(MODULE_NAME, "sidepanel_item_events") +#define TXT_SIDEPANEL_ITEM_HIGHLIGHT format_find_tag(MODULE_NAME, "sidepanel_item_highlight") +#define TXT_SIDEPANEL_NICK_OP format_find_tag(MODULE_NAME, "sidepanel_nick_op") +#define TXT_SIDEPANEL_NICK_VOICE format_find_tag(MODULE_NAME, "sidepanel_nick_voice") +#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_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]; #endif diff --git a/src/fe-text/sidepanels.c b/src/fe-text/sidepanels.c index 937ae8fe..693d0a1c 100644 --- a/src/fe-text/sidepanels.c +++ b/src/fe-text/sidepanels.c @@ -22,7 +22,8 @@ #define DATA_LEVEL_EVENT 10 /* 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); if (chr & 0x80000000) { @@ -30,9 +31,10 @@ static inline unichar read_unichar(const unsigned char *data, const unsigned cha *next = data + 1; *width = 1; } 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; - if (*width < 0) *width = 1; + if (*width < 0) + *width = 1; } return chr; } @@ -62,18 +64,18 @@ static int sp_debug; /* Window Priority State - Simpler approach */ typedef struct { WINDOW_REC *window; - int current_priority; /* 0=none, 1=events, 2=highlight, 3=activity, 4=nick/query */ + int current_priority; /* 0=none, 1=events, 2=highlight, 3=activity, 4=nick/query */ } window_priority_state; static GHashTable *window_priorities = NULL; static int esc_pending; -static int esc_timeout_tag = -1; /* Timer tag for ESC timeout */ +static int esc_timeout_tag = -1; /* Timer tag for ESC timeout */ static int reemit_guard; static gboolean esc_timeout_callback(gpointer data) { - (void)data; + (void) data; if (esc_pending && !reemit_guard) { reemit_guard = 1; signal_emit("gui key pressed", 1, GINT_TO_POINTER(0x1b)); @@ -85,13 +87,19 @@ static gboolean esc_timeout_callback(gpointer data) } 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, ...) { va_list ap; - if (!sp_debug) return; + if (!sp_debug) + return; sp_log_open(); - if (!sp_log) return; + if (!sp_log) + return; va_start(ap, fmt); vfprintf(sp_log, fmt, ap); fprintf(sp_log, "\n"); @@ -102,7 +110,7 @@ static void sp_logf(const char *fmt, ...) static void read_settings(void) { int old_mouse = sp_enable_mouse; - + sp_left_width = settings_get_int("sidepanel_left_width"); sp_right_width = settings_get_int("sidepanel_right_width"); sp_enable_left = settings_get_bool("sidepanel_left"); @@ -110,12 +118,13 @@ static void read_settings(void) sp_auto_hide_right = settings_get_bool("sidepanel_right_auto_hide"); sp_enable_mouse = TRUE; /* always on natively */ sp_debug = settings_get_bool("sidepanel_debug"); - + /* Nick mention color is now handled through theme formats */ - + apply_reservations_all(); apply_and_redraw(); - if (!old_mouse) enable_mouse_tracking(); + if (!old_mouse) + enable_mouse_tracking(); } static void apply_reservations_all(void) @@ -136,7 +145,7 @@ static void apply_reservations_all(void) static void sig_mainwindow_created(MAIN_WINDOW_REC *mw) { /* Panel reservations are now handled dynamically in position_tw() for better control */ - (void)mw; + (void) mw; } typedef struct { @@ -150,8 +159,12 @@ typedef struct { int right_selected_index; int right_scroll_offset; /* cached geometry for hit-test and drawing */ - int left_x; int left_y; int left_h; - int right_x; int right_y; int right_h; + int left_x; + int left_y; + int left_h; + int right_x; + int right_y; + int right_h; /* ordered nick pointers matching rendered order */ GSList *right_order; } 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) { SP_MAINWIN_CTX *ctx = g_hash_table_lookup(mw_to_ctx, mw); - if (!ctx) return; - if (ctx->left_tw) { 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; } + if (!ctx) + return; + if (ctx->left_tw) { + 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_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 */ signal_emit("mainwindow resized", 1, mw); } - ctx->left_x = x; ctx->left_y = y; ctx->left_h = h; - } - else if (ctx->left_tw) { + ctx->left_x = x; + ctx->left_y = y; + ctx->left_h = h; + } else if (ctx->left_tw) { /* Clear the left panel area before destroying */ clear_window_full(ctx->left_tw, ctx->left_w, ctx->left_h); 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; aw = mw->active; 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; } } @@ -241,14 +266,15 @@ static void position_tw(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx) /* Force statusbar redraw to fix input box positioning */ signal_emit("mainwindow resized", 1, mw); } - ctx->right_x = x; ctx->right_y = y; ctx->right_h = h; - } - else if (ctx->right_tw) { + ctx->right_x = x; + ctx->right_y = y; + ctx->right_h = h; + } else if (ctx->right_tw) { /* Clear the right panel area before destroying */ clear_window_full(ctx->right_tw, ctx->right_w, ctx->right_h); - term_window_destroy(ctx->right_tw); - ctx->right_tw = NULL; - ctx->right_h = 0; + term_window_destroy(ctx->right_tw); + ctx->right_tw = NULL; + ctx->right_h = 0; /* Free reserved space - this expands main window */ mainwindows_reserve_columns(0, -ctx->right_w); /* Force complete recreation of mainwindows to clear artifacts */ @@ -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) { - (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) { SP_MAINWIN_CTX *ctx = get_ctx(mw, FALSE); - if (!ctx) return; - + if (!ctx) + return; + /* Draw left border (between left panel and main window) */ if (ctx->left_tw && ctx->left_h > 0) { int border_x = mw->first_column + mw->statusbar_columns_left - 1; 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,20 +311,21 @@ static void draw_main_window_borders(MAIN_WINDOW_REC *mw) if (ctx->right_tw && ctx->right_h > 0) { int border_x = mw->last_column + 1; 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 */ static window_priority_state *get_window_priority_state(WINDOW_REC *window) { window_priority_state *state; 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); if (!state) { state = g_new0(window_priority_state, 1); @@ -345,34 +377,47 @@ static void handle_new_activity(WINDOW_REC *window, int data_level) int new_priority; const char *data_level_name; - if (!window) return; + if (!window) + return; /* Debug: data level name */ switch (data_level) { - case DATA_LEVEL_NONE: data_level_name = "NONE"; break; - case DATA_LEVEL_TEXT: data_level_name = "TEXT"; 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; + case DATA_LEVEL_NONE: + data_level_name = "NONE"; + break; + case DATA_LEVEL_TEXT: + data_level_name = "TEXT"; + 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); new_priority = get_new_activity_priority(window, data_level); /* Debug: Track all activity events - useful for diagnosing priority conflicts */ - sp_logf("ACTIVITY: Window %d data_level=%s(%d) current_priority=%d new_priority=%d", + sp_logf("ACTIVITY: Window %d data_level=%s(%d) current_priority=%d new_priority=%d", window->refnum, data_level_name, data_level, state->current_priority, new_priority); /* Only update if new priority is higher */ if (new_priority > state->current_priority) { state->current_priority = new_priority; /* Debug: Priority changes - essential for activity system debugging */ - sp_logf("PRIORITY: Window %d priority updated from %d to %d (type=%s)", + sp_logf("PRIORITY: Window %d priority updated from %d to %d (type=%s)", window->refnum, state->current_priority, new_priority, data_level_name); } else { /* Debug: Priority ignored - shows when lower priority events are filtered */ - sp_logf("PRIORITY: Window %d ignored - current=%d >= new=%d (type=%s)", + sp_logf("PRIORITY: Window %d ignored - current=%d >= new=%d (type=%s)", window->refnum, state->current_priority, new_priority, data_level_name); } } @@ -382,12 +427,14 @@ static void reset_window_priority(WINDOW_REC *window) { window_priority_state *state; - if (!window) return; + if (!window) + return; state = get_window_priority_state(window); if (state->current_priority > 0) { /* 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; } else { /* 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 x; - if (!tw) return; + if (!tw) + return; term_set_color(tw, ATTR_RESET); for (y = 0; y < height; 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 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 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) { *flags = (*flags & FGATTR) | ATTR_BGCOLOR24; *bg = color; - } - else { + } else { *flags = (*flags & BGATTR) | ATTR_FGCOLOR24; *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) { case FORMAT_STYLE_BLINK: @@ -518,7 +568,8 @@ static inline void unformat(const unsigned char **ptr, int *color, unsigned int 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; THEME_REC *theme; @@ -529,46 +580,48 @@ static void draw_str_themed(TERM_WINDOW *tw, int x, int y, WINDOW_REC *wctx, int int char_width; unsigned int fg24, bg24; unichar chr; - + format_create_dest(&dest, NULL, NULL, 0, wctx); theme = window_get_theme(wctx); out = format_get_text_theme(theme, MODULE_NAME, &dest, format_id, text); /* 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') { /* Convert theme color codes and render with proper color handling */ expanded = format_string_expand(out, NULL); - + /* Initialize color state */ color = ATTR_RESET; fg24 = bg24 = UINT_MAX; - ptr = (const unsigned char *)expanded; - + ptr = (const unsigned char *) expanded; + term_move(tw, x, y); term_set_color(tw, ATTR_RESET); - + /* Process each character with color codes (like textbuffer-view.c) */ while (*ptr != '\0') { if (*ptr == 4) { /* Format code - process color change */ ptr++; - if (*ptr == '\0') break; + if (*ptr == '\0') + break; unformat(&ptr, &color, &fg24, &bg24); term_set_color2(tw, color, fg24, bg24); ptr++; continue; } - + /* Regular character - read UTF-8 properly */ chr = read_unichar(ptr, &next_ptr, &char_width); - + if (unichar_isprint(chr)) { term_add_unichar(tw, chr); } ptr = next_ptr; } - + g_free(expanded); } else { /* Fallback: display plain text if theme formatting fails */ @@ -580,27 +633,28 @@ static void draw_str_themed(TERM_WINDOW *tw, int x, int y, WINDOW_REC *wctx, int /* * NEW DUAL-PARAMETER THEME FORMATS FOR NICKLIST CUSTOMIZATION - * + * * The new *_status formats allow separate styling of status symbols and nicks: - * + * * Example theme customization: - * + * * "fe-text" = { * # Different colors for @ symbol vs nick: * sidepanel_nick_op_status = "%R$0%Y$1"; # Red @ + Yellow nick - * + * * # Decorative brackets around status: * sidepanel_nick_op_status = "%Y[$0]%N$1"; # [@]nick - * + * * # Hide status completely (just colorized nick): * sidepanel_nick_op_status = "%Y$1"; # Only yellow nick, no @ - * + * * # Custom symbols instead of @ and +: * sidepanel_nick_op_status = "%R⚡%N%Y$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; THEME_REC *theme; @@ -612,53 +666,55 @@ static void draw_str_themed_2params(TERM_WINDOW *tw, int x, int y, WINDOW_REC *w unsigned int fg24, bg24; unichar chr; char *args[3]; - + format_create_dest(&dest, NULL, NULL, 0, wctx); theme = window_get_theme(wctx); - + /* Create args array for format_get_text_theme_charargs */ - args[0] = (char*)param1; - args[1] = (char*)param2; + args[0] = (char *) param1; + args[1] = (char *) param2; args[2] = NULL; - + out = format_get_text_theme_charargs(theme, MODULE_NAME, &dest, format_id, args); /* Debug: Uncomment to trace 2-parameter theme format rendering */ - // 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)"); - + // 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)"); + if (out != NULL && *out != '\0') { /* Convert theme color codes and render with proper color handling */ expanded = format_string_expand(out, NULL); - + /* Initialize color state */ color = ATTR_RESET; fg24 = bg24 = UINT_MAX; - ptr = (const unsigned char *)expanded; - + ptr = (const unsigned char *) expanded; + term_move(tw, x, y); term_set_color(tw, ATTR_RESET); - + /* Process each character with color codes (like textbuffer-view.c) */ while (*ptr != '\0') { if (*ptr == 4) { /* Format code - process color change */ ptr++; - if (*ptr == '\0') break; + if (*ptr == '\0') + break; unformat(&ptr, &color, &fg24, &bg24); term_set_color2(tw, color, fg24, bg24); ptr++; continue; } - + /* Regular character - read UTF-8 properly */ chr = read_unichar(ptr, &next_ptr, &char_width); - + if (unichar_isprint(chr)) { term_add_unichar(tw, chr); } ptr = next_ptr; } - + g_free(expanded); } else { /* Fallback: display plain text if theme formatting fails */ @@ -669,63 +725,66 @@ static void draw_str_themed_2params(TERM_WINDOW *tw, int x, int y, WINDOW_REC *w g_free(out); } - - - - /* Renumber all windows according to sorted display order */ typedef struct { WINDOW_REC *win; - 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 */ + 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 */ SERVER_REC *server; /* Server for grouping */ } WINDOW_SORT_REC; static gint compare_window_sort_items(gconstpointer a, gconstpointer b) { - WINDOW_SORT_REC *w1 = (WINDOW_SORT_REC*)a; - WINDOW_SORT_REC *w2 = (WINDOW_SORT_REC*)b; + WINDOW_SORT_REC *w1 = (WINDOW_SORT_REC *) a; + WINDOW_SORT_REC *w2 = (WINDOW_SORT_REC *) b; const char *net1, *net2; int server_cmp; - + /* 1. Notices always comes first */ - if (w1->sort_group == 0) return -1; /* w1 is Notices */ - if (w2->sort_group == 0) return 1; /* w2 is Notices */ - + if (w1->sort_group == 0) + return -1; /* w1 is Notices */ + if (w2->sort_group == 0) + return 1; /* w2 is Notices */ + /* 2. Sort by server (alphabetically) */ if (w1->server && w2->server) { - net1 = w1->server->connrec && w1->server->connrec->chatnet ? w1->server->connrec->chatnet : - (w1->server->connrec ? w1->server->connrec->address : "server"); - net2 = w2->server->connrec && w2->server->connrec->chatnet ? w2->server->connrec->chatnet : - (w2->server->connrec ? w2->server->connrec->address : "server"); + net1 = w1->server->connrec && w1->server->connrec->chatnet ? + w1->server->connrec->chatnet : + (w1->server->connrec ? w1->server->connrec->address : "server"); + net2 = w2->server->connrec && w2->server->connrec->chatnet ? + w2->server->connrec->chatnet : + (w2->server->connrec ? w2->server->connrec->address : "server"); 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) { return -1; /* Server windows come before non-server windows */ } else if (!w1->server && w2->server) { - return 1; /* Server windows come before non-server windows */ + return 1; /* Server windows come before non-server windows */ } - + /* 3. Within same server, sort by type: server status < channels < queries < orphans */ if (w1->sort_group != w2->sort_group) { return w1->sort_group - w2->sort_group; } - + /* 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 */ static GSList *build_sorted_window_list(void) { GSList *w, *sort_list = NULL; - + /* Create sorted list of all windows according to user rules */ for (w = windows; w; w = w->next) { WINDOW_REC *win = w->data; WINDOW_SORT_REC *sort_rec = g_new0(WINDOW_SORT_REC, 1); const char *win_name; - + sort_rec->win = win; /* Try to find server for this window */ if (win->active && win->active->server) { @@ -734,9 +793,9 @@ static GSList *build_sorted_window_list(void) /* For server status windows, try to find server by servertag */ sort_rec->server = win->servertag ? server_find_tag(win->servertag) : NULL; } - + win_name = window_get_active_name(win); - + /* Determine sort group and key according to user rules */ if (win_name && g_ascii_strcasecmp(win_name, "Notices") == 0) { /* 1. Notices window - always first */ @@ -746,9 +805,10 @@ static GSList *build_sorted_window_list(void) /* 2. Server status windows - no active channel/query */ const char *net; sort_rec->sort_group = 1; - net = sort_rec->server->connrec && sort_rec->server->connrec->chatnet ? - sort_rec->server->connrec->chatnet : - (sort_rec->server->connrec ? sort_rec->server->connrec->address : "server"); + net = sort_rec->server->connrec && sort_rec->server->connrec->chatnet ? + sort_rec->server->connrec->chatnet : + (sort_rec->server->connrec ? sort_rec->server->connrec->address : + "server"); sort_rec->sort_key = g_strdup(net ? net : "server"); } else if (win->active && win->active->server) { /* Windows with active channel/query items */ @@ -759,7 +819,7 @@ static GSList *build_sorted_window_list(void) sort_rec->sort_group = 2; sort_rec->sort_key = g_strdup(item->name ? item->name : "channel"); } else if (IS_QUERY(item)) { - /* 4. Queries - alphabetically within server */ + /* 4. Queries - alphabetically within server */ sort_rec->sort_group = 3; sort_rec->sort_key = g_strdup(item->name ? item->name : "query"); } else { @@ -776,13 +836,13 @@ static GSList *build_sorted_window_list(void) sort_rec->sort_group = 5; sort_rec->sort_key = g_strdup_printf("window_%d", win->refnum); } - + sort_list = g_slist_append(sort_list, sort_rec); } - + /* Sort according to our rules */ sort_list = g_slist_sort(sort_list, compare_window_sort_items); - + return sort_list; } @@ -802,32 +862,33 @@ static void renumber_windows_by_position(void) { GSList *sort_list, *s; int position = 1; - + /* Get sorted list using shared function */ sort_list = build_sorted_window_list(); - + /* Renumber all windows according to sorted order */ for (s = sort_list; s; s = s->next) { WINDOW_SORT_REC *sort_rec = s->data; WINDOW_REC *win = sort_rec->win; - + if (win->refnum != position) { window_set_refnum(win, position); } position++; } - + /* Clean up */ free_sorted_window_list(sort_list); } - static gint ci_nick_compare(gconstpointer a, gconstpointer b) { - NICK_REC *n1 = (NICK_REC*)a; - NICK_REC *n2 = (NICK_REC*)b; - if (!n1 || !n1->nick) return 1; - if (!n2 || !n2->nick) return -1; + NICK_REC *n1 = (NICK_REC *) a; + NICK_REC *n2 = (NICK_REC *) b; + if (!n1 || !n1->nick) + return 1; + if (!n2 || !n2->nick) + return -1; return g_ascii_strcasecmp(n1->nick, n2->nick); } @@ -839,19 +900,21 @@ static void draw_left_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx) int height; GSList *sort_list, *s; int list_index; - - if (!ctx) return; + + if (!ctx) + return; tw = ctx->left_tw; - if (!tw) return; + if (!tw) + return; clear_window_full(tw, ctx->left_w, ctx->left_h); - + row = 0; skip = ctx->left_scroll_offset; height = ctx->left_h; - + /* Get sorted list using shared function */ sort_list = build_sorted_window_list(); - + /* Draw windows in sorted order */ list_index = 0; for (s = sort_list; s && row < height; s = s->next) { @@ -860,17 +923,19 @@ static void draw_left_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx) const char *display_name = sort_rec->sort_key; int activity = win->data_level; int format; - + /* Skip items before our scroll offset */ - if (list_index++ < skip) continue; - + if (list_index++ < skip) + continue; + /* Determine format based on selection and activity */ if (win->refnum - 1 == ctx->left_selected_index) { format = TXT_SIDEPANEL_ITEM_SELECTED; } else if (sort_rec->sort_group == 0 || sort_rec->sort_group == 1) { /* Notices and server status windows use header format unless selected */ 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) { format = TXT_SIDEPANEL_ITEM_NICK_MENTION; } else { @@ -885,40 +950,42 @@ static void draw_left_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx) /* Channels, queries, and other windows - SIMPLE PRIORITY SYSTEM */ window_priority_state *state = get_window_priority_state(win); int current_priority = state->current_priority; - + switch (current_priority) { - case 4: /* PRIORITY 4: Nick mention OR Query messages (magenta) */ - /* Use QUERY_MSG only for query windows, NICK_MENTION for channel mentions */ - if (win->active && IS_QUERY(win->active)) { - format = TXT_SIDEPANEL_ITEM_QUERY_MSG; - } else { - format = TXT_SIDEPANEL_ITEM_NICK_MENTION; - } - break; - case 3: /* PRIORITY 3: Channel activity (yellow) */ - format = TXT_SIDEPANEL_ITEM_ACTIVITY; - break; - case 2: /* PRIORITY 2: Keyword highlights (red) */ - format = TXT_SIDEPANEL_ITEM_HIGHLIGHT; - break; - case 1: /* PRIORITY 1: Events (green) */ - format = TXT_SIDEPANEL_ITEM_EVENTS; - break; - default: /* PRIORITY 0: No activity (normal) */ - format = TXT_SIDEPANEL_ITEM; - break; + case 4: /* PRIORITY 4: Nick mention OR Query messages (magenta) */ + /* Use QUERY_MSG only for query windows, NICK_MENTION for channel + * mentions */ + if (win->active && IS_QUERY(win->active)) { + format = TXT_SIDEPANEL_ITEM_QUERY_MSG; + } else { + format = TXT_SIDEPANEL_ITEM_NICK_MENTION; + } + break; + case 3: /* PRIORITY 3: Channel activity (yellow) */ + format = TXT_SIDEPANEL_ITEM_ACTIVITY; + break; + case 2: /* PRIORITY 2: Keyword highlights (red) */ + format = TXT_SIDEPANEL_ITEM_HIGHLIGHT; + break; + case 1: /* PRIORITY 1: Events (green) */ + format = TXT_SIDEPANEL_ITEM_EVENTS; + break; + default: /* PRIORITY 0: No activity (normal) */ + format = TXT_SIDEPANEL_ITEM; + break; } } - + /* Draw the item */ 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++; } - + /* Clean up */ free_sorted_window_list(sort_list); - + /* Only draw border if right panel is also visible */ if (ctx->right_tw && ctx->right_h > 0) { draw_border_vertical(tw, ctx->left_w, ctx->left_h, 1); @@ -935,21 +1002,28 @@ static void draw_right_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx) int index; int row; GSList *nt; - if (!ctx) return; + if (!ctx) + return; tw = ctx->right_tw; - if (!tw) return; + if (!tw) + return; clear_window_full(tw, ctx->right_w, ctx->right_h); aw = mw->active; height = ctx->right_h; skip = ctx->right_scroll_offset; - index = 0; row = 0; - if (ctx->right_order) { g_slist_free(ctx->right_order); ctx->right_order = NULL; } - + index = 0; + 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 (!aw || !aw->active || !aw->active->visible_name || !strchr(aw->active->visible_name, '#')) { - draw_border_vertical(tw, ctx->right_w, ctx->right_h, 0); - irssi_set_dirty(); - return; + if (!aw || !aw->active || !aw->active->visible_name || + !strchr(aw->active->visible_name, '#')) { + draw_border_vertical(tw, ctx->right_w, ctx->right_h, 0); + irssi_set_dirty(); + return; } { CHANNEL_REC *ch = CHANNEL(aw->active); @@ -959,10 +1033,14 @@ static void draw_right_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx) /* Split nicks by status */ for (nt = nicks; nt; nt = nt->next) { NICK_REC *nick = nt->data; - if (!nick || !nick->nick) continue; - if (nick->op) ops = g_slist_prepend(ops, nick); - else if (nick->voice) voices = g_slist_prepend(voices, nick); - else normal = g_slist_prepend(normal, nick); + if (!nick || !nick->nick) + continue; + if (nick->op) + 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 */ ops = g_slist_sort(ops, ci_nick_compare); @@ -970,30 +1048,33 @@ static void draw_right_contents(MAIN_WINDOW_REC *mw, SP_MAINWIN_CTX *ctx) normal = g_slist_sort(normal, ci_nick_compare); /* Build ordered list and render */ for (cur = ops; cur && row < height; cur = cur->next) { - NICK_REC *nick = cur->data; + NICK_REC *nick = cur->data; int format; ctx->right_order = g_slist_append(ctx->right_order, nick); - if (index++ < skip) continue; + if (index++ < skip) + continue; term_move(tw, 1, row); format = TXT_SIDEPANEL_NICK_OP_STATUS; draw_str_themed_2params(tw, 1, row, mw->active, format, "@", nick->nick); row++; } for (cur = voices; cur && row < height; cur = cur->next) { - NICK_REC *nick = cur->data; + NICK_REC *nick = cur->data; int format; ctx->right_order = g_slist_append(ctx->right_order, nick); - if (index++ < skip) continue; + if (index++ < skip) + continue; term_move(tw, 1, row); format = TXT_SIDEPANEL_NICK_VOICE_STATUS; draw_str_themed_2params(tw, 1, row, mw->active, format, "+", nick->nick); row++; } for (cur = normal; cur && row < height; cur = cur->next) { - NICK_REC *nick = cur->data; + NICK_REC *nick = cur->data; int format; ctx->right_order = g_slist_append(ctx->right_order, nick); - if (index++ < skip) continue; + if (index++ < skip) + continue; term_move(tw, 1, row); format = TXT_SIDEPANEL_NICK_NORMAL_STATUS; 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) { SP_MAINWIN_CTX *ctx = get_ctx(mw, FALSE); - if (!ctx) return; + if (!ctx) + return; position_tw(mw, ctx); draw_left_contents(mw, ctx); /* 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) { 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) @@ -1040,7 +1123,7 @@ static void sig_window_changed(WINDOW_REC *w) WI_ITEM_REC *item = w ? w->active : NULL; const char *item_name = item ? item->visible_name : "NULL"; /* Debug: Window switching - tracks user navigation */ - sp_logf("SIGNAL: window_changed from %d to %d '%s' (USER SWITCHED)", + sp_logf("SIGNAL: window_changed from %d to %d '%s' (USER SWITCHED)", active_win ? active_win->refnum : -1, w->refnum, item_name); reset_window_priority(w); } @@ -1051,49 +1134,52 @@ static void sig_window_changed(WINDOW_REC *w) 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_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 */ - 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", w ? w->refnum : -1, item_name, item_type, active_win ? active_win->refnum : -1); - + update_left_selection_to_active(); redraw_all(); } static void sig_window_created(WINDOW_REC *window) { - (void)window; + (void) window; renumber_windows_by_position(); redraw_all(); } -static void sig_window_destroyed(WINDOW_REC *window) +static void sig_window_destroyed(WINDOW_REC *window) { - (void)window; + (void) window; renumber_windows_by_position(); redraw_all(); } static void sig_window_item_new(WINDOW_REC *window, WI_ITEM_REC *item) { - (void)window; - (void)item; + (void) window; + (void) item; renumber_windows_by_position(); redraw_all(); } static void sig_query_created(QUERY_REC *query, int automatic) { - (void)query; - (void)automatic; + (void) query; + (void) automatic; renumber_windows_by_position(); redraw_all(); } static void sig_channel_joined(CHANNEL_REC *channel) { - (void)channel; + (void) channel; renumber_windows_by_position(); redraw_all(); } @@ -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) { /* Nicklist changes don't trigger activity - just redraw */ - (void)channel; (void)nick; (void)old_nick; + (void) channel; + (void) nick; + (void) old_nick; redraw_all(); } static void sig_nicklist_new(CHANNEL_REC *channel, NICK_REC *nick) { /* Nicklist changes don't trigger activity - just redraw */ - (void)channel; (void)nick; + (void) channel; + (void) nick; redraw_all(); } @@ -1119,21 +1208,24 @@ static void sig_print_text(TEXT_DEST_REC *dest, const char *msg) WI_ITEM_REC *item; int data_level; const char *item_name, *item_type; - - if (!dest || !dest->window) return; - + + if (!dest || !dest->window) + return; + window = dest->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 */ - 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)) { - /* 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; } - + /* Determine actual data level based on message level - same logic as window-activity.c */ if (dest->level & MSGLEVEL_HILIGHT) { data_level = DATA_LEVEL_HILIGHT; @@ -1150,49 +1242,53 @@ static void sig_print_text(TEXT_DEST_REC *dest, const char *msg) } else { data_level = DATA_LEVEL_TEXT; /* Default to text level */ } - + /* Debug logging */ item = window->active; 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 */ - 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", window->refnum, item_name, item_type, dest->level, data_level, active_win ? active_win->refnum : -1); - + handle_new_activity(window, data_level); redraw_all(); } - - /* 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); if (window) { /* Debug: Join events - tracks channel join activity */ - sp_logf("SIGNAL: message_join %s on %s (Window %d) active_win=%d", - nick, channel, window->refnum, active_win ? active_win->refnum : -1); + sp_logf("SIGNAL: message_join %s on %s (Window %d) active_win=%d", nick, channel, + window->refnum, active_win ? active_win->refnum : -1); handle_new_activity(window, DATA_LEVEL_EVENT); } 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); if (window) { /* Debug: Part events - tracks channel part activity */ - sp_logf("SIGNAL: message_part %s from %s (Window %d) active_win=%d", - nick, channel, window->refnum, active_win ? active_win->refnum : -1); + sp_logf("SIGNAL: message_part %s from %s (Window %d) active_win=%d", nick, channel, + window->refnum, active_win ? active_win->refnum : -1); handle_new_activity(window, DATA_LEVEL_EVENT); } 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 */ GSList *tmp; @@ -1205,7 +1301,8 @@ static void sig_message_quit(SERVER_REC *server, const char *nick, const char *a 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 */ GSList *tmp; @@ -1218,9 +1315,6 @@ static void sig_message_nick(SERVER_REC *server, const char *newnick, const char redraw_all(); } - - - static void setup_ctx_for(MAIN_WINDOW_REC *mw) { SP_MAINWIN_CTX *ctx; @@ -1233,14 +1327,15 @@ static void setup_ctx_for(MAIN_WINDOW_REC *mw) static void update_left_selection_to_active(void) { GSList *tmp; - + for (tmp = mainwindows; tmp; tmp = tmp->next) { MAIN_WINDOW_REC *mw = tmp->data; SP_MAINWIN_CTX *ctx = get_ctx(mw, FALSE); WINDOW_REC *aw = mw->active; - - if (!ctx || !aw) continue; - + + if (!ctx || !aw) + continue; + /* Simple: selection index = active window refnum - 1 (0-based indexing) */ ctx->left_selected_index = aw->refnum - 1; } @@ -1270,42 +1365,48 @@ static gboolean handle_click_at(int x, int y, int button) for (mt = mainwindows; mt; mt = mt->next) { MAIN_WINDOW_REC *mw = mt->data; SP_MAINWIN_CTX *ctx = get_ctx(mw, FALSE); - if (!ctx) continue; + if (!ctx) + continue; if (ctx->left_tw) { 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) { int row = y - py; int target_index = row + ctx->left_scroll_offset; int idx = 0; GSList *sort_list, *s; - + /* Get sorted list using shared function */ sort_list = build_sorted_window_list(); - + /* Find the window at target_index */ for (s = sort_list; s; s = s->next) { if (idx++ == target_index) { WINDOW_SORT_REC *sort_rec = s->data; WINDOW_REC *win = sort_rec->win; - - /* Debug: Window switches via mouse - tracks click navigation */ - sp_logf("MOUSE_CLICK: switching to window %d (was %d)", - win ? win->refnum : -1, active_win ? active_win->refnum : -1); + + /* Debug: Window switches via mouse - tracks click + * navigation */ + 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; - if (win) window_set_active(win); + if (win) + window_set_active(win); redraw_one(mw); irssi_set_dirty(); free_sorted_window_list(sort_list); return TRUE; } } - + free_sorted_window_list(sort_list); } } if (ctx->right_tw) { - 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) { + 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) { int row = y - py; WINDOW_REC *aw = mw->active; if (aw && IS_CHANNEL(aw->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 count = g_slist_length(ctx->right_order); 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; 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); irssi_set_dirty(); return TRUE; @@ -1340,45 +1443,68 @@ gboolean sidepanels_try_parse_mouse_key(unichar key) int y; gboolean press; GSList *mt; - - if (!sp_enable_mouse) return FALSE; - if (reemit_guard) return FALSE; /* Don't process re-emitted keys */ + + if (!sp_enable_mouse) + return FALSE; + if (reemit_guard) + return FALSE; /* Don't process re-emitted keys */ if (mouse_state == 0) { - if (key == 0x1b) { - mouse_state = 1; - mouse_len = 0; - esc_pending = 1; + if (key == 0x1b) { + mouse_state = 1; + mouse_len = 0; + esc_pending = 1; /* 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); - return TRUE; + return TRUE; } return FALSE; } else if (mouse_state == 1) { - if (key == '[') { + if (key == '[') { /* Cancel timeout - might be mouse sequence or arrow keys */ - if (esc_timeout_tag != -1) { g_source_remove(esc_timeout_tag); esc_timeout_tag = -1; } - mouse_state = 2; + if (esc_timeout_tag != -1) { + g_source_remove(esc_timeout_tag); + esc_timeout_tag = -1; + } + mouse_state = 2; esc_pending = 0; /* clear pending since we'll handle this */ - return TRUE; + return TRUE; } if (key == 'O') { /* 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 */ esc_pending = 0; /* clear pending since we'll handle this immediately */ return TRUE; } /* Not SGR - cancel timeout and re-emit ESC */ - if (esc_timeout_tag != -1) { g_source_remove(esc_timeout_tag); 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; } + if (esc_timeout_tag != -1) { + g_source_remove(esc_timeout_tag); + 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; } else if (mouse_state == 3) { /* 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 */ - 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) { reemit_guard = 1; signal_emit("gui key pressed", 1, GINT_TO_POINTER(0x1b)); @@ -1388,16 +1514,22 @@ gboolean sidepanels_try_parse_mouse_key(unichar key) } return TRUE; } 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'; s = mouse_buf; /* Check if this is arrow keys (A/B/C/D) or other ESC sequences */ - if (mouse_len == 1 && (key == 'A' || key == 'B' || key == 'C' || key == 'D' || - key == 'H' || key == 'F' || key == '1' || key == '2' || + if (mouse_len == 1 && (key == 'A' || key == 'B' || key == 'C' || key == 'D' || + key == 'H' || key == 'F' || key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6')) { /* This is arrow key or function key - re-emit ESC[ and current key */ - mouse_state = 0; mouse_len = 0; esc_pending = 0; - if (esc_timeout_tag != -1) { g_source_remove(esc_timeout_tag); esc_timeout_tag = -1; } + mouse_state = 0; + mouse_len = 0; + esc_pending = 0; + if (esc_timeout_tag != -1) { + g_source_remove(esc_timeout_tag); + esc_timeout_tag = -1; + } if (!reemit_guard) { reemit_guard = 1; signal_emit("gui key pressed", 1, GINT_TO_POINTER(0x1b)); @@ -1407,24 +1539,42 @@ gboolean sidepanels_try_parse_mouse_key(unichar key) } return TRUE; } - if (*s != '<') { /* not SGR mouse - cancel */ - mouse_state = 0; mouse_len = 0; esc_pending = 0; - if (esc_timeout_tag != -1) { g_source_remove(esc_timeout_tag); esc_timeout_tag = -1; } - return TRUE; + if (*s != '<') { /* not SGR mouse - cancel */ + mouse_state = 0; + mouse_len = 0; + esc_pending = 0; + if (esc_timeout_tag != -1) { + g_source_remove(esc_timeout_tag); + esc_timeout_tag = -1; + } + return TRUE; } - sc1 = strchr(s, ';'); if (!sc1) return TRUE; - sc2 = strchr(sc1+1, ';'); if (!sc2) return TRUE; - end = sc2+1; if (*end == '\0') return TRUE; - last = end[(int)strlen(end)-1]; - if (last != 'M' && last != 'm') return TRUE; - braw = atoi(s+1); - x = atoi(sc1+1); - y = atoi(sc2+1); - x -= 1; y -= 1; + sc1 = strchr(s, ';'); + if (!sc1) + return TRUE; + sc2 = strchr(sc1 + 1, ';'); + if (!sc2) + return TRUE; + end = sc2 + 1; + if (*end == '\0') + return TRUE; + last = end[(int) strlen(end) - 1]; + if (last != 'M' && last != 'm') + return TRUE; + braw = atoi(s + 1); + x = atoi(sc1 + 1); + y = atoi(sc2 + 1); + x -= 1; + y -= 1; 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 */ - 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) { int dir; int delta; @@ -1434,20 +1584,29 @@ gboolean sidepanels_try_parse_mouse_key(unichar key) for (mt = mainwindows; mt; mt = mt->next) { MAIN_WINDOW_REC *mw = mt->data; SP_MAINWIN_CTX *ctx = get_ctx(mw, FALSE); - if (!ctx) continue; + if (!ctx) + continue; if (ctx->left_tw) { - 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) { - ctx->left_scroll_offset = MAX(0, ctx->left_scroll_offset + delta); + 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) { + ctx->left_scroll_offset = + MAX(0, ctx->left_scroll_offset + delta); redraw_one(mw); irssi_set_dirty(); return TRUE; } } if (ctx->right_tw) { - 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) { - ctx->right_scroll_offset = MAX(0, ctx->right_scroll_offset + delta); + 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) { + ctx->right_scroll_offset = + MAX(0, ctx->right_scroll_offset + delta); redraw_one(mw); irssi_set_dirty(); return TRUE; @@ -1461,7 +1620,7 @@ gboolean sidepanels_try_parse_mouse_key(unichar key) button = (braw & 3) + 1; if (press && button == 1) { /* consume click always */ - (void)handle_click_at(x, y, button); + (void) handle_click_at(x, y, button); return TRUE; } } @@ -1511,7 +1670,8 @@ void sidepanels_init(void) /* Apply reservations but don't redraw yet - wait for irssi init finished */ apply_reservations_all(); 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("mainwindow created", (SIGNAL_FUNC) sig_mainwindow_created); signal_add("setup changed", (SIGNAL_FUNC) read_settings); @@ -1592,10 +1752,22 @@ void sidepanels_deinit(void) if (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 (window_priorities) { g_hash_table_destroy(window_priorities); window_priorities = NULL; } + if (mw_to_ctx) { + 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(); /* Clean up timeout */ - if (esc_timeout_tag != -1) { g_source_remove(esc_timeout_tag); esc_timeout_tag = -1; } - if (sp_log) { fclose(sp_log); sp_log = NULL; } + if (esc_timeout_tag != -1) { + g_source_remove(esc_timeout_tag); + esc_timeout_tag = -1; + } + if (sp_log) { + fclose(sp_log); + sp_log = NULL; + } } \ No newline at end of file