Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/panel/widgets/notifications/single-notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ WfSingleNotification::WfSingleNotification(const Notification & notification)
text.set_wrap_mode(Pango::WrapMode::CHAR);
if (notification.body.empty())
{
text.set_markup(notification.summary);
text.set_markup(markup_escape(notification.summary));
} else
{
// NOTE: that is not a really right way to implement FDN markup feature, but the easiest one.
text.set_markup("<b>" + notification.summary + "</b>" + "\n" + notification.body);
text.set_markup("<b>" + markup_escape(
notification.summary) + "</b>" + "\n" + markup_escape(notification.body));
}

content.append(text);
Expand Down
9 changes: 5 additions & 4 deletions src/panel/widgets/tray/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ void StatusNotifierItem::setup_tooltip()
get_item_property<std::tuple<Glib::ustring, IconData, Glib::ustring, Glib::ustring>>("ToolTip");

auto tooltip_label_text = !tooltip_text.empty() && !tooltip_title.empty() ?
"<b>" + tooltip_title + "</b>: " + tooltip_text :
!tooltip_title.empty() ? tooltip_title :
!tooltip_text.empty() ? tooltip_text :
get_item_property<Glib::ustring>("Title");
"<b>" + markup_escape(tooltip_title) + "</b>: " +
markup_escape(tooltip_text) :
!tooltip_title.empty() ? markup_escape(tooltip_title) :
!tooltip_text.empty() ? markup_escape(tooltip_text) :
markup_escape(get_item_property<Glib::ustring>("Title"));

const auto pixbuf = extract_pixbuf(std::move(tooltip_icon_data));
bool icon_shown = false;
Expand Down
32 changes: 32 additions & 0 deletions src/util/gtk-utils.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "glibmm/markup.h"
#include "glibmm/ustring.h"
#include <gtk-utils.hpp>
#include <glibmm.h>
Expand Down Expand Up @@ -180,3 +181,34 @@ void load_custom_icons(std::string section_name)
}
}
}

/*
* Check if this string appears to be markup
*
* Does not check it is *valid* markup
*/
bool is_markup(std::string input)
{
int count_left = std::count(input.begin(), input.end(), '<');
int count_right = std::count(input.begin(), input.end(), '>');
int count_amp = std::count(input.begin(), input.end(), '&');
int count_semi = std::count(input.begin(), input.end(), ';');

if ((count_left == count_right) && (count_amp == count_semi))
{
return true;
}

return false;
}

/* Escape string if it doesn't appear to be markup */
std::string markup_escape(std::string input)
{
if (is_markup(input))
{
return input;
}

return Glib::Markup::escape_text(input);
}
3 changes: 3 additions & 0 deletions src/util/gtk-utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Glib::RefPtr<Gdk::Pixbuf> load_icon_pixbuf_safe(std::string icon_path, int size)
/* Loads a CssProvider from the given path to the file, returns null if unsuccessful*/
Glib::RefPtr<Gtk::CssProvider> load_css_from_path(std::string path);

bool is_markup(std::string);
std::string markup_escape(std::string);

struct WfIconLoadOptions
{
int user_scale = -1;
Expand Down
Loading