Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mpris: add blacklist support, fix setup_mpris(), sync doc #430

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion man/swaync.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -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 ++
Expand Down Expand Up @@ -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": {
Expand Down
9 changes: 9 additions & 0 deletions src/configSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}
},
Expand Down
21 changes: 20 additions & 1 deletion src/controlCenter/widgets/mpris/mpris.vala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace SwayNotificationCenter.Widgets.Mpris {
int image_size;
int image_radius;
bool blur;
string[] blacklist;
}

public class Mpris : BaseWidget {
Expand Down Expand Up @@ -99,6 +100,13 @@ namespace SwayNotificationCenter.Widgets.Mpris {
bool blur_found;
bool? blur = get_prop<bool> (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 ();
Expand Down Expand Up @@ -174,7 +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 (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);
}
Expand All @@ -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)
Expand Down