diff --git a/contrib/markup-in-status-messages.patch b/contrib/markup-in-status-messages.patch new file mode 100644 index 0000000..ab7e998 --- /dev/null +++ b/contrib/markup-in-status-messages.patch @@ -0,0 +1,65 @@ +From: Ben Collerson +Date: Tue, 29 Nov 2022 11:29:15 +1000 +Subject: [PATCH] markup in status messages +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Allows pango markup to be used in status messages which allow colours to +be used to highlight parts of status bar messages. eg: + +battery: full 🔇0 Tue 11-20 20:10 +--- + src/bar.cpp | 16 +++++++++++++++- + src/bar.hpp | 1 + + 2 files changed, 16 insertions(+), 1 deletion(-) + +diff --git a/src/bar.cpp b/src/bar.cpp +index 507ce62..a96c547 100644 +--- a/src/bar.cpp ++++ b/src/bar.cpp +@@ -81,6 +81,11 @@ void BarComponent::setText(const std::string& text) + pango_layout_set_text(pangoLayout.get(), _text->c_str(), _text->size()); + } + ++void BarComponent::setAttributes(PangoAttrList *attrs) ++{ ++ pango_layout_set_attributes(pangoLayout.get(), attrs); ++} ++ + Bar::Bar() + { + _pangoContext.reset(pango_font_map_create_context(pango_cairo_font_map_get_default())); +@@ -156,7 +161,16 @@ void Bar::setTitle(const std::string& title) + } + void Bar::setStatus(const std::string& status) + { +- _statusCmp.setText(status); ++ char *buf; ++ GError *error = NULL; ++ PangoAttrList *attrs; ++ if (pango_parse_markup(status.c_str(), -1, 0, &attrs, &buf, NULL, &error)) { ++ _statusCmp.setText(buf); ++ _statusCmp.setAttributes(attrs); ++ } ++ else { ++ _statusCmp.setText(error->message); ++ } + } + + void Bar::invalidate() +diff --git a/src/bar.hpp b/src/bar.hpp +index 176a1bc..dfc2043 100644 +--- a/src/bar.hpp ++++ b/src/bar.hpp +@@ -17,6 +17,7 @@ public: + explicit BarComponent(wl_unique_ptr layout); + int width() const; + void setText(const std::string& text); ++ void setAttributes(PangoAttrList *attrs); + wl_unique_ptr pangoLayout; + int x {0}; + }; +-- +2.38.1 +