From fcdddf11c099aaff5b23d928438453e9e786a48b Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 7 Mar 2018 20:58:07 +0000 Subject: [PATCH 01/21] Draw empty status bar --- src/ui/statusbar.c | 729 +++++++++++++++++++++++---------------------- 1 file changed, 377 insertions(+), 352 deletions(-) diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index a88834e3..2096aa42 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -53,59 +53,73 @@ #define TIME_CHECK 60000000 -static WINDOW *status_bar; -static char *message = NULL; -// 1 2 3 4 5 6 7 8 9 0 > -static char _active[34] = "[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]"; -static char *bracket = "- -"; -static int is_active[12]; -static GHashTable *remaining_active; -static int is_new[12]; -static GHashTable *remaining_new; -static GTimeZone *tz; -static GDateTime *last_time; -static int current; +typedef struct _status_bar_t { + char *time; + char *message; + GList *tabs; +} StatusBar; -static void _update_win_statuses(void); -static void _mark_new(int num); -static void _mark_active(int num); -static void _mark_inactive(int num); +static StatusBar *statusbar; +static WINDOW *statusbar_win; +//static char *message = NULL; +//// 1 2 3 4 5 6 7 8 9 0 > +//static char _active[34] = "[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]"; +//static char *bracket = "- -"; +//static int is_active[12]; +//static GHashTable *remaining_active; +//static int is_new[12]; +//static GHashTable *remaining_new; +//static GTimeZone *tz; +//static GDateTime *last_time; +//static int current; + +//static void _update_win_statuses(void); +//static void _mark_new(int num); +//static void _mark_active(int num); +//static void _mark_inactive(int num); static void _status_bar_draw(void); void create_status_bar(void) { - int i; - int cols = getmaxx(stdscr); - - is_active[1] = TRUE; - is_new[1] = FALSE; - for (i = 2; i < 12; i++) { - is_active[i] = FALSE; - is_new[i] = FALSE; - } - remaining_active = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL); - remaining_new = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL); - current = 1; - - int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); - + statusbar = malloc(sizeof(StatusBar)); int row = screen_statusbar_row(); - status_bar = newwin(1, cols, row, 0); - wbkgd(status_bar, theme_attrs(THEME_STATUS_TEXT)); - wattron(status_bar, bracket_attrs); - mvwprintw(status_bar, 0, cols - 34, _active); - mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); - wattroff(status_bar, bracket_attrs); - - tz = g_time_zone_new_local(); - - if (last_time) { - g_date_time_unref(last_time); - } - last_time = g_date_time_new_now(tz); - + int cols = getmaxx(stdscr); + statusbar_win = newwin(1, cols, row, 0); + wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT)); _status_bar_draw(); + +// int i; +// int cols = getmaxx(stdscr); +// +// is_active[1] = TRUE; +// is_new[1] = FALSE; +// for (i = 2; i < 12; i++) { +// is_active[i] = FALSE; +// is_new[i] = FALSE; +// } +// remaining_active = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL); +// remaining_new = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL); +// current = 1; +// +// int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); +// +// int row = screen_statusbar_row(); +// status_bar = newwin(1, cols, row, 0); +// wbkgd(status_bar, theme_attrs(THEME_STATUS_TEXT)); +// wattron(status_bar, bracket_attrs); +// mvwprintw(status_bar, 0, cols - 34, _active); +// mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); +// wattroff(status_bar, bracket_attrs); +// +// tz = g_time_zone_new_local(); +// +// if (last_time) { +// g_date_time_unref(last_time); +// } +// last_time = g_date_time_new_now(tz); +// +// _status_bar_draw(); } void @@ -118,368 +132,379 @@ void status_bar_resize(void) { int cols = getmaxx(stdscr); - - werase(status_bar); - - int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); - + werase(statusbar_win); int row = screen_statusbar_row(); - mvwin(status_bar, row, 0); - wresize(status_bar, 1, cols); - wbkgd(status_bar, theme_attrs(THEME_STATUS_TEXT)); - wattron(status_bar, bracket_attrs); - mvwprintw(status_bar, 0, cols - 34, _active); - mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); - wattroff(status_bar, bracket_attrs); - - if (message) { - char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); - - gchar *date_fmt = NULL; - if (g_strcmp0(time_pref, "off") == 0) { - date_fmt = g_strdup(""); - } else { - date_fmt = g_date_time_format(last_time, time_pref); - } - assert(date_fmt != NULL); - size_t len = strlen(date_fmt); - g_free(date_fmt); - if (g_strcmp0(time_pref, "off") != 0) { - /* 01234567890123456 - * [HH:MM] message */ - mvwprintw(status_bar, 0, 5 + len, message); - } else { - mvwprintw(status_bar, 0, 1, message); - } - prefs_free_string(time_pref); - } - if (last_time) { - g_date_time_unref(last_time); - } - last_time = g_date_time_new_now_local(); - + mvwin(statusbar_win, row, 0); + wresize(statusbar_win, 1, cols); + wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT)); _status_bar_draw(); + +// int cols = getmaxx(stdscr); +// +// werase(status_bar); +// +// int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); +// +// int row = screen_statusbar_row(); +// mvwin(status_bar, row, 0); +// wresize(status_bar, 1, cols); +// wbkgd(status_bar, theme_attrs(THEME_STATUS_TEXT)); +// wattron(status_bar, bracket_attrs); +// mvwprintw(status_bar, 0, cols - 34, _active); +// mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); +// wattroff(status_bar, bracket_attrs); +// +// if (message) { +// char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); +// +// gchar *date_fmt = NULL; +// if (g_strcmp0(time_pref, "off") == 0) { +// date_fmt = g_strdup(""); +// } else { +// date_fmt = g_date_time_format(last_time, time_pref); +// } +// assert(date_fmt != NULL); +// size_t len = strlen(date_fmt); +// g_free(date_fmt); +// if (g_strcmp0(time_pref, "off") != 0) { +// /* 01234567890123456 +// * [HH:MM] message */ +// mvwprintw(status_bar, 0, 5 + len, message); +// } else { +// mvwprintw(status_bar, 0, 1, message); +// } +// prefs_free_string(time_pref); +// } +// if (last_time) { +// g_date_time_unref(last_time); +// } +// last_time = g_date_time_new_now_local(); +// +// _status_bar_draw(); } void status_bar_set_all_inactive(void) { - int i = 0; - for (i = 0; i < 12; i++) { - is_active[i] = FALSE; - is_new[i] = FALSE; - _mark_inactive(i); - } - - g_hash_table_remove_all(remaining_active); - g_hash_table_remove_all(remaining_new); - - _status_bar_draw(); +// int i = 0; +// for (i = 0; i < 12; i++) { +// is_active[i] = FALSE; +// is_new[i] = FALSE; +// _mark_inactive(i); +// } +// +// g_hash_table_remove_all(remaining_active); +// g_hash_table_remove_all(remaining_new); +// +// _status_bar_draw(); } void status_bar_current(int i) { - if (i == 0) { - current = 10; - } else if (i > 10) { - current = 11; - } else { - current = i; - } - int cols = getmaxx(stdscr); - int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); - wattron(status_bar, bracket_attrs); - mvwprintw(status_bar, 0, cols - 34, _active); - mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); - wattroff(status_bar, bracket_attrs); - - _status_bar_draw(); +// if (i == 0) { +// current = 10; +// } else if (i > 10) { +// current = 11; +// } else { +// current = i; +// } +// int cols = getmaxx(stdscr); +// int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); +// wattron(status_bar, bracket_attrs); +// mvwprintw(status_bar, 0, cols - 34, _active); +// mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); +// wattroff(status_bar, bracket_attrs); +// +// _status_bar_draw(); } void status_bar_inactive(const int win) { - int true_win = win; - if (true_win == 0) { - true_win = 10; - } - - // extra windows - if (true_win > 10) { - g_hash_table_remove(remaining_active, GINT_TO_POINTER(true_win)); - g_hash_table_remove(remaining_new, GINT_TO_POINTER(true_win)); - - // still have new windows - if (g_hash_table_size(remaining_new) != 0) { - is_active[11] = TRUE; - is_new[11] = TRUE; - _mark_new(11); - - // still have active windows - } else if (g_hash_table_size(remaining_active) != 0) { - is_active[11] = TRUE; - is_new[11] = FALSE; - _mark_active(11); - - // no active or new windows - } else { - is_active[11] = FALSE; - is_new[11] = FALSE; - _mark_inactive(11); - } - - // visible window indicators - } else { - is_active[true_win] = FALSE; - is_new[true_win] = FALSE; - _mark_inactive(true_win); - } - - _status_bar_draw(); +// int true_win = win; +// if (true_win == 0) { +// true_win = 10; +// } +// +// // extra windows +// if (true_win > 10) { +// g_hash_table_remove(remaining_active, GINT_TO_POINTER(true_win)); +// g_hash_table_remove(remaining_new, GINT_TO_POINTER(true_win)); +// +// // still have new windows +// if (g_hash_table_size(remaining_new) != 0) { +// is_active[11] = TRUE; +// is_new[11] = TRUE; +// _mark_new(11); +// +// // still have active windows +// } else if (g_hash_table_size(remaining_active) != 0) { +// is_active[11] = TRUE; +// is_new[11] = FALSE; +// _mark_active(11); +// +// // no active or new windows +// } else { +// is_active[11] = FALSE; +// is_new[11] = FALSE; +// _mark_inactive(11); +// } +// +// // visible window indicators +// } else { +// is_active[true_win] = FALSE; +// is_new[true_win] = FALSE; +// _mark_inactive(true_win); +// } +// +// _status_bar_draw(); } void status_bar_active(const int win) { - int true_win = win; - if (true_win == 0) { - true_win = 10; - } - - // extra windows - if (true_win > 10) { - g_hash_table_add(remaining_active, GINT_TO_POINTER(true_win)); - g_hash_table_remove(remaining_new, GINT_TO_POINTER(true_win)); - - // still have new windows - if (g_hash_table_size(remaining_new) != 0) { - is_active[11] = TRUE; - is_new[11] = TRUE; - _mark_new(11); - - // only active windows - } else { - is_active[11] = TRUE; - is_new[11] = FALSE; - _mark_active(11); - } - - // visible window indicators - } else { - is_active[true_win] = TRUE; - is_new[true_win] = FALSE; - _mark_active(true_win); - } - - _status_bar_draw(); +// int true_win = win; +// if (true_win == 0) { +// true_win = 10; +// } +// +// // extra windows +// if (true_win > 10) { +// g_hash_table_add(remaining_active, GINT_TO_POINTER(true_win)); +// g_hash_table_remove(remaining_new, GINT_TO_POINTER(true_win)); +// +// // still have new windows +// if (g_hash_table_size(remaining_new) != 0) { +// is_active[11] = TRUE; +// is_new[11] = TRUE; +// _mark_new(11); +// +// // only active windows +// } else { +// is_active[11] = TRUE; +// is_new[11] = FALSE; +// _mark_active(11); +// } +// +// // visible window indicators +// } else { +// is_active[true_win] = TRUE; +// is_new[true_win] = FALSE; +// _mark_active(true_win); +// } +// +// _status_bar_draw(); } void status_bar_new(const int win) { - int true_win = win; - if (true_win == 0) { - true_win = 10; - } - - if (true_win > 10) { - g_hash_table_add(remaining_active, GINT_TO_POINTER(true_win)); - g_hash_table_add(remaining_new, GINT_TO_POINTER(true_win)); - - is_active[11] = TRUE; - is_new[11] = TRUE; - _mark_new(11); - - } else { - is_active[true_win] = TRUE; - is_new[true_win] = TRUE; - _mark_new(true_win); - } - - _status_bar_draw(); +// int true_win = win; +// if (true_win == 0) { +// true_win = 10; +// } +// +// if (true_win > 10) { +// g_hash_table_add(remaining_active, GINT_TO_POINTER(true_win)); +// g_hash_table_add(remaining_new, GINT_TO_POINTER(true_win)); +// +// is_active[11] = TRUE; +// is_new[11] = TRUE; +// _mark_new(11); +// +// } else { +// is_active[true_win] = TRUE; +// is_new[true_win] = TRUE; +// _mark_new(true_win); +// } +// +// _status_bar_draw(); } void status_bar_get_password(void) { - status_bar_print_message("Enter password:"); - - _status_bar_draw(); +// status_bar_print_message("Enter password:"); +// +// _status_bar_draw(); } void status_bar_print_message(const char *const msg) { - werase(status_bar); - - if (message) { - free(message); - } - message = strdup(msg); - - char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); - gchar *date_fmt = NULL; - if (g_strcmp0(time_pref, "off") == 0) { - date_fmt = g_strdup(""); - } else { - date_fmt = g_date_time_format(last_time, time_pref); - } - - assert(date_fmt != NULL); - size_t len = strlen(date_fmt); - g_free(date_fmt); - if (g_strcmp0(time_pref, "off") != 0) { - mvwprintw(status_bar, 0, 5 + len, message); - } else { - mvwprintw(status_bar, 0, 1, message); - } - prefs_free_string(time_pref); - - int cols = getmaxx(stdscr); - int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); - - wattron(status_bar, bracket_attrs); - mvwprintw(status_bar, 0, cols - 34, _active); - mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); - wattroff(status_bar, bracket_attrs); - - _status_bar_draw(); +// werase(status_bar); +// +// if (message) { +// free(message); +// } +// message = strdup(msg); +// +// char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); +// gchar *date_fmt = NULL; +// if (g_strcmp0(time_pref, "off") == 0) { +// date_fmt = g_strdup(""); +// } else { +// date_fmt = g_date_time_format(last_time, time_pref); +// } +// +// assert(date_fmt != NULL); +// size_t len = strlen(date_fmt); +// g_free(date_fmt); +// if (g_strcmp0(time_pref, "off") != 0) { +// mvwprintw(status_bar, 0, 5 + len, message); +// } else { +// mvwprintw(status_bar, 0, 1, message); +// } +// prefs_free_string(time_pref); +// +// int cols = getmaxx(stdscr); +// int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); +// +// wattron(status_bar, bracket_attrs); +// mvwprintw(status_bar, 0, cols - 34, _active); +// mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); +// wattroff(status_bar, bracket_attrs); +// +// _status_bar_draw(); } void status_bar_clear(void) { - if (message) { - free(message); - message = NULL; - } - - werase(status_bar); - - int cols = getmaxx(stdscr); - int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); - - wattron(status_bar, bracket_attrs); - mvwprintw(status_bar, 0, cols - 34, _active); - mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); - wattroff(status_bar, bracket_attrs); - - _status_bar_draw(); +// if (message) { +// free(message); +// message = NULL; +// } +// +// werase(status_bar); +// +// int cols = getmaxx(stdscr); +// int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); +// +// wattron(status_bar, bracket_attrs); +// mvwprintw(status_bar, 0, cols - 34, _active); +// mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); +// wattroff(status_bar, bracket_attrs); +// +// _status_bar_draw(); } void status_bar_clear_message(void) { - if (message) { - free(message); - message = NULL; - } - - werase(status_bar); - - int cols = getmaxx(stdscr); - int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); - - wattron(status_bar, bracket_attrs); - mvwprintw(status_bar, 0, cols - 34, _active); - mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); - wattroff(status_bar, bracket_attrs); - - _status_bar_draw(); +// if (message) { +// free(message); +// message = NULL; +// } +// +// werase(status_bar); +// +// int cols = getmaxx(stdscr); +// int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); +// +// wattron(status_bar, bracket_attrs); +// mvwprintw(status_bar, 0, cols - 34, _active); +// mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); +// wattroff(status_bar, bracket_attrs); +// +// _status_bar_draw(); } -static void -_update_win_statuses(void) -{ - int i; - for(i = 1; i < 12; i++) { - if (is_new[i]) { - _mark_new(i); - } - else if (is_active[i]) { - _mark_active(i); - } - else { - _mark_inactive(i); - } - } -} +//static void +//_update_win_statuses(void) +//{ +// int i; +// for(i = 1; i < 12; i++) { +// if (is_new[i]) { +// _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 status_attrs = theme_attrs(THEME_STATUS_NEW); - wattron(status_bar, status_attrs); - wattron(status_bar, A_BLINK); - if (num == 10) { - mvwprintw(status_bar, 0, cols - 34 + active_pos, "0"); - } else if (num > 10) { - mvwprintw(status_bar, 0, cols - 34 + active_pos, ">"); - } else { - mvwprintw(status_bar, 0, cols - 34 + active_pos, "%d", num); - } - wattroff(status_bar, status_attrs); - wattroff(status_bar, A_BLINK); -} +//static void +//_mark_new(int num) +//{ +// int active_pos = 1 + ((num-1) * 3); +// int cols = getmaxx(stdscr); +// int status_attrs = theme_attrs(THEME_STATUS_NEW); +// wattron(status_bar, status_attrs); +// wattron(status_bar, A_BLINK); +// if (num == 10) { +// mvwprintw(status_bar, 0, cols - 34 + active_pos, "0"); +// } else if (num > 10) { +// mvwprintw(status_bar, 0, cols - 34 + active_pos, ">"); +// } else { +// mvwprintw(status_bar, 0, cols - 34 + active_pos, "%d", num); +// } +// wattroff(status_bar, status_attrs); +// wattroff(status_bar, A_BLINK); +//} -static void -_mark_active(int num) -{ - int active_pos = 1 + ((num-1) * 3); - int cols = getmaxx(stdscr); - int status_attrs = theme_attrs(THEME_STATUS_ACTIVE); - wattron(status_bar, status_attrs); - if (num == 10) { - mvwprintw(status_bar, 0, cols - 34 + active_pos, "0"); - } else if (num > 10) { - mvwprintw(status_bar, 0, cols - 34 + active_pos, ">"); - } else { - mvwprintw(status_bar, 0, cols - 34 + active_pos, "%d", num); - } - wattroff(status_bar, status_attrs); -} +//static void +//_mark_active(int num) +//{ +// int active_pos = 1 + ((num-1) * 3); +// int cols = getmaxx(stdscr); +// int status_attrs = theme_attrs(THEME_STATUS_ACTIVE); +// wattron(status_bar, status_attrs); +// if (num == 10) { +// mvwprintw(status_bar, 0, cols - 34 + active_pos, "0"); +// } else if (num > 10) { +// mvwprintw(status_bar, 0, cols - 34 + active_pos, ">"); +// } else { +// mvwprintw(status_bar, 0, cols - 34 + active_pos, "%d", num); +// } +// wattroff(status_bar, status_attrs); +//} -static void -_mark_inactive(int num) -{ - int active_pos = 1 + ((num-1) * 3); - int cols = getmaxx(stdscr); - mvwaddch(status_bar, 0, cols - 34 + active_pos, ' '); -} +//static void +//_mark_inactive(int num) +//{ +// int active_pos = 1 + ((num-1) * 3); +// int cols = getmaxx(stdscr); +// mvwaddch(status_bar, 0, cols - 34 + active_pos, ' '); +//} static void _status_bar_draw(void) { - if (last_time) { - g_date_time_unref(last_time); - } - last_time = g_date_time_new_now(tz); - - int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); - int time_attrs = theme_attrs(THEME_STATUS_TIME); - - char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); - if (g_strcmp0(time_pref, "off") != 0) { - gchar *date_fmt = g_date_time_format(last_time, time_pref); - assert(date_fmt != NULL); - size_t len = strlen(date_fmt); - wattron(status_bar, bracket_attrs); - mvwaddch(status_bar, 0, 1, '['); - wattroff(status_bar, bracket_attrs); - wattron(status_bar, time_attrs); - mvwprintw(status_bar, 0, 2, date_fmt); - wattroff(status_bar, time_attrs); - wattron(status_bar, bracket_attrs); - mvwaddch(status_bar, 0, 2 + len, ']'); - wattroff(status_bar, bracket_attrs); - g_free(date_fmt); - } - prefs_free_string(time_pref); - - _update_win_statuses(); - wnoutrefresh(status_bar); + wnoutrefresh(statusbar_win); inp_put_back(); + +// if (last_time) { +// g_date_time_unref(last_time); +// } +// last_time = g_date_time_new_now(tz); +// +// int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); +// int time_attrs = theme_attrs(THEME_STATUS_TIME); +// +// char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); +// if (g_strcmp0(time_pref, "off") != 0) { +// gchar *date_fmt = g_date_time_format(last_time, time_pref); +// assert(date_fmt != NULL); +// size_t len = strlen(date_fmt); +// wattron(status_bar, bracket_attrs); +// mvwaddch(status_bar, 0, 1, '['); +// wattroff(status_bar, bracket_attrs); +// wattron(status_bar, time_attrs); +// mvwprintw(status_bar, 0, 2, date_fmt); +// wattroff(status_bar, time_attrs); +// wattron(status_bar, bracket_attrs); +// mvwaddch(status_bar, 0, 2 + len, ']'); +// wattroff(status_bar, bracket_attrs); +// g_free(date_fmt); +// } +// prefs_free_string(time_pref); +// +// _update_win_statuses(); +// wnoutrefresh(status_bar); +// inp_put_back(); } From 105c9c2943987f89c0429e300e4b6587f975dbb5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 7 Mar 2018 21:29:41 +0000 Subject: [PATCH 02/21] Add time to status bar --- src/ui/core.c | 3 ++- src/ui/statusbar.c | 53 ++++++++++++++++++++++++++++++++++++++++++---- src/ui/statusbar.h | 3 ++- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index 49c8406a..9c26750a 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -102,7 +102,7 @@ ui_init(void) ui_load_colours(); refresh(); create_title_bar(); - create_status_bar(); + status_bar_init(); status_bar_active(1); create_input_window(); wins_init(); @@ -183,6 +183,7 @@ ui_close(void) notifier_uninit(); wins_destroy(); inp_close(); + status_bar_close(); endwin(); } diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 2096aa42..50cb1a0e 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -51,14 +51,13 @@ #include "ui/inputwin.h" #include "ui/screen.h" -#define TIME_CHECK 60000000 - typedef struct _status_bar_t { - char *time; + gchar *time; char *message; GList *tabs; } StatusBar; +static GTimeZone *tz; static StatusBar *statusbar; static WINDOW *statusbar_win; //static char *message = NULL; @@ -80,13 +79,18 @@ static WINDOW *statusbar_win; static void _status_bar_draw(void); void -create_status_bar(void) +status_bar_init(void) { + tz = g_time_zone_new_local(); + statusbar = malloc(sizeof(StatusBar)); + statusbar->time = NULL; + int row = screen_statusbar_row(); int cols = getmaxx(stdscr); statusbar_win = newwin(1, cols, row, 0); wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT)); + _status_bar_draw(); // int i; @@ -122,6 +126,19 @@ create_status_bar(void) // _status_bar_draw(); } +void +status_bar_close(void) +{ + if (tz) { + g_time_zone_unref(tz); + } + if (statusbar) { + if (statusbar->time) { + g_free(statusbar->time); + } + } +} + void status_bar_update_virtual(void) { @@ -475,6 +492,34 @@ status_bar_clear_message(void) static void _status_bar_draw(void) { + char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); + if (g_strcmp0(time_pref, "off") != 0) { + if (statusbar->time) { + g_free(statusbar->time); + statusbar->time = NULL; + } + + GDateTime *datetime = g_date_time_new_now(tz); + statusbar->time = g_date_time_format(datetime, time_pref); + assert(statusbar->time != NULL); + g_date_time_unref(datetime); + + int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); + int time_attrs = theme_attrs(THEME_STATUS_TIME); + + size_t len = strlen(statusbar->time); + wattron(statusbar_win, bracket_attrs); + mvwaddch(statusbar_win, 0, 1, '['); + wattroff(statusbar_win, bracket_attrs); + wattron(statusbar_win, time_attrs); + mvwprintw(statusbar_win, 0, 2, statusbar->time); + wattroff(statusbar_win, time_attrs); + wattron(statusbar_win, bracket_attrs); + mvwaddch(statusbar_win, 0, 2 + len, ']'); + wattroff(statusbar_win, bracket_attrs); + } + prefs_free_string(time_pref); + wnoutrefresh(statusbar_win); inp_put_back(); diff --git a/src/ui/statusbar.h b/src/ui/statusbar.h index def9c04b..370b4bbb 100644 --- a/src/ui/statusbar.h +++ b/src/ui/statusbar.h @@ -35,7 +35,8 @@ #ifndef UI_STATUSBAR_H #define UI_STATUSBAR_H -void create_status_bar(void); +void status_bar_init(void); +void status_bar_close(void); void status_bar_update_virtual(void); void status_bar_resize(void); void status_bar_clear(void); From be8ff9fdcdc162f41c3b8871e549db2428f72964 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 7 Mar 2018 21:37:29 +0000 Subject: [PATCH 03/21] Set background in _status_bar_draw --- src/ui/statusbar.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 50cb1a0e..54c4995c 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -89,7 +89,6 @@ status_bar_init(void) int row = screen_statusbar_row(); int cols = getmaxx(stdscr); statusbar_win = newwin(1, cols, row, 0); - wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT)); _status_bar_draw(); @@ -153,7 +152,7 @@ status_bar_resize(void) int row = screen_statusbar_row(); mvwin(statusbar_win, row, 0); wresize(statusbar_win, 1, cols); - wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT)); + _status_bar_draw(); // int cols = getmaxx(stdscr); @@ -492,6 +491,8 @@ status_bar_clear_message(void) static void _status_bar_draw(void) { + wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT)); + char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); if (g_strcmp0(time_pref, "off") != 0) { if (statusbar->time) { From 1215ec9bc8c11c8f31a3eb9508b23ab349336ca7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 7 Mar 2018 22:12:15 +0000 Subject: [PATCH 04/21] Add message to status bar --- src/ui/statusbar.c | 61 +++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 54c4995c..33c37822 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -85,6 +85,7 @@ status_bar_init(void) statusbar = malloc(sizeof(StatusBar)); statusbar->time = NULL; + statusbar->message = NULL; int row = screen_statusbar_row(); int cols = getmaxx(stdscr); @@ -135,6 +136,10 @@ status_bar_close(void) if (statusbar->time) { g_free(statusbar->time); } + if (statusbar->message) { + free(statusbar->message); + } + free(statusbar); } } @@ -341,14 +346,20 @@ status_bar_new(const int win) void status_bar_get_password(void) { -// status_bar_print_message("Enter password:"); -// -// _status_bar_draw(); + status_bar_print_message("Enter password:"); } void status_bar_print_message(const char *const msg) { + if (statusbar->message) { + free(statusbar->message); + statusbar->message = NULL; + } + statusbar->message = strdup(msg); + + _status_bar_draw(); + // werase(status_bar); // // if (message) { @@ -409,22 +420,12 @@ status_bar_clear(void) void status_bar_clear_message(void) { -// if (message) { -// free(message); -// message = NULL; -// } -// -// werase(status_bar); -// -// int cols = getmaxx(stdscr); -// int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); -// -// wattron(status_bar, bracket_attrs); -// mvwprintw(status_bar, 0, cols - 34, _active); -// mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); -// wattroff(status_bar, bracket_attrs); -// -// _status_bar_draw(); + if (statusbar->message) { + free(statusbar->message); + statusbar->message = NULL; + } + + _status_bar_draw(); } //static void @@ -493,8 +494,11 @@ _status_bar_draw(void) { wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT)); + int pos = 1; + char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); if (g_strcmp0(time_pref, "off") != 0) { + // time if (statusbar->time) { g_free(statusbar->time); statusbar->time = NULL; @@ -510,14 +514,27 @@ _status_bar_draw(void) size_t len = strlen(statusbar->time); wattron(statusbar_win, bracket_attrs); - mvwaddch(statusbar_win, 0, 1, '['); + mvwaddch(statusbar_win, 0, pos, '['); + pos++; wattroff(statusbar_win, bracket_attrs); wattron(statusbar_win, time_attrs); - mvwprintw(statusbar_win, 0, 2, statusbar->time); + mvwprintw(statusbar_win, 0, pos, statusbar->time); + pos += len; wattroff(statusbar_win, time_attrs); wattron(statusbar_win, bracket_attrs); - mvwaddch(statusbar_win, 0, 2 + len, ']'); + mvwaddch(statusbar_win, 0, pos, ']'); wattroff(statusbar_win, bracket_attrs); + pos += 2; + + // message + if (statusbar->message) { + mvwprintw(statusbar_win, 0, pos, statusbar->message); + } + } else { + // message + if (statusbar->message) { + mvwprintw(statusbar_win, 0, pos, statusbar->message); + } } prefs_free_string(time_pref); From 119c5650cf1b40d3074faae1a280e8d3dfbedc03 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 8 Mar 2018 19:55:17 +0000 Subject: [PATCH 05/21] Show name in statusbar tabs WIP --- src/command/cmd_funcs.c | 2 +- src/event/server_events.c | 4 +- src/plugins/api.c | 2 +- src/ui/chatwin.c | 14 +- src/ui/console.c | 2 +- src/ui/core.c | 20 +- src/ui/mucwin.c | 12 +- src/ui/privwin.c | 4 +- src/ui/statusbar.c | 531 ++++++++++++----------------------- src/ui/ui.h | 4 +- src/ui/win_types.h | 3 +- src/ui/window.c | 14 +- src/ui/window_list.c | 21 +- tests/unittests/ui/stub_ui.c | 4 +- 14 files changed, 242 insertions(+), 395 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 53c8b9ed..b4840afd 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -2095,7 +2095,7 @@ cmd_who(ProfWin *window, const char *const command, gchar **args) } if (window->type != WIN_CONSOLE && window->type != WIN_MUC) { - status_bar_new(1); + status_bar_new(1, "console"); } return TRUE; diff --git a/src/event/server_events.c b/src/event/server_events.c index efd8756d..230184e7 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -282,7 +282,7 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha // currently in groupchat window if (wins_is_current(window)) { is_current = TRUE; - status_bar_active(num); + status_bar_active(num, window->tab_name); if ((g_strcmp0(mynick, nick) != 0) && (prefs_get_boolean(PREF_BEEP))) { beep(); @@ -290,7 +290,7 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha // not currently on groupchat window } else { - status_bar_new(num); + status_bar_new(num, window->tab_name); if ((g_strcmp0(mynick, nick) != 0) && (prefs_get_boolean(PREF_FLASH))) { flash(); diff --git a/src/plugins/api.c b/src/plugins/api.c index 0ca58452..e75dccf1 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -333,7 +333,7 @@ api_win_create( // set status bar active ProfPluginWin *pluginwin = wins_get_plugin(tag); int num = wins_get_num((ProfWin*)pluginwin); - status_bar_active(num); + status_bar_active(num, pluginwin->plugin_name); } int diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index ad62c6c7..29c8cff4 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -105,7 +105,7 @@ chatwin_otr_secured(ProfChatWin *chatwin, gboolean trusted) title_bar_switch(); } else { int num = wins_get_num(window); - status_bar_new(num); + status_bar_new(num, window->tab_name); int ui_index = num; if (ui_index == 10) { @@ -249,11 +249,11 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha if (wins_is_current(window)) { win_print_incoming(window, timestamp, display_name, plugin_message, enc_mode); title_bar_set_typing(FALSE); - status_bar_active(num); + status_bar_active(num, window->tab_name); // not currently viewing chat window with sender } else { - status_bar_new(num); + status_bar_new(num, window->tab_name); cons_show_incoming_message(display_name, num, chatwin->unread); if (prefs_get_boolean(PREF_FLASH)) { @@ -324,9 +324,11 @@ chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message, prof_en enc_char = prefs_get_pgp_char(); } - win_print_outgoing((ProfWin*)chatwin, enc_char, "%s", message); - int num = wins_get_num((ProfWin*)chatwin); - status_bar_active(num); + ProfWin *window = (ProfWin*)chatwin; + + win_print_outgoing(window, enc_char, "%s", message); + int num = wins_get_num(window); + status_bar_active(num, window->tab_name); } void diff --git a/src/ui/console.c b/src/ui/console.c index e646cf85..55bba1c5 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -2161,7 +2161,7 @@ cons_alert(void) { ProfWin *current = wins_get_current(); if (current->type != WIN_CONSOLE) { - status_bar_new(1); + status_bar_new(1, "console"); } } diff --git a/src/ui/core.c b/src/ui/core.c index 9c26750a..67205f73 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -103,7 +103,7 @@ ui_init(void) refresh(); create_title_bar(); status_bar_init(); - status_bar_active(1); + status_bar_active(1, "console"); create_input_window(); wins_init(); notifier_initialise(); @@ -287,7 +287,7 @@ ui_contact_typing(const char *const barejid, const char *const resource) title_bar_set_typing(TRUE); int num = wins_get_num(window); - status_bar_active(num); + status_bar_active(num, window->tab_name); } } @@ -673,7 +673,7 @@ ui_focus_win(ProfWin *window) title_bar_switch(); } status_bar_current(i); - status_bar_active(i); + status_bar_active(i, window->tab_name); } void @@ -690,7 +690,7 @@ ui_close_win(int index) wins_close_by_num(index); title_bar_console(); status_bar_current(1); - status_bar_active(1); + status_bar_active(1, "console"); } void @@ -738,17 +738,18 @@ ui_print_system_msg_from_recipient(const char *const barejid, const char *messag if (barejid == NULL || message == NULL) return; - ProfWin *window = (ProfWin*)wins_get_chat(barejid); + ProfChatWin *chatwin = wins_get_chat(barejid); + ProfWin *window = (ProfWin*)chatwin; if (window == NULL) { int num = 0; window = wins_new_chat(barejid); if (window) { num = wins_get_num(window); - status_bar_active(num); + status_bar_active(num, window->tab_name); } else { num = 0; window = wins_get_console(); - status_bar_active(1); + status_bar_active(1, window->tab_name); } } @@ -758,7 +759,8 @@ ui_print_system_msg_from_recipient(const char *const barejid, const char *messag void ui_room_join(const char *const roomjid, gboolean focus) { - ProfWin *window = (ProfWin*)wins_get_muc(roomjid); + ProfMucWin *mucwin = wins_get_muc(roomjid); + ProfWin *window = (ProfWin*)mucwin; if (!window) { window = wins_new_muc(roomjid); } @@ -781,7 +783,7 @@ ui_room_join(const char *const roomjid, gboolean focus) ui_focus_win(window); } else { int num = wins_get_num(window); - status_bar_active(num); + status_bar_active(num, window->tab_name); ProfWin *console = wins_get_console(); char *nick = muc_nick(roomjid); win_println(console, THEME_TYPING, '!', "-> Autojoined %s as %s (%d).", roomjid, nick, num); diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index 15564ed8..10575915 100644 --- a/src/ui/mucwin.c +++ b/src/ui/mucwin.c @@ -519,11 +519,11 @@ mucwin_requires_config(ProfMucWin *mucwin) // currently in groupchat window if (wins_is_current(window)) { - status_bar_active(num); + status_bar_active(num, window->tab_name); // not currently on groupchat window } else { - status_bar_new(num); + status_bar_new(num, window->tab_name); } } @@ -553,11 +553,11 @@ mucwin_subject(ProfMucWin *mucwin, const char *const nick, const char *const sub // currently in groupchat window if (wins_is_current(window)) { - status_bar_active(num); + status_bar_active(num, window->tab_name); // not currently on groupchat window } else { - status_bar_active(num); + status_bar_new(num, window->tab_name); } } @@ -583,11 +583,11 @@ mucwin_broadcast(ProfMucWin *mucwin, const char *const message) // currently in groupchat window if (wins_is_current(window)) { - status_bar_active(num); + status_bar_active(num, window->tab_name); // not currently on groupchat window } else { - status_bar_new(num); + status_bar_new(num, window->tab_name); } } diff --git a/src/ui/privwin.c b/src/ui/privwin.c index 675ca061..76c95fb8 100644 --- a/src/ui/privwin.c +++ b/src/ui/privwin.c @@ -62,11 +62,11 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat if (wins_is_current(window)) { win_print_incoming(window, timestamp, jidp->resourcepart, message, PROF_MSG_PLAIN); title_bar_set_typing(FALSE); - status_bar_active(num); + status_bar_active(num, window->tab_name); // not currently viewing chat window with sender } else { - status_bar_new(num); + status_bar_new(num, window->tab_name); cons_show_incoming_private_message(jidp->resourcepart, jidp->barejid, num, privatewin->unread); win_print_incoming(window, timestamp, jidp->resourcepart, message, PROF_MSG_PLAIN); diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 33c37822..ff264202 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -51,33 +51,39 @@ #include "ui/inputwin.h" #include "ui/screen.h" +typedef struct _status_bar_tab_t { + char *display_name; + gboolean highlight; +} StatusBarTab; + typedef struct _status_bar_t { gchar *time; char *message; - GList *tabs; + GHashTable *tabs; + int current_tab; } StatusBar; +#define MAX_TABS 5 +#define SHOW_EMPTY_TABS FALSE +#define SHOW_NAME TRUE + static GTimeZone *tz; static StatusBar *statusbar; static WINDOW *statusbar_win; -//static char *message = NULL; -//// 1 2 3 4 5 6 7 8 9 0 > -//static char _active[34] = "[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]"; -//static char *bracket = "- -"; -//static int is_active[12]; -//static GHashTable *remaining_active; -//static int is_new[12]; -//static GHashTable *remaining_new; -//static GTimeZone *tz; -//static GDateTime *last_time; -//static int current; -//static void _update_win_statuses(void); -//static void _mark_new(int num); -//static void _mark_active(int num); -//static void _mark_inactive(int num); static void _status_bar_draw(void); +void +_destroy_tab(StatusBarTab *tab) +{ + if (tab) { + if (tab->display_name) { + free(tab->display_name); + } + free(tab); + } +} + void status_bar_init(void) { @@ -86,44 +92,17 @@ status_bar_init(void) statusbar = malloc(sizeof(StatusBar)); statusbar->time = NULL; statusbar->message = NULL; + statusbar->tabs = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)_destroy_tab); + StatusBarTab *console = malloc(sizeof(StatusBarTab)); + console->display_name = strdup("console"); + g_hash_table_insert(statusbar->tabs, GINT_TO_POINTER(1), console); + statusbar->current_tab = 1; int row = screen_statusbar_row(); int cols = getmaxx(stdscr); statusbar_win = newwin(1, cols, row, 0); _status_bar_draw(); - -// int i; -// int cols = getmaxx(stdscr); -// -// is_active[1] = TRUE; -// is_new[1] = FALSE; -// for (i = 2; i < 12; i++) { -// is_active[i] = FALSE; -// is_new[i] = FALSE; -// } -// remaining_active = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL); -// remaining_new = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL); -// current = 1; -// -// int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); -// -// int row = screen_statusbar_row(); -// status_bar = newwin(1, cols, row, 0); -// wbkgd(status_bar, theme_attrs(THEME_STATUS_TEXT)); -// wattron(status_bar, bracket_attrs); -// mvwprintw(status_bar, 0, cols - 34, _active); -// mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); -// wattroff(status_bar, bracket_attrs); -// -// tz = g_time_zone_new_local(); -// -// if (last_time) { -// g_date_time_unref(last_time); -// } -// last_time = g_date_time_new_now(tz); -// -// _status_bar_draw(); } void @@ -159,188 +138,69 @@ status_bar_resize(void) wresize(statusbar_win, 1, cols); _status_bar_draw(); - -// int cols = getmaxx(stdscr); -// -// werase(status_bar); -// -// int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); -// -// int row = screen_statusbar_row(); -// mvwin(status_bar, row, 0); -// wresize(status_bar, 1, cols); -// wbkgd(status_bar, theme_attrs(THEME_STATUS_TEXT)); -// wattron(status_bar, bracket_attrs); -// mvwprintw(status_bar, 0, cols - 34, _active); -// mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); -// wattroff(status_bar, bracket_attrs); -// -// if (message) { -// char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); -// -// gchar *date_fmt = NULL; -// if (g_strcmp0(time_pref, "off") == 0) { -// date_fmt = g_strdup(""); -// } else { -// date_fmt = g_date_time_format(last_time, time_pref); -// } -// assert(date_fmt != NULL); -// size_t len = strlen(date_fmt); -// g_free(date_fmt); -// if (g_strcmp0(time_pref, "off") != 0) { -// /* 01234567890123456 -// * [HH:MM] message */ -// mvwprintw(status_bar, 0, 5 + len, message); -// } else { -// mvwprintw(status_bar, 0, 1, message); -// } -// prefs_free_string(time_pref); -// } -// if (last_time) { -// g_date_time_unref(last_time); -// } -// last_time = g_date_time_new_now_local(); -// -// _status_bar_draw(); } void status_bar_set_all_inactive(void) { -// int i = 0; -// for (i = 0; i < 12; i++) { -// is_active[i] = FALSE; -// is_new[i] = FALSE; -// _mark_inactive(i); -// } -// -// g_hash_table_remove_all(remaining_active); -// g_hash_table_remove_all(remaining_new); -// -// _status_bar_draw(); + g_hash_table_remove_all(statusbar->tabs); } void status_bar_current(int i) { -// if (i == 0) { -// current = 10; -// } else if (i > 10) { -// current = 11; -// } else { -// current = i; -// } -// int cols = getmaxx(stdscr); -// int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); -// wattron(status_bar, bracket_attrs); -// mvwprintw(status_bar, 0, cols - 34, _active); -// mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); -// wattroff(status_bar, bracket_attrs); -// -// _status_bar_draw(); + if (i == 0) { + statusbar->current_tab = 10; + } else { + statusbar->current_tab = i; + } + + _status_bar_draw(); } void status_bar_inactive(const int win) { -// int true_win = win; -// if (true_win == 0) { -// true_win = 10; -// } -// -// // extra windows -// if (true_win > 10) { -// g_hash_table_remove(remaining_active, GINT_TO_POINTER(true_win)); -// g_hash_table_remove(remaining_new, GINT_TO_POINTER(true_win)); -// -// // still have new windows -// if (g_hash_table_size(remaining_new) != 0) { -// is_active[11] = TRUE; -// is_new[11] = TRUE; -// _mark_new(11); -// -// // still have active windows -// } else if (g_hash_table_size(remaining_active) != 0) { -// is_active[11] = TRUE; -// is_new[11] = FALSE; -// _mark_active(11); -// -// // no active or new windows -// } else { -// is_active[11] = FALSE; -// is_new[11] = FALSE; -// _mark_inactive(11); -// } -// -// // visible window indicators -// } else { -// is_active[true_win] = FALSE; -// is_new[true_win] = FALSE; -// _mark_inactive(true_win); -// } -// -// _status_bar_draw(); + int true_win = win; + if (true_win == 0) { + true_win = 10; + } + + g_hash_table_remove(statusbar->tabs, GINT_TO_POINTER(true_win)); + + _status_bar_draw(); } void -status_bar_active(const int win) +status_bar_active(const int win, char *name) { -// int true_win = win; -// if (true_win == 0) { -// true_win = 10; -// } -// -// // extra windows -// if (true_win > 10) { -// g_hash_table_add(remaining_active, GINT_TO_POINTER(true_win)); -// g_hash_table_remove(remaining_new, GINT_TO_POINTER(true_win)); -// -// // still have new windows -// if (g_hash_table_size(remaining_new) != 0) { -// is_active[11] = TRUE; -// is_new[11] = TRUE; -// _mark_new(11); -// -// // only active windows -// } else { -// is_active[11] = TRUE; -// is_new[11] = FALSE; -// _mark_active(11); -// } -// -// // visible window indicators -// } else { -// is_active[true_win] = TRUE; -// is_new[true_win] = FALSE; -// _mark_active(true_win); -// } -// -// _status_bar_draw(); + int true_win = win; + if (true_win == 0) { + true_win = 10; + } + + StatusBarTab *tab = malloc(sizeof(StatusBarTab)); + tab->display_name = strdup(name); + tab->highlight = FALSE; + g_hash_table_replace(statusbar->tabs, GINT_TO_POINTER(true_win), tab); + + _status_bar_draw(); } void -status_bar_new(const int win) +status_bar_new(const int win, char* name) { -// int true_win = win; -// if (true_win == 0) { -// true_win = 10; -// } -// -// if (true_win > 10) { -// g_hash_table_add(remaining_active, GINT_TO_POINTER(true_win)); -// g_hash_table_add(remaining_new, GINT_TO_POINTER(true_win)); -// -// is_active[11] = TRUE; -// is_new[11] = TRUE; -// _mark_new(11); -// -// } else { -// is_active[true_win] = TRUE; -// is_new[true_win] = TRUE; -// _mark_new(true_win); -// } -// -// _status_bar_draw(); + int true_win = win; + if (true_win == 0) { + true_win = 10; + } + + StatusBarTab *tab = malloc(sizeof(StatusBarTab)); + tab->display_name = strdup(name); + tab->highlight = TRUE; + g_hash_table_replace(statusbar->tabs, GINT_TO_POINTER(true_win), tab); + + _status_bar_draw(); } void @@ -359,62 +219,19 @@ status_bar_print_message(const char *const msg) statusbar->message = strdup(msg); _status_bar_draw(); - -// werase(status_bar); -// -// if (message) { -// free(message); -// } -// message = strdup(msg); -// -// char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); -// gchar *date_fmt = NULL; -// if (g_strcmp0(time_pref, "off") == 0) { -// date_fmt = g_strdup(""); -// } else { -// date_fmt = g_date_time_format(last_time, time_pref); -// } -// -// assert(date_fmt != NULL); -// size_t len = strlen(date_fmt); -// g_free(date_fmt); -// if (g_strcmp0(time_pref, "off") != 0) { -// mvwprintw(status_bar, 0, 5 + len, message); -// } else { -// mvwprintw(status_bar, 0, 1, message); -// } -// prefs_free_string(time_pref); -// -// int cols = getmaxx(stdscr); -// int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); -// -// wattron(status_bar, bracket_attrs); -// mvwprintw(status_bar, 0, cols - 34, _active); -// mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); -// wattroff(status_bar, bracket_attrs); -// -// _status_bar_draw(); } void status_bar_clear(void) { -// if (message) { -// free(message); -// message = NULL; -// } -// -// werase(status_bar); -// -// int cols = getmaxx(stdscr); -// int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); -// -// wattron(status_bar, bracket_attrs); -// mvwprintw(status_bar, 0, cols - 34, _active); -// mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); -// wattroff(status_bar, bracket_attrs); -// -// _status_bar_draw(); + if (statusbar->message) { + free(statusbar->message); + statusbar->message = NULL; + } + + werase(statusbar_win); + + _status_bar_draw(); } void @@ -428,66 +245,43 @@ status_bar_clear_message(void) _status_bar_draw(); } -//static void -//_update_win_statuses(void) -//{ -// int i; -// for(i = 1; i < 12; i++) { -// if (is_new[i]) { -// _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 status_attrs = theme_attrs(THEME_STATUS_NEW); -// wattron(status_bar, status_attrs); -// wattron(status_bar, A_BLINK); -// if (num == 10) { -// mvwprintw(status_bar, 0, cols - 34 + active_pos, "0"); -// } else if (num > 10) { -// mvwprintw(status_bar, 0, cols - 34 + active_pos, ">"); -// } else { -// mvwprintw(status_bar, 0, cols - 34 + active_pos, "%d", num); -// } -// wattroff(status_bar, status_attrs); -// wattroff(status_bar, A_BLINK); -//} - -//static void -//_mark_active(int num) -//{ -// int active_pos = 1 + ((num-1) * 3); -// int cols = getmaxx(stdscr); -// int status_attrs = theme_attrs(THEME_STATUS_ACTIVE); -// wattron(status_bar, status_attrs); -// if (num == 10) { -// mvwprintw(status_bar, 0, cols - 34 + active_pos, "0"); -// } else if (num > 10) { -// mvwprintw(status_bar, 0, cols - 34 + active_pos, ">"); -// } else { -// mvwprintw(status_bar, 0, cols - 34 + active_pos, "%d", num); -// } -// wattroff(status_bar, status_attrs); -//} - -//static void -//_mark_inactive(int num) -//{ -// int active_pos = 1 + ((num-1) * 3); -// int cols = getmaxx(stdscr); -// mvwaddch(status_bar, 0, cols - 34 + active_pos, ' '); -//} +static int +_tabs_width(void) +{ + if (SHOW_NAME) { + if (SHOW_EMPTY_TABS) { + int width = 4; + int i = 0; + for (i = 1; i <= MAX_TABS; i++) { + StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); + if (tab) { + width += strlen(tab->display_name); + width += 4; + } else { + width += 3; + } + } + return width; + } else { + int width = 4; + int i = 0; + for (i = 1; i <= MAX_TABS; i++) { + StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); + if (tab) { + width += strlen(tab->display_name); + width += 4; + } + } + return width; + } + } else { + if (SHOW_EMPTY_TABS) { + return MAX_TABS * 3 + 4; + } else { + return g_hash_table_size(statusbar->tabs) * 3 + 4; + } + } +} static void _status_bar_draw(void) @@ -538,36 +332,77 @@ _status_bar_draw(void) } prefs_free_string(time_pref); + // tabs + int cols = getmaxx(stdscr); + pos = cols - _tabs_width(); + int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); + + int i = 1; + for (i = 1; i <= MAX_TABS; i++) { + int display_num = i == 10 ? 0 : i; + + StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); + if (tab || (tab == NULL && SHOW_EMPTY_TABS)) { + wattron(statusbar_win, bracket_attrs); + if (i == statusbar->current_tab) { + mvwprintw(statusbar_win, 0, pos, "-"); + } else { + mvwprintw(statusbar_win, 0, pos, "["); + } + wattroff(statusbar_win, bracket_attrs); + pos++; + if (tab) { + if (tab->highlight) { + int status_attrs = theme_attrs(THEME_STATUS_NEW); + wattron(statusbar_win, status_attrs); + mvwprintw(statusbar_win, 0, pos, "%d", display_num); + if (SHOW_NAME) { + pos++; + mvwprintw(statusbar_win, 0, pos, ":"); + pos++; + mvwprintw(statusbar_win, 0, pos, tab->display_name); + pos += strlen(tab->display_name) -1 ; + } + wattroff(statusbar_win, status_attrs); + } else { + int status_attrs = theme_attrs(THEME_STATUS_ACTIVE); + wattron(statusbar_win, status_attrs); + mvwprintw(statusbar_win, 0, pos, "%d", display_num); + if (SHOW_NAME) { + pos++; + mvwprintw(statusbar_win, 0, pos, ":"); + pos++; + mvwprintw(statusbar_win, 0, pos, tab->display_name); + pos += strlen(tab->display_name) - 1; + } + wattroff(statusbar_win, status_attrs); + } + } else { + mvwprintw(statusbar_win, 0, pos, " "); + } + pos++; + wattron(statusbar_win, bracket_attrs); + if (i == statusbar->current_tab) { + mvwprintw(statusbar_win, 0, pos, "-"); + } else { + mvwprintw(statusbar_win, 0, pos, "]"); + } + pos++; + wattroff(statusbar_win, bracket_attrs); + } + } + + wattron(statusbar_win, bracket_attrs); + mvwprintw(statusbar_win, 0, pos, "["); + wattroff(statusbar_win, bracket_attrs); + pos++; + mvwprintw(statusbar_win, 0, pos, " "); + pos++; + wattron(statusbar_win, bracket_attrs); + mvwprintw(statusbar_win, 0, pos, "]"); + wattroff(statusbar_win, bracket_attrs); + pos++; + wnoutrefresh(statusbar_win); inp_put_back(); - -// if (last_time) { -// g_date_time_unref(last_time); -// } -// last_time = g_date_time_new_now(tz); -// -// int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); -// int time_attrs = theme_attrs(THEME_STATUS_TIME); -// -// char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); -// if (g_strcmp0(time_pref, "off") != 0) { -// gchar *date_fmt = g_date_time_format(last_time, time_pref); -// assert(date_fmt != NULL); -// size_t len = strlen(date_fmt); -// wattron(status_bar, bracket_attrs); -// mvwaddch(status_bar, 0, 1, '['); -// wattroff(status_bar, bracket_attrs); -// wattron(status_bar, time_attrs); -// mvwprintw(status_bar, 0, 2, date_fmt); -// wattroff(status_bar, time_attrs); -// wattron(status_bar, bracket_attrs); -// mvwaddch(status_bar, 0, 2 + len, ']'); -// wattroff(status_bar, bracket_attrs); -// g_free(date_fmt); -// } -// prefs_free_string(time_pref); -// -// _update_win_statuses(); -// wnoutrefresh(status_bar); -// inp_put_back(); } diff --git a/src/ui/ui.h b/src/ui/ui.h index 9168f58a..5d779df6 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -331,8 +331,8 @@ void title_bar_set_presence(contact_presence_t presence); // status bar void status_bar_inactive(const int win); -void status_bar_active(const int win); -void status_bar_new(const int win); +void status_bar_active(const int win, char *name); +void status_bar_new(const int win, char *name); void status_bar_set_all_inactive(void); // roster window diff --git a/src/ui/win_types.h b/src/ui/win_types.h index 3eb48b29..284dbc1f 100644 --- a/src/ui/win_types.h +++ b/src/ui/win_types.h @@ -136,6 +136,7 @@ typedef enum { typedef struct prof_win_t { win_type_t type; + char *tab_name; ProfLayout *layout; } ProfWin; @@ -194,7 +195,7 @@ typedef struct prof_xml_win_t { } ProfXMLWin; typedef struct prof_plugin_win_t { - ProfWin super; + ProfWin window; char *tag; char *plugin_name; unsigned long memcheck; diff --git a/src/ui/window.c b/src/ui/window.c index 2ca5621c..83da1219 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -125,6 +125,7 @@ win_create_console(void) { ProfConsoleWin *new_win = malloc(sizeof(ProfConsoleWin)); new_win->window.type = WIN_CONSOLE; + new_win->window.tab_name = strdup("console"); new_win->window.layout = _win_create_split_layout(); return &new_win->window; @@ -135,6 +136,7 @@ win_create_chat(const char *const barejid) { ProfChatWin *new_win = malloc(sizeof(ProfChatWin)); new_win->window.type = WIN_CHAT; + new_win->window.tab_name = strdup(barejid); new_win->window.layout = _win_create_simple_layout(); new_win->barejid = strdup(barejid); @@ -162,6 +164,7 @@ win_create_muc(const char *const roomjid) int cols = getmaxx(stdscr); new_win->window.type = WIN_MUC; + new_win->window.tab_name = strdup(roomjid); ProfLayoutSplit *layout = malloc(sizeof(ProfLayoutSplit)); layout->base.type = LAYOUT_SPLIT; @@ -207,6 +210,7 @@ win_create_muc_config(const char *const roomjid, DataForm *form) { ProfMucConfWin *new_win = malloc(sizeof(ProfMucConfWin)); new_win->window.type = WIN_MUC_CONFIG; + new_win->window.tab_name = strdup(roomjid); new_win->window.layout = _win_create_simple_layout(); new_win->roomjid = strdup(roomjid); @@ -222,6 +226,7 @@ win_create_private(const char *const fulljid) { ProfPrivateWin *new_win = malloc(sizeof(ProfPrivateWin)); new_win->window.type = WIN_PRIVATE; + new_win->window.tab_name = strdup(fulljid); new_win->window.layout = _win_create_simple_layout(); new_win->fulljid = strdup(fulljid); @@ -239,6 +244,7 @@ win_create_xmlconsole(void) { ProfXMLWin *new_win = malloc(sizeof(ProfXMLWin)); new_win->window.type = WIN_XML; + new_win->window.tab_name = strdup("xmlconsole"); new_win->window.layout = _win_create_simple_layout(); new_win->memcheck = PROFXMLWIN_MEMCHECK; @@ -250,15 +256,16 @@ ProfWin* win_create_plugin(const char *const plugin_name, const char *const tag) { ProfPluginWin *new_win = malloc(sizeof(ProfPluginWin)); - new_win->super.type = WIN_PLUGIN; - new_win->super.layout = _win_create_simple_layout(); + new_win->window.type = WIN_PLUGIN; + new_win->window.tab_name = strdup(plugin_name); + new_win->window.layout = _win_create_simple_layout(); new_win->tag = strdup(tag); new_win->plugin_name = strdup(plugin_name); new_win->memcheck = PROFPLUGINWIN_MEMCHECK; - return &new_win->super; + return &new_win->window; } char* @@ -416,6 +423,7 @@ win_show_subwin(ProfWin *window) void win_free(ProfWin* window) { + free(window->tab_name); if (window->layout->type == LAYOUT_SPLIT) { ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout; if (layout->subwin) { diff --git a/src/ui/window_list.c b/src/ui/window_list.c index 8c3c4739..640196b5 100644 --- a/src/ui/window_list.c +++ b/src/ui/window_list.c @@ -45,7 +45,6 @@ #include "config/theme.h" #include "plugins/plugins.h" #include "ui/ui.h" -#include "ui/statusbar.h" #include "ui/window_list.h" #include "xmpp/xmpp.h" #include "xmpp/roster_list.h" @@ -862,9 +861,9 @@ wins_swap(int source_win, int target_win) g_hash_table_insert(windows, GINT_TO_POINTER(target_win), source); status_bar_inactive(source_win); if (win_unread(source) > 0) { - status_bar_new(target_win); + status_bar_new(target_win, source->tab_name); } else { - status_bar_active(target_win); + status_bar_active(target_win, source->tab_name); } if (wins_get_current_num() == source_win) { wins_set_current_by_num(target_win); @@ -879,14 +878,14 @@ wins_swap(int source_win, int target_win) g_hash_table_insert(windows, GINT_TO_POINTER(source_win), target); g_hash_table_insert(windows, GINT_TO_POINTER(target_win), source); if (win_unread(source) > 0) { - status_bar_new(target_win); + status_bar_new(target_win, source->tab_name); } else { - status_bar_active(target_win); + status_bar_active(target_win, source->tab_name); } if (win_unread(target) > 0) { - status_bar_new(source_win); + status_bar_new(source_win, target->tab_name); } else { - status_bar_active(source_win); + status_bar_active(source_win, target->tab_name); } if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) { ui_focus_win(console); @@ -1003,16 +1002,16 @@ wins_tidy(void) if (num == 10) { g_hash_table_insert(new_windows, GINT_TO_POINTER(0), window); if (win_unread(window) > 0) { - status_bar_new(0); + status_bar_new(0, window->tab_name); } else { - status_bar_active(0); + status_bar_active(0, window->tab_name); } } else { g_hash_table_insert(new_windows, GINT_TO_POINTER(num), window); if (win_unread(window) > 0) { - status_bar_new(num); + status_bar_new(num, window->tab_name); } else { - status_bar_active(num); + status_bar_active(num, window->tab_name); } } num++; diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 51e8d84a..e31e88f5 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -466,8 +466,8 @@ void title_bar_set_presence(contact_presence_t presence) {} // status bar void status_bar_inactive(const int win) {} -void status_bar_active(const int win) {} -void status_bar_new(const int win) {} +void status_bar_active(const int win, char *name) {} +void status_bar_new(const int win, char *name) {} void status_bar_set_all_inactive(void) {} // roster window From 720dce866eb759a7b5ecdaff7c7d9ceeb6e2487c Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 8 Mar 2018 22:27:49 +0000 Subject: [PATCH 06/21] Add prefs for empty tabs and tab names --- src/command/cmd_ac.c | 45 ++++++++++++++++++++++++++++++++++-- src/command/cmd_defs.c | 19 +++++++++++---- src/command/cmd_funcs.c | 38 ++++++++++++++++++++++++++++++ src/config/preferences.c | 6 +++++ src/config/preferences.h | 2 ++ src/ui/console.c | 16 +++++++++++++ src/ui/statusbar.c | 25 +++++++++++--------- src/ui/ui.h | 1 + src/ui/window.c | 7 ++++-- tests/unittests/ui/stub_ui.c | 1 + 10 files changed, 140 insertions(+), 20 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index bb6e9cd6..ec572325 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -99,6 +99,7 @@ static char* _blocked_autocomplete(ProfWin *window, const char *const input, gbo static char* _tray_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _presence_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _rooms_autocomplete(ProfWin *window, const char *const input, gboolean previous); +static char* _statusbar_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _script_autocomplete_func(const char *const prefix, gboolean previous); @@ -199,6 +200,8 @@ static Autocomplete tray_ac; static Autocomplete presence_ac; static Autocomplete presence_setting_ac; static Autocomplete winpos_ac; +static Autocomplete statusbar_ac; +static Autocomplete statusbar_show_ac; void cmd_ac_init(void) @@ -774,6 +777,16 @@ cmd_ac_init(void) winpos_ac = autocomplete_new(); autocomplete_add(winpos_ac, "up"); autocomplete_add(winpos_ac, "down"); + + statusbar_ac = autocomplete_new(); + autocomplete_add(statusbar_ac, "up"); + autocomplete_add(statusbar_ac, "down"); + autocomplete_add(statusbar_ac, "show"); + autocomplete_add(statusbar_ac, "hide"); + + statusbar_show_ac = autocomplete_new(); + autocomplete_add(statusbar_show_ac, "empty"); + autocomplete_add(statusbar_show_ac, "name"); } void @@ -1055,6 +1068,8 @@ cmd_ac_reset(ProfWin *window) autocomplete_reset(presence_ac); autocomplete_reset(presence_setting_ac); autocomplete_reset(winpos_ac); + autocomplete_reset(statusbar_ac); + autocomplete_reset(statusbar_show_ac); autocomplete_reset(script_ac); if (script_show_ac) { @@ -1182,6 +1197,8 @@ cmd_ac_uninit(void) autocomplete_free(presence_ac); autocomplete_free(presence_setting_ac); autocomplete_free(winpos_ac); + autocomplete_free(statusbar_ac); + autocomplete_free(statusbar_show_ac); } char* @@ -1369,8 +1386,8 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ } } - gchar *cmds[] = { "/prefs", "/disco", "/room", "/autoping", "/titlebar", "/mainwin", "/statusbar", "/inputwin" }; - Autocomplete completers[] = { prefs_ac, disco_ac, room_ac, autoping_ac, winpos_ac, winpos_ac, winpos_ac, winpos_ac }; + gchar *cmds[] = { "/prefs", "/disco", "/room", "/autoping", "/titlebar", "/mainwin", "/inputwin" }; + Autocomplete completers[] = { prefs_ac, disco_ac, room_ac, autoping_ac, winpos_ac, winpos_ac, winpos_ac }; for (i = 0; i < ARRAY_SIZE(cmds); i++) { result = autocomplete_param_with_ac(input, cmds[i], completers[i], TRUE, previous); @@ -1421,6 +1438,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ g_hash_table_insert(ac_funcs, "/tray", _tray_autocomplete); g_hash_table_insert(ac_funcs, "/presence", _presence_autocomplete); g_hash_table_insert(ac_funcs, "/rooms", _rooms_autocomplete); + g_hash_table_insert(ac_funcs, "/statusbar", _statusbar_autocomplete); int len = strlen(input); char parsed[len+1]; @@ -3181,3 +3199,26 @@ _rooms_autocomplete(ProfWin *window, const char *const input, gboolean previous) return NULL; } + +static char* +_statusbar_autocomplete(ProfWin *window, const char *const input, gboolean previous) +{ + char *found = NULL; + + found = autocomplete_param_with_ac(input, "/statusbar", statusbar_ac, TRUE, previous); + if (found) { + return found; + } + + found = autocomplete_param_with_ac(input, "/statusbar show", statusbar_show_ac, TRUE, previous); + if (found) { + return found; + } + + found = autocomplete_param_with_ac(input, "/statusbar hide", statusbar_show_ac, TRUE, previous); + if (found) { + return found; + } + + return NULL; +} diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index cb2aa842..f8c50739 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1358,20 +1358,29 @@ static struct cmd_t command_defs[] = }, { "/statusbar", - parse_args, 1, 1, &cons_winpos_setting, + parse_args, 1, 2, &cons_statusbar_setting, CMD_NOSUBFUNCS CMD_MAINFUNC(cmd_statusbar) CMD_TAGS( CMD_TAG_UI) CMD_SYN( + "/statusbar show empty|name", + "/statusbar hide empty|name", +// "/statusbar maxtabs ", "/statusbar up", "/statusbar down") CMD_DESC( - "Move the status bar.") + "Manage statusbar display preferences.") CMD_ARGS( - { "up", "Move the status bar up the screen." }, - { "down", "Move the status bar down the screen." }) - CMD_NOEXAMPLES +// { "maxtabs ", "Set the maximum number of tabs to display, must be between 0 and 10" }, + { "show|hide empty", "Show or hide empty tabs." }, + { "show|hide name", "Show or hide names in tabs." }, + { "up", "Move the status bar up the screen." }, + { "down", "Move the status bar down the screen." }) + CMD_EXAMPLES( +// "/statusbar maxtabs 5", + "/statusbar show empty", + "/statusbar hide name") }, { "/inputwin", diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index b4840afd..1e5b3b55 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -5792,6 +5792,44 @@ cmd_mainwin(ProfWin *window, const char *const command, gchar **args) gboolean cmd_statusbar(ProfWin *window, const char *const command, gchar **args) { + if (g_strcmp0(args[0], "show") == 0) { + if (g_strcmp0(args[1], "empty") == 0) { + prefs_set_boolean(PREF_STATUSBAR_SHOW_EMPTY, TRUE); + cons_show("Enabled showing empty tabs."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "name") == 0) { + prefs_set_boolean(PREF_STATUSBAR_SHOW_NAME, TRUE); + cons_show("Enabled showing tab names."); + ui_resize(); + return TRUE; + } + cons_bad_cmd_usage(command); + return TRUE; + } + + if (g_strcmp0(args[0], "hide") == 0) { + if (g_strcmp0(args[1], "empty") == 0) { + prefs_set_boolean(PREF_STATUSBAR_SHOW_EMPTY, FALSE); + cons_show("Disabled showing empty tabs."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "name") == 0) { + prefs_set_boolean(PREF_STATUSBAR_SHOW_NAME, FALSE); + cons_show("Disabled showing tab names."); + ui_resize(); + return TRUE; + } + cons_bad_cmd_usage(command); + return TRUE; + } + + if (g_strcmp0(args[0], "maxtabs") == 0) { + + } + if (g_strcmp0(args[0], "up") == 0) { gboolean result = prefs_statusbar_pos_up(); if (result) { diff --git a/src/config/preferences.c b/src/config/preferences.c index d935061c..63089a20 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1570,6 +1570,8 @@ _get_group(preference_t pref) case PREF_CONSOLE_MUC: case PREF_CONSOLE_PRIVATE: case PREF_CONSOLE_CHAT: + case PREF_STATUSBAR_SHOW_EMPTY: + case PREF_STATUSBAR_SHOW_NAME: return PREF_GROUP_UI; case PREF_STATES: case PREF_OUTTYPE: @@ -1825,6 +1827,10 @@ _get_key(preference_t pref) return "sourcepath"; case PREF_ROOM_LIST_CACHE: return "rooms.cache"; + case PREF_STATUSBAR_SHOW_EMPTY: + return "statusbar.show.empty"; + case PREF_STATUSBAR_SHOW_NAME: + return "statusbar.show.name"; default: return NULL; } diff --git a/src/config/preferences.h b/src/config/preferences.h index 6eb2241d..183d033a 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -144,6 +144,8 @@ typedef enum { PREF_BOOKMARK_INVITE, PREF_PLUGINS_SOURCEPATH, PREF_ROOM_LIST_CACHE, + PREF_STATUSBAR_SHOW_EMPTY, + PREF_STATUSBAR_SHOW_NAME, } preference_t; typedef struct prof_alias_t { diff --git a/src/ui/console.c b/src/ui/console.c index 55bba1c5..84e7b59b 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1747,6 +1747,22 @@ cons_inpblock_setting(void) } } +void +cons_statusbar_setting(void) +{ + cons_winpos_setting(); + if (prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY)) { + cons_show("Show empty tabs (/statusbar) : ON"); + } else { + cons_show("Show empty tabs (/statusbar) : OFF"); + } + if (prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME)) { + cons_show("Show tab names (/statusbar) : ON"); + } else { + cons_show("Show tab names (/statusbar) : OFF"); + } +} + void cons_winpos_setting(void) { diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index ff264202..ca8e8a47 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -63,9 +63,7 @@ typedef struct _status_bar_t { int current_tab; } StatusBar; -#define MAX_TABS 5 -#define SHOW_EMPTY_TABS FALSE -#define SHOW_NAME TRUE +#define MAX_TABS 10 static GTimeZone *tz; static StatusBar *statusbar; @@ -229,8 +227,6 @@ status_bar_clear(void) statusbar->message = NULL; } - werase(statusbar_win); - _status_bar_draw(); } @@ -248,8 +244,11 @@ status_bar_clear_message(void) static int _tabs_width(void) { - if (SHOW_NAME) { - if (SHOW_EMPTY_TABS) { + gboolean show_empty = prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY); + gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME); + + if (show_name) { + if (show_empty) { int width = 4; int i = 0; for (i = 1; i <= MAX_TABS; i++) { @@ -275,7 +274,7 @@ _tabs_width(void) return width; } } else { - if (SHOW_EMPTY_TABS) { + if (show_empty) { return MAX_TABS * 3 + 4; } else { return g_hash_table_size(statusbar->tabs) * 3 + 4; @@ -286,6 +285,7 @@ _tabs_width(void) static void _status_bar_draw(void) { + werase(statusbar_win); wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT)); int pos = 1; @@ -337,12 +337,15 @@ _status_bar_draw(void) pos = cols - _tabs_width(); int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); + gboolean show_empty = prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY); + gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME); + int i = 1; for (i = 1; i <= MAX_TABS; i++) { int display_num = i == 10 ? 0 : i; StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); - if (tab || (tab == NULL && SHOW_EMPTY_TABS)) { + if (tab || (tab == NULL && show_empty)) { wattron(statusbar_win, bracket_attrs); if (i == statusbar->current_tab) { mvwprintw(statusbar_win, 0, pos, "-"); @@ -356,7 +359,7 @@ _status_bar_draw(void) int status_attrs = theme_attrs(THEME_STATUS_NEW); wattron(statusbar_win, status_attrs); mvwprintw(statusbar_win, 0, pos, "%d", display_num); - if (SHOW_NAME) { + if (show_name) { pos++; mvwprintw(statusbar_win, 0, pos, ":"); pos++; @@ -368,7 +371,7 @@ _status_bar_draw(void) int status_attrs = theme_attrs(THEME_STATUS_ACTIVE); wattron(statusbar_win, status_attrs); mvwprintw(statusbar_win, 0, pos, "%d", display_num); - if (SHOW_NAME) { + if (show_name) { pos++; mvwprintw(statusbar_win, 0, pos, ":"); pos++; diff --git a/src/ui/ui.h b/src/ui/ui.h index 5d779df6..81af4b30 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -318,6 +318,7 @@ void cons_autoping_setting(void); void cons_autoconnect_setting(void); void cons_room_cache_setting(void); void cons_inpblock_setting(void); +void cons_statusbar_setting(void); void cons_winpos_setting(void); void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity); void cons_show_contact_offline(PContact contact, char *resource, char *status); diff --git a/src/ui/window.c b/src/ui/window.c index 83da1219..39d178ee 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -210,7 +210,10 @@ win_create_muc_config(const char *const roomjid, DataForm *form) { ProfMucConfWin *new_win = malloc(sizeof(ProfMucConfWin)); new_win->window.type = WIN_MUC_CONFIG; - new_win->window.tab_name = strdup(roomjid); + GString *tab_str = g_string_new(roomjid); + g_string_append(tab_str, " config"); + new_win->window.tab_name = strdup(tab_str->str); + g_string_free(tab_str, TRUE); new_win->window.layout = _win_create_simple_layout(); new_win->roomjid = strdup(roomjid); @@ -257,7 +260,7 @@ win_create_plugin(const char *const plugin_name, const char *const tag) { ProfPluginWin *new_win = malloc(sizeof(ProfPluginWin)); new_win->window.type = WIN_PLUGIN; - new_win->window.tab_name = strdup(plugin_name); + new_win->window.tab_name = strdup(tag); new_win->window.layout = _win_create_simple_layout(); new_win->tag = strdup(tag); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index e31e88f5..da226092 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -448,6 +448,7 @@ void cons_autoconnect_setting(void) {} void cons_rooms_cache_setting(void) {} void cons_inpblock_setting(void) {} void cons_winpos_setting(void) {} +void cons_statusbar_setting(void) {} void cons_tray_setting(void) {} void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity) From a957c545d30750776e5b3307e71d4069e56a9ea5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 8 Mar 2018 23:11:49 +0000 Subject: [PATCH 07/21] Add max tabs preference for statusbar --- src/command/cmd_ac.c | 1 + src/command/cmd_defs.c | 6 +-- src/command/cmd_funcs.c | 27 ++++++++++ src/config/preferences.c | 17 ++++++ src/config/preferences.h | 3 ++ src/ui/console.c | 4 +- src/ui/statusbar.c | 112 ++++++++++++++++++++------------------- 7 files changed, 111 insertions(+), 59 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index ec572325..75638cae 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -783,6 +783,7 @@ cmd_ac_init(void) autocomplete_add(statusbar_ac, "down"); autocomplete_add(statusbar_ac, "show"); autocomplete_add(statusbar_ac, "hide"); + autocomplete_add(statusbar_ac, "maxtabs"); statusbar_show_ac = autocomplete_new(); autocomplete_add(statusbar_show_ac, "empty"); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index f8c50739..2634645f 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1366,19 +1366,19 @@ static struct cmd_t command_defs[] = CMD_SYN( "/statusbar show empty|name", "/statusbar hide empty|name", -// "/statusbar maxtabs ", + "/statusbar maxtabs ", "/statusbar up", "/statusbar down") CMD_DESC( "Manage statusbar display preferences.") CMD_ARGS( -// { "maxtabs ", "Set the maximum number of tabs to display, must be between 0 and 10" }, + { "maxtabs ", "Set the maximum number of tabs to display, must be between 0 and 10" }, { "show|hide empty", "Show or hide empty tabs." }, { "show|hide name", "Show or hide names in tabs." }, { "up", "Move the status bar up the screen." }, { "down", "Move the status bar down the screen." }) CMD_EXAMPLES( -// "/statusbar maxtabs 5", + "/statusbar maxtabs 5", "/statusbar show empty", "/statusbar hide name") }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 1e5b3b55..8901fbca 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -5827,7 +5827,34 @@ cmd_statusbar(ProfWin *window, const char *const command, gchar **args) } if (g_strcmp0(args[0], "maxtabs") == 0) { + if (args[1] == NULL) { + cons_bad_cmd_usage(command); + return TRUE; + } + char *value = args[1]; + int intval = 0; + char *err_msg = NULL; + gboolean res = strtoi_range(value, &intval, 0, INT_MAX, &err_msg); + if (res) { + if (intval < 0 || intval > 10) { + cons_bad_cmd_usage(command); + return TRUE; + } + + prefs_set_statusbartabs(intval); + if (intval == 0) { + cons_show("Status bar tabs disabled."); + } else { + cons_show("Status bar tabs set to %d.", intval); + } + return TRUE; + } else { + cons_show(err_msg); + cons_bad_cmd_usage(command); + free(err_msg); + return TRUE; + } } if (g_strcmp0(args[0], "up") == 0) { diff --git a/src/config/preferences.c b/src/config/preferences.c index 63089a20..8166e3bd 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -663,6 +663,23 @@ prefs_get_tray_timer(void) } } +gint +prefs_get_statusbartabs(void) +{ + if (!g_key_file_has_key(prefs, PREF_GROUP_UI, "statusbar.tabs", NULL)) { + return 10; + } else { + return g_key_file_get_integer(prefs, PREF_GROUP_UI, "statusbar.tabs", NULL); + } +} + +void +prefs_set_statusbartabs(gint value) +{ + g_key_file_set_integer(prefs, PREF_GROUP_UI, "statusbar.tabs", value); + _save_prefs(); +} + gchar** prefs_get_plugins(void) { diff --git a/src/config/preferences.h b/src/config/preferences.h index 183d033a..4e6bff97 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -190,6 +190,9 @@ gint prefs_get_autoping_timeout(void); gint prefs_get_inpblock(void); void prefs_set_inpblock(gint value); +void prefs_set_statusbartabs(gint value); +gint prefs_get_statusbartabs(void); + void prefs_set_occupants_size(gint value); gint prefs_get_occupants_size(void); void prefs_set_roster_size(gint value); diff --git a/src/ui/console.c b/src/ui/console.c index 84e7b59b..a6948c5b 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1544,6 +1544,7 @@ cons_show_ui_prefs(void) cons_presence_setting(); cons_inpblock_setting(); cons_tlsshow_setting(); + cons_statusbar_setting(); cons_alert(); } @@ -1750,7 +1751,6 @@ cons_inpblock_setting(void) void cons_statusbar_setting(void) { - cons_winpos_setting(); if (prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY)) { cons_show("Show empty tabs (/statusbar) : ON"); } else { @@ -1761,6 +1761,8 @@ cons_statusbar_setting(void) } else { cons_show("Show tab names (/statusbar) : OFF"); } + cons_show("Max tabs (/statusbar) : %d", prefs_get_statusbartabs()); + } void diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index ca8e8a47..d16e0660 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -63,24 +63,13 @@ typedef struct _status_bar_t { int current_tab; } StatusBar; -#define MAX_TABS 10 - static GTimeZone *tz; static StatusBar *statusbar; static WINDOW *statusbar_win; static void _status_bar_draw(void); - -void -_destroy_tab(StatusBarTab *tab) -{ - if (tab) { - if (tab->display_name) { - free(tab->display_name); - } - free(tab); - } -} +static void _destroy_tab(StatusBarTab *tab); +static int _tabs_width(void); void status_bar_init(void) @@ -241,47 +230,6 @@ status_bar_clear_message(void) _status_bar_draw(); } -static int -_tabs_width(void) -{ - gboolean show_empty = prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY); - gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME); - - if (show_name) { - if (show_empty) { - int width = 4; - int i = 0; - for (i = 1; i <= MAX_TABS; i++) { - StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); - if (tab) { - width += strlen(tab->display_name); - width += 4; - } else { - width += 3; - } - } - return width; - } else { - int width = 4; - int i = 0; - for (i = 1; i <= MAX_TABS; i++) { - StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); - if (tab) { - width += strlen(tab->display_name); - width += 4; - } - } - return width; - } - } else { - if (show_empty) { - return MAX_TABS * 3 + 4; - } else { - return g_hash_table_size(statusbar->tabs) * 3 + 4; - } - } -} - static void _status_bar_draw(void) { @@ -339,9 +287,10 @@ _status_bar_draw(void) gboolean show_empty = prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY); gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME); + gint max_tabs = prefs_get_statusbartabs(); int i = 1; - for (i = 1; i <= MAX_TABS; i++) { + for (i = 1; i <= max_tabs; i++) { int display_num = i == 10 ? 0 : i; StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); @@ -409,3 +358,56 @@ _status_bar_draw(void) wnoutrefresh(statusbar_win); inp_put_back(); } + +static void +_destroy_tab(StatusBarTab *tab) +{ + if (tab) { + if (tab->display_name) { + free(tab->display_name); + } + free(tab); + } +} + +static int +_tabs_width(void) +{ + gboolean show_empty = prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY); + gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME); + gint max_tabs = prefs_get_statusbartabs(); + + if (show_name) { + if (show_empty) { + int width = 4; + int i = 0; + for (i = 1; i <= max_tabs; i++) { + StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); + if (tab) { + width += strlen(tab->display_name); + width += 4; + } else { + width += 3; + } + } + return width; + } else { + int width = 4; + int i = 0; + for (i = 1; i <= max_tabs; i++) { + StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); + if (tab) { + width += strlen(tab->display_name); + width += 4; + } + } + return width; + } + } else { + if (show_empty) { + return max_tabs * 3 + 4; + } else { + return g_hash_table_size(statusbar->tabs) * 3 + 4; + } + } +} From 59382984c054bca832329c0e365e7f05346fa478 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 9 Mar 2018 21:11:59 +0000 Subject: [PATCH 08/21] Add preferences for tab display --- src/command/cmd_ac.c | 26 ++++++++ src/command/cmd_defs.c | 5 ++ src/command/cmd_funcs.c | 37 +++++++++++- src/config/preferences.c | 10 ++++ src/config/preferences.h | 2 + src/event/server_events.c | 4 +- src/plugins/api.c | 2 +- src/ui/chatwin.c | 8 +-- src/ui/console.c | 10 +++- src/ui/core.c | 24 ++++---- src/ui/mucwin.c | 12 ++-- src/ui/privwin.c | 4 +- src/ui/statusbar.c | 113 ++++++++++++++++++++++++++++++----- src/ui/ui.h | 5 +- src/ui/win_types.h | 1 - src/ui/window.c | 59 +++++++++++++----- src/ui/window_list.c | 30 ++++++---- tests/unittests/ui/stub_ui.c | 9 ++- 18 files changed, 290 insertions(+), 71 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 75638cae..f47b3727 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -201,6 +201,8 @@ static Autocomplete presence_ac; static Autocomplete presence_setting_ac; static Autocomplete winpos_ac; static Autocomplete statusbar_ac; +static Autocomplete statusbar_chat_ac; +static Autocomplete statusbar_room_ac; static Autocomplete statusbar_show_ac; void @@ -784,6 +786,16 @@ cmd_ac_init(void) autocomplete_add(statusbar_ac, "show"); autocomplete_add(statusbar_ac, "hide"); autocomplete_add(statusbar_ac, "maxtabs"); + autocomplete_add(statusbar_ac, "chat"); + autocomplete_add(statusbar_ac, "room"); + + statusbar_chat_ac = autocomplete_new(); + autocomplete_add(statusbar_chat_ac, "user"); + autocomplete_add(statusbar_chat_ac, "jid"); + + statusbar_room_ac = autocomplete_new(); + autocomplete_add(statusbar_room_ac, "room"); + autocomplete_add(statusbar_room_ac, "jid"); statusbar_show_ac = autocomplete_new(); autocomplete_add(statusbar_show_ac, "empty"); @@ -1070,6 +1082,8 @@ cmd_ac_reset(ProfWin *window) autocomplete_reset(presence_setting_ac); autocomplete_reset(winpos_ac); autocomplete_reset(statusbar_ac); + autocomplete_reset(statusbar_chat_ac); + autocomplete_reset(statusbar_room_ac); autocomplete_reset(statusbar_show_ac); autocomplete_reset(script_ac); @@ -1199,6 +1213,8 @@ cmd_ac_uninit(void) autocomplete_free(presence_setting_ac); autocomplete_free(winpos_ac); autocomplete_free(statusbar_ac); + autocomplete_free(statusbar_chat_ac); + autocomplete_free(statusbar_room_ac); autocomplete_free(statusbar_show_ac); } @@ -3221,5 +3237,15 @@ _statusbar_autocomplete(ProfWin *window, const char *const input, gboolean previ return found; } + found = autocomplete_param_with_ac(input, "/statusbar chat", statusbar_chat_ac, TRUE, previous); + if (found) { + return found; + } + + found = autocomplete_param_with_ac(input, "/statusbar room", statusbar_room_ac, TRUE, previous); + if (found) { + return found; + } + return NULL; } diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 2634645f..1c5a6cba 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1367,6 +1367,8 @@ static struct cmd_t command_defs[] = "/statusbar show empty|name", "/statusbar hide empty|name", "/statusbar maxtabs ", + "/statusbar chat user|jid", + "/statusbar room room|jid", "/statusbar up", "/statusbar down") CMD_DESC( @@ -1375,11 +1377,14 @@ static struct cmd_t command_defs[] = { "maxtabs ", "Set the maximum number of tabs to display, must be between 0 and 10" }, { "show|hide empty", "Show or hide empty tabs." }, { "show|hide name", "Show or hide names in tabs." }, + { "chat user|jid", "Show only the users name, or the full jid if no nick is present for chat tabs." }, + { "room room|jid", "Show only the rooms name, or the full jid for room tabs." }, { "up", "Move the status bar up the screen." }, { "down", "Move the status bar down the screen." }) CMD_EXAMPLES( "/statusbar maxtabs 5", "/statusbar show empty", + "/statusbar chat jid", "/statusbar hide name") }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 8901fbca..5e416359 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -2095,7 +2095,7 @@ cmd_who(ProfWin *window, const char *const command, gchar **args) } if (window->type != WIN_CONSOLE && window->type != WIN_MUC) { - status_bar_new(1, "console"); + status_bar_new(1, WIN_CONSOLE, "console"); } return TRUE; @@ -5848,6 +5848,7 @@ cmd_statusbar(ProfWin *window, const char *const command, gchar **args) } else { cons_show("Status bar tabs set to %d.", intval); } + ui_resize(); return TRUE; } else { cons_show(err_msg); @@ -5857,6 +5858,40 @@ cmd_statusbar(ProfWin *window, const char *const command, gchar **args) } } + if (g_strcmp0(args[0], "chat") == 0) { + if (g_strcmp0(args[1], "jid") == 0) { + prefs_set_string(PREF_STATUSBAR_CHAT, "jid"); + cons_show("Using jid for chat tabs."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "user") == 0) { + prefs_set_string(PREF_STATUSBAR_CHAT, "user"); + cons_show("Using user for chat tabs."); + ui_resize(); + return TRUE; + } + cons_bad_cmd_usage(command); + return TRUE; + } + + if (g_strcmp0(args[0], "room") == 0) { + if (g_strcmp0(args[1], "jid") == 0) { + prefs_set_string(PREF_STATUSBAR_ROOM, "jid"); + cons_show("Using jid for room tabs."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "room") == 0) { + prefs_set_string(PREF_STATUSBAR_ROOM, "room"); + cons_show("Using room name for room tabs."); + ui_resize(); + return TRUE; + } + cons_bad_cmd_usage(command); + return TRUE; + } + if (g_strcmp0(args[0], "up") == 0) { gboolean result = prefs_statusbar_pos_up(); if (result) { diff --git a/src/config/preferences.c b/src/config/preferences.c index 8166e3bd..2d2aeef8 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1589,6 +1589,8 @@ _get_group(preference_t pref) case PREF_CONSOLE_CHAT: case PREF_STATUSBAR_SHOW_EMPTY: case PREF_STATUSBAR_SHOW_NAME: + case PREF_STATUSBAR_CHAT: + case PREF_STATUSBAR_ROOM: return PREF_GROUP_UI; case PREF_STATES: case PREF_OUTTYPE: @@ -1848,6 +1850,10 @@ _get_key(preference_t pref) return "statusbar.show.empty"; case PREF_STATUSBAR_SHOW_NAME: return "statusbar.show.name"; + case PREF_STATUSBAR_CHAT: + return "statusbar.chat"; + case PREF_STATUSBAR_ROOM: + return "statusbar.room"; default: return NULL; } @@ -1960,6 +1966,10 @@ _get_default_string(preference_t pref) case PREF_CONSOLE_PRIVATE: case PREF_CONSOLE_CHAT: return "all"; + case PREF_STATUSBAR_CHAT: + return "user"; + case PREF_STATUSBAR_ROOM: + return "room"; default: return NULL; } diff --git a/src/config/preferences.h b/src/config/preferences.h index 4e6bff97..f06d3845 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -146,6 +146,8 @@ typedef enum { PREF_ROOM_LIST_CACHE, PREF_STATUSBAR_SHOW_EMPTY, PREF_STATUSBAR_SHOW_NAME, + PREF_STATUSBAR_CHAT, + PREF_STATUSBAR_ROOM, } preference_t; typedef struct prof_alias_t { diff --git a/src/event/server_events.c b/src/event/server_events.c index 230184e7..b735c22f 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -282,7 +282,7 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha // currently in groupchat window if (wins_is_current(window)) { is_current = TRUE; - status_bar_active(num, window->tab_name); + status_bar_active(num, WIN_MUC, mucwin->roomjid); if ((g_strcmp0(mynick, nick) != 0) && (prefs_get_boolean(PREF_BEEP))) { beep(); @@ -290,7 +290,7 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha // not currently on groupchat window } else { - status_bar_new(num, window->tab_name); + status_bar_new(num, WIN_MUC, mucwin->roomjid); if ((g_strcmp0(mynick, nick) != 0) && (prefs_get_boolean(PREF_FLASH))) { flash(); diff --git a/src/plugins/api.c b/src/plugins/api.c index e75dccf1..d30914dc 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -333,7 +333,7 @@ api_win_create( // set status bar active ProfPluginWin *pluginwin = wins_get_plugin(tag); int num = wins_get_num((ProfWin*)pluginwin); - status_bar_active(num, pluginwin->plugin_name); + status_bar_active(num, WIN_PLUGIN, pluginwin->tag); } int diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 29c8cff4..31604db4 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -105,7 +105,7 @@ chatwin_otr_secured(ProfChatWin *chatwin, gboolean trusted) title_bar_switch(); } else { int num = wins_get_num(window); - status_bar_new(num, window->tab_name); + status_bar_new(num, WIN_CHAT, chatwin->barejid); int ui_index = num; if (ui_index == 10) { @@ -249,11 +249,11 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha if (wins_is_current(window)) { win_print_incoming(window, timestamp, display_name, plugin_message, enc_mode); title_bar_set_typing(FALSE); - status_bar_active(num, window->tab_name); + status_bar_active(num, WIN_CHAT, chatwin->barejid); // not currently viewing chat window with sender } else { - status_bar_new(num, window->tab_name); + status_bar_new(num, WIN_CHAT, chatwin->barejid); cons_show_incoming_message(display_name, num, chatwin->unread); if (prefs_get_boolean(PREF_FLASH)) { @@ -328,7 +328,7 @@ chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message, prof_en win_print_outgoing(window, enc_char, "%s", message); int num = wins_get_num(window); - status_bar_active(num, window->tab_name); + status_bar_active(num, WIN_CHAT, chatwin->barejid); } void diff --git a/src/ui/console.c b/src/ui/console.c index a6948c5b..f3c7816b 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1761,8 +1761,16 @@ cons_statusbar_setting(void) } else { cons_show("Show tab names (/statusbar) : OFF"); } + cons_show("Max tabs (/statusbar) : %d", prefs_get_statusbartabs()); + char *pref_chat = prefs_get_string(PREF_STATUSBAR_CHAT); + cons_show("Chat tab display (/statusbar) : %s", pref_chat); + prefs_free_string(pref_chat); + + char *pref_room = prefs_get_string(PREF_STATUSBAR_ROOM); + cons_show("Room tab display (/statusbar) : %s", pref_room); + prefs_free_string(pref_room); } void @@ -2179,7 +2187,7 @@ cons_alert(void) { ProfWin *current = wins_get_current(); if (current->type != WIN_CONSOLE) { - status_bar_new(1, "console"); + status_bar_new(1, WIN_CONSOLE, "console"); } } diff --git a/src/ui/core.c b/src/ui/core.c index 67205f73..af0d55a9 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -103,7 +103,7 @@ ui_init(void) refresh(); create_title_bar(); status_bar_init(); - status_bar_active(1, "console"); + status_bar_active(1, WIN_CONSOLE, "console"); create_input_window(); wins_init(); notifier_initialise(); @@ -287,7 +287,7 @@ ui_contact_typing(const char *const barejid, const char *const resource) title_bar_set_typing(TRUE); int num = wins_get_num(window); - status_bar_active(num, window->tab_name); + status_bar_active(num, WIN_CHAT, chatwin->barejid); } } @@ -673,7 +673,10 @@ ui_focus_win(ProfWin *window) title_bar_switch(); } status_bar_current(i); - status_bar_active(i, window->tab_name); + + char *identifier = win_get_tab_identifier(window); + status_bar_active(i, window->type, identifier); + free(identifier); } void @@ -690,7 +693,7 @@ ui_close_win(int index) wins_close_by_num(index); title_bar_console(); status_bar_current(1); - status_bar_active(1, "console"); + status_bar_active(1, WIN_CONSOLE, "console"); } void @@ -744,12 +747,13 @@ ui_print_system_msg_from_recipient(const char *const barejid, const char *messag int num = 0; window = wins_new_chat(barejid); if (window) { + chatwin = (ProfChatWin*)window; num = wins_get_num(window); - status_bar_active(num, window->tab_name); + status_bar_active(num, WIN_CHAT, chatwin->barejid); } else { num = 0; window = wins_get_console(); - status_bar_active(1, window->tab_name); + status_bar_active(1, WIN_CONSOLE, "console"); } } @@ -760,10 +764,10 @@ void ui_room_join(const char *const roomjid, gboolean focus) { ProfMucWin *mucwin = wins_get_muc(roomjid); - ProfWin *window = (ProfWin*)mucwin; - if (!window) { - window = wins_new_muc(roomjid); + if (mucwin == NULL) { + mucwin = (ProfMucWin*)wins_new_muc(roomjid); } + ProfWin *window = (ProfWin*)mucwin; char *nick = muc_nick(roomjid); win_print(window, THEME_ROOMINFO, '!', "-> You have joined the room as %s", nick); @@ -783,7 +787,7 @@ ui_room_join(const char *const roomjid, gboolean focus) ui_focus_win(window); } else { int num = wins_get_num(window); - status_bar_active(num, window->tab_name); + status_bar_active(num, WIN_MUC, mucwin->roomjid); ProfWin *console = wins_get_console(); char *nick = muc_nick(roomjid); win_println(console, THEME_TYPING, '!', "-> Autojoined %s as %s (%d).", roomjid, nick, num); diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index 10575915..02eca6a4 100644 --- a/src/ui/mucwin.c +++ b/src/ui/mucwin.c @@ -519,11 +519,11 @@ mucwin_requires_config(ProfMucWin *mucwin) // currently in groupchat window if (wins_is_current(window)) { - status_bar_active(num, window->tab_name); + status_bar_active(num, WIN_MUC, mucwin->roomjid); // not currently on groupchat window } else { - status_bar_new(num, window->tab_name); + status_bar_new(num, WIN_MUC, mucwin->roomjid); } } @@ -553,11 +553,11 @@ mucwin_subject(ProfMucWin *mucwin, const char *const nick, const char *const sub // currently in groupchat window if (wins_is_current(window)) { - status_bar_active(num, window->tab_name); + status_bar_active(num, WIN_MUC, mucwin->roomjid); // not currently on groupchat window } else { - status_bar_new(num, window->tab_name); + status_bar_new(num, WIN_MUC, mucwin->roomjid); } } @@ -583,11 +583,11 @@ mucwin_broadcast(ProfMucWin *mucwin, const char *const message) // currently in groupchat window if (wins_is_current(window)) { - status_bar_active(num, window->tab_name); + status_bar_active(num, WIN_MUC, mucwin->roomjid); // not currently on groupchat window } else { - status_bar_new(num, window->tab_name); + status_bar_new(num, WIN_MUC, mucwin->roomjid); } } diff --git a/src/ui/privwin.c b/src/ui/privwin.c index 76c95fb8..8de59683 100644 --- a/src/ui/privwin.c +++ b/src/ui/privwin.c @@ -62,11 +62,11 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat if (wins_is_current(window)) { win_print_incoming(window, timestamp, jidp->resourcepart, message, PROF_MSG_PLAIN); title_bar_set_typing(FALSE); - status_bar_active(num, window->tab_name); + status_bar_active(num, WIN_PRIVATE, privatewin->fulljid); // not currently viewing chat window with sender } else { - status_bar_new(num, window->tab_name); + status_bar_new(num, WIN_PRIVATE, privatewin->fulljid); cons_show_incoming_private_message(jidp->resourcepart, jidp->barejid, num, privatewin->unread); win_print_incoming(window, timestamp, jidp->resourcepart, message, PROF_MSG_PLAIN); diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index d16e0660..2b507039 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -50,9 +50,12 @@ #include "ui/statusbar.h" #include "ui/inputwin.h" #include "ui/screen.h" +#include "xmpp/roster_list.h" +#include "xmpp/contact.h" typedef struct _status_bar_tab_t { - char *display_name; + win_type_t window_type; + char *identifier; gboolean highlight; } StatusBarTab; @@ -70,6 +73,7 @@ static WINDOW *statusbar_win; static void _status_bar_draw(void); static void _destroy_tab(StatusBarTab *tab); static int _tabs_width(void); +static char* _display_name(StatusBarTab *tab); void status_bar_init(void) @@ -81,7 +85,8 @@ status_bar_init(void) statusbar->message = NULL; statusbar->tabs = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)_destroy_tab); StatusBarTab *console = malloc(sizeof(StatusBarTab)); - console->display_name = strdup("console"); + console->window_type = WIN_CONSOLE; + console->identifier = strdup("console"); g_hash_table_insert(statusbar->tabs, GINT_TO_POINTER(1), console); statusbar->current_tab = 1; @@ -159,7 +164,7 @@ status_bar_inactive(const int win) } void -status_bar_active(const int win, char *name) +status_bar_active(const int win, win_type_t wintype, char *identifier) { int true_win = win; if (true_win == 0) { @@ -167,15 +172,16 @@ status_bar_active(const int win, char *name) } StatusBarTab *tab = malloc(sizeof(StatusBarTab)); - tab->display_name = strdup(name); + tab->identifier = strdup(identifier); tab->highlight = FALSE; + tab->window_type = wintype; g_hash_table_replace(statusbar->tabs, GINT_TO_POINTER(true_win), tab); _status_bar_draw(); } void -status_bar_new(const int win, char* name) +status_bar_new(const int win, win_type_t wintype, char* identifier) { int true_win = win; if (true_win == 0) { @@ -183,8 +189,9 @@ status_bar_new(const int win, char* name) } StatusBarTab *tab = malloc(sizeof(StatusBarTab)); - tab->display_name = strdup(name); + tab->identifier = strdup(identifier); tab->highlight = TRUE; + tab->window_type = wintype; g_hash_table_replace(statusbar->tabs, GINT_TO_POINTER(true_win), tab); _status_bar_draw(); @@ -304,6 +311,7 @@ _status_bar_draw(void) wattroff(statusbar_win, bracket_attrs); pos++; if (tab) { + char *display_name = _display_name(tab); if (tab->highlight) { int status_attrs = theme_attrs(THEME_STATUS_NEW); wattron(statusbar_win, status_attrs); @@ -312,8 +320,8 @@ _status_bar_draw(void) pos++; mvwprintw(statusbar_win, 0, pos, ":"); pos++; - mvwprintw(statusbar_win, 0, pos, tab->display_name); - pos += strlen(tab->display_name) -1 ; + mvwprintw(statusbar_win, 0, pos, display_name); + pos += strlen(display_name) -1 ; } wattroff(statusbar_win, status_attrs); } else { @@ -324,11 +332,12 @@ _status_bar_draw(void) pos++; mvwprintw(statusbar_win, 0, pos, ":"); pos++; - mvwprintw(statusbar_win, 0, pos, tab->display_name); - pos += strlen(tab->display_name) - 1; + mvwprintw(statusbar_win, 0, pos, display_name); + pos += strlen(display_name) - 1; } wattroff(statusbar_win, status_attrs); } + free(display_name); } else { mvwprintw(statusbar_win, 0, pos, " "); } @@ -363,8 +372,8 @@ static void _destroy_tab(StatusBarTab *tab) { if (tab) { - if (tab->display_name) { - free(tab->display_name); + if (tab->identifier) { + free(tab->identifier); } free(tab); } @@ -384,8 +393,10 @@ _tabs_width(void) for (i = 1; i <= max_tabs; i++) { StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); if (tab) { - width += strlen(tab->display_name); + char *display_name = _display_name(tab); + width += strlen(display_name); width += 4; + free(display_name); } else { width += 3; } @@ -397,8 +408,10 @@ _tabs_width(void) for (i = 1; i <= max_tabs; i++) { StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); if (tab) { - width += strlen(tab->display_name); + char *display_name = _display_name(tab); + width += strlen(display_name); width += 4; + free(display_name); } } return width; @@ -411,3 +424,75 @@ _tabs_width(void) } } } + +static char* +_display_name(StatusBarTab *tab) +{ + if (tab->window_type == WIN_CONSOLE) { + return strdup("console"); + } + if (tab->window_type == WIN_XML) { + return strdup("xmlconsole"); + } + if (tab->window_type == WIN_PLUGIN) { + return strdup(tab->identifier); + } + if (tab->window_type == WIN_CHAT) { + PContact contact = roster_get_contact(tab->identifier); + if (contact && p_contact_name(contact)) { + return strdup(p_contact_name(contact)); + } + char *pref = prefs_get_string(PREF_STATUSBAR_CHAT); + if (g_strcmp0("user", pref) == 0) { + Jid *jidp = jid_create(tab->identifier); + char *user = strdup(jidp->localpart); + jid_destroy(jidp); + return user; + } else { + return strdup(tab->identifier); + } + } + if (tab->window_type == WIN_MUC) { + char *pref = prefs_get_string(PREF_STATUSBAR_ROOM); + if (g_strcmp0("room", pref) == 0) { + Jid *jidp = jid_create(tab->identifier); + char *room = strdup(jidp->localpart); + jid_destroy(jidp); + return room; + } else { + return strdup(tab->identifier); + } + } + if (tab->window_type == WIN_MUC_CONFIG) { + char *pref = prefs_get_string(PREF_STATUSBAR_ROOM); + GString *display_str = g_string_new(""); + if (g_strcmp0("room", pref) == 0) { + Jid *jidp = jid_create(tab->identifier); + g_string_append(display_str, jidp->localpart); + jid_destroy(jidp); + } else { + g_string_append(display_str, tab->identifier); + } + g_string_append(display_str, " conf"); + char *result = strdup(display_str->str); + g_string_free(display_str, TRUE); + return result; + } + if (tab->window_type == WIN_PRIVATE) { + char *pref = prefs_get_string(PREF_STATUSBAR_ROOM); + if (g_strcmp0("room", pref) == 0) { + GString *display_str = g_string_new(""); + Jid *jidp = jid_create(tab->identifier); + g_string_append(display_str, jidp->localpart); + g_string_append(display_str, "/"); + g_string_append(display_str, jidp->resourcepart); + jid_destroy(jidp); + char *result = strdup(display_str->str); + g_string_free(display_str, TRUE); + return result; + } else { + return strdup(tab->identifier); + } + } + return strdup("window"); +} diff --git a/src/ui/ui.h b/src/ui/ui.h index 81af4b30..4630145c 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -332,8 +332,8 @@ void title_bar_set_presence(contact_presence_t presence); // status bar void status_bar_inactive(const int win); -void status_bar_active(const int win, char *name); -void status_bar_new(const int win, char *name); +void status_bar_active(const int win, win_type_t wintype, char *identifier); +void status_bar_new(const int win, win_type_t wintype, char *identifier); void status_bar_set_all_inactive(void); // roster window @@ -376,6 +376,7 @@ void win_show_occupant_info(ProfWin *window, const char *const room, Occupant *o void win_show_contact(ProfWin *window, PContact contact); void win_show_info(ProfWin *window, PContact contact); void win_clear(ProfWin *window); +char* win_get_tab_identifier(ProfWin *window); char* win_to_string(ProfWin *window); // desktop notifications diff --git a/src/ui/win_types.h b/src/ui/win_types.h index 284dbc1f..7fa75b34 100644 --- a/src/ui/win_types.h +++ b/src/ui/win_types.h @@ -136,7 +136,6 @@ typedef enum { typedef struct prof_win_t { win_type_t type; - char *tab_name; ProfLayout *layout; } ProfWin; diff --git a/src/ui/window.c b/src/ui/window.c index 39d178ee..5543707d 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -125,7 +125,6 @@ win_create_console(void) { ProfConsoleWin *new_win = malloc(sizeof(ProfConsoleWin)); new_win->window.type = WIN_CONSOLE; - new_win->window.tab_name = strdup("console"); new_win->window.layout = _win_create_split_layout(); return &new_win->window; @@ -136,7 +135,6 @@ win_create_chat(const char *const barejid) { ProfChatWin *new_win = malloc(sizeof(ProfChatWin)); new_win->window.type = WIN_CHAT; - new_win->window.tab_name = strdup(barejid); new_win->window.layout = _win_create_simple_layout(); new_win->barejid = strdup(barejid); @@ -164,8 +162,7 @@ win_create_muc(const char *const roomjid) int cols = getmaxx(stdscr); new_win->window.type = WIN_MUC; - new_win->window.tab_name = strdup(roomjid); - + new_win->window.layout = _win_create_simple_layout(); ProfLayoutSplit *layout = malloc(sizeof(ProfLayoutSplit)); layout->base.type = LAYOUT_SPLIT; @@ -210,12 +207,7 @@ win_create_muc_config(const char *const roomjid, DataForm *form) { ProfMucConfWin *new_win = malloc(sizeof(ProfMucConfWin)); new_win->window.type = WIN_MUC_CONFIG; - GString *tab_str = g_string_new(roomjid); - g_string_append(tab_str, " config"); - new_win->window.tab_name = strdup(tab_str->str); - g_string_free(tab_str, TRUE); new_win->window.layout = _win_create_simple_layout(); - new_win->roomjid = strdup(roomjid); new_win->form = form; @@ -229,9 +221,7 @@ win_create_private(const char *const fulljid) { ProfPrivateWin *new_win = malloc(sizeof(ProfPrivateWin)); new_win->window.type = WIN_PRIVATE; - new_win->window.tab_name = strdup(fulljid); new_win->window.layout = _win_create_simple_layout(); - new_win->fulljid = strdup(fulljid); new_win->unread = 0; new_win->occupant_offline = FALSE; @@ -247,7 +237,6 @@ win_create_xmlconsole(void) { ProfXMLWin *new_win = malloc(sizeof(ProfXMLWin)); new_win->window.type = WIN_XML; - new_win->window.tab_name = strdup("xmlconsole"); new_win->window.layout = _win_create_simple_layout(); new_win->memcheck = PROFXMLWIN_MEMCHECK; @@ -260,7 +249,6 @@ win_create_plugin(const char *const plugin_name, const char *const tag) { ProfPluginWin *new_win = malloc(sizeof(ProfPluginWin)); new_win->window.type = WIN_PLUGIN; - new_win->window.tab_name = strdup(tag); new_win->window.layout = _win_create_simple_layout(); new_win->tag = strdup(tag); @@ -330,6 +318,50 @@ win_get_title(ProfWin *window) return NULL; } +char* +win_get_tab_identifier(ProfWin *window) +{ + assert(window != NULL); + + switch (window->type) { + case WIN_CONSOLE: + { + return strdup("console"); + } + case WIN_CHAT: + { + ProfChatWin *chatwin = (ProfChatWin*)window; + return strdup(chatwin->barejid); + } + case WIN_MUC: + { + ProfMucWin *mucwin = (ProfMucWin*)window; + return strdup(mucwin->roomjid); + } + case WIN_MUC_CONFIG: + { + ProfMucConfWin *mucconfwin = (ProfMucConfWin*)window; + return strdup(mucconfwin->roomjid); + } + case WIN_PRIVATE: + { + ProfPrivateWin *privwin = (ProfPrivateWin*)window; + return strdup(privwin->fulljid); + } + case WIN_PLUGIN: + { + ProfPluginWin *pluginwin = (ProfPluginWin*)window; + return strdup(pluginwin->tag); + } + case WIN_XML: + { + return strdup("xmlconsole"); + } + default: + return strdup("UNKNOWN"); + } +} + char* win_to_string(ProfWin *window) { @@ -426,7 +458,6 @@ win_show_subwin(ProfWin *window) void win_free(ProfWin* window) { - free(window->tab_name); if (window->layout->type == LAYOUT_SPLIT) { ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout; if (layout->subwin) { diff --git a/src/ui/window_list.c b/src/ui/window_list.c index 640196b5..990a17f1 100644 --- a/src/ui/window_list.c +++ b/src/ui/window_list.c @@ -856,15 +856,17 @@ wins_swap(int source_win, int target_win) ProfWin *target = g_hash_table_lookup(windows, GINT_TO_POINTER(target_win)); // target window empty - if (!target) { + if (target == NULL) { g_hash_table_steal(windows, GINT_TO_POINTER(source_win)); g_hash_table_insert(windows, GINT_TO_POINTER(target_win), source); status_bar_inactive(source_win); + char *identifier = win_get_tab_identifier(source); if (win_unread(source) > 0) { - status_bar_new(target_win, source->tab_name); + status_bar_new(target_win, source->type, identifier); } else { - status_bar_active(target_win, source->tab_name); + status_bar_active(target_win, source->type, identifier); } + free(identifier); if (wins_get_current_num() == source_win) { wins_set_current_by_num(target_win); ui_focus_win(console); @@ -877,16 +879,20 @@ wins_swap(int source_win, int target_win) g_hash_table_steal(windows, GINT_TO_POINTER(target_win)); g_hash_table_insert(windows, GINT_TO_POINTER(source_win), target); g_hash_table_insert(windows, GINT_TO_POINTER(target_win), source); + char *source_identifier = win_get_tab_identifier(source); + char *target_identifier = win_get_tab_identifier(target); if (win_unread(source) > 0) { - status_bar_new(target_win, source->tab_name); + status_bar_new(target_win, source->type, source_identifier); } else { - status_bar_active(target_win, source->tab_name); + status_bar_active(target_win, source->type, source_identifier); } if (win_unread(target) > 0) { - status_bar_new(source_win, target->tab_name); + status_bar_new(source_win, target->type, target_identifier); } else { - status_bar_active(source_win, target->tab_name); + status_bar_active(source_win, target->type, target_identifier); } + free(source_identifier); + free(target_identifier); if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) { ui_focus_win(console); } @@ -998,22 +1004,24 @@ wins_tidy(void) GList *curr = keys; while (curr) { ProfWin *window = g_hash_table_lookup(windows, curr->data); + char *identifier = win_get_tab_identifier(window); g_hash_table_steal(windows, curr->data); if (num == 10) { g_hash_table_insert(new_windows, GINT_TO_POINTER(0), window); if (win_unread(window) > 0) { - status_bar_new(0, window->tab_name); + status_bar_new(0, window->type, identifier); } else { - status_bar_active(0, window->tab_name); + status_bar_active(0, window->type, identifier); } } else { g_hash_table_insert(new_windows, GINT_TO_POINTER(num), window); if (win_unread(window) > 0) { - status_bar_new(num, window->tab_name); + status_bar_new(num, window->type, identifier); } else { - status_bar_active(num, window->tab_name); + status_bar_active(num, window->type, identifier); } } + free(identifier); num++; curr = g_list_next(curr); } diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index da226092..420653e1 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -467,8 +467,8 @@ void title_bar_set_presence(contact_presence_t presence) {} // status bar void status_bar_inactive(const int win) {} -void status_bar_active(const int win, char *name) {} -void status_bar_new(const int win, char *name) {} +void status_bar_active(const int win, win_type_t type, char *identifier) {} +void status_bar_new(const int win, win_type_t type, char *identifier) {} void status_bar_set_all_inactive(void) {} // roster window @@ -507,6 +507,11 @@ ProfWin* win_create_plugin(const char *const plugin_name, const char * const tag return NULL; } +char* win_get_tab_identifier(ProfWin *window) +{ + return NULL; +} + void win_update_virtual(ProfWin *window) {} void win_free(ProfWin *window) {} gboolean win_notify_remind(ProfWin *window) From 136b975b6cb1df03ff55faa50dffd5f0da75d0c0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 9 Mar 2018 22:42:20 +0000 Subject: [PATCH 09/21] Remove empty tabs --- src/command/cmd_ac.c | 10 +------- src/command/cmd_defs.c | 17 ++++--------- src/command/cmd_funcs.c | 52 ++-------------------------------------- src/command/cmd_funcs.h | 2 -- src/config/preferences.c | 7 ------ src/config/preferences.h | 2 -- src/config/theme.c | 1 - src/ui/console.c | 15 ------------ src/ui/statusbar.c | 47 ++++++++++-------------------------- src/ui/ui.h | 1 - src/ui/window_list.c | 4 +--- 11 files changed, 21 insertions(+), 137 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index f47b3727..31f719bd 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -391,8 +391,6 @@ cmd_ac_init(void) wins_ac = autocomplete_new(); autocomplete_add(wins_ac, "unread"); autocomplete_add(wins_ac, "prune"); - autocomplete_add(wins_ac, "tidy"); - autocomplete_add(wins_ac, "autotidy"); autocomplete_add(wins_ac, "swap"); roster_ac = autocomplete_new(); @@ -798,7 +796,6 @@ cmd_ac_init(void) autocomplete_add(statusbar_room_ac, "jid"); statusbar_show_ac = autocomplete_new(); - autocomplete_add(statusbar_show_ac, "empty"); autocomplete_add(statusbar_show_ac, "name"); } @@ -1335,7 +1332,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ // autocomplete boolean settings gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash", "/chlog", "/grlog", - "/history", "/vercheck", "/privileges", "/wrap", "/winstidy", "/carbons", "/encwarn", + "/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/encwarn", "/lastactivity" }; for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { @@ -2667,11 +2664,6 @@ _wins_autocomplete(ProfWin *window, const char *const input, gboolean previous) { char *result = NULL; - result = autocomplete_param_with_func(input, "/wins autotidy", prefs_autocomplete_boolean_choice, previous); - if (result) { - return result; - } - result = autocomplete_param_with_ac(input, "/wins", wins_ac, TRUE, previous); if (result) { return result; diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 1c5a6cba..fd1c5697 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -962,18 +962,14 @@ static struct cmd_t command_defs[] = parse_args, 0, 3, NULL, CMD_SUBFUNCS( { "unread", cmd_wins_unread }, - { "tidy", cmd_wins_tidy }, { "prune", cmd_wins_prune }, - { "swap", cmd_wins_swap }, - { "autotidy", cmd_wins_autotidy }) + { "swap", cmd_wins_swap }) CMD_MAINFUNC(cmd_wins) CMD_TAGS( CMD_TAG_UI) CMD_SYN( "/wins", "/wins unread", - "/wins tidy", - "/wins autotidy on|off", "/wins prune", "/wins swap ") CMD_DESC( @@ -981,9 +977,7 @@ static struct cmd_t command_defs[] = "Passing no argument will list all currently active windows and information about their usage.") CMD_ARGS( { "unread", "List windows with unread messages." }, - { "tidy", "Move windows so there are no gaps." }, - { "autotidy on|off", "Automatically remove gaps when closing windows." }, - { "prune", "Close all windows with no unread messages, and then tidy so there are no gaps." }, + { "prune", "Close all windows with no unread messages." }, { "swap ", "Swap windows, target may be an empty position." }) CMD_NOEXAMPLES }, @@ -1364,8 +1358,8 @@ static struct cmd_t command_defs[] = CMD_TAGS( CMD_TAG_UI) CMD_SYN( - "/statusbar show empty|name", - "/statusbar hide empty|name", + "/statusbar show name", + "/statusbar hide name", "/statusbar maxtabs ", "/statusbar chat user|jid", "/statusbar room room|jid", @@ -1375,7 +1369,6 @@ static struct cmd_t command_defs[] = "Manage statusbar display preferences.") CMD_ARGS( { "maxtabs ", "Set the maximum number of tabs to display, must be between 0 and 10" }, - { "show|hide empty", "Show or hide empty tabs." }, { "show|hide name", "Show or hide names in tabs." }, { "chat user|jid", "Show only the users name, or the full jid if no nick is present for chat tabs." }, { "room room|jid", "Show only the rooms name, or the full jid for room tabs." }, @@ -1383,7 +1376,7 @@ static struct cmd_t command_defs[] = { "down", "Move the status bar down the screen." }) CMD_EXAMPLES( "/statusbar maxtabs 5", - "/statusbar show empty", + "/statusbar hide name", "/statusbar chat jid", "/statusbar hide name") }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 5e416359..3fec5e16 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -1252,17 +1252,6 @@ cmd_wins_unread(ProfWin *window, const char *const command, gchar **args) return TRUE; } -gboolean -cmd_wins_tidy(ProfWin *window, const char *const command, gchar **args) -{ - if (wins_tidy()) { - cons_show("Windows tidied."); - } else { - cons_show("No tidy needed."); - } - return TRUE; -} - gboolean cmd_wins_prune(ProfWin *window, const char *const command, gchar **args) { @@ -1298,23 +1287,6 @@ cmd_wins_swap(ProfWin *window, const char *const command, gchar **args) return TRUE; } -gboolean -cmd_wins_autotidy(ProfWin *window, const char *const command, gchar **args) -{ - if (g_strcmp0(args[1], "on") == 0) { - cons_show("Window autotidy enabled"); - prefs_set_boolean(PREF_WINS_AUTO_TIDY, TRUE); - wins_tidy(); - } else if (g_strcmp0(args[1], "off") == 0) { - cons_show("Window autotidy disabled"); - prefs_set_boolean(PREF_WINS_AUTO_TIDY, FALSE); - } else { - cons_bad_cmd_usage(command); - } - - return TRUE; -} - gboolean cmd_wins(ProfWin *window, const char *const command, gchar **args) { @@ -1407,11 +1379,7 @@ cmd_close(ProfWin *window, const char *const command, gchar **args) // close the window ui_close_win(index); cons_show("Closed window %d", index); - - // Tidy up the window list. - if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) { - wins_tidy(); - } + wins_tidy(); rosterwin_roster(); return TRUE; @@ -1442,11 +1410,7 @@ cmd_close(ProfWin *window, const char *const command, gchar **args) // close the window ui_close_win(index); cons_show("Closed window %s", args[0]); - - // Tidy up the window list. - if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) { - wins_tidy(); - } + wins_tidy(); rosterwin_roster(); return TRUE; @@ -5793,12 +5757,6 @@ gboolean cmd_statusbar(ProfWin *window, const char *const command, gchar **args) { if (g_strcmp0(args[0], "show") == 0) { - if (g_strcmp0(args[1], "empty") == 0) { - prefs_set_boolean(PREF_STATUSBAR_SHOW_EMPTY, TRUE); - cons_show("Enabled showing empty tabs."); - ui_resize(); - return TRUE; - } if (g_strcmp0(args[1], "name") == 0) { prefs_set_boolean(PREF_STATUSBAR_SHOW_NAME, TRUE); cons_show("Enabled showing tab names."); @@ -5810,12 +5768,6 @@ cmd_statusbar(ProfWin *window, const char *const command, gchar **args) } if (g_strcmp0(args[0], "hide") == 0) { - if (g_strcmp0(args[1], "empty") == 0) { - prefs_set_boolean(PREF_STATUSBAR_SHOW_EMPTY, FALSE); - cons_show("Disabled showing empty tabs."); - ui_resize(); - return TRUE; - } if (g_strcmp0(args[1], "name") == 0) { prefs_set_boolean(PREF_STATUSBAR_SHOW_NAME, FALSE); cons_show("Disabled showing tab names."); diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index aa703f6d..0bbf338e 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -205,10 +205,8 @@ gboolean cmd_otr_answer(ProfWin *window, const char *const command, gchar **args gboolean cmd_wins(ProfWin *window, const char *const command, gchar **args); gboolean cmd_wins_unread(ProfWin *window, const char *const command, gchar **args); -gboolean cmd_wins_tidy(ProfWin *window, const char *const command, gchar **args); gboolean cmd_wins_prune(ProfWin *window, const char *const command, gchar **args); gboolean cmd_wins_swap(ProfWin *window, const char *const command, gchar **args); -gboolean cmd_wins_autotidy(ProfWin *window, const char *const command, gchar **args); gboolean cmd_form_field(ProfWin *window, char *tag, gchar **args); diff --git a/src/config/preferences.c b/src/config/preferences.c index 2d2aeef8..aea2786d 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1547,7 +1547,6 @@ _get_group(preference_t pref) case PREF_MUC_PRIVILEGES: case PREF_PRESENCE: case PREF_WRAP: - case PREF_WINS_AUTO_TIDY: case PREF_TIME_CONSOLE: case PREF_TIME_CHAT: case PREF_TIME_MUC: @@ -1587,7 +1586,6 @@ _get_group(preference_t pref) case PREF_CONSOLE_MUC: case PREF_CONSOLE_PRIVATE: case PREF_CONSOLE_CHAT: - case PREF_STATUSBAR_SHOW_EMPTY: case PREF_STATUSBAR_SHOW_NAME: case PREF_STATUSBAR_CHAT: case PREF_STATUSBAR_ROOM: @@ -1754,8 +1752,6 @@ _get_key(preference_t pref) return "presence"; case PREF_WRAP: return "wrap"; - case PREF_WINS_AUTO_TIDY: - return "wins.autotidy"; case PREF_TIME_CONSOLE: return "time.console"; case PREF_TIME_CHAT: @@ -1846,8 +1842,6 @@ _get_key(preference_t pref) return "sourcepath"; case PREF_ROOM_LIST_CACHE: return "rooms.cache"; - case PREF_STATUSBAR_SHOW_EMPTY: - return "statusbar.show.empty"; case PREF_STATUSBAR_SHOW_NAME: return "statusbar.show.name"; case PREF_STATUSBAR_CHAT: @@ -1883,7 +1877,6 @@ _get_default_boolean(preference_t pref) case PREF_MUC_PRIVILEGES: case PREF_PRESENCE: case PREF_WRAP: - case PREF_WINS_AUTO_TIDY: case PREF_INPBLOCK_DYNAMIC: case PREF_RESOURCE_TITLE: case PREF_RESOURCE_MESSAGE: diff --git a/src/config/preferences.h b/src/config/preferences.h index f06d3845..aef019e1 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -89,7 +89,6 @@ typedef enum { PREF_MUC_PRIVILEGES, PREF_PRESENCE, PREF_WRAP, - PREF_WINS_AUTO_TIDY, PREF_TIME_CONSOLE, PREF_TIME_CHAT, PREF_TIME_MUC, @@ -144,7 +143,6 @@ typedef enum { PREF_BOOKMARK_INVITE, PREF_PLUGINS_SOURCEPATH, PREF_ROOM_LIST_CACHE, - PREF_STATUSBAR_SHOW_EMPTY, PREF_STATUSBAR_SHOW_NAME, PREF_STATUSBAR_CHAT, PREF_STATUSBAR_ROOM, diff --git a/src/config/theme.c b/src/config/theme.c index 7c5937fb..9d28f421 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -384,7 +384,6 @@ _load_preferences(void) _set_boolean_preference("flash", PREF_FLASH); _set_boolean_preference("splash", PREF_SPLASH); _set_boolean_preference("wrap", PREF_WRAP); - _set_boolean_preference("wins.autotidy", PREF_WINS_AUTO_TIDY); _set_boolean_preference("resource.title", PREF_RESOURCE_TITLE); _set_boolean_preference("resource.message", PREF_RESOURCE_MESSAGE); _set_boolean_preference("occupants", PREF_OCCUPANTS); diff --git a/src/ui/console.c b/src/ui/console.c index f3c7816b..dfc54df3 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1123,15 +1123,6 @@ cons_wrap_setting(void) cons_show("Word wrap (/wrap) : OFF"); } -void -cons_winstidy_setting(void) -{ - if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) - cons_show("Window Auto Tidy (/wins) : ON"); - else - cons_show("Window Auto Tidy (/wins) : OFF"); -} - void cons_encwarn_setting(void) { @@ -1531,7 +1522,6 @@ cons_show_ui_prefs(void) cons_splash_setting(); cons_winpos_setting(); cons_wrap_setting(); - cons_winstidy_setting(); cons_time_setting(); cons_resource_setting(); cons_vercheck_setting(); @@ -1751,11 +1741,6 @@ cons_inpblock_setting(void) void cons_statusbar_setting(void) { - if (prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY)) { - cons_show("Show empty tabs (/statusbar) : ON"); - } else { - cons_show("Show empty tabs (/statusbar) : OFF"); - } if (prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME)) { cons_show("Show tab names (/statusbar) : ON"); } else { diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 2b507039..991d21f2 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -292,7 +292,6 @@ _status_bar_draw(void) pos = cols - _tabs_width(); int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); - gboolean show_empty = prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY); gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME); gint max_tabs = prefs_get_statusbartabs(); @@ -301,7 +300,7 @@ _status_bar_draw(void) int display_num = i == 10 ? 0 : i; StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); - if (tab || (tab == NULL && show_empty)) { + if (tab) { wattron(statusbar_win, bracket_attrs); if (i == statusbar->current_tab) { mvwprintw(statusbar_win, 0, pos, "-"); @@ -382,46 +381,24 @@ _destroy_tab(StatusBarTab *tab) static int _tabs_width(void) { - gboolean show_empty = prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY); gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME); gint max_tabs = prefs_get_statusbartabs(); if (show_name) { - if (show_empty) { - int width = 4; - int i = 0; - for (i = 1; i <= max_tabs; i++) { - StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); - if (tab) { - char *display_name = _display_name(tab); - width += strlen(display_name); - width += 4; - free(display_name); - } else { - width += 3; - } + int width = 4; + int i = 0; + for (i = 1; i <= max_tabs; i++) { + StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); + if (tab) { + char *display_name = _display_name(tab); + width += strlen(display_name); + width += 4; + free(display_name); } - return width; - } else { - int width = 4; - int i = 0; - for (i = 1; i <= max_tabs; i++) { - StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); - if (tab) { - char *display_name = _display_name(tab); - width += strlen(display_name); - width += 4; - free(display_name); - } - } - return width; } + return width; } else { - if (show_empty) { - return max_tabs * 3 + 4; - } else { - return g_hash_table_size(statusbar->tabs) * 3 + 4; - } + return g_hash_table_size(statusbar->tabs) * 3 + 4; } } diff --git a/src/ui/ui.h b/src/ui/ui.h index 4630145c..d344f855 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -297,7 +297,6 @@ void cons_occupants_setting(void); void cons_roster_setting(void); void cons_presence_setting(void); void cons_wrap_setting(void); -void cons_winstidy_setting(void); void cons_time_setting(void); void cons_wintitle_setting(void); void cons_notify_setting(void); diff --git a/src/ui/window_list.c b/src/ui/window_list.c index 990a17f1..09a53ed1 100644 --- a/src/ui/window_list.c +++ b/src/ui/window_list.c @@ -238,9 +238,7 @@ wins_close_plugin(char *tag) int index = wins_get_num(toclose); ui_close_win(index); - if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) { - wins_tidy(); - } + wins_tidy(); } GList* From e96af8537c8a0e3e53904be7e035f51f155e2493 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 9 Mar 2018 22:59:38 +0000 Subject: [PATCH 10/21] Only allow swapping active windows --- src/command/cmd_funcs.c | 35 ++++++++++++++++++++++++----------- src/ui/window_list.c | 6 +----- src/ui/window_list.h | 2 +- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 3fec5e16..ae7f2abc 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -1269,21 +1269,34 @@ cmd_wins_swap(ProfWin *window, const char *const command, gchar **args) int source_win = atoi(args[1]); int target_win = atoi(args[2]); + if ((source_win == 1) || (target_win == 1)) { cons_show("Cannot move console window."); - } else if (source_win == 10 || target_win == 10) { - cons_show("Window 10 does not exist"); - } else if (source_win != target_win) { - gboolean swapped = wins_swap(source_win, target_win); - if (swapped) { - cons_show("Swapped windows %d <-> %d", source_win, target_win); - } else { - cons_show("Window %d does not exist", source_win); - } - } else { - cons_show("Same source and target window supplied."); + return TRUE; } + if (source_win == 10 || target_win == 10) { + cons_show("Window 10 does not exist"); + return TRUE; + } + + if (source_win == target_win) { + cons_show("Same source and target window supplied."); + return TRUE; + } + + if (wins_get_by_num(source_win) == NULL) { + cons_show("Window %d does not exist", source_win); + return TRUE; + } + + if (wins_get_by_num(target_win) == NULL) { + cons_show("Window %d does not exist", target_win); + return TRUE; + } + + wins_swap(source_win, target_win); + cons_show("Swapped windows %d <-> %d", source_win, target_win); return TRUE; } diff --git a/src/ui/window_list.c b/src/ui/window_list.c index 09a53ed1..798f4e41 100644 --- a/src/ui/window_list.c +++ b/src/ui/window_list.c @@ -844,7 +844,7 @@ wins_lost_connection(void) g_list_free(values); } -gboolean +void wins_swap(int source_win, int target_win) { ProfWin *source = g_hash_table_lookup(windows, GINT_TO_POINTER(source_win)); @@ -869,7 +869,6 @@ wins_swap(int source_win, int target_win) wins_set_current_by_num(target_win); ui_focus_win(console); } - return TRUE; // target window occupied } else { @@ -894,10 +893,7 @@ wins_swap(int source_win, int target_win) if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) { ui_focus_win(console); } - return TRUE; } - } else { - return FALSE; } } diff --git a/src/ui/window_list.h b/src/ui/window_list.h index f1a2ee24..68e72739 100644 --- a/src/ui/window_list.h +++ b/src/ui/window_list.h @@ -87,7 +87,7 @@ gboolean wins_tidy(void); GSList* wins_create_summary(gboolean unread); void wins_destroy(void); GList* wins_get_nums(void); -gboolean wins_swap(int source_win, int target_win); +void wins_swap(int source_win, int target_win); void wins_hide_subwin(ProfWin *window); void wins_show_subwin(ProfWin *window); From 6f5c0eb52505709fd92d01ed9102653cb47da4b4 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 9 Mar 2018 23:44:28 +0000 Subject: [PATCH 11/21] Preference to show/hide tab number --- src/command/cmd_ac.c | 1 + src/command/cmd_defs.c | 5 +-- src/command/cmd_funcs.c | 22 ++++++++++++ src/config/preferences.c | 5 +++ src/config/preferences.h | 1 + src/ui/console.c | 5 +++ src/ui/statusbar.c | 73 ++++++++++++++++++++++------------------ 7 files changed, 77 insertions(+), 35 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 31f719bd..de57ac82 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -797,6 +797,7 @@ cmd_ac_init(void) statusbar_show_ac = autocomplete_new(); autocomplete_add(statusbar_show_ac, "name"); + autocomplete_add(statusbar_show_ac, "number"); } void diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index fd1c5697..5a873309 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1358,8 +1358,8 @@ static struct cmd_t command_defs[] = CMD_TAGS( CMD_TAG_UI) CMD_SYN( - "/statusbar show name", - "/statusbar hide name", + "/statusbar show name|number", + "/statusbar hide name|number", "/statusbar maxtabs ", "/statusbar chat user|jid", "/statusbar room room|jid", @@ -1370,6 +1370,7 @@ static struct cmd_t command_defs[] = CMD_ARGS( { "maxtabs ", "Set the maximum number of tabs to display, must be between 0 and 10" }, { "show|hide name", "Show or hide names in tabs." }, + { "show|hide number", "Show or hide numbers in tabs." }, { "chat user|jid", "Show only the users name, or the full jid if no nick is present for chat tabs." }, { "room room|jid", "Show only the rooms name, or the full jid for room tabs." }, { "up", "Move the status bar up the screen." }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index ae7f2abc..e6e53ca4 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -5776,17 +5776,39 @@ cmd_statusbar(ProfWin *window, const char *const command, gchar **args) ui_resize(); return TRUE; } + if (g_strcmp0(args[1], "number") == 0) { + prefs_set_boolean(PREF_STATUSBAR_SHOW_NUMBER, TRUE); + cons_show("Enabled showing tab numbers."); + ui_resize(); + return TRUE; + } cons_bad_cmd_usage(command); return TRUE; } if (g_strcmp0(args[0], "hide") == 0) { if (g_strcmp0(args[1], "name") == 0) { + if (prefs_get_boolean(PREF_STATUSBAR_SHOW_NUMBER) == FALSE) { + cons_show("Cannot disable both names and numbers in statusbar."); + cons_show("Use '/statusbar maxtabs 0' to hide tabs."); + return TRUE; + } prefs_set_boolean(PREF_STATUSBAR_SHOW_NAME, FALSE); cons_show("Disabled showing tab names."); ui_resize(); return TRUE; } + if (g_strcmp0(args[1], "number") == 0) { + if (prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME) == FALSE) { + cons_show("Cannot disable both names and numbers in statusbar."); + cons_show("Use '/statusbar maxtabs 0' to hide tabs."); + return TRUE; + } + prefs_set_boolean(PREF_STATUSBAR_SHOW_NUMBER, FALSE); + cons_show("Disabled showing tab numbers."); + ui_resize(); + return TRUE; + } cons_bad_cmd_usage(command); return TRUE; } diff --git a/src/config/preferences.c b/src/config/preferences.c index aea2786d..28883e76 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1587,6 +1587,7 @@ _get_group(preference_t pref) case PREF_CONSOLE_PRIVATE: case PREF_CONSOLE_CHAT: case PREF_STATUSBAR_SHOW_NAME: + case PREF_STATUSBAR_SHOW_NUMBER: case PREF_STATUSBAR_CHAT: case PREF_STATUSBAR_ROOM: return PREF_GROUP_UI; @@ -1844,6 +1845,8 @@ _get_key(preference_t pref) return "rooms.cache"; case PREF_STATUSBAR_SHOW_NAME: return "statusbar.show.name"; + case PREF_STATUSBAR_SHOW_NUMBER: + return "statusbar.show.number"; case PREF_STATUSBAR_CHAT: return "statusbar.chat"; case PREF_STATUSBAR_ROOM: @@ -1896,6 +1899,8 @@ _get_default_boolean(preference_t pref) case PREF_TRAY_READ: case PREF_BOOKMARK_INVITE: case PREF_ROOM_LIST_CACHE: + case PREF_STATUSBAR_SHOW_NAME: + case PREF_STATUSBAR_SHOW_NUMBER: return TRUE; default: return FALSE; diff --git a/src/config/preferences.h b/src/config/preferences.h index aef019e1..e1b666a0 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -144,6 +144,7 @@ typedef enum { PREF_PLUGINS_SOURCEPATH, PREF_ROOM_LIST_CACHE, PREF_STATUSBAR_SHOW_NAME, + PREF_STATUSBAR_SHOW_NUMBER, PREF_STATUSBAR_CHAT, PREF_STATUSBAR_ROOM, } preference_t; diff --git a/src/ui/console.c b/src/ui/console.c index dfc54df3..60c5c8f5 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1746,6 +1746,11 @@ cons_statusbar_setting(void) } else { cons_show("Show tab names (/statusbar) : OFF"); } + if (prefs_get_boolean(PREF_STATUSBAR_SHOW_NUMBER)) { + cons_show("Show tab numbers (/statusbar) : ON"); + } else { + cons_show("Show tab numbers (/statusbar) : OFF"); + } cons_show("Max tabs (/statusbar) : %d", prefs_get_statusbartabs()); diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 991d21f2..36011cbd 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -292,6 +292,7 @@ _status_bar_draw(void) pos = cols - _tabs_width(); int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); + gboolean show_number = prefs_get_boolean(PREF_STATUSBAR_SHOW_NUMBER); gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME); gint max_tabs = prefs_get_statusbartabs(); @@ -309,38 +310,28 @@ _status_bar_draw(void) } wattroff(statusbar_win, bracket_attrs); pos++; - if (tab) { - char *display_name = _display_name(tab); - if (tab->highlight) { - int status_attrs = theme_attrs(THEME_STATUS_NEW); - wattron(statusbar_win, status_attrs); - mvwprintw(statusbar_win, 0, pos, "%d", display_num); - if (show_name) { - pos++; - mvwprintw(statusbar_win, 0, pos, ":"); - pos++; - mvwprintw(statusbar_win, 0, pos, display_name); - pos += strlen(display_name) -1 ; - } - wattroff(statusbar_win, status_attrs); - } else { - int status_attrs = theme_attrs(THEME_STATUS_ACTIVE); - wattron(statusbar_win, status_attrs); - mvwprintw(statusbar_win, 0, pos, "%d", display_num); - if (show_name) { - pos++; - mvwprintw(statusbar_win, 0, pos, ":"); - pos++; - mvwprintw(statusbar_win, 0, pos, display_name); - pos += strlen(display_name) - 1; - } - wattroff(statusbar_win, status_attrs); - } - free(display_name); + char *display_name = _display_name(tab); + int status_attrs = 0; + if (tab->highlight) { + status_attrs = theme_attrs(THEME_STATUS_NEW); } else { - mvwprintw(statusbar_win, 0, pos, " "); + status_attrs = theme_attrs(THEME_STATUS_ACTIVE); } - pos++; + wattron(statusbar_win, status_attrs); + if (show_number) { + mvwprintw(statusbar_win, 0, pos, "%d", display_num); + pos++; + } + if (show_number && show_name) { + mvwprintw(statusbar_win, 0, pos, ":"); + pos++; + } + if (show_name) { + mvwprintw(statusbar_win, 0, pos, display_name); + pos += strlen(display_name); + } + wattroff(statusbar_win, status_attrs); + free(display_name); wattron(statusbar_win, bracket_attrs); if (i == statusbar->current_tab) { mvwprintw(statusbar_win, 0, pos, "-"); @@ -381,10 +372,11 @@ _destroy_tab(StatusBarTab *tab) static int _tabs_width(void) { + gboolean show_number = prefs_get_boolean(PREF_STATUSBAR_SHOW_NUMBER); gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME); gint max_tabs = prefs_get_statusbartabs(); - if (show_name) { + if (show_name && show_number) { int width = 4; int i = 0; for (i = 1; i <= max_tabs; i++) { @@ -397,9 +389,24 @@ _tabs_width(void) } } return width; - } else { - return g_hash_table_size(statusbar->tabs) * 3 + 4; } + + if (show_name && !show_number) { + int width = 4; + int i = 0; + for (i = 1; i <= max_tabs; i++) { + StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); + if (tab) { + char *display_name = _display_name(tab); + width += strlen(display_name); + width += 2; + free(display_name); + } + } + return width; + } + + return g_hash_table_size(statusbar->tabs) * 3 + 4; } static char* From 73bb628fd8aef7391b79faf54b1ebc5bbcb1e1f7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 10 Mar 2018 00:32:56 +0000 Subject: [PATCH 12/21] Refactor statusbar --- src/ui/statusbar.c | 209 ++++++++++++++++++++++++--------------------- 1 file changed, 113 insertions(+), 96 deletions(-) diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 36011cbd..919e63ce 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -71,6 +71,10 @@ static StatusBar *statusbar; static WINDOW *statusbar_win; static void _status_bar_draw(void); +static int _status_bar_draw_time(int pos); +static void _status_bar_draw_message(int pos); +static int _status_bar_draw_bracket(gboolean current, int pos, char* ch); +static int _status_bar_draw_tab(StatusBarTab *tab, int pos, int display_num, gboolean is_current); static void _destroy_tab(StatusBarTab *tab); static int _tabs_width(void); static char* _display_name(StatusBarTab *tab); @@ -245,119 +249,132 @@ _status_bar_draw(void) int pos = 1; - char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); - if (g_strcmp0(time_pref, "off") != 0) { - // time - if (statusbar->time) { - g_free(statusbar->time); - statusbar->time = NULL; - } + pos = _status_bar_draw_time(pos); - GDateTime *datetime = g_date_time_new_now(tz); - statusbar->time = g_date_time_format(datetime, time_pref); - assert(statusbar->time != NULL); - g_date_time_unref(datetime); + _status_bar_draw_message(pos); - int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); - int time_attrs = theme_attrs(THEME_STATUS_TIME); - - size_t len = strlen(statusbar->time); - wattron(statusbar_win, bracket_attrs); - mvwaddch(statusbar_win, 0, pos, '['); - pos++; - wattroff(statusbar_win, bracket_attrs); - wattron(statusbar_win, time_attrs); - mvwprintw(statusbar_win, 0, pos, statusbar->time); - pos += len; - wattroff(statusbar_win, time_attrs); - wattron(statusbar_win, bracket_attrs); - mvwaddch(statusbar_win, 0, pos, ']'); - wattroff(statusbar_win, bracket_attrs); - pos += 2; - - // message - if (statusbar->message) { - mvwprintw(statusbar_win, 0, pos, statusbar->message); - } - } else { - // message - if (statusbar->message) { - mvwprintw(statusbar_win, 0, pos, statusbar->message); - } - } - prefs_free_string(time_pref); - - // tabs - int cols = getmaxx(stdscr); - pos = cols - _tabs_width(); - int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); - - gboolean show_number = prefs_get_boolean(PREF_STATUSBAR_SHOW_NUMBER); - gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME); + pos = getmaxx(stdscr) - _tabs_width(); gint max_tabs = prefs_get_statusbartabs(); - int i = 1; for (i = 1; i <= max_tabs; i++) { - int display_num = i == 10 ? 0 : i; - StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); if (tab) { - wattron(statusbar_win, bracket_attrs); - if (i == statusbar->current_tab) { - mvwprintw(statusbar_win, 0, pos, "-"); - } else { - mvwprintw(statusbar_win, 0, pos, "["); - } - wattroff(statusbar_win, bracket_attrs); - pos++; - char *display_name = _display_name(tab); - int status_attrs = 0; - if (tab->highlight) { - status_attrs = theme_attrs(THEME_STATUS_NEW); - } else { - status_attrs = theme_attrs(THEME_STATUS_ACTIVE); - } - wattron(statusbar_win, status_attrs); - if (show_number) { - mvwprintw(statusbar_win, 0, pos, "%d", display_num); - pos++; - } - if (show_number && show_name) { - mvwprintw(statusbar_win, 0, pos, ":"); - pos++; - } - if (show_name) { - mvwprintw(statusbar_win, 0, pos, display_name); - pos += strlen(display_name); - } - wattroff(statusbar_win, status_attrs); - free(display_name); - wattron(statusbar_win, bracket_attrs); - if (i == statusbar->current_tab) { - mvwprintw(statusbar_win, 0, pos, "-"); - } else { - mvwprintw(statusbar_win, 0, pos, "]"); - } - pos++; - wattroff(statusbar_win, bracket_attrs); + int display_num = i == 10 ? 0 : i; + gboolean is_current = i == statusbar->current_tab; + pos = _status_bar_draw_tab(tab, pos, display_num, is_current); } } - wattron(statusbar_win, bracket_attrs); - mvwprintw(statusbar_win, 0, pos, "["); - wattroff(statusbar_win, bracket_attrs); - pos++; + pos = _status_bar_draw_bracket(FALSE, pos, "["); mvwprintw(statusbar_win, 0, pos, " "); pos++; - wattron(statusbar_win, bracket_attrs); - mvwprintw(statusbar_win, 0, pos, "]"); - wattroff(statusbar_win, bracket_attrs); - pos++; + pos = _status_bar_draw_bracket(FALSE, pos, "]"); wnoutrefresh(statusbar_win); inp_put_back(); } +static int +_status_bar_draw_tab(StatusBarTab *tab, int pos, int display_num, gboolean is_current) +{ + gboolean show_number = prefs_get_boolean(PREF_STATUSBAR_SHOW_NUMBER); + gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME); + + pos = _status_bar_draw_bracket(is_current, pos, "["); + + int status_attrs = 0; + if (tab->highlight) { + status_attrs = theme_attrs(THEME_STATUS_NEW); + } else { + status_attrs = theme_attrs(THEME_STATUS_ACTIVE); + } + wattron(statusbar_win, status_attrs); + if (show_number) { + mvwprintw(statusbar_win, 0, pos, "%d", display_num); + pos++; + } + if (show_number && show_name) { + mvwprintw(statusbar_win, 0, pos, ":"); + pos++; + } + if (show_name) { + char *display_name = _display_name(tab); + mvwprintw(statusbar_win, 0, pos, display_name); + pos += strlen(display_name); + free(display_name); + } + wattroff(statusbar_win, status_attrs); + + pos = _status_bar_draw_bracket(is_current, pos, "]"); + + return pos; +} + +static int +_status_bar_draw_bracket(gboolean current, int pos, char* ch) +{ + int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); + wattron(statusbar_win, bracket_attrs); + if (current) { + mvwprintw(statusbar_win, 0, pos, "-"); + } else { + mvwprintw(statusbar_win, 0, pos, ch); + } + wattroff(statusbar_win, bracket_attrs); + pos++; + + return pos; +} + +static int +_status_bar_draw_time(int pos) +{ + char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); + if (g_strcmp0(time_pref, "off") == 0) { + prefs_free_string(time_pref); + return pos; + } + + if (statusbar->time) { + g_free(statusbar->time); + statusbar->time = NULL; + } + + GDateTime *datetime = g_date_time_new_now(tz); + statusbar->time = g_date_time_format(datetime, time_pref); + assert(statusbar->time != NULL); + g_date_time_unref(datetime); + + int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); + int time_attrs = theme_attrs(THEME_STATUS_TIME); + + size_t len = strlen(statusbar->time); + wattron(statusbar_win, bracket_attrs); + mvwaddch(statusbar_win, 0, pos, '['); + pos++; + wattroff(statusbar_win, bracket_attrs); + wattron(statusbar_win, time_attrs); + mvwprintw(statusbar_win, 0, pos, statusbar->time); + pos += len; + wattroff(statusbar_win, time_attrs); + wattron(statusbar_win, bracket_attrs); + mvwaddch(statusbar_win, 0, pos, ']'); + wattroff(statusbar_win, bracket_attrs); + pos += 2; + + prefs_free_string(time_pref); + + return pos; +} + +static void +_status_bar_draw_message(int pos) +{ + if (statusbar->message) { + mvwprintw(statusbar_win, 0, pos, statusbar->message); + } +} + static void _destroy_tab(StatusBarTab *tab) { From 5dbddf4d43aac901026c6d31fa8657e752820c9c Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 10 Mar 2018 01:30:28 +0000 Subject: [PATCH 13/21] Show extended tabs --- src/ui/statusbar.c | 74 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 13 deletions(-) diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 919e63ce..af6f49a2 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -74,10 +74,12 @@ static void _status_bar_draw(void); static int _status_bar_draw_time(int pos); static void _status_bar_draw_message(int pos); static int _status_bar_draw_bracket(gboolean current, int pos, char* ch); -static int _status_bar_draw_tab(StatusBarTab *tab, int pos, int display_num, gboolean is_current); +static int _status_bar_draw_extended_tabs(int pos); +static int _status_bar_draw_tab(StatusBarTab *tab, int pos, int num); static void _destroy_tab(StatusBarTab *tab); static int _tabs_width(void); static char* _display_name(StatusBarTab *tab); +static gboolean _extended_new(void); void status_bar_init(void) @@ -259,24 +261,67 @@ _status_bar_draw(void) for (i = 1; i <= max_tabs; i++) { StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); if (tab) { - int display_num = i == 10 ? 0 : i; - gboolean is_current = i == statusbar->current_tab; - pos = _status_bar_draw_tab(tab, pos, display_num, is_current); + pos = _status_bar_draw_tab(tab, pos, i); } } - pos = _status_bar_draw_bracket(FALSE, pos, "["); - mvwprintw(statusbar_win, 0, pos, " "); - pos++; - pos = _status_bar_draw_bracket(FALSE, pos, "]"); + pos = _status_bar_draw_extended_tabs(pos); wnoutrefresh(statusbar_win); inp_put_back(); } -static int -_status_bar_draw_tab(StatusBarTab *tab, int pos, int display_num, gboolean is_current) +static gboolean +_extended_new(void) { + gint max_tabs = prefs_get_statusbartabs(); + int tabs_count = g_hash_table_size(statusbar->tabs); + if (tabs_count <= max_tabs) { + return FALSE; + } + + int i = 0; + for (i = max_tabs + 1; i <= tabs_count; i++) { + StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); + if (tab && tab->highlight) { + return TRUE; + } + } + + return FALSE; +} + +static int +_status_bar_draw_extended_tabs(int pos) +{ + gint max_tabs = prefs_get_statusbartabs(); + + if (g_hash_table_size(statusbar->tabs) > max_tabs) { + gboolean is_current = statusbar->current_tab > max_tabs; + + pos = _status_bar_draw_bracket(is_current, pos, "["); + + int status_attrs = theme_attrs(THEME_STATUS_ACTIVE); + if (_extended_new()) { + status_attrs = theme_attrs(THEME_STATUS_NEW); + } + wattron(statusbar_win, status_attrs); + mvwprintw(statusbar_win, 0, pos, ">"); + wattroff(statusbar_win, status_attrs); + pos++; + + pos = _status_bar_draw_bracket(is_current, pos, "]"); + } + + return pos; +} + +static int +_status_bar_draw_tab(StatusBarTab *tab, int pos, int num) +{ + int display_num = num == 10 ? 0 : num; + gboolean is_current = num == statusbar->current_tab; + gboolean show_number = prefs_get_boolean(PREF_STATUSBAR_SHOW_NUMBER); gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME); @@ -394,7 +439,7 @@ _tabs_width(void) gint max_tabs = prefs_get_statusbartabs(); if (show_name && show_number) { - int width = 4; + int width = g_hash_table_size(statusbar->tabs) > max_tabs ? 4 : 1; int i = 0; for (i = 1; i <= max_tabs; i++) { StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); @@ -409,7 +454,7 @@ _tabs_width(void) } if (show_name && !show_number) { - int width = 4; + int width = g_hash_table_size(statusbar->tabs) > max_tabs ? 4 : 1; int i = 0; for (i = 1; i <= max_tabs; i++) { StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); @@ -423,7 +468,10 @@ _tabs_width(void) return width; } - return g_hash_table_size(statusbar->tabs) * 3 + 4; + if (g_hash_table_size(statusbar->tabs) > max_tabs) { + return max_tabs * 3 + (g_hash_table_size(statusbar->tabs) > max_tabs ? 4 : 1); + } + return g_hash_table_size(statusbar->tabs) * 3 + (g_hash_table_size(statusbar->tabs) > max_tabs ? 4 : 1); } static char* From b7cb527608204db6e2c085c2610516714955e1c8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 10 Mar 2018 01:48:43 +0000 Subject: [PATCH 14/21] Tidy windows when closing room config --- src/command/cmd_funcs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index e6e53ca4..98a08267 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -3919,6 +3919,7 @@ cmd_form(ProfWin *window, const char *const command, gchar **args) } ui_focus_win(new_current); wins_close_by_num(num); + wins_tidy(); } return TRUE; From b38f6ba5128a7ce091021537b2253da81f65cddb Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 10 Mar 2018 16:58:52 +0000 Subject: [PATCH 15/21] Do not highlight room tab on subject change --- src/ui/mucwin.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index 02eca6a4..f64a401e 100644 --- a/src/ui/mucwin.c +++ b/src/ui/mucwin.c @@ -533,8 +533,6 @@ mucwin_subject(ProfMucWin *mucwin, const char *const nick, const char *const sub assert(mucwin != NULL); ProfWin *window = (ProfWin*)mucwin; - int num = wins_get_num(window); - if (subject) { if (nick) { win_print(window, THEME_ROOMINFO, '!', "*%s has set the room subject: ", nick); @@ -550,15 +548,6 @@ mucwin_subject(ProfMucWin *mucwin, const char *const nick, const char *const sub win_println(window, THEME_ROOMINFO, '!', "Room subject cleared"); } } - - // currently in groupchat window - if (wins_is_current(window)) { - status_bar_active(num, WIN_MUC, mucwin->roomjid); - - // not currently on groupchat window - } else { - status_bar_new(num, WIN_MUC, mucwin->roomjid); - } } void From 95b639a21f77c825a36076562363154216cdad05 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 10 Mar 2018 22:16:52 +0000 Subject: [PATCH 16/21] WIP add self prefs for statusbar --- src/command/cmd_ac.c | 15 ++++++++ src/command/cmd_defs.c | 19 +++++----- src/command/cmd_funcs.c | 29 +++++++++++++++ src/config/preferences.c | 5 +++ src/config/preferences.h | 1 + src/ui/console.c | 8 +++++ src/ui/core.c | 16 ++++----- src/ui/inputwin.c | 4 +-- src/ui/statusbar.c | 78 ++++++++++++++-------------------------- src/ui/statusbar.h | 8 ++--- 10 files changed, 107 insertions(+), 76 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index de57ac82..c996d814 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -201,6 +201,7 @@ static Autocomplete presence_ac; static Autocomplete presence_setting_ac; static Autocomplete winpos_ac; static Autocomplete statusbar_ac; +static Autocomplete statusbar_self_ac; static Autocomplete statusbar_chat_ac; static Autocomplete statusbar_room_ac; static Autocomplete statusbar_show_ac; @@ -784,9 +785,16 @@ cmd_ac_init(void) autocomplete_add(statusbar_ac, "show"); autocomplete_add(statusbar_ac, "hide"); autocomplete_add(statusbar_ac, "maxtabs"); + autocomplete_add(statusbar_ac, "self"); autocomplete_add(statusbar_ac, "chat"); autocomplete_add(statusbar_ac, "room"); + statusbar_self_ac = autocomplete_new(); + autocomplete_add(statusbar_self_ac, "user"); + autocomplete_add(statusbar_self_ac, "barejid"); + autocomplete_add(statusbar_self_ac, "fulljid"); + autocomplete_add(statusbar_self_ac, "off"); + statusbar_chat_ac = autocomplete_new(); autocomplete_add(statusbar_chat_ac, "user"); autocomplete_add(statusbar_chat_ac, "jid"); @@ -1080,6 +1088,7 @@ cmd_ac_reset(ProfWin *window) autocomplete_reset(presence_setting_ac); autocomplete_reset(winpos_ac); autocomplete_reset(statusbar_ac); + autocomplete_reset(statusbar_self_ac); autocomplete_reset(statusbar_chat_ac); autocomplete_reset(statusbar_room_ac); autocomplete_reset(statusbar_show_ac); @@ -1211,6 +1220,7 @@ cmd_ac_uninit(void) autocomplete_free(presence_setting_ac); autocomplete_free(winpos_ac); autocomplete_free(statusbar_ac); + autocomplete_free(statusbar_self_ac); autocomplete_free(statusbar_chat_ac); autocomplete_free(statusbar_room_ac); autocomplete_free(statusbar_show_ac); @@ -3230,6 +3240,11 @@ _statusbar_autocomplete(ProfWin *window, const char *const input, gboolean previ return found; } + found = autocomplete_param_with_ac(input, "/statusbar self", statusbar_self_ac, TRUE, previous); + if (found) { + return found; + } + found = autocomplete_param_with_ac(input, "/statusbar chat", statusbar_chat_ac, TRUE, previous); if (found) { return found; diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 5a873309..d6ee9be6 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1361,6 +1361,7 @@ static struct cmd_t command_defs[] = "/statusbar show name|number", "/statusbar hide name|number", "/statusbar maxtabs ", + "/statusbar self user|barejid|fulljid|off", "/statusbar chat user|jid", "/statusbar room room|jid", "/statusbar up", @@ -1368,16 +1369,18 @@ static struct cmd_t command_defs[] = CMD_DESC( "Manage statusbar display preferences.") CMD_ARGS( - { "maxtabs ", "Set the maximum number of tabs to display, must be between 0 and 10" }, - { "show|hide name", "Show or hide names in tabs." }, - { "show|hide number", "Show or hide numbers in tabs." }, - { "chat user|jid", "Show only the users name, or the full jid if no nick is present for chat tabs." }, - { "room room|jid", "Show only the rooms name, or the full jid for room tabs." }, - { "up", "Move the status bar up the screen." }, - { "down", "Move the status bar down the screen." }) + { "maxtabs ", "Set the maximum number of tabs to display, must be between 0 and 10" }, + { "show|hide name", "Show or hide names in tabs." }, + { "show|hide number", "Show or hide numbers in tabs." }, + { "self user|barejid|fulljid", "Show account user name, barejid, fulljid as status bar title." }, + { "self off", "Disable showing self as status bar title." }, + { "chat user|jid", "Show users name, or the fulljid if no nick is present for chat tabs." }, + { "room room|jid", "Show room name, or the fulljid for room tabs." }, + { "up", "Move the status bar up the screen." }, + { "down", "Move the status bar down the screen." }) CMD_EXAMPLES( "/statusbar maxtabs 5", - "/statusbar hide name", + "/statusbar self user", "/statusbar chat jid", "/statusbar hide name") }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 98a08267..11f1f51c 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -5846,6 +5846,35 @@ cmd_statusbar(ProfWin *window, const char *const command, gchar **args) } } + if (g_strcmp0(args[0], "self") == 0) { + if (g_strcmp0(args[1], "barejid") == 0) { + prefs_set_string(PREF_STATUSBAR_SELF, "barejid"); + cons_show("Using barejid for statusbar title."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "fulljid") == 0) { + prefs_set_string(PREF_STATUSBAR_SELF, "fulljid"); + cons_show("Using fulljid for statusbar title."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "user") == 0) { + prefs_set_string(PREF_STATUSBAR_SELF, "user"); + cons_show("Using user for statusbar title."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "off") == 0) { + prefs_set_string(PREF_STATUSBAR_SELF, "off"); + cons_show("Disabling statusbar title."); + ui_resize(); + return TRUE; + } + cons_bad_cmd_usage(command); + return TRUE; + } + if (g_strcmp0(args[0], "chat") == 0) { if (g_strcmp0(args[1], "jid") == 0) { prefs_set_string(PREF_STATUSBAR_CHAT, "jid"); diff --git a/src/config/preferences.c b/src/config/preferences.c index 28883e76..bc97b0a1 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1588,6 +1588,7 @@ _get_group(preference_t pref) case PREF_CONSOLE_CHAT: case PREF_STATUSBAR_SHOW_NAME: case PREF_STATUSBAR_SHOW_NUMBER: + case PREF_STATUSBAR_SELF: case PREF_STATUSBAR_CHAT: case PREF_STATUSBAR_ROOM: return PREF_GROUP_UI; @@ -1847,6 +1848,8 @@ _get_key(preference_t pref) return "statusbar.show.name"; case PREF_STATUSBAR_SHOW_NUMBER: return "statusbar.show.number"; + case PREF_STATUSBAR_SELF: + return "statusbar.self"; case PREF_STATUSBAR_CHAT: return "statusbar.chat"; case PREF_STATUSBAR_ROOM: @@ -1964,6 +1967,8 @@ _get_default_string(preference_t pref) case PREF_CONSOLE_PRIVATE: case PREF_CONSOLE_CHAT: return "all"; + case PREF_STATUSBAR_SELF: + return "fulljid"; case PREF_STATUSBAR_CHAT: return "user"; case PREF_STATUSBAR_ROOM: diff --git a/src/config/preferences.h b/src/config/preferences.h index e1b666a0..808ffafd 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -145,6 +145,7 @@ typedef enum { PREF_ROOM_LIST_CACHE, PREF_STATUSBAR_SHOW_NAME, PREF_STATUSBAR_SHOW_NUMBER, + PREF_STATUSBAR_SELF, PREF_STATUSBAR_CHAT, PREF_STATUSBAR_ROOM, } preference_t; diff --git a/src/ui/console.c b/src/ui/console.c index 60c5c8f5..26c830fc 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1754,6 +1754,14 @@ cons_statusbar_setting(void) cons_show("Max tabs (/statusbar) : %d", prefs_get_statusbartabs()); + char *pref_self = prefs_get_string(PREF_STATUSBAR_SELF); + if (g_strcmp0(pref_self, "off") == 0) { + cons_show("Self statusbar display (/statusbar) : OFF"); + } else { + cons_show("Self statusbar display (/statusbar) : %s", pref_self); + } + prefs_free_string(pref_self); + char *pref_chat = prefs_get_string(PREF_STATUSBAR_CHAT); cons_show("Chat tab display (/statusbar) : %s", pref_chat); prefs_free_string(pref_chat); diff --git a/src/ui/core.c b/src/ui/core.c index af0d55a9..a0ca8495 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -137,7 +137,7 @@ ui_update(void) _ui_draw_term_title(); } title_bar_update_virtual(); - status_bar_update_virtual(); + status_bar_draw(); inp_put_back(); doupdate(); @@ -388,8 +388,7 @@ ui_handle_login_account_success(ProfAccount *account, gboolean secured) title_bar_set_connected(TRUE); title_bar_set_tls(secured); - status_bar_print_message(connection_get_fulljid()); - status_bar_update_virtual(); + status_bar_set_prompt(connection_get_fulljid()); } void @@ -482,8 +481,7 @@ ui_disconnected(void) title_bar_set_connected(FALSE); title_bar_set_tls(FALSE); title_bar_set_presence(CONTACT_OFFLINE); - status_bar_clear_message(); - status_bar_update_virtual(); + status_bar_clear_prompt(); ui_hide_roster(); } @@ -975,15 +973,14 @@ ui_win_unread(int index) char* ui_ask_password(void) { - status_bar_get_password(); - status_bar_update_virtual(); + status_bar_set_prompt("Enter password:"); return inp_get_password(); } char* ui_get_line(void) { - status_bar_update_virtual(); + status_bar_draw(); return inp_get_line(); } @@ -1006,8 +1003,7 @@ ui_ask_pgp_passphrase(const char *hint, int prev_fail) ui_update(); - status_bar_get_password(); - status_bar_update_virtual(); + status_bar_set_prompt("Enter password:"); return inp_get_password(); } diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 0173a201..654a4602 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -251,7 +251,7 @@ inp_get_line(void) line = inp_readline(); ui_update(); } - status_bar_clear(); + status_bar_clear_prompt(); return line; } @@ -269,7 +269,7 @@ inp_get_password(void) ui_update(); } get_password = FALSE; - status_bar_clear(); + status_bar_clear_prompt(); return password; } diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index af6f49a2..28b20f01 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -61,7 +61,7 @@ typedef struct _status_bar_tab_t { typedef struct _status_bar_t { gchar *time; - char *message; + char *prompt; GHashTable *tabs; int current_tab; } StatusBar; @@ -70,9 +70,8 @@ static GTimeZone *tz; static StatusBar *statusbar; static WINDOW *statusbar_win; -static void _status_bar_draw(void); static int _status_bar_draw_time(int pos); -static void _status_bar_draw_message(int pos); +static void _status_bar_draw_prompt(int pos); static int _status_bar_draw_bracket(gboolean current, int pos, char* ch); static int _status_bar_draw_extended_tabs(int pos); static int _status_bar_draw_tab(StatusBarTab *tab, int pos, int num); @@ -88,7 +87,7 @@ status_bar_init(void) statusbar = malloc(sizeof(StatusBar)); statusbar->time = NULL; - statusbar->message = NULL; + statusbar->prompt = NULL; statusbar->tabs = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)_destroy_tab); StatusBarTab *console = malloc(sizeof(StatusBarTab)); console->window_type = WIN_CONSOLE; @@ -100,7 +99,7 @@ status_bar_init(void) int cols = getmaxx(stdscr); statusbar_win = newwin(1, cols, row, 0); - _status_bar_draw(); + status_bar_draw(); } void @@ -113,19 +112,13 @@ status_bar_close(void) if (statusbar->time) { g_free(statusbar->time); } - if (statusbar->message) { - free(statusbar->message); + if (statusbar->prompt) { + free(statusbar->prompt); } free(statusbar); } } -void -status_bar_update_virtual(void) -{ - _status_bar_draw(); -} - void status_bar_resize(void) { @@ -135,7 +128,7 @@ status_bar_resize(void) mvwin(statusbar_win, row, 0); wresize(statusbar_win, 1, cols); - _status_bar_draw(); + status_bar_draw(); } void @@ -153,7 +146,7 @@ status_bar_current(int i) statusbar->current_tab = i; } - _status_bar_draw(); + status_bar_draw(); } void @@ -166,7 +159,7 @@ status_bar_inactive(const int win) g_hash_table_remove(statusbar->tabs, GINT_TO_POINTER(true_win)); - _status_bar_draw(); + status_bar_draw(); } void @@ -183,7 +176,7 @@ status_bar_active(const int win, win_type_t wintype, char *identifier) tab->window_type = wintype; g_hash_table_replace(statusbar->tabs, GINT_TO_POINTER(true_win), tab); - _status_bar_draw(); + status_bar_draw(); } void @@ -200,51 +193,34 @@ status_bar_new(const int win, win_type_t wintype, char* identifier) tab->window_type = wintype; g_hash_table_replace(statusbar->tabs, GINT_TO_POINTER(true_win), tab); - _status_bar_draw(); + status_bar_draw(); } void -status_bar_get_password(void) +status_bar_set_prompt(const char *const prompt) { - status_bar_print_message("Enter password:"); -} - -void -status_bar_print_message(const char *const msg) -{ - if (statusbar->message) { - free(statusbar->message); - statusbar->message = NULL; + if (statusbar->prompt) { + free(statusbar->prompt); + statusbar->prompt = NULL; } - statusbar->message = strdup(msg); + statusbar->prompt = strdup(prompt); - _status_bar_draw(); + status_bar_draw(); } void -status_bar_clear(void) +status_bar_clear_prompt(void) { - if (statusbar->message) { - free(statusbar->message); - statusbar->message = NULL; + if (statusbar->prompt) { + free(statusbar->prompt); + statusbar->prompt = NULL; } - _status_bar_draw(); + status_bar_draw(); } void -status_bar_clear_message(void) -{ - if (statusbar->message) { - free(statusbar->message); - statusbar->message = NULL; - } - - _status_bar_draw(); -} - -static void -_status_bar_draw(void) +status_bar_draw(void) { werase(statusbar_win); wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT)); @@ -253,7 +229,7 @@ _status_bar_draw(void) pos = _status_bar_draw_time(pos); - _status_bar_draw_message(pos); + _status_bar_draw_prompt(pos); pos = getmaxx(stdscr) - _tabs_width(); gint max_tabs = prefs_get_statusbartabs(); @@ -413,10 +389,10 @@ _status_bar_draw_time(int pos) } static void -_status_bar_draw_message(int pos) +_status_bar_draw_prompt(int pos) { - if (statusbar->message) { - mvwprintw(statusbar_win, 0, pos, statusbar->message); + if (statusbar->prompt) { + mvwprintw(statusbar_win, 0, pos, statusbar->prompt); } } diff --git a/src/ui/statusbar.h b/src/ui/statusbar.h index 370b4bbb..ce1f5482 100644 --- a/src/ui/statusbar.h +++ b/src/ui/statusbar.h @@ -36,13 +36,11 @@ #define UI_STATUSBAR_H void status_bar_init(void); +void status_bar_draw(void); void status_bar_close(void); -void status_bar_update_virtual(void); void status_bar_resize(void); -void status_bar_clear(void); -void status_bar_clear_message(void); -void status_bar_get_password(void); -void status_bar_print_message(const char *const msg); +void status_bar_clear_prompt(void); +void status_bar_set_prompt(const char *const prompt); void status_bar_current(int i); #endif From 4bf67fb35ac0fa9d78f3fe32d5ef14d146b39b6a Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 10 Mar 2018 22:41:55 +0000 Subject: [PATCH 17/21] Use jid prefs in statusbar --- src/ui/core.c | 4 ++-- src/ui/statusbar.c | 58 +++++++++++++++++++++++++++++++++++++++++++--- src/ui/statusbar.h | 4 +++- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index a0ca8495..5246d06a 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -388,7 +388,7 @@ ui_handle_login_account_success(ProfAccount *account, gboolean secured) title_bar_set_connected(TRUE); title_bar_set_tls(secured); - status_bar_set_prompt(connection_get_fulljid()); + status_bar_set_fulljid(connection_get_fulljid()); } void @@ -481,7 +481,7 @@ ui_disconnected(void) title_bar_set_connected(FALSE); title_bar_set_tls(FALSE); title_bar_set_presence(CONTACT_OFFLINE); - status_bar_clear_prompt(); + status_bar_clear_fulljid(); ui_hide_roster(); } diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 28b20f01..3515b0a7 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -62,6 +62,7 @@ typedef struct _status_bar_tab_t { typedef struct _status_bar_t { gchar *time; char *prompt; + char *fulljid; GHashTable *tabs; int current_tab; } StatusBar; @@ -71,7 +72,7 @@ static StatusBar *statusbar; static WINDOW *statusbar_win; static int _status_bar_draw_time(int pos); -static void _status_bar_draw_prompt(int pos); +static void _status_bar_draw_maintext(int pos); static int _status_bar_draw_bracket(gboolean current, int pos, char* ch); static int _status_bar_draw_extended_tabs(int pos); static int _status_bar_draw_tab(StatusBarTab *tab, int pos, int num); @@ -88,6 +89,7 @@ status_bar_init(void) statusbar = malloc(sizeof(StatusBar)); statusbar->time = NULL; statusbar->prompt = NULL; + statusbar->fulljid = NULL; statusbar->tabs = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)_destroy_tab); StatusBarTab *console = malloc(sizeof(StatusBarTab)); console->window_type = WIN_CONSOLE; @@ -115,6 +117,12 @@ status_bar_close(void) if (statusbar->prompt) { free(statusbar->prompt); } + if (statusbar->fulljid) { + free(statusbar->fulljid); + } + if (statusbar->tabs) { + g_hash_table_destroy(statusbar->tabs); + } free(statusbar); } } @@ -219,6 +227,29 @@ status_bar_clear_prompt(void) status_bar_draw(); } +void +status_bar_set_fulljid(const char *const fulljid) +{ + if (statusbar->fulljid) { + free(statusbar->fulljid); + statusbar->fulljid = NULL; + } + statusbar->fulljid = strdup(fulljid); + + status_bar_draw(); +} + +void +status_bar_clear_fulljid(void) +{ + if (statusbar->fulljid) { + free(statusbar->fulljid); + statusbar->fulljid = NULL; + } + + status_bar_draw(); +} + void status_bar_draw(void) { @@ -229,7 +260,7 @@ status_bar_draw(void) pos = _status_bar_draw_time(pos); - _status_bar_draw_prompt(pos); + _status_bar_draw_maintext(pos); pos = getmaxx(stdscr) - _tabs_width(); gint max_tabs = prefs_get_statusbartabs(); @@ -389,10 +420,31 @@ _status_bar_draw_time(int pos) } static void -_status_bar_draw_prompt(int pos) +_status_bar_draw_maintext(int pos) { if (statusbar->prompt) { mvwprintw(statusbar_win, 0, pos, statusbar->prompt); + return; + } + + if (statusbar->fulljid) { + char *pref = prefs_get_string(PREF_STATUSBAR_SELF); + if (g_strcmp0(pref, "off") == 0) { + return; + } + if (g_strcmp0(pref, "user") == 0) { + Jid *jidp = jid_create(statusbar->fulljid); + mvwprintw(statusbar_win, 0, pos, jidp->localpart); + jid_destroy(jidp); + return; + } + if (g_strcmp0(pref, "barejid") == 0) { + Jid *jidp = jid_create(statusbar->fulljid); + mvwprintw(statusbar_win, 0, pos, jidp->barejid); + jid_destroy(jidp); + return; + } + mvwprintw(statusbar_win, 0, pos, statusbar->fulljid); } } diff --git a/src/ui/statusbar.h b/src/ui/statusbar.h index ce1f5482..de8b51cc 100644 --- a/src/ui/statusbar.h +++ b/src/ui/statusbar.h @@ -39,8 +39,10 @@ void status_bar_init(void); void status_bar_draw(void); void status_bar_close(void); void status_bar_resize(void); -void status_bar_clear_prompt(void); void status_bar_set_prompt(const char *const prompt); +void status_bar_clear_prompt(void); +void status_bar_set_fulljid(const char *const fulljid); +void status_bar_clear_fulljid(void); void status_bar_current(int i); #endif From b0e70e6caad8b594cdd89bebaeaa3be9b82330b3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 10 Mar 2018 22:54:02 +0000 Subject: [PATCH 18/21] Dont show extended tabs when max 0 --- src/ui/statusbar.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 3515b0a7..ccb00452 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -302,6 +302,9 @@ static int _status_bar_draw_extended_tabs(int pos) { gint max_tabs = prefs_get_statusbartabs(); + if (max_tabs == 0) { + return pos; + } if (g_hash_table_size(statusbar->tabs) > max_tabs) { gboolean is_current = statusbar->current_tab > max_tabs; From 8718b368a1ba9a2ab4f2561c9e2df5bee6a895be Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 10 Mar 2018 23:01:51 +0000 Subject: [PATCH 19/21] Statusbar render at start of small window --- src/ui/statusbar.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index ccb00452..e84e3b60 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -263,6 +263,9 @@ status_bar_draw(void) _status_bar_draw_maintext(pos); pos = getmaxx(stdscr) - _tabs_width(); + if (pos < 0) { + pos = 0; + } gint max_tabs = prefs_get_statusbartabs(); int i = 1; for (i = 1; i <= max_tabs; i++) { From aa520f4f7c8ce466368b9c88bf2473318582064f Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 10 Mar 2018 23:22:58 +0000 Subject: [PATCH 20/21] Add statusbar pref to themes --- src/config/theme.c | 10 ++++++++++ themes/boothj5 | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/src/config/theme.c b/src/config/theme.c index 9d28f421..24dbc9ae 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -407,6 +407,8 @@ _load_preferences(void) _set_boolean_preference("intype", PREF_INTYPE); _set_boolean_preference("enc.warn", PREF_ENC_WARN); _set_boolean_preference("tls.show", PREF_TLS_SHOW); + _set_boolean_preference("statusbar.show.name", PREF_STATUSBAR_SHOW_NAME); + _set_boolean_preference("statusbar.show.nuumber", PREF_STATUSBAR_SHOW_NUMBER); _set_string_preference("time.console", PREF_TIME_CONSOLE); _set_string_preference("time.chat", PREF_TIME_CHAT); @@ -431,6 +433,14 @@ _load_preferences(void) _set_string_preference("roster.rooms.by", PREF_ROSTER_ROOMS_BY); _set_string_preference("roster.private", PREF_ROSTER_PRIVATE); _set_string_preference("roster.count", PREF_ROSTER_COUNT); + _set_string_preference("statusbar.self", PREF_STATUSBAR_SELF); + _set_string_preference("statusbar.chat", PREF_STATUSBAR_CHAT); + _set_string_preference("statusbar.room", PREF_STATUSBAR_ROOM); + + if (g_key_file_has_key(theme, "ui", "statusbar.tabs", NULL)) { + gint tabs_size = g_key_file_get_integer(theme, "ui", "statusbar.tabs", NULL); + prefs_set_statusbartabs(tabs_size); + } if (g_key_file_has_key(theme, "ui", "occupants.size", NULL)) { gint occupants_size = g_key_file_get_integer(theme, "ui", "occupants.size", NULL); diff --git a/themes/boothj5 b/themes/boothj5 index b97a4499..2f9a94e0 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -142,4 +142,10 @@ titlebar.position=1 mainwin.position=2 statusbar.position=3 inputwin.position=4 +statusbar.self=user +statusbar.chat=user +statusbar.room=room +statusbar.tabs=8 +statusbar.show.name=true +statusbar.show.number=true From b01dd7c48b3f693053ca2efcc2b0d345e29562cd Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 10 Mar 2018 23:31:02 +0000 Subject: [PATCH 21/21] Default tab name to false --- src/config/preferences.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index bc97b0a1..8b2ad10a 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1902,7 +1902,6 @@ _get_default_boolean(preference_t pref) case PREF_TRAY_READ: case PREF_BOOKMARK_INVITE: case PREF_ROOM_LIST_CACHE: - case PREF_STATUSBAR_SHOW_NAME: case PREF_STATUSBAR_SHOW_NUMBER: return TRUE; default: