From 1fcef5c966af523a24369d0897e01d8349e9a36e Mon Sep 17 00:00:00 2001
From: Erik Reider <35975961+ErikReider@users.noreply.github.com>
Date: Fri, 15 Dec 2023 16:15:48 +0100
Subject: [PATCH] Add app icon above the regular icon (#354)
* Add app icon above the regular icon
* Fixed linting issues
* Tweaked the CSS
---
data/style/style.scss | 14 +++++---
src/configSchema.json | 4 +--
src/functions.vala | 24 +++++++-------
src/notification/notification.ui | 34 +++++++++++++++----
src/notification/notification.vala | 52 ++++++++++++++++++++++--------
5 files changed, 91 insertions(+), 37 deletions(-)
diff --git a/data/style/style.scss b/data/style/style.scss
index 97b409c..f5d9bd1 100644
--- a/data/style/style.scss
+++ b/data/style/style.scss
@@ -109,19 +109,25 @@ $notification-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3),
.notification-content {
background: transparent;
- $padding: 6px;
- padding: $padding;
border-radius: $border-radius;
+ $margin: 8px;
.image {
/* Notification Primary Image */
-gtk-icon-effect: none;
border-radius: 100px; /* Size in px */
- margin: 4px;
+ margin: $margin;
+ }
+ .app-icon {
+ /* Notification app icon (only visible when the primary image is set) */
+ -gtk-icon-effect: none;
+ -gtk-icon-shadow: 0 1px 4px black;
+ margin: 6px;
}
.text-box {
- margin: 0 8px;
+ margin: $margin;
+
.summary {
/* Notification summary/title */
font-size: $font-size-summary;
diff --git a/src/configSchema.json b/src/configSchema.json
index f5e962a..db5cc52 100644
--- a/src/configSchema.json
+++ b/src/configSchema.json
@@ -92,7 +92,7 @@
},
"notification-icon-size": {
"type": "integer",
- "description": "The notification icon size (in pixels)",
+ "description": "The notification icon size (in pixels). The app icon size is 1/3",
"default": 64,
"minimum": 16
},
@@ -157,7 +157,7 @@
},
"image-visibility": {
"type": "string",
- "description": "An explanation about the purpose of this instance.",
+ "description": "The notification image visibility when no icon is available.",
"default": "when-available",
"enum": ["always", "when-available", "never"]
},
diff --git a/src/functions.vala b/src/functions.vala
index bc176cc..c263e4e 100644
--- a/src/functions.vala
+++ b/src/functions.vala
@@ -14,30 +14,30 @@ namespace SwayNotificationCenter {
theme.add_resource_path ("/org/erikreider/swaync/icons");
}
- public static void set_image_path (owned string path,
- Gtk.Image img,
- int icon_size,
- int radius,
- bool file_exists) {
- if ((path.length > 6 && path.slice (0, 7) == "file://") || file_exists) {
+ public static void set_image_uri (owned string uri,
+ Gtk.Image img,
+ int icon_size,
+ int radius,
+ bool file_exists) {
+ 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) {
// Try as a URI (file:// is the only URI schema supported right now)
try {
- if (!file_exists) path = path.slice (7, path.length);
+ if (is_uri) uri = uri.slice (PREFIX_SIZE, uri.length);
- var pixbuf = new Gdk.Pixbuf.from_file (path);
+ var pixbuf = new Gdk.Pixbuf.from_file (uri);
var surface = scale_round_pixbuf (pixbuf,
icon_size,
icon_size,
img.scale_factor,
radius);
img.set_from_surface (surface);
- return;
} catch (Error e) {
stderr.printf (e.message + "\n");
}
- } else if (Gtk.IconTheme.get_default ().has_icon (path)) {
- // Try as a freedesktop.org-compliant icon theme
- img.set_from_icon_name (path, Notification.icon_size);
}
}
diff --git a/src/notification/notification.ui b/src/notification/notification.ui
index af0e92c..b948f48 100644
--- a/src/notification/notification.ui
+++ b/src/notification/notification.ui
@@ -60,15 +60,37 @@
True
False
-