mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Add max tabs preference for statusbar
This commit is contained in:
parent
720dce866e
commit
a957c545d3
@ -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");
|
||||
|
@ -1366,19 +1366,19 @@ static struct cmd_t command_defs[] =
|
||||
CMD_SYN(
|
||||
"/statusbar show empty|name",
|
||||
"/statusbar hide empty|name",
|
||||
// "/statusbar maxtabs <value>",
|
||||
"/statusbar maxtabs <value>",
|
||||
"/statusbar up",
|
||||
"/statusbar down")
|
||||
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 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")
|
||||
},
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user