diff options
author | Mykyta Holubakha <hilobakho@gmail.com> | 2016-04-24 19:57:35 +0300 |
---|---|---|
committer | Mykyta Holubakha <hilobakho@gmail.com> | 2016-04-24 19:57:35 +0300 |
commit | 53b53dd8c24004d9b2a2170590432d62656c43c2 (patch) | |
tree | aba12b0488a16e198e4fdd4fe02ca8ee63b56bb8 | |
parent | Merge pull request #598 from Hummer12007/pango_fix (diff) | |
download | sway-53b53dd8c24004d9b2a2170590432d62656c43c2.tar.gz sway-53b53dd8c24004d9b2a2170590432d62656c43c2.tar.zst sway-53b53dd8c24004d9b2a2170590432d62656c43c2.zip |
Added plaintext markup configuration
-rw-r--r-- | include/bar/config.h | 1 | ||||
-rw-r--r-- | include/config.h | 1 | ||||
-rw-r--r-- | sway/commands.c | 25 | ||||
-rw-r--r-- | sway/config.c | 1 | ||||
-rw-r--r-- | sway/sway-bar.5.txt | 3 | ||||
-rw-r--r-- | swaybar/config.c | 1 | ||||
-rw-r--r-- | swaybar/render.c | 2 |
7 files changed, 33 insertions, 1 deletions
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 { | |||
20 | */ | 20 | */ |
21 | struct config { | 21 | struct config { |
22 | char *status_command; | 22 | char *status_command; |
23 | bool plaintext_markup; | ||
23 | uint32_t position; | 24 | uint32_t position; |
24 | char *font; | 25 | char *font; |
25 | char *sep_symbol; | 26 | 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 { | |||
116 | enum desktop_shell_panel_position position; | 116 | enum desktop_shell_panel_position position; |
117 | list_t *bindings; | 117 | list_t *bindings; |
118 | char *status_command; | 118 | char *status_command; |
119 | bool plaintext_markup; | ||
119 | char *swaybar_command; | 120 | char *swaybar_command; |
120 | char *font; | 121 | char *font; |
121 | int height; // -1 not defined | 122 | 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; | |||
103 | static sway_cmd bar_cmd_position; | 103 | static sway_cmd bar_cmd_position; |
104 | static sway_cmd bar_cmd_separator_symbol; | 104 | static sway_cmd bar_cmd_separator_symbol; |
105 | static sway_cmd bar_cmd_status_command; | 105 | static sway_cmd bar_cmd_status_command; |
106 | static sway_cmd bar_cmd_plaintext_markup; | ||
106 | static sway_cmd bar_cmd_strip_workspace_numbers; | 107 | static sway_cmd bar_cmd_strip_workspace_numbers; |
107 | static sway_cmd bar_cmd_swaybar_command; | 108 | static sway_cmd bar_cmd_swaybar_command; |
108 | static sway_cmd bar_cmd_tray_output; | 109 | static sway_cmd bar_cmd_tray_output; |
@@ -2757,6 +2758,29 @@ static struct cmd_results *bar_cmd_status_command(int argc, char **argv) { | |||
2757 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 2758 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
2758 | } | 2759 | } |
2759 | 2760 | ||
2761 | static struct cmd_results *bar_cmd_plaintext_markup(int argc, char **argv) { | ||
2762 | struct cmd_results *error = NULL; | ||
2763 | if ((error = checkarg(argc, "plaintext_markup", EXPECTED_EQUAL_TO, 1))) { | ||
2764 | return error; | ||
2765 | } | ||
2766 | |||
2767 | if (!config->current_bar) { | ||
2768 | return cmd_results_new(CMD_FAILURE, "plaintext_markup", "No bar defined."); | ||
2769 | } | ||
2770 | |||
2771 | if (strcasecmp("pango", argv[0]) == 0) { | ||
2772 | config->current_bar->plaintext_markup = true; | ||
2773 | sway_log(L_DEBUG, "Enabling pango markup for bar: %s", config->current_bar->id); | ||
2774 | } else if (strcasecmp("none", argv[0]) == 0) { | ||
2775 | config->current_bar->plaintext_markup = false; | ||
2776 | sway_log(L_DEBUG, "Disabling pango markup for bar: %s", config->current_bar->id); | ||
2777 | } else { | ||
2778 | error = cmd_results_new(CMD_INVALID, "plaintext_markup", "Invalid value %s", argv[0]); | ||
2779 | return error; | ||
2780 | } | ||
2781 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2782 | } | ||
2783 | |||
2760 | static struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) { | 2784 | static struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) { |
2761 | struct cmd_results *error = NULL; | 2785 | struct cmd_results *error = NULL; |
2762 | if ((error = checkarg(argc, "strip_workspace_numbers", EXPECTED_EQUAL_TO, 1))) { | 2786 | if ((error = checkarg(argc, "strip_workspace_numbers", EXPECTED_EQUAL_TO, 1))) { |
@@ -2861,6 +2885,7 @@ static struct cmd_handler bar_handlers[] = { | |||
2861 | { "mode", bar_cmd_mode }, | 2885 | { "mode", bar_cmd_mode }, |
2862 | { "modifier", bar_cmd_modifier }, | 2886 | { "modifier", bar_cmd_modifier }, |
2863 | { "output", bar_cmd_output }, | 2887 | { "output", bar_cmd_output }, |
2888 | { "plaintext_markup", bar_cmd_plaintext_markup }, | ||
2864 | { "position", bar_cmd_position }, | 2889 | { "position", bar_cmd_position }, |
2865 | { "separator_symbol", bar_cmd_separator_symbol }, | 2890 | { "separator_symbol", bar_cmd_separator_symbol }, |
2866 | { "status_command", bar_cmd_status_command }, | 2891 | { "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) { | |||
1022 | bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; | 1022 | bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; |
1023 | bar->bindings = create_list(); | 1023 | bar->bindings = create_list(); |
1024 | bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p' && sleep 1; done"); | 1024 | bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p' && sleep 1; done"); |
1025 | bar->plaintext_markup = true; | ||
1025 | bar->swaybar_command = NULL; | 1026 | bar->swaybar_command = NULL; |
1026 | bar->font = NULL; | 1027 | bar->font = NULL; |
1027 | bar->height = -1; | 1028 | 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 | |||
21 | **status_command** <status command>:: | 21 | **status_command** <status command>:: |
22 | Executes the bar _status command_ with _sh -c_. | 22 | Executes the bar _status command_ with _sh -c_. |
23 | 23 | ||
24 | **plaintext_markup** <pango|none>:: | ||
25 | Enables or disables pango markup for plaintext statuslines. | ||
26 | |||
24 | **id** <bar_id>:: | 27 | **id** <bar_id>:: |
25 | Sets the ID of the bar. | 28 | Sets the ID of the bar. |
26 | 29 | ||
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) { | |||
46 | struct config *init_config() { | 46 | struct config *init_config() { |
47 | struct config *config = calloc(1, sizeof(struct config)); | 47 | struct config *config = calloc(1, sizeof(struct config)); |
48 | config->status_command = NULL; | 48 | config->status_command = NULL; |
49 | config->plaintext_markup = true; | ||
49 | config->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; | 50 | config->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; |
50 | config->font = strdup("monospace 10"); | 51 | config->font = strdup("monospace 10"); |
51 | config->mode = NULL; | 52 | 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 | |||
280 | if (line->protocol == TEXT) { | 280 | if (line->protocol == TEXT) { |
281 | get_text_size(window->cairo, window->font, &width, &height, true, "%s", line->text_line); | 281 | get_text_size(window->cairo, window->font, &width, &height, true, "%s", line->text_line); |
282 | cairo_move_to(cairo, window->width - margin - width, margin); | 282 | cairo_move_to(cairo, window->width - margin - width, margin); |
283 | pango_printf(window->cairo, window->font, true, "%s", line->text_line); | 283 | pango_printf(window->cairo, window->font, config->plaintext_markup, "%s", line->text_line); |
284 | } else if (line->protocol == I3BAR && line->block_line) { | 284 | } else if (line->protocol == I3BAR && line->block_line) { |
285 | double pos = window->width - 0.5; | 285 | double pos = window->width - 0.5; |
286 | bool edge = true; | 286 | bool edge = true; |