From 53b53dd8c24004d9b2a2170590432d62656c43c2 Mon Sep 17 00:00:00 2001 From: Mykyta Holubakha Date: Sun, 24 Apr 2016 19:57:35 +0300 Subject: [PATCH 1/5] Added plaintext markup configuration --- include/bar/config.h | 1 + include/config.h | 1 + sway/commands.c | 25 +++++++++++++++++++++++++ sway/config.c | 1 + sway/sway-bar.5.txt | 3 +++ swaybar/config.c | 1 + swaybar/render.c | 2 +- 7 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/bar/config.h b/include/bar/config.h index fc938c38..27e0ec29 100644 --- a/include/bar/config.h +++ b/include/bar/config.h @@ -20,6 +20,7 @@ struct box_colors { */ struct config { char *status_command; + bool plaintext_markup; uint32_t position; char *font; char *sep_symbol; diff --git a/include/config.h b/include/config.h index d7e96e74..c6f63134 100644 --- a/include/config.h +++ b/include/config.h @@ -116,6 +116,7 @@ struct bar_config { enum desktop_shell_panel_position position; list_t *bindings; char *status_command; + bool plaintext_markup; char *swaybar_command; char *font; int height; // -1 not defined diff --git a/sway/commands.c b/sway/commands.c index b7c1a344..3c312ae8 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -103,6 +103,7 @@ static sway_cmd bar_cmd_id; static sway_cmd bar_cmd_position; static sway_cmd bar_cmd_separator_symbol; static sway_cmd bar_cmd_status_command; +static sway_cmd bar_cmd_plaintext_markup; static sway_cmd bar_cmd_strip_workspace_numbers; static sway_cmd bar_cmd_swaybar_command; static sway_cmd bar_cmd_tray_output; @@ -2757,6 +2758,29 @@ static struct cmd_results *bar_cmd_status_command(int argc, char **argv) { return cmd_results_new(CMD_SUCCESS, NULL, NULL); } +static struct cmd_results *bar_cmd_plaintext_markup(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "plaintext_markup", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + if (!config->current_bar) { + return cmd_results_new(CMD_FAILURE, "plaintext_markup", "No bar defined."); + } + + if (strcasecmp("pango", argv[0]) == 0) { + config->current_bar->plaintext_markup = true; + sway_log(L_DEBUG, "Enabling pango markup for bar: %s", config->current_bar->id); + } else if (strcasecmp("none", argv[0]) == 0) { + config->current_bar->plaintext_markup = false; + sway_log(L_DEBUG, "Disabling pango markup for bar: %s", config->current_bar->id); + } else { + error = cmd_results_new(CMD_INVALID, "plaintext_markup", "Invalid value %s", argv[0]); + return error; + } + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} + static struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "strip_workspace_numbers", EXPECTED_EQUAL_TO, 1))) { @@ -2861,6 +2885,7 @@ static struct cmd_handler bar_handlers[] = { { "mode", bar_cmd_mode }, { "modifier", bar_cmd_modifier }, { "output", bar_cmd_output }, + { "plaintext_markup", bar_cmd_plaintext_markup }, { "position", bar_cmd_position }, { "separator_symbol", bar_cmd_separator_symbol }, { "status_command", bar_cmd_status_command }, diff --git a/sway/config.c b/sway/config.c index a917d348..3c14032b 100644 --- a/sway/config.c +++ b/sway/config.c @@ -1022,6 +1022,7 @@ struct bar_config *default_bar_config(void) { bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; bar->bindings = create_list(); bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p' && sleep 1; done"); + bar->plaintext_markup = true; bar->swaybar_command = NULL; bar->font = NULL; bar->height = -1; diff --git a/sway/sway-bar.5.txt b/sway/sway-bar.5.txt index c23519a4..558a9564 100644 --- a/sway/sway-bar.5.txt +++ b/sway/sway-bar.5.txt @@ -21,6 +21,9 @@ Commands **status_command** :: Executes the bar _status command_ with _sh -c_. +**plaintext_markup** :: + Enables or disables pango markup for plaintext statuslines. + **id** :: Sets the ID of the bar. diff --git a/swaybar/config.c b/swaybar/config.c index 6b9ff86b..7ef9a07e 100644 --- a/swaybar/config.c +++ b/swaybar/config.c @@ -46,6 +46,7 @@ char *parse_font(const char *font) { struct config *init_config() { struct config *config = calloc(1, sizeof(struct config)); config->status_command = NULL; + config->plaintext_markup = true; config->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; config->font = strdup("monospace 10"); config->mode = NULL; diff --git a/swaybar/render.c b/swaybar/render.c index 5901b557..833198fd 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -280,7 +280,7 @@ void render(struct output *output, struct config *config, struct status_line *li if (line->protocol == TEXT) { get_text_size(window->cairo, window->font, &width, &height, true, "%s", line->text_line); cairo_move_to(cairo, window->width - margin - width, margin); - pango_printf(window->cairo, window->font, true, "%s", line->text_line); + pango_printf(window->cairo, window->font, config->plaintext_markup, "%s", line->text_line); } else if (line->protocol == I3BAR && line->block_line) { double pos = window->width - 0.5; bool edge = true; From 2e6c43e62b9b34c0ce019c013d3f6e4863a9d482 Mon Sep 17 00:00:00 2001 From: Mykyta Holubakha Date: Sun, 24 Apr 2016 20:11:23 +0300 Subject: [PATCH 2/5] Added plaintext_markup to swaybar IPC --- sway/ipc-server.c | 1 + swaybar/ipc.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/sway/ipc-server.c b/sway/ipc-server.c index f6116921..0ab6af49 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -600,6 +600,7 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) { json_object_object_add(json, "strip_workspace_numbers", json_object_new_boolean(bar->strip_workspace_numbers)); json_object_object_add(json, "binding_mode_indicator", json_object_new_boolean(bar->binding_mode_indicator)); json_object_object_add(json, "verbose", json_object_new_boolean(bar->verbose)); + json_object_object_add(json, "plaintext_markup", json_object_new_boolean(bar->plaintext_markup)); json_object *colors = json_object_new_object(); json_object_object_add(colors, "background", json_object_new_string(bar->colors.background)); diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 312c79b9..0446f38a 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -12,6 +12,7 @@ static void ipc_parse_config(struct config *config, const char *payload) { json_object *tray_output, *mode, *hidden_bar, *position, *status_command; json_object *font, *bar_height, *workspace_buttons, *strip_workspace_numbers; json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs; + json_object *markup; json_object_object_get_ex(bar_config, "tray_output", &tray_output); json_object_object_get_ex(bar_config, "mode", &mode); json_object_object_get_ex(bar_config, "hidden_bar", &hidden_bar); @@ -26,6 +27,7 @@ static void ipc_parse_config(struct config *config, const char *payload) { json_object_object_get_ex(bar_config, "separator_symbol", &sep_symbol); json_object_object_get_ex(bar_config, "colors", &colors); json_object_object_get_ex(bar_config, "outputs", &outputs); + json_object_object_get_ex(bar_config, "plaintext_markup", &markup); if (status_command) { free(config->status_command); @@ -62,6 +64,10 @@ static void ipc_parse_config(struct config *config, const char *payload) { config->height = json_object_get_int(bar_height); } + if (markup) { + config->plaintext_markup = json_object_get_boolean(markup); + } + // free previous outputs list int i; for (i = 0; i < config->outputs->length; ++i) { From ee4e245f167f0e5a859a03b06568c282d11b52d2 Mon Sep 17 00:00:00 2001 From: Mykyta Holubakha Date: Sun, 24 Apr 2016 20:20:07 +0300 Subject: [PATCH 3/5] Fix line length calculation --- swaybar/render.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swaybar/render.c b/swaybar/render.c index 833198fd..b9ef2242 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -278,7 +278,7 @@ void render(struct output *output, struct config *config, struct status_line *li int width, height; if (line->protocol == TEXT) { - get_text_size(window->cairo, window->font, &width, &height, true, "%s", line->text_line); + get_text_size(window->cairo, window->font, &width, &height, config->plaintext_markup, "%s", line->text_line); cairo_move_to(cairo, window->width - margin - width, margin); pango_printf(window->cairo, window->font, config->plaintext_markup, "%s", line->text_line); } else if (line->protocol == I3BAR && line->block_line) { From 0f1cfdec617d122afbc87eb6466d5d2e5c348259 Mon Sep 17 00:00:00 2001 From: Mykyta Holubakha Date: Sun, 24 Apr 2016 20:35:21 +0300 Subject: [PATCH 4/5] Renamed to pango_markup --- include/bar/config.h | 2 +- include/config.h | 2 +- sway/commands.c | 16 ++++++++-------- sway/config.c | 2 +- sway/ipc-server.c | 2 +- sway/sway-bar.5.txt | 2 +- swaybar/config.c | 2 +- swaybar/ipc.c | 4 ++-- swaybar/render.c | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/bar/config.h b/include/bar/config.h index 27e0ec29..c0e3d2a7 100644 --- a/include/bar/config.h +++ b/include/bar/config.h @@ -20,7 +20,7 @@ struct box_colors { */ struct config { char *status_command; - bool plaintext_markup; + bool pango_markup; uint32_t position; char *font; char *sep_symbol; diff --git a/include/config.h b/include/config.h index c6f63134..37b97665 100644 --- a/include/config.h +++ b/include/config.h @@ -116,7 +116,7 @@ struct bar_config { enum desktop_shell_panel_position position; list_t *bindings; char *status_command; - bool plaintext_markup; + bool pango_markup; char *swaybar_command; char *font; int height; // -1 not defined diff --git a/sway/commands.c b/sway/commands.c index 3c312ae8..08d3f09d 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -103,7 +103,7 @@ static sway_cmd bar_cmd_id; static sway_cmd bar_cmd_position; static sway_cmd bar_cmd_separator_symbol; static sway_cmd bar_cmd_status_command; -static sway_cmd bar_cmd_plaintext_markup; +static sway_cmd bar_cmd_pango_markup; static sway_cmd bar_cmd_strip_workspace_numbers; static sway_cmd bar_cmd_swaybar_command; static sway_cmd bar_cmd_tray_output; @@ -2758,24 +2758,24 @@ static struct cmd_results *bar_cmd_status_command(int argc, char **argv) { return cmd_results_new(CMD_SUCCESS, NULL, NULL); } -static struct cmd_results *bar_cmd_plaintext_markup(int argc, char **argv) { +static struct cmd_results *bar_cmd_pango_markup(int argc, char **argv) { struct cmd_results *error = NULL; - if ((error = checkarg(argc, "plaintext_markup", EXPECTED_EQUAL_TO, 1))) { + if ((error = checkarg(argc, "pango_markup", EXPECTED_EQUAL_TO, 1))) { return error; } if (!config->current_bar) { - return cmd_results_new(CMD_FAILURE, "plaintext_markup", "No bar defined."); + return cmd_results_new(CMD_FAILURE, "pango_markup", "No bar defined."); } if (strcasecmp("pango", argv[0]) == 0) { - config->current_bar->plaintext_markup = true; + config->current_bar->pango_markup = true; sway_log(L_DEBUG, "Enabling pango markup for bar: %s", config->current_bar->id); } else if (strcasecmp("none", argv[0]) == 0) { - config->current_bar->plaintext_markup = false; + config->current_bar->pango_markup = false; sway_log(L_DEBUG, "Disabling pango markup for bar: %s", config->current_bar->id); } else { - error = cmd_results_new(CMD_INVALID, "plaintext_markup", "Invalid value %s", argv[0]); + error = cmd_results_new(CMD_INVALID, "pango_markup", "Invalid value %s", argv[0]); return error; } return cmd_results_new(CMD_SUCCESS, NULL, NULL); @@ -2885,7 +2885,7 @@ static struct cmd_handler bar_handlers[] = { { "mode", bar_cmd_mode }, { "modifier", bar_cmd_modifier }, { "output", bar_cmd_output }, - { "plaintext_markup", bar_cmd_plaintext_markup }, + { "pango_markup", bar_cmd_pango_markup }, { "position", bar_cmd_position }, { "separator_symbol", bar_cmd_separator_symbol }, { "status_command", bar_cmd_status_command }, diff --git a/sway/config.c b/sway/config.c index 3c14032b..ebcee95b 100644 --- a/sway/config.c +++ b/sway/config.c @@ -1022,7 +1022,7 @@ struct bar_config *default_bar_config(void) { bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; bar->bindings = create_list(); bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p' && sleep 1; done"); - bar->plaintext_markup = true; + bar->pango_markup = true; bar->swaybar_command = NULL; bar->font = NULL; bar->height = -1; diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 0ab6af49..4d9264e8 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -600,7 +600,7 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) { json_object_object_add(json, "strip_workspace_numbers", json_object_new_boolean(bar->strip_workspace_numbers)); json_object_object_add(json, "binding_mode_indicator", json_object_new_boolean(bar->binding_mode_indicator)); json_object_object_add(json, "verbose", json_object_new_boolean(bar->verbose)); - json_object_object_add(json, "plaintext_markup", json_object_new_boolean(bar->plaintext_markup)); + json_object_object_add(json, "pango_markup", json_object_new_boolean(bar->pango_markup)); json_object *colors = json_object_new_object(); json_object_object_add(colors, "background", json_object_new_string(bar->colors.background)); diff --git a/sway/sway-bar.5.txt b/sway/sway-bar.5.txt index 558a9564..25b59946 100644 --- a/sway/sway-bar.5.txt +++ b/sway/sway-bar.5.txt @@ -21,7 +21,7 @@ Commands **status_command** :: Executes the bar _status command_ with _sh -c_. -**plaintext_markup** :: +**pango_markup** :: Enables or disables pango markup for plaintext statuslines. **id** :: diff --git a/swaybar/config.c b/swaybar/config.c index 7ef9a07e..7bd22c91 100644 --- a/swaybar/config.c +++ b/swaybar/config.c @@ -46,7 +46,7 @@ char *parse_font(const char *font) { struct config *init_config() { struct config *config = calloc(1, sizeof(struct config)); config->status_command = NULL; - config->plaintext_markup = true; + config->pango_markup = true; config->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; config->font = strdup("monospace 10"); config->mode = NULL; diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 0446f38a..dacee4c2 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -27,7 +27,7 @@ static void ipc_parse_config(struct config *config, const char *payload) { json_object_object_get_ex(bar_config, "separator_symbol", &sep_symbol); json_object_object_get_ex(bar_config, "colors", &colors); json_object_object_get_ex(bar_config, "outputs", &outputs); - json_object_object_get_ex(bar_config, "plaintext_markup", &markup); + json_object_object_get_ex(bar_config, "pango_markup", &markup); if (status_command) { free(config->status_command); @@ -65,7 +65,7 @@ static void ipc_parse_config(struct config *config, const char *payload) { } if (markup) { - config->plaintext_markup = json_object_get_boolean(markup); + config->pango_markup = json_object_get_boolean(markup); } // free previous outputs list diff --git a/swaybar/render.c b/swaybar/render.c index b9ef2242..273bd4f0 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -278,9 +278,9 @@ void render(struct output *output, struct config *config, struct status_line *li int width, height; if (line->protocol == TEXT) { - get_text_size(window->cairo, window->font, &width, &height, config->plaintext_markup, "%s", line->text_line); + get_text_size(window->cairo, window->font, &width, &height, config->pango_markup, "%s", line->text_line); cairo_move_to(cairo, window->width - margin - width, margin); - pango_printf(window->cairo, window->font, config->plaintext_markup, "%s", line->text_line); + pango_printf(window->cairo, window->font, config->pango_markup, "%s", line->text_line); } else if (line->protocol == I3BAR && line->block_line) { double pos = window->width - 0.5; bool edge = true; From 09d69f606a49d784ae3c11c927d1bfbba77b1f55 Mon Sep 17 00:00:00 2001 From: Mykyta Holubakha Date: Sun, 24 Apr 2016 20:39:41 +0300 Subject: [PATCH 5/5] Renamed pango_markup config options --- sway/commands.c | 4 ++-- sway/sway-bar.5.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sway/commands.c b/sway/commands.c index 08d3f09d..11284577 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -2768,10 +2768,10 @@ static struct cmd_results *bar_cmd_pango_markup(int argc, char **argv) { return cmd_results_new(CMD_FAILURE, "pango_markup", "No bar defined."); } - if (strcasecmp("pango", argv[0]) == 0) { + if (strcasecmp("enabled", argv[0]) == 0) { config->current_bar->pango_markup = true; sway_log(L_DEBUG, "Enabling pango markup for bar: %s", config->current_bar->id); - } else if (strcasecmp("none", argv[0]) == 0) { + } else if (strcasecmp("disabled", argv[0]) == 0) { config->current_bar->pango_markup = false; sway_log(L_DEBUG, "Disabling pango markup for bar: %s", config->current_bar->id); } else { diff --git a/sway/sway-bar.5.txt b/sway/sway-bar.5.txt index 25b59946..30c7d9bf 100644 --- a/sway/sway-bar.5.txt +++ b/sway/sway-bar.5.txt @@ -21,7 +21,7 @@ Commands **status_command** :: Executes the bar _status command_ with _sh -c_. -**pango_markup** :: +**pango_markup** :: Enables or disables pango markup for plaintext statuslines. **id** ::