Added image_visibility parameter to config

This commit is contained in:
Erik Reider
2021-10-16 18:44:30 +02:00
parent 565f2cf87d
commit e5b1579e08
4 changed files with 49 additions and 14 deletions

View File

@@ -89,6 +89,7 @@ To reload the config, you'll need to run `swaync-client --reload-config`
- `timeout`: Any positive number. The notification timeout for notifications with normal priority
- `timeout-low`: Any positive number. The notification timeout for notifications with low priority
- `keyboard-shortcuts`: Boolean. If control center should use keyboard shortcuts
- `image-visibility`: `always`, `when-available` or `never`. Notification image visiblilty
The main CSS style file is located in `/etc/xdg/swaync/style.css`. Copy it over to your `.config/swaync/` folder to customize without needing root access.

View File

@@ -9,4 +9,6 @@
"timeout-low": 5,
// If control center should use keyboard shortcuts
"keyboard_shortcuts": true,
// Sets the notification image visiblilty
"image-visibility": "always"
}

View File

@@ -17,6 +17,15 @@ namespace SwayNotificatonCenter {
}
}
public enum ImageVisibility {
ALWAYS, WHEN_AVAILABLE, NEVER;
public string parse () {
EnumClass enumc = (EnumClass) typeof (ImageVisibility).class_ref ();
return enumc.get_value_by_name (this.to_string ()).value_nick;
}
}
public class ConfigModel : Object, Json.Serializable {
private static ConfigModel _instance;
@@ -80,7 +89,8 @@ namespace SwayNotificatonCenter {
public int timeout {
get {
return _timeout;
} set {
}
set {
_timeout = value < 1 ? _timeout_def : value;
}
}
@@ -91,7 +101,8 @@ namespace SwayNotificatonCenter {
public int timeout_low {
get {
return _timeout_low;
} set {
}
set {
_timeout_low = value < 1 ? _timeout_low_def : value;
}
}
@@ -102,6 +113,13 @@ namespace SwayNotificatonCenter {
*/
public bool keyboard_shortcuts { get; set; default = true; }
/** Specifies if the notifcation image should be shown or not */
public ImageVisibility image_visibility {
get;
set;
default = ImageVisibility.ALWAYS;
}
/* Methods */
/**
@@ -118,6 +136,10 @@ namespace SwayNotificatonCenter {
case "positionY":
node.set_string (((PositionY) value.get_enum ()).parse ());
break;
case "image-visibility":
var val = ((ImageVisibility) value.get_enum ()).parse ();
node.set_string (val);
break;
default:
node.set_value (value);
break;

View File

@@ -246,6 +246,12 @@ namespace SwayNotificatonCenter {
}
private void set_icon () {
var image_visibility = ConfigModel.instance.image_visibility;
if (image_visibility == ImageVisibility.NEVER) {
img.set_visible (false);
return;
}
img.set_pixel_size (48);
var img_path_exists = File.new_for_path (
@@ -266,25 +272,29 @@ namespace SwayNotificatonCenter {
} else {
// Get the app icon
GLib.Icon ? icon = null;
foreach (var app in AppInfo.get_all ()) {
var entry = app.get_id ();
var ref_entry = param.desktop_entry;
var entry_same = true;
if (entry != null && ref_entry != null) {
entry_same = (entry == ref_entry);
}
if (param.desktop_entry != null) {
foreach (var app in AppInfo.get_all ()) {
var entry = app.get_id ();
var ref_entry = param.desktop_entry;
var entry_same = true;
if (entry != null && ref_entry != null) {
entry_same = (entry == ref_entry);
}
if (entry_same
&& app.get_name ().down () == param.app_name.down ()) {
icon = app.get_icon ();
break;
if (entry_same &&
app.get_name ().down () == param.app_name.down ()) {
icon = app.get_icon ();
break;
}
}
}
if (icon != null) {
img.set_from_gicon (icon, Gtk.IconSize.DIALOG);
} else {
} else if (image_visibility == ImageVisibility.ALWAYS) {
// Default icon
img.set_from_icon_name ("image-missing", Gtk.IconSize.DIALOG);
} else {
img.set_visible (false);
}
}
}