diff options
author | emersion <contact@emersion.fr> | 2018-11-24 23:07:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-24 23:07:13 +0100 |
commit | 827e5513e030eff40323832466e8a39f11aae4eb (patch) | |
tree | c4e3a60478d6ca1fe856dbe46943a15238d8b8df | |
parent | Merge pull request #3145 from fdlamotte/master (diff) | |
parent | fixes pango_markup support with title_format (diff) | |
download | sway-827e5513e030eff40323832466e8a39f11aae4eb.tar.gz sway-827e5513e030eff40323832466e8a39f11aae4eb.tar.zst sway-827e5513e030eff40323832466e8a39f11aae4eb.zip |
Merge pull request #3179 from baloo/baloo/title_format-pango_markup
fixes pango_markup support with title_format
-rw-r--r-- | sway/tree/view.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c index d7110619..63bb8e26 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -824,12 +824,30 @@ struct sway_view *view_from_wlr_surface(struct wlr_surface *wlr_surface) { | |||
824 | return NULL; | 824 | return NULL; |
825 | } | 825 | } |
826 | 826 | ||
827 | static char *escape_pango_markup(const char *buffer) { | ||
828 | size_t length = escape_markup_text(buffer, NULL); | ||
829 | char *escaped_title = calloc(length + 1, sizeof(char)); | ||
830 | escape_markup_text(buffer, escaped_title); | ||
831 | return escaped_title; | ||
832 | } | ||
833 | |||
827 | static size_t append_prop(char *buffer, const char *value) { | 834 | static size_t append_prop(char *buffer, const char *value) { |
828 | if (!value) { | 835 | if (!value) { |
829 | return 0; | 836 | return 0; |
830 | } | 837 | } |
831 | lenient_strcat(buffer, value); | 838 | // if using pango_markup in font, we need to escape all markup char |
832 | return strlen(value); | 839 | // from values to avoid messing with pango markup |
840 | if (!config->pango_markup) { | ||
841 | char *escaped_value = escape_pango_markup(value); | ||
842 | |||
843 | lenient_strcat(buffer, escaped_value); | ||
844 | size_t len = strlen(escaped_value); | ||
845 | free(escaped_value); | ||
846 | return len; | ||
847 | } else { | ||
848 | lenient_strcat(buffer, value); | ||
849 | return strlen(value); | ||
850 | } | ||
833 | } | 851 | } |
834 | 852 | ||
835 | /** | 853 | /** |
@@ -882,14 +900,6 @@ static size_t parse_title_format(struct sway_view *view, char *buffer) { | |||
882 | return len; | 900 | return len; |
883 | } | 901 | } |
884 | 902 | ||
885 | static char *escape_title(char *buffer) { | ||
886 | size_t length = escape_markup_text(buffer, NULL); | ||
887 | char *escaped_title = calloc(length + 1, sizeof(char)); | ||
888 | escape_markup_text(buffer, escaped_title); | ||
889 | free(buffer); | ||
890 | return escaped_title; | ||
891 | } | ||
892 | |||
893 | void view_update_title(struct sway_view *view, bool force) { | 903 | void view_update_title(struct sway_view *view, bool force) { |
894 | const char *title = view_get_title(view); | 904 | const char *title = view_get_title(view); |
895 | 905 | ||
@@ -912,10 +922,6 @@ void view_update_title(struct sway_view *view, bool force) { | |||
912 | return; | 922 | return; |
913 | } | 923 | } |
914 | parse_title_format(view, buffer); | 924 | parse_title_format(view, buffer); |
915 | // now we have the title, but needs to be escaped when using pango markup | ||
916 | if (config->pango_markup) { | ||
917 | buffer = escape_title(buffer); | ||
918 | } | ||
919 | 925 | ||
920 | view->container->title = strdup(title); | 926 | view->container->title = strdup(title); |
921 | view->container->formatted_title = buffer; | 927 | view->container->formatted_title = buffer; |