mirror of
https://github.com/ErikReider/SwayNotificationCenter.git
synced 2024-09-11 15:56:04 +03:00
Add notification-image-size property to config
This commit is contained in:
parent
725b80c615
commit
735f2c5ab1
@ -6,6 +6,7 @@
|
||||
"control-center-margin-bottom": 0,
|
||||
"control-center-margin-right": 0,
|
||||
"control-center-margin-left": 0,
|
||||
"notification-icon-size": 64,
|
||||
"timeout": 10,
|
||||
"timeout-low": 5,
|
||||
"timeout-critical": 0,
|
||||
|
@ -453,6 +453,22 @@ namespace SwayNotificationCenter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification icon size, in pixels.
|
||||
*/
|
||||
private const int NOTIFICATION_ICON_MINIMUM_SIZE = 16;
|
||||
private const int NOTIFICATION_ICON_DEFAULT_SIZE = 64;
|
||||
private int _notification_icon_size = NOTIFICATION_ICON_DEFAULT_SIZE;
|
||||
public int notification_icon_size {
|
||||
get {
|
||||
return _notification_icon_size;
|
||||
}
|
||||
set {
|
||||
_notification_icon_size = value > NOTIFICATION_ICON_MINIMUM_SIZE
|
||||
? value : NOTIFICATION_ICON_MINIMUM_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
|
@ -39,6 +39,12 @@
|
||||
"description": "The margin (in pixels) at the left of the notification center. 0 to disable",
|
||||
"default": 0
|
||||
},
|
||||
"notification-icon-size": {
|
||||
"type": "integer",
|
||||
"description": "The notification icon size (in pixels)",
|
||||
"default": 64,
|
||||
"minimum": 16
|
||||
},
|
||||
"timeout": {
|
||||
"type": "integer",
|
||||
"description": "The notification timeout for notifications with normal priority",
|
||||
|
@ -2,6 +2,7 @@ namespace SwayNotificationCenter {
|
||||
public class Functions {
|
||||
public static void set_image_path (owned string path,
|
||||
Gtk.Image img,
|
||||
int icon_size,
|
||||
bool file_exists) {
|
||||
if ((path.length > 6 && path.slice (0, 7) == "file://") || file_exists) {
|
||||
// Try as a URI (file:// is the only URI schema supported right now)
|
||||
@ -10,8 +11,8 @@ namespace SwayNotificationCenter {
|
||||
|
||||
var pixbuf = new Gdk.Pixbuf.from_file_at_scale (
|
||||
path,
|
||||
Notification.icon_image_size * img.scale_factor,
|
||||
Notification.icon_image_size * img.scale_factor,
|
||||
icon_size * img.scale_factor,
|
||||
icon_size * img.scale_factor,
|
||||
true);
|
||||
var surface = Gdk.cairo_surface_create_from_pixbuf (
|
||||
pixbuf,
|
||||
@ -32,7 +33,7 @@ namespace SwayNotificationCenter {
|
||||
}
|
||||
}
|
||||
|
||||
public static void set_image_data (ImageData data, Gtk.Image img) {
|
||||
public static void set_image_data (ImageData data, Gtk.Image img, int icon_size) {
|
||||
// Rebuild and scale the image
|
||||
var pixbuf = new Gdk.Pixbuf.with_unowned_data (data.data,
|
||||
Gdk.Colorspace.RGB,
|
||||
@ -44,8 +45,8 @@ namespace SwayNotificationCenter {
|
||||
null);
|
||||
|
||||
pixbuf = pixbuf.scale_simple (
|
||||
Notification.icon_image_size * img.scale_factor,
|
||||
Notification.icon_image_size * img.scale_factor,
|
||||
icon_size * img.scale_factor,
|
||||
icon_size * img.scale_factor,
|
||||
Gdk.InterpType.BILINEAR);
|
||||
var surface = Gdk.cairo_surface_create_from_pixbuf (
|
||||
pixbuf,
|
||||
|
@ -63,7 +63,7 @@
|
||||
<object class="GtkImage" id="img">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="valign">start</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="margin-end">12</property>
|
||||
<property name="icon_size">6</property>
|
||||
<style>
|
||||
|
@ -37,7 +37,7 @@ namespace SwayNotificationCenter {
|
||||
unowned Gtk.Image body_image;
|
||||
|
||||
public static Gtk.IconSize icon_size = Gtk.IconSize.INVALID;
|
||||
public static int icon_image_size = 64;
|
||||
private int notification_icon_size { get; default = ConfigModel.instance.notification_icon_size; }
|
||||
|
||||
private uint timeout_id = 0;
|
||||
|
||||
@ -402,9 +402,9 @@ namespace SwayNotificationCenter {
|
||||
return;
|
||||
}
|
||||
|
||||
img.set_pixel_size (Notification.icon_image_size);
|
||||
img.height_request = Notification.icon_image_size;
|
||||
img.width_request = Notification.icon_image_size;
|
||||
img.set_pixel_size (notification_icon_size);
|
||||
img.height_request = notification_icon_size;
|
||||
img.width_request = notification_icon_size;
|
||||
|
||||
var img_path_exists = File.new_for_path (
|
||||
param.image_path ?? "").query_exists ();
|
||||
@ -412,15 +412,21 @@ namespace SwayNotificationCenter {
|
||||
param.app_icon ?? "").query_exists ();
|
||||
|
||||
if (param.image_data.is_initialized) {
|
||||
Functions.set_image_data (param.image_data, img);
|
||||
Functions.set_image_data (param.image_data, img,
|
||||
notification_icon_size);
|
||||
} else if (param.image_path != null &&
|
||||
param.image_path != "" &&
|
||||
img_path_exists) {
|
||||
Functions.set_image_path (param.image_path, img, img_path_exists);
|
||||
Functions.set_image_path (param.image_path, img,
|
||||
notification_icon_size,
|
||||
img_path_exists);
|
||||
} else if (param.app_icon != null && param.app_icon != "") {
|
||||
Functions.set_image_path (param.app_icon, img, app_icon_exists);
|
||||
Functions.set_image_path (param.app_icon, img,
|
||||
notification_icon_size,
|
||||
app_icon_exists);
|
||||
} else if (param.icon_data.is_initialized) {
|
||||
Functions.set_image_data (param.icon_data, img);
|
||||
Functions.set_image_data (param.icon_data, img,
|
||||
notification_icon_size);
|
||||
} else {
|
||||
// Get the app icon
|
||||
GLib.Icon ? icon = null;
|
||||
|
Loading…
Reference in New Issue
Block a user