Skip to content
Merged
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
37 changes: 8 additions & 29 deletions src/Bubble.vala
Original file line number Diff line number Diff line change
Expand Up @@ -109,40 +109,19 @@ public class Notifications.Bubble : AbstractBubble {
}

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

if (notification.app_icon.contains ("/")) {
var file = File.new_for_uri (notification.app_icon);
if (file.query_exists ()) {
app_image.gicon = new FileIcon (file);
} else {
app_image.icon_name = "dialog-information";
}
} else {
app_image.icon_name = notification.app_icon;
}
var app_image = new Gtk.Image () {
gicon = notification.primary_icon
};

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

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;
app_image.halign = app_image.valign = Gtk.Align.END;
if (notification.image != null) {
app_image.pixel_size = 24;
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;
image_overlay.add (app_image);
}
image_overlay.add (notification.image);
image_overlay.add_overlay (app_image);
} else {
app_image.pixel_size = 48;
image_overlay.add (app_image);
Expand Down
35 changes: 22 additions & 13 deletions src/Notification.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ public class Notifications.Notification : GLib.Object {
public string app_id { get; private set; default = OTHER_APP_ID; }
public string app_name { get; construct; }
public string body { get; construct set; }
public string? image_path { get; private set; default = null; }
public string summary { get; construct set; }
public GLib.Icon badge_icon { get; construct set; }

public GLib.Icon? primary_icon { get; set; default = null; }
public GLib.Icon? badge_icon { get; set; default = null; }
public MaskedImage? image { get; set; default = null; }

private static Regex entity_regex;
private static Regex tag_regex;
Expand Down Expand Up @@ -75,26 +77,33 @@ public class Notifications.Notification : GLib.Object {
}

// Always "" if sent by GLib.Notification
if (app_icon == "") {
if (app_info != null) {
app_icon = app_info.get_icon ().to_string ();
} else {
app_icon = "dialog-information";
if (app_icon == "" && app_info != null) {
primary_icon = app_info.get_icon ();
} else if (app_icon.contains ("/")) {
var file = File.new_for_uri (app_icon);
if (file.query_exists ()) {
primary_icon = new FileIcon (file);
}
}

if (primary_icon == null) {
primary_icon = new ThemedIcon ("dialog-information");
}

// GLib.Notification.set_icon ()
if ((variant = hints.lookup ("image-path")) != null || (variant = hints.lookup ("image_path")) != null) {
image_path = variant.get_string ();
var image_path = variant.get_string ();

// GLib.Notification also sends icon names via this hint
if (Gtk.IconTheme.get_default ().has_icon (image_path) && image_path != app_icon) {
badge_icon = new ThemedIcon (image_path);
}

var is_a_path = image_path.has_prefix ("/") || image_path.has_prefix ("file://");
if (badge_icon != null || !is_a_path) {
image_path = null;
} else if (image_path.has_prefix ("/") || image_path.has_prefix ("file://")) {
try {
var pixbuf = new Gdk.Pixbuf.from_file (image_path);
image = new Notifications.MaskedImage (pixbuf);
} catch (Error e) {
critical ("Unable to mask image: %s", e.message);
}
}
}

Expand Down