diff options
author | Heghedus Razvan <heghedus.razvan@protonmail.com> | 2018-05-07 19:30:45 +0300 |
---|---|---|
committer | Heghedus Razvan <heghedus.razvan@gmail.com> | 2018-05-13 17:53:45 +0300 |
commit | 789a877b379cd35c350610be62b971ae00feb542 (patch) | |
tree | 417eb755118e7dedae3badeeaa7d713f204994e2 /sway/tree/view.c | |
parent | Merge pull request #1824 from snaggen/idle (diff) | |
download | sway-789a877b379cd35c350610be62b971ae00feb542.tar.gz sway-789a877b379cd35c350610be62b971ae00feb542.tar.zst sway-789a877b379cd35c350610be62b971ae00feb542.zip |
Fix crash when using pango markup font
The characters & < > ' " needs to be escaped when using pango markup
Signed-off-by: Heghedus Razvan <heghedus.razvan@gmail.com>
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r-- | sway/tree/view.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c index e2cb8a7a..9bdc5198 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -14,6 +14,8 @@ | |||
14 | #include "sway/tree/layout.h" | 14 | #include "sway/tree/layout.h" |
15 | #include "sway/tree/view.h" | 15 | #include "sway/tree/view.h" |
16 | #include "sway/tree/workspace.h" | 16 | #include "sway/tree/workspace.h" |
17 | #include "sway/config.h" | ||
18 | #include "pango.h" | ||
17 | 19 | ||
18 | void view_init(struct sway_view *view, enum sway_view_type type, | 20 | void view_init(struct sway_view *view, enum sway_view_type type, |
19 | const struct sway_view_impl *impl) { | 21 | const struct sway_view_impl *impl) { |
@@ -612,6 +614,19 @@ static size_t parse_title_format(struct sway_view *view, char *buffer) { | |||
612 | return len; | 614 | return len; |
613 | } | 615 | } |
614 | 616 | ||
617 | static char *escape_title(char *buffer) { | ||
618 | int length = escape_markup_text(buffer, NULL, 0); | ||
619 | char *escaped_title = calloc(length + 1, sizeof(char)); | ||
620 | int result = escape_markup_text(buffer, escaped_title, length); | ||
621 | if (result != length) { | ||
622 | wlr_log(L_ERROR, "Could not escape title: %s", buffer); | ||
623 | free(escaped_title); | ||
624 | return buffer; | ||
625 | } | ||
626 | free(buffer); | ||
627 | return escaped_title; | ||
628 | } | ||
629 | |||
615 | void view_update_title(struct sway_view *view, bool force) { | 630 | void view_update_title(struct sway_view *view, bool force) { |
616 | if (!view->swayc) { | 631 | if (!view->swayc) { |
617 | return; | 632 | return; |
@@ -631,11 +646,15 @@ void view_update_title(struct sway_view *view, bool force) { | |||
631 | free(view->swayc->formatted_title); | 646 | free(view->swayc->formatted_title); |
632 | if (title) { | 647 | if (title) { |
633 | size_t len = parse_title_format(view, NULL); | 648 | size_t len = parse_title_format(view, NULL); |
634 | char *buffer = calloc(len + 1, 1); | 649 | char *buffer = calloc(len + 1, sizeof(char)); |
635 | if (!sway_assert(buffer, "Unable to allocate title string")) { | 650 | if (!sway_assert(buffer, "Unable to allocate title string")) { |
636 | return; | 651 | return; |
637 | } | 652 | } |
638 | parse_title_format(view, buffer); | 653 | parse_title_format(view, buffer); |
654 | // now we have the title, but needs to be escaped when using pango markup | ||
655 | if (config->pango_markup) { | ||
656 | buffer = escape_title(buffer); | ||
657 | } | ||
639 | 658 | ||
640 | view->swayc->name = strdup(title); | 659 | view->swayc->name = strdup(title); |
641 | view->swayc->formatted_title = buffer; | 660 | view->swayc->formatted_title = buffer; |