diff --git a/src/ui/console.c b/src/ui/console.c index 9e21da48..de3625b4 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 53f4776b..55719245 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -618,6 +618,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) { diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 900e1d40..07ff1fb3 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 82f722a3..0c026b1f 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 03398c68..d4c518ae 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -90,6 +90,59 @@ wins_get_by_num(int i) return g_hash_table_lookup(windows, GINT_TO_POINTER(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) { diff --git a/src/ui/windows.h b/src/ui/windows.h index 9a64f3c7..07495ca3 100644 --- a/src/ui/windows.h +++ b/src/ui/windows.h @@ -30,6 +30,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);