1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-09 21:30:42 +00:00
This commit is contained in:
John Hernandez 2024-03-01 12:59:57 +01:00 committed by GitHub
commit beae9f461b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 11 deletions

View File

@ -1298,7 +1298,7 @@ static const struct cmd_t command_defs[] = {
CMD_DESC(
"Manage statusbar display preferences.")
CMD_ARGS(
{ "maxtabs <value>", "Set the maximum number of tabs to display, <value> must be between 0 and 10." },
{ "maxtabs <value>", "Set the maximum number of tabs to display, <value> must be more than or equal to 0." },
{ "tablen <value>", "Set the maximum number of characters to show as the tab name, 0 sets to unlimited." },
{ "tabmode default|dynamic|actlist", "Set the mode tabs are shown. `dynamic` is a mode that displays tabs conveniently around current tab, thus providing proper pagination. `actlist` setting shows only active tabs. `default` setting always shows tabs in 1 to max_tabs range." },
{ "show|hide name", "Show or hide names in tabs." },

View File

@ -6182,11 +6182,6 @@ cmd_statusbar(ProfWin* window, const char* const command, gchar** args)
auto_char 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.");

View File

@ -77,8 +77,10 @@ typedef struct _status_bar_t
static GTimeZone* tz;
static StatusBar* statusbar;
static WINDOW* statusbar_win;
static int left_part_size;
void _get_range_bounds(int* start, int* end, gboolean is_static);
static int _get_max_tabs();
static int _status_bar_draw_time(int pos);
static int _status_bar_draw_maintext(int pos);
static int _status_bar_draw_bracket(gboolean current, int pos, const char* ch);
@ -285,11 +287,14 @@ status_bar_draw(void)
werase(statusbar_win);
wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT));
gint max_tabs = prefs_get_statusbartabs();
gint max_tabs = _get_max_tabs();
int pos = 1;
pos = _status_bar_draw_time(pos);
pos = _status_bar_draw_maintext(pos);
left_part_size = pos;
if (max_tabs != 0)
pos = _status_bar_draw_tabs(pos);
@ -367,7 +372,7 @@ _status_bar_draw_tabs(int pos)
static gboolean
_has_new_msgs_beyond_range_on_side(gboolean left_side, int display_tabs_start, int display_tabs_end)
{
gint max_tabs = prefs_get_statusbartabs();
gint max_tabs = _get_max_tabs();
int tabs_count = g_hash_table_size(statusbar->tabs);
if (tabs_count <= max_tabs) {
return FALSE;
@ -389,7 +394,7 @@ _has_new_msgs_beyond_range_on_side(gboolean left_side, int display_tabs_start, i
static int
_status_bar_draw_extended_tabs(int pos, gboolean prefix, int start, int end, gboolean is_static)
{
gint max_tabs = prefs_get_statusbartabs();
gint max_tabs = _get_max_tabs();
if (max_tabs == 0) {
return pos;
}
@ -620,7 +625,7 @@ _tabs_width(int start, int end)
gboolean show_number = prefs_get_boolean(PREF_STATUSBAR_SHOW_NUMBER);
gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME);
gboolean show_read = prefs_get_boolean(PREF_STATUSBAR_SHOW_READ);
gint max_tabs = prefs_get_statusbartabs();
gint max_tabs = _get_max_tabs();
guint opened_tabs = g_hash_table_size(statusbar->tabs);
int width = start < 2 ? 1 : 4;
@ -718,7 +723,7 @@ void
_get_range_bounds(int* start, int* end, gboolean is_static)
{
int current_tab = statusbar->current_tab;
gint display_range = prefs_get_statusbartabs();
gint display_range = _get_max_tabs();
int total_tabs = g_hash_table_size(statusbar->tabs);
int side_range = display_range / 2;
@ -766,3 +771,9 @@ _count_digits_in_range(int start, int end)
return total_digits;
}
static int
_get_max_tabs()
{
return MIN(prefs_get_statusbartabs(), (getmaxx(stdscr) - left_part_size) / 3);
}