From 9ef7e2d233733d32514420c7dd52c104d4fd3f6b Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 28 Aug 2013 00:50:15 +0100 Subject: [PATCH] Changes to status bar for unlimited windows - WIP --- src/command/command.c | 4 +- src/ui/console.c | 2 +- src/ui/core.c | 12 +++--- src/ui/inputwin.c | 22 +++++----- src/ui/statusbar.c | 93 +++++++++++++++++++++++++++---------------- 5 files changed, 78 insertions(+), 55 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 33550e07..360daa07 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1822,7 +1822,7 @@ _cmd_about(gchar **args, struct cmd_help_t help) cons_show(""); cons_about(); if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); + status_bar_new(1); } return TRUE; } @@ -2124,7 +2124,7 @@ _cmd_who(gchar **args, struct cmd_help_t help) } if (win_type != WIN_CONSOLE && win_type != WIN_MUC) { - status_bar_new(0); + status_bar_new(1); } return TRUE; diff --git a/src/ui/console.c b/src/ui/console.c index ef9787c7..d0b340d9 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1338,7 +1338,7 @@ void cons_alert(void) { if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); + status_bar_new(1); } } diff --git a/src/ui/core.c b/src/ui/core.c index 846a7dea..21102eed 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -85,7 +85,7 @@ ui_init(void) refresh(); create_title_bar(); create_status_bar(); - status_bar_active(0); + status_bar_active(1); create_input_window(); wins_init(); cons_about(); @@ -574,9 +574,9 @@ ui_switch_win(const int i) new_current->unread = 0; - if (i == 0) { + if (i == 1) { title_bar_title(); - status_bar_active(0); + status_bar_active(1); } else { PContact contact = roster_get_contact(new_current->from); if (contact != NULL) { @@ -607,7 +607,7 @@ ui_close_current(void) int current_index = wins_get_current_num(); wins_close_current(); status_bar_inactive(current_index); - status_bar_active(0); + status_bar_active(1); title_bar_title(); } @@ -616,7 +616,7 @@ ui_close_win(int index) { wins_close_by_num(index); status_bar_inactive(index); - status_bar_active(0); + status_bar_active(1); title_bar_title(); wins_refresh_current(); @@ -797,7 +797,7 @@ ui_print_system_msg_from_recipient(const char * const from, const char *message) } else { num = 0; window = wins_get_console(); - status_bar_active(0); + status_bar_active(1); } } diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 0ab53131..b6162938 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -526,35 +526,35 @@ _handle_alt_key(char *input, int *size, int key) switch (key) { case '1': - ui_switch_win(0); - break; - case '2': ui_switch_win(1); break; - case '3': + case '2': ui_switch_win(2); break; - case '4': + case '3': ui_switch_win(3); break; - case '5': + case '4': ui_switch_win(4); break; - case '6': + case '5': ui_switch_win(5); break; - case '7': + case '6': ui_switch_win(6); break; - case '8': + case '7': ui_switch_win(7); break; - case '9': + case '8': ui_switch_win(8); break; - case '0': + case '9': ui_switch_win(9); break; + case '0': + ui_switch_win(0); + break; case 263: case 127: input[*size] = '\0'; diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 6e7eae30..90430e8d 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -37,9 +37,10 @@ static WINDOW *status_bar; static char *message = NULL; -static char _active[31] = "[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]"; -static int is_active[10]; -static int is_new[10]; +// 1 2 3 4 5 6 7 8 9 0 > +static char _active[34] = "[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]"; +static int is_active[12]; +static int is_new[12]; static int dirty; static GDateTime *last_time; @@ -51,9 +52,9 @@ create_status_bar(void) int rows, cols, i; getmaxyx(stdscr, rows, cols); - is_active[0] = TRUE; - is_new[0] = FALSE; - for (i = 1; i < 10; i++) { + is_active[1] = TRUE; + is_new[1] = FALSE; + for (i = 2; i < 12; i++) { is_active[i] = FALSE; is_new[i] = FALSE; } @@ -61,7 +62,7 @@ create_status_bar(void) status_bar = newwin(1, cols, rows-2, 0); wbkgd(status_bar, COLOUR_STATUS_TEXT); wattron(status_bar, COLOUR_STATUS_BRACKET); - mvwprintw(status_bar, 0, cols - 31, _active); + mvwprintw(status_bar, 0, cols - 34, _active); wattroff(status_bar, COLOUR_STATUS_BRACKET); if (last_time != NULL) @@ -105,10 +106,10 @@ status_bar_resize(void) wbkgd(status_bar, COLOUR_STATUS_TEXT); werase(status_bar); wattron(status_bar, COLOUR_STATUS_BRACKET); - mvwprintw(status_bar, 0, cols - 31, _active); + mvwprintw(status_bar, 0, cols - 34, _active); wattroff(status_bar, COLOUR_STATUS_BRACKET); - for(i = 0; i < 10; i++) { + for(i = 1; i < 12; i++) { if (is_new[i]) status_bar_new(i); else if (is_active[i]) @@ -127,14 +128,18 @@ status_bar_resize(void) void status_bar_inactive(const int win) { - is_active[win] = FALSE; - is_new[win] = FALSE; + int true_win = win; + if (true_win == 0) { + true_win = 10; + } + is_active[true_win] = FALSE; + is_new[true_win] = FALSE; - int active_pos = 1 + (win * 3); + int active_pos = 1 + ((true_win-1) * 3); int cols = getmaxx(stdscr); - mvwaddch(status_bar, 0, cols - 31 + active_pos, ' '); + mvwaddch(status_bar, 0, cols - 34 + active_pos, ' '); dirty = TRUE; } @@ -142,18 +147,27 @@ status_bar_inactive(const int win) void status_bar_active(const int win) { - is_active[win] = TRUE; - is_new[win] = FALSE; + int true_win = win; + if (true_win == 0) { + true_win = 10; + } + is_active[true_win] = TRUE; + is_new[true_win] = FALSE; - int active_pos = 1 + (win * 3); + int active_pos = 1 + ((true_win-1) * 3); int cols = getmaxx(stdscr); wattron(status_bar, COLOUR_STATUS_ACTIVE); - if (win+1 < 10) - mvwprintw(status_bar, 0, cols - 31 + active_pos, "%d", win+1); - else - mvwprintw(status_bar, 0, cols - 31 + active_pos, "0"); + + if (true_win == 10) { + mvwprintw(status_bar, 0, cols - 34 + active_pos, "0"); + } else if (true_win > 10) { + mvwprintw(status_bar, 0, cols - 34 + active_pos, ">"); + } else { + mvwprintw(status_bar, 0, cols - 34 + active_pos, "%d", true_win); + } + wattroff(status_bar, COLOUR_STATUS_ACTIVE); dirty = TRUE; @@ -162,19 +176,28 @@ status_bar_active(const int win) void status_bar_new(const int win) { - is_active[win] = TRUE; - is_new[win] = TRUE; + int true_win = win; + if (true_win == 0) { + true_win = 10; + } + is_active[true_win] = TRUE; + is_new[true_win] = TRUE; - int active_pos = 1 + (win * 3); + int active_pos = 1 + ((true_win-1) * 3); int cols = getmaxx(stdscr); wattron(status_bar, COLOUR_STATUS_NEW); wattron(status_bar, A_BLINK); - if (win+1 < 10) - mvwprintw(status_bar, 0, cols - 31 + active_pos, "%d", win+1); - else - mvwprintw(status_bar, 0, cols - 31 + active_pos, "0"); + + if (true_win == 10) { + mvwprintw(status_bar, 0, cols - 34 + active_pos, "0"); + } else if (true_win > 10) { + mvwprintw(status_bar, 0, cols - 34 + active_pos, ">"); + } else { + mvwprintw(status_bar, 0, cols - 34 + active_pos, "%d", true_win); + } + wattroff(status_bar, COLOUR_STATUS_NEW); wattroff(status_bar, A_BLINK); @@ -203,11 +226,11 @@ status_bar_print_message(const char * const msg) int cols = getmaxx(stdscr); wattron(status_bar, COLOUR_STATUS_BRACKET); - mvwprintw(status_bar, 0, cols - 31, _active); + mvwprintw(status_bar, 0, cols - 34, _active); wattroff(status_bar, COLOUR_STATUS_BRACKET); int i; - for(i = 0; i < 10; i++) { + for(i = 1; i < 12; i++) { if (is_new[i]) status_bar_new(i); else if (is_active[i]) @@ -226,9 +249,9 @@ status_bar_clear(void) } int i; - is_active[0] = TRUE; - is_new[0] = FALSE; - for (i = 1; i < 10; i++) { + is_active[1] = TRUE; + is_new[1] = FALSE; + for (i = 2; i < 12; i++) { is_active[i] = FALSE; is_new[i] = FALSE; } @@ -238,7 +261,7 @@ status_bar_clear(void) int cols = getmaxx(stdscr); wattron(status_bar, COLOUR_STATUS_BRACKET); - mvwprintw(status_bar, 0, cols - 31, _active); + mvwprintw(status_bar, 0, cols - 34, _active); wattroff(status_bar, COLOUR_STATUS_BRACKET); dirty = TRUE; @@ -257,11 +280,11 @@ status_bar_clear_message(void) int cols = getmaxx(stdscr); wattron(status_bar, COLOUR_STATUS_BRACKET); - mvwprintw(status_bar, 0, cols - 31, _active); + mvwprintw(status_bar, 0, cols - 34, _active); wattroff(status_bar, COLOUR_STATUS_BRACKET); int i; - for(i = 0; i < 10; i++) { + for(i = 1; i < 12; i++) { if (is_new[i]) status_bar_new(i); else if (is_active[i])