diff options
| author | stkhan <personal@slickd.xyz> | 2023-03-31 19:42:29 -0500 |
|---|---|---|
| committer | stkhan <personal@slickd.xyz> | 2023-03-31 19:42:29 -0500 |
| commit | 0e71af11a27631e45c0160842e4498507420eff0 (patch) | |
| tree | 4eed4eba5b0273f26bc55243cce36a2670ac0fef /wm/somebar/contrib/markup-in-status-messages.patch | |
| parent | 07afc07ffff324f3a355f2437bd643b616fe0af4 (diff) | |
bar and blocks
Diffstat (limited to 'wm/somebar/contrib/markup-in-status-messages.patch')
| -rw-r--r-- | wm/somebar/contrib/markup-in-status-messages.patch | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/wm/somebar/contrib/markup-in-status-messages.patch b/wm/somebar/contrib/markup-in-status-messages.patch new file mode 100644 index 0000000..ab7e998 --- /dev/null +++ b/wm/somebar/contrib/markup-in-status-messages.patch @@ -0,0 +1,65 @@ +From: Ben Collerson <benc@benc.cc> +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 <span color="#ffff00">🔇0</span> 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<PangoLayout> layout); + int width() const; + void setText(const std::string& text); ++ void setAttributes(PangoAttrList *attrs); + wl_unique_ptr<PangoLayout> pangoLayout; + int x {0}; + }; +-- +2.38.1 + |