From 31266a3671f189bd2952d461b9de32515f2c0603 Mon Sep 17 00:00:00 2001 From: giskard Date: Tue, 14 May 2024 12:51:13 +0800 Subject: [PATCH 1/3] mpris: add blacklist support --- src/configSchema.json | 9 +++++++++ src/controlCenter/widgets/mpris/mpris.vala | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/configSchema.json b/src/configSchema.json index 64210075..6a8d50c6 100644 --- a/src/configSchema.json +++ b/src/configSchema.json @@ -410,6 +410,15 @@ "type": "boolean", "description": "Appy the artwork as the MPRIS background and blur it", "default": true + }, + "blacklist": { + "type": "array", + "description": "Mpris players to be ignored, without the bus name prefix", + "default": [], + "items": { + "type": "string", + "description": "Basename of mpris bus name, Uses Regex." + } } } }, diff --git a/src/controlCenter/widgets/mpris/mpris.vala b/src/controlCenter/widgets/mpris/mpris.vala index 4c4cb98b..605f5475 100644 --- a/src/controlCenter/widgets/mpris/mpris.vala +++ b/src/controlCenter/widgets/mpris/mpris.vala @@ -3,6 +3,7 @@ namespace SwayNotificationCenter.Widgets.Mpris { int image_size; int image_radius; bool blur; + string[] blacklist; } public class Mpris : BaseWidget { @@ -99,6 +100,13 @@ namespace SwayNotificationCenter.Widgets.Mpris { bool blur_found; bool? blur = get_prop (config, "blur", out blur_found); if (blur_found) mpris_config.blur = blur; + + Json.Array ? blacklist = get_prop_array (config, "blacklist"); + if (blacklist != null) { + mpris_config.blacklist = new string[blacklist.get_length ()]; + for (int i = 0; i < blacklist.get_length (); i++) + mpris_config.blacklist[i] = blacklist.get_string_element (i); + } } hide (); @@ -174,6 +182,7 @@ namespace SwayNotificationCenter.Widgets.Mpris { string[] names = dbus_iface.list_names (); foreach (string name in names) { if (!name.has_prefix (MPRIS_PREFIX)) continue; + if (is_blacklisted (name)) return; if (check_player_exists (name)) return; MprisSource ? source = MprisSource.get_player (name); if (source != null) add_player (name, source); @@ -185,12 +194,22 @@ namespace SwayNotificationCenter.Widgets.Mpris { remove_player (name); return; } + if (is_blacklisted (name)) return; if (check_player_exists (name)) return; MprisSource ? source = MprisSource.get_player (name); if (source != null) add_player (name, source); }); } + private bool is_blacklisted (string name) { + foreach (string blacklistedPattern in mpris_config.blacklist) { + string fullPattern = MPRIS_PREFIX + blacklistedPattern; + if (GLib.Regex.match_simple (fullPattern, name)) + return true; + } + return false; + } + private bool check_player_exists (string name) { foreach (string name_check in players.get_keys_as_array ()) { if (name_check.has_prefix (name) From 49abb2e8f1d6de6a7d87d817b6b4c60d1219f025 Mon Sep 17 00:00:00 2001 From: giskard Date: Tue, 14 May 2024 13:02:48 +0800 Subject: [PATCH 2/3] man/mpris: sync manual for blur, blacklist --- man/swaync.5.scd | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/man/swaync.5.scd b/man/swaync.5.scd index ada6f9b7..bae54a2c 100644 --- a/man/swaync.5.scd +++ b/man/swaync.5.scd @@ -330,6 +330,17 @@ config file to be able to detect config errors optional: true ++ default: 12 ++ description: The border radius of the album art. ++ + blur: ++ + type: bool ++ + optional: true ++ + default: true ++ + description: Appy the artwork as the MPRIS background and blur it ++ + blacklist: ++ + type: array ++ + optional: true ++ + default: [] ++ + description: Mpris players to be ignored, without the bus name prefix. ++ + you may check with `qdbus|grep -i mpris` ++ description: A widget that displays multiple music players. ++ *menubar*++ type: object ++ @@ -595,7 +606,8 @@ config file to be able to detect config errors }, "mpris": { "image-size": 96, - "image-radius": 12 + "image-radius": 12, + "blacklist": ["playerctld"] }, "menubar": { "menu#power": { From 0f4becc51e0e29594fe4dad37c23495b232de85c Mon Sep 17 00:00:00 2001 From: giskard Date: Tue, 14 May 2024 13:49:14 +0800 Subject: [PATCH 3/3] fix mpris: continue in foreach in setup_mpris() --- src/controlCenter/widgets/mpris/mpris.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controlCenter/widgets/mpris/mpris.vala b/src/controlCenter/widgets/mpris/mpris.vala index 605f5475..08ffe80a 100644 --- a/src/controlCenter/widgets/mpris/mpris.vala +++ b/src/controlCenter/widgets/mpris/mpris.vala @@ -182,8 +182,8 @@ namespace SwayNotificationCenter.Widgets.Mpris { string[] names = dbus_iface.list_names (); foreach (string name in names) { if (!name.has_prefix (MPRIS_PREFIX)) continue; - if (is_blacklisted (name)) return; - if (check_player_exists (name)) return; + if (is_blacklisted (name)) continue; + if (check_player_exists (name)) continue; MprisSource ? source = MprisSource.get_player (name); if (source != null) add_player (name, source); }