1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Reduced screen flicker, and fixed end page

This commit is contained in:
James Booth 2012-03-06 01:04:45 +00:00
parent 51738d4aba
commit 54c43b613c
4 changed files with 102 additions and 15 deletions

View File

@ -63,7 +63,6 @@ void inp_clear(void)
{
wclear(inp_win);
wmove(inp_win, 0, 1);
touchwin(inp_win);
wrefresh(inp_win);
}

View File

@ -20,6 +20,8 @@
*
*/
#include <string.h>
#include <ncurses.h>
#include "windows.h"
#include "util.h"
@ -27,6 +29,9 @@
static WINDOW *status_bar;
static char _active[29] = "[ ][ ][ ][ ][ ][ ][ ][ ][ ]";
static int dirty;
static char curr_time[80];
static void _status_bar_update_time(void);
void create_status_bar(void)
@ -39,15 +44,27 @@ void create_status_bar(void)
wattron(status_bar, COLOR_PAIR(4));
mvwprintw(status_bar, 0, cols - 29, _active);
wattroff(status_bar, COLOR_PAIR(4));
wrefresh(status_bar);
get_time(curr_time);
dirty = TRUE;
}
void status_bar_refresh(void)
{
_status_bar_update_time();
touchwin(status_bar);
wrefresh(status_bar);
inp_put_back();
char new_time[80];
get_time(new_time);
if (strcmp(new_time, curr_time) != 0) {
dirty = TRUE;
strcpy(curr_time, new_time);
}
if (dirty) {
_status_bar_update_time();
wrefresh(status_bar);
inp_put_back();
dirty = FALSE;
}
}
void status_bar_inactive(int win)
@ -60,6 +77,8 @@ void status_bar_inactive(int win)
mvwaddch(status_bar, 0, cols - 29 + active_pos, ' ');
if (win == 9)
mvwaddch(status_bar, 0, cols - 29 + active_pos + 1, ' ');
dirty = TRUE;
}
void status_bar_active(int win)
@ -73,16 +92,22 @@ void status_bar_active(int win)
mvwprintw(status_bar, 0, cols - 29 + active_pos, "%d", win+1);
else
mvwprintw(status_bar, 0, cols - 29 + active_pos, "10");
dirty = TRUE;
}
void status_bar_get_password(void)
{
mvwprintw(status_bar, 0, 9, "Enter password:");
dirty = TRUE;
}
void status_bar_print_message(const char *msg)
{
mvwprintw(status_bar, 0, 9, msg);
dirty = TRUE;
}
void status_bar_clear(void)
@ -94,6 +119,8 @@ void status_bar_clear(void)
wattron(status_bar, COLOR_PAIR(4));
mvwprintw(status_bar, 0, cols - 29, _active);
wattroff(status_bar, COLOR_PAIR(4));
dirty = TRUE;
}
static void _status_bar_update_time(void)
@ -110,6 +137,7 @@ static void _status_bar_update_time(void)
wattron(status_bar, COLOR_PAIR(4));
mvwaddch(status_bar, 0, 7, ']');
wattroff(status_bar, COLOR_PAIR(4));
dirty = TRUE;
}

View File

@ -24,6 +24,7 @@
#include "windows.h"
static WINDOW *title_bar;
static int dirty;
void create_title_bar(void)
{
@ -34,12 +35,14 @@ void create_title_bar(void)
wbkgd(title_bar, COLOR_PAIR(3));
title_bar_title();
title_bar_disconnected();
dirty = TRUE;
}
void title_bar_title()
{
char *title = "Profanity. Type /help for help information.";
title_bar_show(title);
dirty = TRUE;
}
void title_bar_connected(void)
@ -56,6 +59,8 @@ void title_bar_connected(void)
wattron(title_bar, COLOR_PAIR(4));
mvwaddch(title_bar, 0, cols - 2, ']');
wattroff(title_bar, COLOR_PAIR(4));
dirty = TRUE;
}
void title_bar_disconnected(void)
@ -72,13 +77,17 @@ void title_bar_disconnected(void)
wattron(title_bar, COLOR_PAIR(4));
mvwaddch(title_bar, 0, cols - 2, ']');
wattroff(title_bar, COLOR_PAIR(4));
dirty = TRUE;
}
void title_bar_refresh(void)
{
touchwin(title_bar);
wrefresh(title_bar);
inp_put_back();
if (dirty) {
wrefresh(title_bar);
inp_put_back();
dirty = FALSE;
}
}
void title_bar_show(char *title)
@ -88,5 +97,7 @@ void title_bar_show(char *title)
for (i = 0; i < 45; i++)
waddch(title_bar, ' ');
mvwprintw(title_bar, 0, 0, " %s", title);
dirty = TRUE;
}

View File

