about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-09-30 18:28:05 +0200
committerMichael Vetter <jubalh@iodoru.org>2019-09-30 18:28:05 +0200
commite8420e7235c4a9217f32ef98984e7b6ee5a11cdf (patch)
tree99a6a6b5dbf23963e75461f4a19d8537b9d5cc9e /src
parentd6c638c70fd6fe7170ac144fe858b93bdfd2eacb (diff)
downloadprofani-tty-e8420e7235c4a9217f32ef98984e7b6ee5a11cdf.tar.gz
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
Diffstat (limited to 'src')
-rw-r--r--src/ui/inputwin.c14
-rw-r--r--src/ui/window_list.c26
-rw-r--r--src/ui/window_list.h1
3 files changed, 41 insertions, 0 deletions
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);
@@ -770,6 +774,16 @@ _inp_rl_win_next_handler(int count, int key)
 }
 
 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)
 {
     ProfWin *current = wins_get_current();
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);