From 0f361e6b524e9ddd2a6d778a3acfa166bd5353b4 Mon Sep 17 00:00:00 2001 From: John Hernandez <129467592+H3rnand3zzz@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:25:27 +0100 Subject: [PATCH] Remove maxtabs limitation for statusbar --- src/command/cmd_defs.c | 2 +- src/command/cmd_funcs.c | 5 ----- src/ui/statusbar.c | 21 ++++++++++++++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 727b8dd1..929133e2 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1298,7 +1298,7 @@ static const 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." }, + { "maxtabs ", "Set the maximum number of tabs to display, must be more than or equal to 0." }, { "tablen ", "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." }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index f3dd5ba0..3624c6eb 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -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."); diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 05bc4b44..3ebb7147 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -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); +}