Unverified Commit 35d3a14f authored by Erik Reider's avatar Erik Reider Committed by GitHub

Fixed image-path not being considered as theme icon (#515)

parent 01eb2221
......@@ -18,15 +18,15 @@ namespace SwayNotificationCenter {
Gtk.Image img,
int icon_size,
int radius,
bool file_exists) {
bool file_exists,
bool is_theme_icon = false) {
const string URI_PREFIX = "file://";
const uint PREFIX_SIZE = 7;
bool is_uri = (uri.length >= PREFIX_SIZE
&& uri.slice (0, PREFIX_SIZE) == URI_PREFIX);
if (is_uri || file_exists) {
bool is_uri = (uri.length >= URI_PREFIX.length
&& uri.slice (0, URI_PREFIX.length) == URI_PREFIX);
if (!is_theme_icon && (is_uri || file_exists)) {
// Try as a URI (file:// is the only URI schema supported right now)
try {
if (is_uri) uri = uri.slice (PREFIX_SIZE, uri.length);
if (is_uri) uri = uri.slice (URI_PREFIX.length, uri.length);
var pixbuf = new Gdk.Pixbuf.from_file_at_scale (
uri,
......
......@@ -690,15 +690,25 @@ namespace SwayNotificationCenter {
int app_icon_size = notification_icon_size / 3;
img_app_icon.set_pixel_size (app_icon_size);
var img_path_exists = File.new_for_uri (
bool img_path_is_theme_icon = false;
bool img_path_exists = File.new_for_uri (
param.image_path ?? "").query_exists ();
if (param.image_path != null && !img_path_exists) {
// Check if it's not a URI
img_path_exists = File.new_for_path (
param.image_path ?? "").query_exists ();
// Check if it's a freedesktop.org-compliant icon
if (!img_path_exists) {
unowned Gtk.IconTheme icon_theme = Gtk.IconTheme.get_default ();
Gtk.IconInfo? info = icon_theme.lookup_icon (param.image_path,
notification_icon_size,
Gtk.IconLookupFlags.USE_BUILTIN);
img_path_exists = info != null;
img_path_is_theme_icon = img_path_exists;
}
}
var app_icon_exists = File.new_for_uri (
app_icon_uri ?? "").query_exists ();
var app_icon_exists = File.new_for_uri (app_icon_uri ?? "").query_exists ();
if (app_icon_uri != null && !img_path_exists) {
// Check if it's not a URI
app_icon_exists = File.new_for_path (
......@@ -722,9 +732,10 @@ namespace SwayNotificationCenter {
param.image_path != "" &&
img_path_exists) {
Functions.set_image_uri (param.image_path, img,
notification_icon_size,
radius,
img_path_exists);
notification_icon_size,
radius,
img_path_exists,
img_path_is_theme_icon);
} else if (param.icon_data.is_initialized) {
Functions.set_image_data (param.icon_data, img,
notification_icon_size, radius);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment