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

Refactor marking windows as dirty and status bar new indicator

This commit is contained in:
James Booth 2013-04-22 21:11:08 +01:00
parent 9a59631cbc
commit 9373f41fa4
3 changed files with 128 additions and 168 deletions

View File

@ -40,46 +40,31 @@
#define CONS_WIN_TITLE "_cons"
static ProfWin* console;
static int dirty;
static void _cons_splash_logo(void);
static void _cons_show_basic_help(void);
static void _cons_alert(void);
ProfWin *
cons_create(void)
{
int cols = getmaxx(stdscr);
console = win_create(CONS_WIN_TITLE, cols, WIN_CONSOLE);
dirty = FALSE;
return console;
}
void
cons_refresh(void)
{
int rows, cols;
if (dirty == TRUE) {
getmaxyx(stdscr, rows, cols);
prefresh(console->win, console->y_pos, 0, 1, 0, rows-3, cols-1);
dirty = FALSE;
}
}
void
cons_show_time(void)
{
win_print_time(console, '-');
ui_console_dirty();
}
void
cons_show_word(const char * const word)
{
wprintw(console->win, "%s", word);
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
}
void
@ -95,10 +80,8 @@ cons_debug(const char * const msg, ...)
g_string_free(fmt_msg, TRUE);
va_end(arg);
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
ui_current_page_off();
ui_refresh();
@ -116,8 +99,7 @@ cons_show(const char * const msg, ...)
wprintw(console->win, "%s\n", fmt_msg->str);
g_string_free(fmt_msg, TRUE);
va_end(arg);
dirty = TRUE;
ui_console_dirty();
}
void
@ -134,10 +116,8 @@ cons_show_error(const char * const msg, ...)
g_string_free(fmt_msg, TRUE);
va_end(arg);
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -147,6 +127,9 @@ cons_show_typing(const char * const short_from)
wattron(console->win, COLOUR_TYPING);
wprintw(console->win, "!! %s is typing a message...\n", short_from);
wattroff(console->win, COLOUR_TYPING);
ui_console_dirty();
_cons_alert();
}
void
@ -156,6 +139,9 @@ cons_show_incoming_message(const char * const short_from, const int win_index)
wattron(console->win, COLOUR_INCOMING);
wprintw(console->win, "<< incoming from %s (%d)\n", short_from, win_index + 1);
wattroff(console->win, COLOUR_INCOMING);
ui_console_dirty();
_cons_alert();
}
void
@ -199,10 +185,8 @@ cons_about(void)
prefresh(console->win, 0, 0, 1, 0, rows-3, cols-1);
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -229,10 +213,8 @@ cons_check_version(gboolean not_available_msg)
}
}
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
}
}
@ -252,6 +234,8 @@ cons_show_login_success(ProfAccount *account)
wprintw(console->win, " (priority %d)",
accounts_get_priority_for_presence_type(account->name, presence));
wprintw(console->win, ".\n");
ui_console_dirty();
_cons_alert();
}
void
@ -324,10 +308,8 @@ cons_show_wins(void)
}
cons_show("");
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -458,10 +440,8 @@ cons_show_info(PContact pcontact)
ordered_resources = g_list_next(ordered_resources);
}
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -534,10 +514,8 @@ cons_show_caps(const char * const contact, Resource *resource)
}
}
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -562,10 +540,8 @@ cons_show_software_version(const char * const jid, const char * const presence,
cons_show("OS : %s", os);
}
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -587,10 +563,8 @@ cons_show_room_list(GSList *rooms, const char * const conference_node)
cons_show("No chat rooms at %s", conference_node);
}
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -631,10 +605,8 @@ cons_show_disco_info(const char *jid, GSList *identities, GSList *features)
features = g_slist_next(features);
}
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
}
@ -658,10 +630,8 @@ cons_show_disco_items(GSList *items, const char * const jid)
cons_show("");
cons_show("No service discovery items for %s", jid);
}
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -674,6 +644,8 @@ cons_show_status(const char * const contact)
} else {
cons_show("No such contact \"%s\" in roster.", contact);
}
ui_console_dirty();
_cons_alert();
}
void
@ -706,10 +678,8 @@ cons_show_room_invite(const char * const invitor, const char * const room,
jid_destroy(room_jid);
g_string_free(default_service, TRUE);
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -737,10 +707,8 @@ cons_show_account_list(gchar **accounts)
cons_show("");
}
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -852,10 +820,8 @@ cons_show_account(ProfAccount *account)
}
}
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -911,10 +877,8 @@ cons_show_ui_prefs(void)
else
cons_show("Status (/statuses) : OFF");
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -941,6 +905,9 @@ cons_show_desktop_prefs(void)
} else {
cons_show("Reminder period (/notify remind) : %d seconds", remind_period);
}
ui_console_dirty();
_cons_alert();
}
void
@ -968,10 +935,8 @@ cons_show_chat_prefs(void)
cons_show("Leave conversation (/gone) : %d minutes", gone_time);
}
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -987,10 +952,8 @@ cons_show_log_prefs(void)
else
cons_show("Chat logging (/chlog) : OFF");
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -1020,10 +983,8 @@ cons_show_presence_prefs(void)
cons_show("Autoaway check (/autoaway check) : OFF");
}
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -1050,10 +1011,8 @@ cons_show_connection_prefs(void)
cons_show("Autoping interval (/autoping) : %d seconds", autoping_interval);
}
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -1071,10 +1030,8 @@ cons_show_themes(GSList *themes)
}
}
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -1094,10 +1051,8 @@ cons_prefs(void)
cons_show_connection_prefs();
cons_show("");
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -1114,10 +1069,8 @@ cons_help(void)
cons_show("/help [command] - Detailed help on a specific command.");
cons_show("");
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -1127,10 +1080,8 @@ cons_basic_help(void)
cons_show("Basic Commands:");
_cons_show_basic_help();
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -1149,10 +1100,8 @@ cons_settings_help(void)
cons_show("");
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -1171,10 +1120,8 @@ cons_presence_help(void)
cons_show("");
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -1194,10 +1141,8 @@ cons_navigation_help(void)
cons_show("PAGE UP, PAGE DOWN : Page the main window.");
cons_show("");
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
void
@ -1213,10 +1158,8 @@ cons_show_contacts(GSList *list)
curr = g_slist_next(curr);
}
dirty = TRUE;
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
ui_console_dirty();
_cons_alert();
}
static void
@ -1283,5 +1226,15 @@ _cons_show_basic_help(void)
}
cons_show("");
ui_console_dirty();
_cons_alert();
}
static void
_cons_alert(void)
{
if (ui_current_win_type() != WIN_CONSOLE) {
status_bar_new(0);
}
}

View File

@ -54,7 +54,7 @@ static ProfWin *current;
static ProfWin *console;
// current window state
static int dirty;
static gboolean current_win_dirty;
// max columns for main windows, never resize below
static int max_cols = 0;
@ -112,7 +112,7 @@ ui_init(void)
display = XOpenDisplay(0);
#endif
ui_idle_time = g_timer_new();
dirty = TRUE;
current_win_dirty = TRUE;
}
void
@ -122,16 +122,23 @@ ui_refresh(void)
title_bar_refresh();
status_bar_refresh();
cons_refresh();
if (dirty) {
if (current_win_dirty) {
_current_window_refresh();
dirty = FALSE;
current_win_dirty = FALSE;
}
inp_put_back();
}
void
ui_console_dirty(void)
{
if (ui_current_win_type() == WIN_CONSOLE) {
current_win_dirty = TRUE;
}
}
unsigned long
ui_get_idle_time(void)
{
@ -172,7 +179,7 @@ ui_resize(const int ch, const char * const input, const int size)
status_bar_resize();
_win_resize_all();
inp_win_resize(input, size);
dirty = TRUE;
current_win_dirty = TRUE;
}
void
@ -211,7 +218,7 @@ ui_contact_typing(const char * const from)
// have chat window but not currently in it
} else if (win_index != current_index) {
cons_show_typing(from);
dirty = TRUE;
current_win_dirty = TRUE;
// in chat window with user
} else {
@ -219,7 +226,7 @@ ui_contact_typing(const char * const from)
title_bar_draw();
status_bar_active(win_index);
dirty = TRUE;
current_win_dirty = TRUE;
}
}
@ -299,7 +306,7 @@ ui_incoming_msg(const char * const from, const char * const message,
cons_show("Windows all used, close a window to respond.");
if (current_index == 0) {
dirty = TRUE;
current_win_dirty = TRUE;
} else {
status_bar_new(0);
}
@ -335,7 +342,7 @@ ui_incoming_msg(const char * const from, const char * const message,
title_bar_set_typing(FALSE);
title_bar_draw();
status_bar_active(win_index);
dirty = TRUE;
current_win_dirty = TRUE;
// not currently viewing chat window with sender
} else {
@ -408,7 +415,7 @@ ui_contact_online(const char * const barejid, const char * const resource,
jid_destroy(jid);
if (win_index == current_index)
dirty = TRUE;
current_win_dirty = TRUE;
}
void
@ -433,7 +440,7 @@ ui_contact_offline(const char * const from, const char * const show,
}
if (win_index == current_index)
dirty = TRUE;
current_win_dirty = TRUE;
}
void
@ -449,9 +456,9 @@ ui_disconnected(void)
wprintw(window->win, "%s\n", "Lost connection.");
wattroff(window->win, COLOUR_ERROR);
// if current win, set dirty
// if current win, set current_win_dirty
if (i == current_index) {
dirty = TRUE;
current_win_dirty = TRUE;
}
}
}
@ -494,14 +501,14 @@ ui_switch_win(const int i)
}
}
dirty = TRUE;
current_win_dirty = TRUE;
}
void
ui_clear_current(void)
{
werase(current->win);
dirty = TRUE;
current_win_dirty = TRUE;
}
void
@ -518,7 +525,7 @@ ui_close_current(void)
status_bar_active(0);
title_bar_title();
dirty = TRUE;
current_win_dirty = TRUE;
}
win_type_t
@ -545,7 +552,7 @@ ui_current_print_line(const char * const msg, ...)
g_string_free(fmt_msg, TRUE);
va_end(arg);
dirty = TRUE;
current_win_dirty = TRUE;
}
void
@ -556,7 +563,7 @@ ui_current_error_line(const char * const msg)
wprintw(current->win, "%s\n", msg);
wattroff(current->win, COLOUR_ERROR);
dirty = TRUE;
current_win_dirty = TRUE;
}
void
@ -575,7 +582,7 @@ ui_current_page_off(void)
if (window->y_pos < 0)
window->y_pos = 0;
dirty = TRUE;
current_win_dirty = TRUE;
}
void
@ -594,7 +601,7 @@ ui_print_error_from_recipient(const char * const from, const char *err_msg)
win_print_time(window, '-');
_win_show_error_msg(window->win, err_msg);
if (win_index == current_index) {
dirty = TRUE;
current_win_dirty = TRUE;
}
}
}
@ -617,7 +624,7 @@ ui_print_system_msg_from_recipient(const char * const from, const char *message)
if (win_index == NUM_WINS) {
win_index = _new_prof_win(bare_jid, WIN_CHAT);
status_bar_active(win_index);
dirty = TRUE;
current_win_dirty = TRUE;
}
window = windows[win_index];
@ -626,7 +633,7 @@ ui_print_system_msg_from_recipient(const char * const from, const char *message)
// this is the current window
if (win_index == current_index) {
dirty = TRUE;
current_win_dirty = TRUE;
}
}
@ -650,7 +657,7 @@ ui_recipient_gone(const char * const from)
wprintw(window->win, "\n");
wattroff(window->win, COLOUR_GONE);
if (win_index == current_index) {
dirty = TRUE;
current_win_dirty = TRUE;
}
}
}
@ -810,7 +817,7 @@ ui_room_roster(const char * const room, GList *roster, const char * const presen
}
if (win_index == current_index)
dirty = TRUE;
current_win_dirty = TRUE;
}
void
@ -825,7 +832,7 @@ ui_room_member_offline(const char * const room, const char * const nick)
wattroff(window->win, COLOUR_OFFLINE);
if (win_index == current_index)
dirty = TRUE;
current_win_dirty = TRUE;
}
void
@ -841,7 +848,7 @@ ui_room_member_online(const char * const room, const char * const nick,
wattroff(window->win, COLOUR_ONLINE);
if (win_index == current_index)
dirty = TRUE;
current_win_dirty = TRUE;
}
void
@ -855,7 +862,7 @@ ui_room_member_presence(const char * const room, const char * const nick,
}
if (win_index == current_index)
dirty = TRUE;
current_win_dirty = TRUE;
}
void
@ -871,7 +878,7 @@ ui_room_member_nick_change(const char * const room,
wattroff(window->win, COLOUR_THEM);
if (win_index == current_index)
dirty = TRUE;
current_win_dirty = TRUE;
}
void
@ -886,7 +893,7 @@ ui_room_nick_change(const char * const room, const char * const nick)
wattroff(window->win, COLOUR_ME);
if (win_index == current_index)
dirty = TRUE;
current_win_dirty = TRUE;
}
void
@ -912,7 +919,7 @@ ui_room_history(const char * const room_jid, const char * const nick,
}
if (win_index == current_index)
dirty = TRUE;
current_win_dirty = TRUE;
}
void
@ -951,14 +958,14 @@ ui_room_message(const char * const room_jid, const char * const nick,
// currently in groupchat window
if (win_index == current_index) {
status_bar_active(win_index);
dirty = TRUE;
current_win_dirty = TRUE;
// not currenlty on groupchat window
} else {
status_bar_new(win_index);
cons_show_incoming_message(nick, win_index);
if (current_index == 0) {
dirty = TRUE;
current_win_dirty = TRUE;
}
if (strcmp(nick, muc_get_room_nick(room_jid)) != 0) {
@ -995,7 +1002,7 @@ ui_room_subject(const char * const room_jid, const char * const subject)
// currently in groupchat window
if (win_index == current_index) {
status_bar_active(win_index);
dirty = TRUE;
current_win_dirty = TRUE;
// not currenlty on groupchat window
} else {
@ -1018,7 +1025,7 @@ ui_room_broadcast(const char * const room_jid, const char * const message)
// currently in groupchat window
if (win_index == current_index) {
status_bar_active(win_index);
dirty = TRUE;
current_win_dirty = TRUE;
// not currenlty on groupchat window
} else {
@ -1355,7 +1362,7 @@ _win_handle_page(const wint_t * const ch)
*page_start = y - page_space;
current->paged = 1;
dirty = TRUE;
current_win_dirty = TRUE;
} else if (mouse_event.bstate & BUTTON4_PRESSED) { // mouse wheel up
*page_start -= 4;
@ -1364,7 +1371,7 @@ _win_handle_page(const wint_t * const ch)
*page_start = 0;
current->paged = 1;
dirty = TRUE;
current_win_dirty = TRUE;
}
}
}
@ -1379,7 +1386,7 @@ _win_handle_page(const wint_t * const ch)
*page_start = 0;
current->paged = 1;
dirty = TRUE;
current_win_dirty = TRUE;
// page down
} else if (*ch == KEY_NPAGE) {
@ -1394,7 +1401,7 @@ _win_handle_page(const wint_t * const ch)
*page_start = y - page_space;
current->paged = 1;
dirty = TRUE;
current_win_dirty = TRUE;
}
}

View File

@ -63,6 +63,7 @@ void ui_new_chat_win(const char * const to);
void ui_print_error_from_recipient(const char * const from, const char *err_msg);
void ui_print_system_msg_from_recipient(const char * const from, const char *message);
gint ui_unread(void);
void ui_console_dirty(void);
// current window actions
void ui_close_current(void);
@ -126,7 +127,6 @@ void title_bar_draw(void);
// console window actions
ProfWin* cons_create(void);
void cons_refresh(void);
void cons_show(const char * const msg, ...);
void cons_about(void);
void cons_help(void);