about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-09-26 00:43:31 +0100
committerJames Booth <boothj5@gmail.com>2013-09-26 00:43:31 +0100
commit3512114cf1bfeb05a4412b93d85c27b5abd66e19 (patch)
tree18a3fbedcb08a45df75116437e1b94f1c5bb01a0
parentaac605ccbb13c1f47f0588b2985caa2a98f76544 (diff)
parent2625630ff367eeab566065e92258d4724bfeefed (diff)
downloadprofani-tty-3512114cf1bfeb05a4412b93d85c27b5abd66e19.tar.gz
Merge branch 'master' into otr
-rw-r--r--src/ui/console.c2
-rw-r--r--src/ui/core.c62
-rw-r--r--src/ui/inputwin.c17
-rw-r--r--src/ui/ui.h2
-rw-r--r--src/ui/windows.c53
-rw-r--r--src/ui/windows.h2
6 files changed, 138 insertions, 0 deletions
diff --git a/src/ui/console.c b/src/ui/console.c
index 17e97ca3..192edfc4 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -1289,6 +1289,8 @@ cons_navigation_help(void)
     cons_show("");
     cons_show("Alt-1                    : This console window.");
     cons_show("Alt-2..Alt-0             : Chat windows.");
+    cons_show("Alt-LEFT                 : Previous chat window");
+    cons_show("Alt-RIGHT                : Next chat window");
     cons_show("F1                       : This console window.");
     cons_show("F2..F10                  : Chat windows.");
     cons_show("UP, DOWN                 : Navigate input history.");
diff --git a/src/ui/core.c b/src/ui/core.c
index 6b415a2b..86d216ad 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -616,6 +616,68 @@ ui_switch_win(const int i)
 }
 
 void
+ui_next_win(void)
+{
+    ui_current_page_off();
+    ProfWin *new_current = wins_get_next();
+    int i = wins_get_num(new_current);
+    wins_set_current_by_num(i);
+    ui_current_page_off();
+
+    new_current->unread = 0;
+
+    if (i == 1) {
+        title_bar_title();
+        status_bar_active(1);
+    } else {
+        PContact contact = roster_get_contact(new_current->from);
+        if (contact != NULL) {
+            if (p_contact_name(contact) != NULL) {
+                title_bar_set_recipient(p_contact_name(contact));
+            } else {
+                title_bar_set_recipient(new_current->from);
+            }
+        } else {
+            title_bar_set_recipient(new_current->from);
+        }
+        title_bar_draw();;
+        status_bar_active(i);
+    }
+    wins_refresh_current();
+}
+
+void
+ui_previous_win(void)
+{
+    ui_current_page_off();
+    ProfWin *new_current = wins_get_previous();
+    int i = wins_get_num(new_current);
+    wins_set_current_by_num(i);
+    ui_current_page_off();
+
+    new_current->unread = 0;
+
+    if (i == 1) {
+        title_bar_title();
+        status_bar_active(1);
+    } else {
+        PContact contact = roster_get_contact(new_current->from);
+        if (contact != NULL) {
+            if (p_contact_name(contact) != NULL) {
+                title_bar_set_recipient(p_contact_name(contact));
+            } else {
+                title_bar_set_recipient(new_current->from);
+            }
+        } else {
+            title_bar_set_recipient(new_current->from);
+        }
+        title_bar_draw();;
+        status_bar_active(i);
+    }
+    wins_refresh_current();
+}
+
+void
 ui_clear_current(void)
 {
     wins_clear_current();
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index 598911cd..dfcb533d 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -40,6 +40,7 @@
 #include "log.h"
 #include "profanity.h"
 #include "ui/ui.h"
+#include "ui/windows.h"
 #include "xmpp/xmpp.h"
 
 #define _inp_win_refresh() prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1)
@@ -359,6 +360,16 @@ _handle_edit(int result, const wint_t ch, char *input, int *size)
 
         return 1;
 
+    // ALT-LEFT
+    } else if ((result == KEY_CODE_YES) && (ch == 537)) {
+        ui_previous_win();
+        return 1;
+
+    // ALT-RIGHT
+    } else if ((result == KEY_CODE_YES) && (ch == 552)) {
+        ui_next_win();
+        return 1;
+
     // other editing keys
     } else {
         switch(ch) {
@@ -592,6 +603,12 @@ _handle_alt_key(char *input, int *size, int key)
         case '0':
             ui_switch_win(0);
             break;
+        case KEY_LEFT:
+            ui_previous_win();
+            break;
+        case KEY_RIGHT:
+            ui_next_win();
+            break;
         case 263:
         case 127:
             input[*size] = '\0';
diff --git a/src/ui/ui.h b/src/ui/ui.h
index fa74bed6..4cde751e 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -52,6 +52,8 @@ void ui_idle(void);
 void ui_handle_special_keys(const wint_t * const ch, const char * const inp,
     const int size);
 void ui_switch_win(const int i);
+void ui_next_win(void);
+void ui_previous_win(void);
 unsigned long ui_get_idle_time(void);
 void ui_reset_idle_time(void);
 void ui_new_chat_win(const char * const to);
diff --git a/src/ui/windows.c b/src/ui/windows.c
index e69b2433..684e98fd 100644
--- a/src/ui/windows.c
+++ b/src/ui/windows.c
@@ -91,6 +91,59 @@ wins_get_by_num(int i)
 }
 
 ProfWin *
+wins_get_next(void)
+{
+    // get and sort win nums
+    GList *keys = g_hash_table_get_keys(windows);
+    keys = g_list_sort(keys, cmp_win_num);
+    GList *curr = keys;
+
+    // find our place in the list
+    while (curr != NULL) {
+        if (current == GPOINTER_TO_INT(curr->data)) {
+            break;
+        }
+        curr = g_list_next(curr);
+    }
+
+    // if there is a next window return it
+    curr = g_list_next(curr);
+    if (curr != NULL) {
+        return wins_get_by_num(GPOINTER_TO_INT(curr->data));
+    // otherwise return the first window (console)
+    } else {
+        return wins_get_console();
+    }
+}
+
+ProfWin *
+wins_get_previous(void)
+{
+    // get and sort win nums
+    GList *keys = g_hash_table_get_keys(windows);
+    keys = g_list_sort(keys, cmp_win_num);
+    GList *curr = keys;
+
+    // find our place in the list
+    while (curr != NULL) {
+        if (current == GPOINTER_TO_INT(curr->data)) {
+            break;
+        }
+        curr = g_list_next(curr);
+    }
+
+    // if there is a previous window return it
+    curr = g_list_previous(curr);
+    if (curr != NULL) {
+        return wins_get_by_num(GPOINTER_TO_INT(curr->data));
+    // otherwise return the last window
+    } else {
+        int new_num = GPOINTER_TO_INT(g_list_last(keys)->data);
+        return wins_get_by_num(new_num);
+    }
+}
+
+ProfWin *
 wins_get_by_recipient(const char * const recipient)
 {
     GList *values = g_hash_table_get_values(windows);
diff --git a/src/ui/windows.h b/src/ui/windows.h
index 6d93c434..3cf593e8 100644
--- a/src/ui/windows.h
+++ b/src/ui/windows.h
@@ -28,6 +28,8 @@ ProfWin * wins_get_console(void);
 ProfWin * wins_get_current(void);
 void wins_set_current_by_num(int i);
 ProfWin * wins_get_by_num(int i);
+ProfWin * wins_get_next(void);
+ProfWin * wins_get_previous(void);
 ProfWin * wins_get_by_recipient(const char * const recipient);
 int wins_get_num(ProfWin *window);
 int wins_get_current_num(void);