Skip to content

Commit

Permalink
Add notification-body-image-height/width property to config. Fixes #131
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikReider committed May 31, 2022
1 parent 735f2c5 commit b84a24a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/config.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"control-center-margin-right": 0,
"control-center-margin-left": 0,
"notification-icon-size": 64,
"notification-body-image-height": 100,
"notification-body-image-width": 200,
"timeout": 10,
"timeout-low": 5,
"timeout-critical": 0,
Expand Down
34 changes: 34 additions & 0 deletions src/configModel/configModel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,40 @@ namespace SwayNotificationCenter {
}
}

/**
* Notification body image height, in pixels.
*/
private const int NOTIFICATION_BODY_IMAGE_MINIMUM_HEIGHT = 100;
private const int NOTIFICATION_BODY_IMAGE_DEFAULT_HEIGHT = 100;
private int _notification_body_image_height = NOTIFICATION_BODY_IMAGE_DEFAULT_HEIGHT;
public int notification_body_image_height {
get {
return _notification_body_image_height;
}
set {
_notification_body_image_height =
value > NOTIFICATION_BODY_IMAGE_MINIMUM_HEIGHT
? value : NOTIFICATION_BODY_IMAGE_MINIMUM_HEIGHT;
}
}

/**
* Notification body image width, in pixels.
*/
private const int NOTIFICATION_BODY_IMAGE_MINIMUM_WIDTH = 200;
private const int NOTIFICATION_BODY_IMAGE_DEFAULT_WIDTH = 200;
private int _notification_body_image_width = NOTIFICATION_BODY_IMAGE_DEFAULT_WIDTH;
public int notification_body_image_width {
get {
return _notification_body_image_width;
}
set {
_notification_body_image_width =
value > NOTIFICATION_BODY_IMAGE_MINIMUM_WIDTH
? value : NOTIFICATION_BODY_IMAGE_MINIMUM_WIDTH;
}
}

/* Methods */

/**
Expand Down
12 changes: 12 additions & 0 deletions src/configSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@
"default": 64,
"minimum": 16
},
"notification-body-image-height": {
"type": "integer",
"description": "The notification body image height (in pixels)",
"default": 100,
"minimum": 100
},
"notification-body-image-width": {
"type": "integer",
"description": "The notification body image width (in pixels)",
"default": 200,
"minimum": 200
},
"timeout": {
"type": "integer",
"description": "The notification timeout for notifications with normal priority",
Expand Down
15 changes: 11 additions & 4 deletions src/notification/notification.vala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ namespace SwayNotificationCenter {
public static Gtk.IconSize icon_size = Gtk.IconSize.INVALID;
private int notification_icon_size { get; default = ConfigModel.instance.notification_icon_size; }

private int notification_body_image_height {
get;
default = ConfigModel.instance.notification_body_image_height;
}
private int notification_body_image_width {
get;
default = ConfigModel.instance.notification_body_image_width;
}

private uint timeout_id = 0;

public bool is_timed { get; construct; default = false; }
Expand Down Expand Up @@ -236,12 +245,10 @@ namespace SwayNotificationCenter {
var img = img_paths[0];
var file = File.new_for_path (img);
if (img.length > 0 && file.query_exists ()) {
const int MAX_WIDTH = 200;
const int MAX_HEIGHT = 100;
var buf = new Gdk.Pixbuf.from_file_at_scale (
file.get_path (),
MAX_WIDTH,
MAX_HEIGHT,
notification_body_image_width,
notification_body_image_height,
true);
this.body_image.set_from_pixbuf (buf);
this.body_image.show ();
Expand Down

0 comments on commit b84a24a

Please sign in to comment.