Unverified Commit 3320bdb1 authored by Erik Reider's avatar Erik Reider Committed by GitHub

Add option to hide the MPRIS album art (#566)

parent 6f1bf432
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
"control-center-margin-left": 0, "control-center-margin-left": 0,
"notification-2fa-action": true, "notification-2fa-action": true,
"notification-inline-replies": false, "notification-inline-replies": false,
"notification-icon-size": 64,
"notification-body-image-height": 100, "notification-body-image-height": 100,
"notification-body-image-width": 200, "notification-body-image-width": 200,
"timeout": 10, "timeout": 10,
...@@ -74,9 +73,9 @@ ...@@ -74,9 +73,9 @@
"text": "Label Text" "text": "Label Text"
}, },
"mpris": { "mpris": {
"image-size": 96,
"blacklist": [], "blacklist": [],
"autohide": false "autohide": false,
"show-album-art": "always"
}, },
"buttons-grid": { "buttons-grid": {
"actions": [ "actions": [
......
...@@ -415,6 +415,12 @@ ...@@ -415,6 +415,12 @@
"deprecated": true, "deprecated": true,
"description": "deprecated (change the CSS root variable \"--mpris-album-art-icon-size\"): The size of the album art", "description": "deprecated (change the CSS root variable \"--mpris-album-art-icon-size\"): The size of the album art",
"default": -1 "default": -1
},
"show-album-art": {
"type": "string",
"description": "Whether or not the album art should be hidden, always visible, or only visible when a valid album art is provided.",
"default": "always",
"enum": ["always", "when-available", "never"]
} }
} }
}, },
......
namespace SwayNotificationCenter.Widgets.Mpris { namespace SwayNotificationCenter.Widgets.Mpris {
public enum AlbumArtState {
ALWAYS, WHEN_AVAILABLE, NEVER;
public static AlbumArtState parse (string value) {
switch (value) {
default:
case "always":
return AlbumArtState.ALWAYS;
case "when-available":
return AlbumArtState.WHEN_AVAILABLE;
case "never":
return AlbumArtState.NEVER;
}
}
}
public struct Config { public struct Config {
[Version (deprecated = true, replacement = "CSS root variable")] [Version (deprecated = true, replacement = "CSS root variable")]
int image_size; int image_size;
AlbumArtState show_album_art;
bool autohide; bool autohide;
string[] blacklist; string[] blacklist;
} }
...@@ -29,6 +46,7 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -29,6 +46,7 @@ namespace SwayNotificationCenter.Widgets.Mpris {
// Default config values // Default config values
Config mpris_config = Config () { Config mpris_config = Config () {
image_size = -1, image_size = -1,
show_album_art = AlbumArtState.ALWAYS,
autohide = false, autohide = false,
}; };
...@@ -88,6 +106,12 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -88,6 +106,12 @@ namespace SwayNotificationCenter.Widgets.Mpris {
mpris_config.image_size = image_size; mpris_config.image_size = image_size;
} }
bool show_art_found;
string? show_album_art = get_prop<string> (config, "show-album-art", out show_art_found);
if (show_art_found && show_album_art != null) {
mpris_config.show_album_art = AlbumArtState.parse (show_album_art);
}
Json.Array ? blacklist = get_prop_array (config, "blacklist"); Json.Array ? blacklist = get_prop_array (config, "blacklist");
if (blacklist != null) { if (blacklist != null) {
mpris_config.blacklist = new string[blacklist.get_length ()]; mpris_config.blacklist = new string[blacklist.get_length ()];
......
...@@ -95,6 +95,7 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -95,6 +95,7 @@ namespace SwayNotificationCenter.Widgets.Mpris {
}); });
}); });
album_art.set_pixel_size (mpris_config.image_size); album_art.set_pixel_size (mpris_config.image_size);
album_art.set_visible (mpris_config.show_album_art == AlbumArtState.ALWAYS);
} }
public void before_destroy () { public void before_destroy () {
...@@ -280,6 +281,7 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -280,6 +281,7 @@ namespace SwayNotificationCenter.Widgets.Mpris {
get_scale_factor (), snapshot); get_scale_factor (), snapshot);
Graphene.Size size = Graphene.Size ().init (icon_size, icon_size); Graphene.Size size = Graphene.Size ().init (icon_size, icon_size);
album_art.set_from_paintable (snapshot.free_to_paintable (size)); album_art.set_from_paintable (snapshot.free_to_paintable (size));
album_art.set_visible (mpris_config.show_album_art != AlbumArtState.NEVER);
// Set background album art // Set background album art
background_picture.set_paintable (album_art_texture); background_picture.set_paintable (album_art_texture);
...@@ -289,6 +291,8 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -289,6 +291,8 @@ namespace SwayNotificationCenter.Widgets.Mpris {
} }
} }
album_art.set_visible (mpris_config.show_album_art == AlbumArtState.ALWAYS);
// Get the app icon // Get the app icon
Icon ? icon = null; Icon ? icon = null;
if (desktop_entry is DesktopAppInfo) { if (desktop_entry is DesktopAppInfo) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment