1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Refactored status bar indicators

This commit is contained in:
James Booth 2013-08-30 00:10:05 +01:00
parent f99504d0ec
commit 00547bd116

View File

@ -48,6 +48,9 @@ static GDateTime *last_time;
static void _status_bar_update_time(void); static void _status_bar_update_time(void);
static void _update_win_statuses(void); static void _update_win_statuses(void);
static void _mark_new(int num);
static void _mark_active(int num);
static void _mark_inactive(int num);
void void
create_status_bar(void) create_status_bar(void)
@ -143,44 +146,26 @@ status_bar_inactive(const int win)
if (g_hash_table_size(remaining_new) != 0) { if (g_hash_table_size(remaining_new) != 0) {
is_active[11] = TRUE; is_active[11] = TRUE;
is_new[11] = TRUE; is_new[11] = TRUE;
int active_pos = 1 + ((11-1) * 3); _mark_new(11);
int cols = getmaxx(stdscr);
wattron(status_bar, COLOUR_STATUS_NEW);
wattron(status_bar, A_BLINK);
mvwprintw(status_bar, 0, cols - 34 + active_pos, ">");
wattroff(status_bar, COLOUR_STATUS_NEW);
wattroff(status_bar, A_BLINK);
dirty = TRUE;
// still have active winsows // still have active winsows
} else if (g_hash_table_size(remaining_active) != 0) { } else if (g_hash_table_size(remaining_active) != 0) {
is_active[11] = TRUE; is_active[11] = TRUE;
is_new[11] = FALSE; is_new[11] = FALSE;
int active_pos = 1 + ((11-1) * 3); _mark_active(11);
int cols = getmaxx(stdscr);
wattron(status_bar, COLOUR_STATUS_ACTIVE);
mvwprintw(status_bar, 0, cols - 34 + active_pos, ">");
wattroff(status_bar, COLOUR_STATUS_ACTIVE);
dirty = TRUE;
// no active or new windows // no active or new windows
} else { } else {
is_active[11] = FALSE; is_active[11] = FALSE;
is_new[11] = FALSE; is_new[11] = FALSE;
int active_pos = 1 + ((11-1) * 3); _mark_inactive(11);
int cols = getmaxx(stdscr);
mvwaddch(status_bar, 0, cols - 34 + active_pos, ' ');
dirty = TRUE;
} }
// visible window indicators // visible window indicators
} else { } else {
is_active[true_win] = FALSE; is_active[true_win] = FALSE;
is_new[true_win] = FALSE; is_new[true_win] = FALSE;
int active_pos = 1 + ((true_win-1) * 3); _mark_inactive(true_win);
int cols = getmaxx(stdscr);
mvwaddch(status_bar, 0, cols - 34 + active_pos, ' ');
dirty = TRUE;
} }
} }
@ -201,45 +186,20 @@ status_bar_active(const int win)
if (g_hash_table_size(remaining_new) != 0) { if (g_hash_table_size(remaining_new) != 0) {
is_active[11] = TRUE; is_active[11] = TRUE;
is_new[11] = TRUE; is_new[11] = TRUE;
int active_pos = 1 + ((11-1) * 3); _mark_new(11);
int cols = getmaxx(stdscr);
wattron(status_bar, COLOUR_STATUS_NEW);
wattron(status_bar, A_BLINK);
mvwprintw(status_bar, 0, cols - 34 + active_pos, ">");
wattroff(status_bar, COLOUR_STATUS_NEW);
wattroff(status_bar, A_BLINK);
dirty = TRUE;
// only active windows // only active windows
} else { } else {
is_active[11] = TRUE; is_active[11] = TRUE;
is_new[11] = FALSE; is_new[11] = FALSE;
int active_pos = 1 + ((11-1) * 3); _mark_active(11);
int cols = getmaxx(stdscr);
wattron(status_bar, COLOUR_STATUS_ACTIVE);
mvwprintw(status_bar, 0, cols - 34 + active_pos, ">");
wattroff(status_bar, COLOUR_STATUS_ACTIVE);
dirty = TRUE;
} }
// visible winsow indicators // visible winsow indicators
} else { } else {
is_active[true_win] = TRUE; is_active[true_win] = TRUE;
is_new[true_win] = FALSE; is_new[true_win] = FALSE;
int active_pos = 1 + ((true_win-1) * 3); _mark_active(true_win);
int cols = getmaxx(stdscr);
wattron(status_bar, COLOUR_STATUS_ACTIVE);
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;
} }
} }
@ -257,34 +217,12 @@ status_bar_new(const int win)
is_active[11] = TRUE; is_active[11] = TRUE;
is_new[11] = TRUE; is_new[11] = TRUE;
int active_pos = 1 + ((11-1) * 3); _mark_new(11);
int cols = getmaxx(stdscr);
wattron(status_bar, COLOUR_STATUS_NEW);
wattron(status_bar, A_BLINK);
mvwprintw(status_bar, 0, cols - 34 + active_pos, ">");
wattroff(status_bar, COLOUR_STATUS_NEW);
wattroff(status_bar, A_BLINK);
dirty = TRUE;
} else { } else {
is_active[true_win] = TRUE; is_active[true_win] = TRUE;
is_new[true_win] = TRUE; is_new[true_win] = TRUE;
int active_pos = 1 + ((true_win-1) * 3); _mark_new(true_win);
int cols = getmaxx(stdscr);
wattron(status_bar, COLOUR_STATUS_NEW);
wattron(status_bar, A_BLINK);
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);
dirty = TRUE;
} }
} }
@ -389,41 +327,58 @@ _update_win_statuses(void)
int i; int i;
for(i = 1; i < 12; i++) { for(i = 1; i < 12; i++) {
if (is_new[i]) { if (is_new[i]) {
int active_pos = 1 + ((i-1) * 3); _mark_new(i);
}
else if (is_active[i]) {
_mark_active(i);
}
else {
_mark_inactive(i);
}
}
}
static void
_mark_new(int num)
{
int active_pos = 1 + ((num-1) * 3);
int cols = getmaxx(stdscr); int cols = getmaxx(stdscr);
wattron(status_bar, COLOUR_STATUS_NEW); wattron(status_bar, COLOUR_STATUS_NEW);
wattron(status_bar, A_BLINK); wattron(status_bar, A_BLINK);
if (num == 10) {
if (i == 10) {
mvwprintw(status_bar, 0, cols - 34 + active_pos, "0"); mvwprintw(status_bar, 0, cols - 34 + active_pos, "0");
} else if (i > 10) { } else if (num > 10) {
mvwprintw(status_bar, 0, cols - 34 + active_pos, ">"); mvwprintw(status_bar, 0, cols - 34 + active_pos, ">");
} else { } else {
mvwprintw(status_bar, 0, cols - 34 + active_pos, "%d", i); mvwprintw(status_bar, 0, cols - 34 + active_pos, "%d", num);
} }
wattroff(status_bar, COLOUR_STATUS_NEW); wattroff(status_bar, COLOUR_STATUS_NEW);
wattroff(status_bar, A_BLINK); wattroff(status_bar, A_BLINK);
dirty = TRUE;
} }
else if (is_active[i]) {
int active_pos = 1 + ((i-1) * 3); static void
_mark_active(int num)
{
int active_pos = 1 + ((num-1) * 3);
int cols = getmaxx(stdscr); int cols = getmaxx(stdscr);
wattron(status_bar, COLOUR_STATUS_ACTIVE); wattron(status_bar, COLOUR_STATUS_ACTIVE);
if (num == 10) {
if (i == 10) {
mvwprintw(status_bar, 0, cols - 34 + active_pos, "0"); mvwprintw(status_bar, 0, cols - 34 + active_pos, "0");
} else if (i > 10) { } else if (num > 10) {
mvwprintw(status_bar, 0, cols - 34 + active_pos, ">"); mvwprintw(status_bar, 0, cols - 34 + active_pos, ">");
} else { } else {
mvwprintw(status_bar, 0, cols - 34 + active_pos, "%d", i); mvwprintw(status_bar, 0, cols - 34 + active_pos, "%d", num);
}
wattroff(status_bar, COLOUR_STATUS_ACTIVE);
dirty = TRUE;
} }
wattroff(status_bar, COLOUR_STATUS_ACTIVE); static void
} _mark_inactive(int num)
else { {
int active_pos = 1 + ((i-1) * 3); int active_pos = 1 + ((num-1) * 3);
int cols = getmaxx(stdscr); int cols = getmaxx(stdscr);
mvwaddch(status_bar, 0, cols - 34 + active_pos, ' '); mvwaddch(status_bar, 0, cols - 34 + active_pos, ' ');
} dirty = TRUE;
}
} }