config: Fix swaybar pango_markup inconsistency

Until now, swaybar did not have pango markup enabled by default, even if
the sway config had it on. This patch aims to mimic the i3 behavior, but
maintaining the functionality of the "pango_markup" sway config command.
This commit is contained in:
Daniel Otero 2021-03-19 18:02:46 +01:00 committed by Simon Ser
parent cad6e59b93
commit b997147284
4 changed files with 25 additions and 4 deletions

View file

@ -292,6 +292,12 @@ struct workspace_config {
struct side_gaps gaps_outer; struct side_gaps gaps_outer;
}; };
enum pango_markup_config {
PANGO_MARKUP_DISABLED = false,
PANGO_MARKUP_ENABLED = true,
PANGO_MARKUP_DEFAULT // The default is font dependent ("pango:" prefix)
};
struct bar_config { struct bar_config {
char *swaybar_command; char *swaybar_command;
struct wl_client *client; struct wl_client *client;
@ -323,7 +329,7 @@ struct bar_config {
char *position; char *position;
list_t *bindings; list_t *bindings;
char *status_command; char *status_command;
bool pango_markup; enum pango_markup_config pango_markup;
char *font; char *font;
int height; // -1 not defined int height; // -1 not defined
bool workspace_buttons; bool workspace_buttons;

View file

@ -11,7 +11,20 @@ struct cmd_results *bar_cmd_font(int argc, char **argv) {
} }
char *font = join_args(argv, argc); char *font = join_args(argv, argc);
free(config->current_bar->font); free(config->current_bar->font);
config->current_bar->font = font;
if (strncmp(font, "pango:", 6) == 0) {
if (config->current_bar->pango_markup == PANGO_MARKUP_DEFAULT) {
config->current_bar->pango_markup = true;
}
config->current_bar->font = strdup(font + 6);
} else {
if (config->current_bar->pango_markup == PANGO_MARKUP_DEFAULT) {
config->current_bar->pango_markup = false;
}
config->current_bar->font = strdup(font);
}
free(font);
sway_log(SWAY_DEBUG, "Settings font '%s' for bar: %s", sway_log(SWAY_DEBUG, "Settings font '%s' for bar: %s",
config->current_bar->font, config->current_bar->id); config->current_bar->font, config->current_bar->id);
return cmd_results_new(CMD_SUCCESS, NULL); return cmd_results_new(CMD_SUCCESS, NULL);

View file

@ -91,7 +91,7 @@ struct bar_config *default_bar_config(void) {
} }
bar->outputs = NULL; bar->outputs = NULL;
bar->position = strdup("bottom"); bar->position = strdup("bottom");
bar->pango_markup = false; bar->pango_markup = PANGO_MARKUP_DEFAULT;
bar->swaybar_command = NULL; bar->swaybar_command = NULL;
bar->font = NULL; bar->font = NULL;
bar->height = 0; bar->height = 0;

View file

@ -1127,7 +1127,9 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
json_object_object_add(json, "verbose", json_object_object_add(json, "verbose",
json_object_new_boolean(bar->verbose)); json_object_new_boolean(bar->verbose));
json_object_object_add(json, "pango_markup", json_object_object_add(json, "pango_markup",
json_object_new_boolean(bar->pango_markup)); json_object_new_boolean(bar->pango_markup == PANGO_MARKUP_DEFAULT
? config->pango_markup
: bar->pango_markup));
json_object *colors = json_object_new_object(); json_object *colors = json_object_new_object();
json_object_object_add(colors, "background", json_object_object_add(colors, "background",