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
33 changes: 33 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 <gtk-utils.hpp>
#include <glibmm.h>
#include <gtkmm/icontheme.h>
Expand Down Expand Up @@ -72,3 +73,35 @@ void image_set_icon(Gtk::Image *image, std::string path)
image->set_from_icon_name(path);
}
}

/*
* 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))
{
/* And they pair up */
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);
}
4 changes: 4 additions & 0 deletions src/util/gtk-utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ struct WfIconLoadOptions
void invert_pixbuf(Glib::RefPtr<Gdk::Pixbuf>& pbuff);

void image_set_icon(Gtk::Image *image, std::string path);

bool is_markup(std::string);

std::string markup_escape(std::string);