From e8420e7235c4a9217f32ef98984e7b6ee5a11cdf Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 30 Sep 2019 18:28:05 +0200 Subject: Bind key to switch to next active window alt-a brings one to the next window with unread messages. Regards https://github.com/profanity-im/profanity/issues/1114 --- src/ui/inputwin.c | 14 ++++++++++++++ src/ui/window_list.c | 26 ++++++++++++++++++++++++++ src/ui/window_list.h | 1 + 3 files changed, 41 insertions(+) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 157cab83..44d0091e 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -121,6 +121,7 @@ static int _inp_rl_win_19_handler(int count, int key); static int _inp_rl_win_20_handler(int count, int key); static int _inp_rl_win_prev_handler(int count, int key); static int _inp_rl_win_next_handler(int count, int key); +static int _inp_rl_win_next_unread_handler(int count, int key); static int _inp_rl_win_pageup_handler(int count, int key); static int _inp_rl_win_pagedown_handler(int count, int key); static int _inp_rl_subwin_pageup_handler(int count, int key); @@ -403,6 +404,7 @@ _inp_rl_addfuncs(void) rl_add_funmap_entry("prof_win_20", _inp_rl_win_20_handler); rl_add_funmap_entry("prof_win_prev", _inp_rl_win_prev_handler); rl_add_funmap_entry("prof_win_next", _inp_rl_win_next_handler); + rl_add_funmap_entry("prof_win_next_unread", _inp_rl_win_next_unread_handler); rl_add_funmap_entry("prof_win_pageup", _inp_rl_win_pageup_handler); rl_add_funmap_entry("prof_win_pagedown", _inp_rl_win_pagedown_handler); rl_add_funmap_entry("prof_subwin_pageup", _inp_rl_subwin_pageup_handler); @@ -456,6 +458,8 @@ _inp_rl_startup_hook(void) rl_bind_keyseq("\\e[1;3C", _inp_rl_win_next_handler); rl_bind_keyseq("\\e\\e[C", _inp_rl_win_next_handler); + rl_bind_keyseq("\\ea", _inp_rl_win_next_unread_handler); + rl_bind_keyseq("\\e\\e[5~", _inp_rl_subwin_pageup_handler); rl_bind_keyseq("\\e[5;3~", _inp_rl_subwin_pageup_handler); rl_bind_keyseq("\\e\\eOy", _inp_rl_subwin_pageup_handler); @@ -769,6 +773,16 @@ _inp_rl_win_next_handler(int count, int key) return 0; } +static int +_inp_rl_win_next_unread_handler(int count, int key) +{ + ProfWin *window = wins_get_next_unread(); + if (window) { + ui_focus_win(window); + } + return 0; +} + static int _inp_rl_win_pageup_handler(int count, int key) { diff --git a/src/ui/window_list.c b/src/ui/window_list.c index d8c8a0ae..36e63477 100644 --- a/src/ui/window_list.c +++ b/src/ui/window_list.c @@ -1130,3 +1130,29 @@ wins_destroy(void) autocomplete_free(wins_ac); autocomplete_free(wins_close_ac); } + +ProfWin* +wins_get_next_unread(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) { + if (current == GPOINTER_TO_INT(curr->data)) { + break; + } + + ProfWin *window = curr->data; + if (win_unread(window) > 0) { + g_list_free(values); + return window; + } + + curr = g_list_next(curr); + } + + g_list_free(values); + return NULL; +} diff --git a/src/ui/window_list.h b/src/ui/window_list.h index c79e9dd7..003e1dc5 100644 --- a/src/ui/window_list.h +++ b/src/ui/window_list.h @@ -72,6 +72,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); int wins_get_num(ProfWin *window); int wins_get_current_num(void); void wins_close_current(void); -- cgit 1.4.1-2-gfad0