Skip to content

Commit

Permalink
Handle URIs used for application icons (#119) (#120)
Browse files Browse the repository at this point in the history
* Handle URIs used for application icons (#119)

* Add missing space
  • Loading branch information
bluesabre committed May 13, 2021
1 parent eec89e6 commit 1a91b81
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/Bubble.vala
Expand Up @@ -95,6 +95,28 @@ public class Notifications.Bubble : AbstractBubble {
content_area.visible_child = new_contents;
}

static bool is_uri (string? uri) {
return uri.contains ("/");
}

static Gtk.Image get_app_image (string? icon_name, int pixel_size, int scale) {
Gtk.Image app_image = new Gtk.Image ();
if (is_uri (icon_name)) {
try {
var filename = GLib.Filename.from_uri (icon_name);
var pixbuf = new Gdk.Pixbuf.from_file_at_size (filename, pixel_size * scale, pixel_size * scale);
app_image.pixbuf = pixbuf;
} catch (Error e) {
critical ("Failed to generate app icon: %s", e.message);
app_image.icon_name = "image-missing";
}
} else {
app_image.icon_name = icon_name;
}
app_image.pixel_size = pixel_size;
return app_image;
}

private class Contents : Gtk.Grid {
public Notifications.Notification notification { get; construct; }

Expand All @@ -103,32 +125,29 @@ public class Notifications.Bubble : AbstractBubble {
}

construct {
var app_image = new Gtk.Image ();
app_image.icon_name = notification.app_icon;

var image_overlay = new Gtk.Overlay ();
image_overlay.valign = Gtk.Align.START;

var scale = get_style_context ().get_scale ();
if (notification.image_path != null) {
try {
var scale = get_style_context ().get_scale ();
var pixbuf = new Gdk.Pixbuf.from_file_at_size (notification.image_path, 48 * scale, 48 * scale);

var masked_image = new Notifications.MaskedImage (pixbuf);

app_image.pixel_size = 24;
var app_image = get_app_image (notification.app_icon, 24, scale);
app_image.halign = app_image.valign = Gtk.Align.END;

image_overlay.add (masked_image);
image_overlay.add_overlay (app_image);
} catch (Error e) {
critical ("Unable to mask image: %s", e.message);

app_image.pixel_size = 48;
var app_image = get_app_image (notification.app_icon, 48, scale);
image_overlay.add (app_image);
}
} else {
app_image.pixel_size = 48;
var app_image = get_app_image (notification.app_icon, 48, scale);
image_overlay.add (app_image);
}

Expand Down

0 comments on commit 1a91b81

Please sign in to comment.