From 181c423636e4131597104e088563df276393a3db Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 13 Feb 2012 00:59:04 +0000 Subject: [PATCH] Tidy up refreshing current chat --- windows.c | 51 +++++++++++++++------------------------------------ 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/windows.c b/windows.c index 94620dcf..a30fa80d 100644 --- a/windows.c +++ b/windows.c @@ -8,6 +8,7 @@ static int _curr_win = 0; static void _create_windows(void); static void _send_message_to_win(char *contact, char *line); +static void _refresh_if_current(int i); void gui_init(void) { @@ -140,11 +141,7 @@ void cons_help(void) wprintw(_wins[0].win, " [%s] F2-10 : Chat windows.\n", tstmp); - // if its the current window, draw it - if (_curr_win == 0) { - touchwin(_wins[0].win); - wrefresh(_wins[0].win); - } + _refresh_if_current(0); } void cons_show(char *msg) @@ -153,12 +150,7 @@ void cons_show(char *msg) get_time(tstmp); wprintw(_wins[0].win, " [%s] %s\n", tstmp, msg); - - // if its the current window, draw it - if (_curr_win == 0) { - touchwin(_wins[0].win); - wrefresh(_wins[0].win); - } + _refresh_if_current(0); } void cons_bad_command(char *cmd) @@ -167,12 +159,7 @@ void cons_bad_command(char *cmd) get_time(tstmp); wprintw(_wins[0].win, " [%s] Unknown command: %s\n", tstmp, cmd); - - // if its the current window, draw it - if (_curr_win == 0) { - touchwin(_wins[0].win); - wrefresh(_wins[0].win); - } + _refresh_if_current(0); } static void _create_windows(void) @@ -220,33 +207,25 @@ static void _send_message_to_win(char *contact, char *line) if (strcmp(_wins[i].from, "") == 0) break; - // set it up and print the message to it + // set it up and use it strcpy(_wins[i].from, contact); wclear(_wins[i].win); wprintw(_wins[i].win, line); - - // signify active window in status bar status_bar_active(i); - - // if its the current window, draw it - if (_curr_win == i) { - touchwin(_wins[i].win); - wrefresh(_wins[i].win); - } + _refresh_if_current(i); } - // otherwise + // otherwise, just use it else { - // add the line to the senders window wprintw(_wins[i].win, line); - - // signify active window in status bar status_bar_active(i); - - // if its the current window, draw it - if (_curr_win == i) { - touchwin(_wins[i].win); - wrefresh(_wins[i].win); - } + _refresh_if_current(i); } } +static void _refresh_if_current(int i) +{ + if (_curr_win == i) { + touchwin(_wins[i].win); + wrefresh(_wins[i].win); + } +}