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 blacklist support #390

Merged
merged 15 commits into from
Jul 24, 2024
12 changes: 11 additions & 1 deletion man/swaync.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,15 @@ config file to be able to detect config errors
optional: true ++
default: 12 ++
description: The border radius of the album art. ++
blacklist: ++
type: array ++
optional: true ++
default: [] ++
description: Audio sources for the mpris widget to ignore. ++
Valid array values: ++
type: string ++
description: Audio source/app name. Regex alowed. Hint ++
`$ qdbus | grep mpris` to find source names. ++
description: A widget that displays multiple music players. ++
*menubar*++
type: object ++
Expand Down Expand Up @@ -595,7 +604,8 @@ config file to be able to detect config errors
},
"mpris": {
"image-size": 96,
"image-radius": 12
"image-radius": 12,
"blacklist": ["playerctld"]
ErikReider marked this conversation as resolved.
Show resolved Hide resolved
},
"menubar": {
"menu#power": {
Expand Down
1 change: 1 addition & 0 deletions src/config.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"mpris": {
"image-size": 96,
"image-radius": 12
"blacklist": []
},
"buttons-grid": {
"actions": [
Expand Down
28 changes: 28 additions & 0 deletions 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,18 @@ 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++) {
if (blacklist.get_element (i).get_node_type () != Json.NodeType.VALUE) {
warning ("Blacklist entries should be strings");
continue;
}
mpris_config.blacklist[i] = blacklist.get_string_element (i);
}
}
}

hide ();
Expand Down Expand Up @@ -174,6 +187,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)) continue;
if (check_player_exists (name)) return;
abmantis marked this conversation as resolved.
Show resolved Hide resolved
MprisSource ? source = MprisSource.get_player (name);
if (source != null) add_player (name, source);
Expand All @@ -185,6 +199,7 @@ 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);
Expand Down Expand Up @@ -243,5 +258,18 @@ namespace SwayNotificationCenter.Widgets.Mpris {
0, children_length - 1);
carousel.scroll_to (children.nth_data (position));
}

private bool is_blacklisted (string name) {
foreach (string blacklistedPattern in mpris_config.blacklist) {
if (blacklistedPattern == null || blacklistedPattern.length == 0) {
continue;
}
if (GLib.Regex.match_simple (blacklistedPattern, name, GLib.RegexCompileFlags.JAVASCRIPT_COMPAT, 0)) {
message ("\"%s\" is blacklisted", name);
return true;
}
}
return false;
}
}
}
Loading