diff --git a/src/ui/core.c b/src/ui/core.c index 4e4e39a0..50fba846 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -996,6 +996,18 @@ ui_win_unread(int index) } } +gboolean +ui_win_has_attention(int index) +{ + ProfWin* window = wins_get_by_num(index); + if (window) { + return win_has_attention(window); + } else { + return 0; + } +} + + char* ui_ask_password(gboolean confirm) { diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 8de12115..f8b67bfe 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -36,7 +36,6 @@ #define _XOPEN_SOURCE_EXTENDED #include "config.h" -#include #include #include #include @@ -815,15 +814,7 @@ static int _inp_rl_win_attention_handler(int count, int key) { ProfWin* current = wins_get_current(); if ( current ) { - if (current->type == WIN_CHAT) { - ProfChatWin* chatwin = (ProfChatWin*)current; - assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); - chatwin->has_attention = !chatwin->has_attention; - } else if (current->type == WIN_MUC) { - ProfMucWin* mucwin = (ProfMucWin*)current; - assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); - mucwin->has_attention = !mucwin->has_attention; - } + win_toggle_attention(current); win_redraw(current); } return 0; @@ -831,7 +822,10 @@ _inp_rl_win_attention_handler(int count, int key) { static int _inp_rl_win_attention_next_handler(int count, int key) { - //ProfWin* current = wins_get_current(); + ProfWin* window = wins_get_next_attention(); + if (window) { + ui_focus_win(window); + } return 0; } diff --git a/src/ui/ui.h b/src/ui/ui.h index 3404992d..f9ef5cff 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -75,6 +75,9 @@ int ui_close_all_wins(void); int ui_close_read_wins(void); void ui_close_win(int index); int ui_win_unread(int index); +gboolean ui_win_has_attention(int index); +gboolean win_has_attention(ProfWin* window); +gboolean win_toggle_attention(ProfWin* window); char* ui_ask_password(gboolean confirm); char* ui_get_line(void); char* ui_ask_pgp_passphrase(const char* hint, int prev_fail); diff --git a/src/ui/window.c b/src/ui/window.c index 36825eab..4fb7d5f7 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1842,6 +1842,39 @@ win_unread(ProfWin* window) } } +gboolean +win_has_attention(ProfWin* window) +{ + if (window->type == WIN_CHAT) { + ProfChatWin* chatwin = (ProfChatWin*)window; + assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); + return chatwin->has_attention; + } else if (window->type == WIN_MUC) { + ProfMucWin* mucwin = (ProfMucWin*)window; + assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + return mucwin->has_attention; + } + return FALSE; +} + +gboolean +win_toggle_attention(ProfWin* window) +{ + if (window->type == WIN_CHAT) { + ProfChatWin* chatwin = (ProfChatWin*)window; + assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); + chatwin->has_attention = !chatwin->has_attention; + return chatwin->has_attention; + } else if (window->type == WIN_MUC) { + ProfMucWin* mucwin = (ProfMucWin*)window; + assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + mucwin->has_attention = !mucwin->has_attention; + return mucwin->has_attention; + } + return FALSE; +} + + void win_sub_print(WINDOW* win, char* msg, gboolean newline, gboolean wrap, int indent) { diff --git a/src/ui/window_list.c b/src/ui/window_list.c index 2c45ea97..3a46f59e 100644 --- a/src/ui/window_list.c +++ b/src/ui/window_list.c @@ -1205,6 +1205,38 @@ wins_get_next_unread(void) return NULL; } +ProfWin* +wins_get_next_attention(void) +{ + // get and sort win nums + GList* values = g_hash_table_get_values(windows); + values = g_list_sort(values, _wins_cmp_num); + GList* curr = values; + + while (curr) { + // copy from wins_get_next_unread - what is it? + if (current == GPOINTER_TO_INT(curr->data)) { + curr = g_list_next(curr); + continue; + } + + ProfWin* window_current = wins_get_by_num( current); + ProfWin* window = curr->data; + if( window_current == window ) { + curr = g_list_next(curr); + continue; + } + if (win_has_attention(window)) { + g_list_free(values); + return window; + } + curr = g_list_next(curr); + } + + g_list_free(values); + return NULL; +} + void wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message) { diff --git a/src/ui/window_list.h b/src/ui/window_list.h index b2c752e0..06ae6d7e 100644 --- a/src/ui/window_list.h +++ b/src/ui/window_list.h @@ -74,6 +74,7 @@ ProfWin* wins_get_by_string(const char* str); ProfWin* wins_get_next(void); ProfWin* wins_get_previous(void); ProfWin* wins_get_next_unread(void); +ProfWin* wins_get_next_attention(void); int wins_get_num(ProfWin* window); int wins_get_current_num(void); void wins_close_by_num(int i);