@ -39,6 +39,9 @@ static int _curr_prof_win = 0;
// shortcut pointer to console window
static WINDOW * _cons_win = NULL;
// current window state
static int dirty;
static void _create_windows(void);
static int _find_prof_win_index(char *contact);
static int _new_prof_win(char *contact);
@ -74,13 +77,20 @@ void gui_init(void)
create_status_bar();
create_input_window();
_create_windows();
dirty = TRUE;
}
void gui_refresh(void)
{
title_bar_refresh();
status_bar_refresh();
_current_window_refresh();
if (dirty) {
_current_window_refresh();
dirty = FALSE;
}
inp_put_back();
}
@ -102,6 +112,8 @@ int win_close_win(void)
// go back to console window
_curr_prof_win = 0;
title_bar_title();
dirty = TRUE;
// success
return 1;
@ -141,6 +153,9 @@ void win_show_incomming_msg(char *from, char *message)
_win_show_message(win, message);
status_bar_active(win_index);
if (win_index == _curr_prof_win)
dirty = TRUE;
}
void win_show_outgoing_msg(char *from, char *to, char *message)
@ -155,6 +170,9 @@ void win_show_outgoing_msg(char *from, char *to, char *message)
_win_show_message(win, message);
status_bar_active(win_index);
if (win_index == _curr_prof_win)
dirty = TRUE;
}
void win_contact_online(char *from, char *show, char *status)
@ -166,6 +184,9 @@ void win_contact_online(char *from, char *show, char *status)
WINDOW *win = _wins[win_index].win;
_show_status_string(win, from, show, status, "++", "online");
}
if (win_index == _curr_prof_win)
dirty = TRUE;
}
void win_contact_offline(char *from, char *show, char *status)
@ -177,6 +198,9 @@ void win_contact_offline(char *from, char *show, char *status)
WINDOW *win = _wins[win_index].win;
_show_status_string(win, from, show, status, "--", "offline");
}
if (win_index == _curr_prof_win)
dirty = TRUE;
}
void cons_help(void)
@ -197,6 +221,9 @@ void cons_help(void)
cons_show(" UP, DOWN : Navigate input history.");
cons_show(" LEFT, RIGHT : Edit current input.");
cons_show(" PAGE UP, PAGE DOWN : Page the chat window.");
if (_curr_prof_win == 0)
dirty = TRUE;
}
void cons_bad_show(char *msg)
@ -205,18 +232,27 @@ void cons_bad_show(char *msg)
wattron(_cons_win, COLOR_PAIR(6));
wprintw(_cons_win, "%s\n", msg);
wattroff(_cons_win, COLOR_PAIR(6));
if (_curr_prof_win == 0)
dirty = TRUE;
}
void cons_show(char *msg)
{
_win_show_time(_cons_win);
wprintw(_cons_win, "%s\n", msg);
if (_curr_prof_win == 0)
dirty = TRUE;
}
void cons_bad_command(char *cmd)
{
_win_show_time(_cons_win);
wprintw(_cons_win, "Unknown command: %s\n", cmd);
if (_curr_prof_win == 0)
dirty = TRUE;
}
void cons_bad_connect(void)
@ -278,6 +314,8 @@ void win_page_off(void)
_wins[_curr_prof_win].y_pos = y - (size - 1);
if (_wins[_curr_prof_win].y_pos < 0)
_wins[_curr_prof_win].y_pos = 0;
dirty = TRUE;
}
void win_handle_page(int *ch)
@ -291,17 +329,26 @@ void win_handle_page(int *ch)
_wins[_curr_prof_win].y_pos = 0;
_wins[_curr_prof_win].paged = 1;
dirty = TRUE;
} else if (*ch == KEY_NPAGE) {
int rows, cols, y, x;
getmaxyx(stdscr, rows, cols);
getyx(_wins[_curr_prof_win].win, y, x);
_wins[_curr_prof_win].y_pos = _wins[_curr_prof_win].y_pos + (rows - 4);
if (_wins[_curr_prof_win].y_pos >= y)
_wins[_curr_prof_win].y_pos = y - 1;
// only got half a screen, show full screen
if ((y - _wins[_curr_prof_win].y_pos) < (rows - 4))
_wins[_curr_prof_win].y_pos = y - (rows - 4);
// went past end, show full screen
else if (_wins[_curr_prof_win].y_pos >= y)
_wins[_curr_prof_win].y_pos = y - (rows - 4);
_wins[_curr_prof_win].paged = 1;
dirty = TRUE;
}
}
static void _create_windows(void)
@ -323,8 +370,9 @@ static void _create_windows(void)
wattrset(_cons_win, A_BOLD);
_win_show_time(_cons_win);
wprintw(_cons_win, "Welcome to Profanity.\n");
touchwin(_cons_win);
prefresh(_cons_win, 0, 0, 1, 0, rows-3, cols-1);
dirty = TRUE;
// create the chat windows
int i;
@ -377,6 +425,8 @@ static void _win_switch_if_active(int i)
else
title_bar_show(_wins[i].from);
}
dirty = TRUE;
}
static void _win_show_time(WINDOW *win)
@ -408,7 +458,6 @@ static void _current_window_refresh()
getmaxyx(stdscr, rows, cols);
WINDOW *current = _wins[_curr_prof_win].win;
touchwin(current);
prefresh(current, _wins[_curr_prof_win].y_pos, 0, 1, 0, rows-3, cols-1);
}