Unverified Commit 723645eb authored by Abílio Costa's avatar Abílio Costa Committed by GitHub

Mpris blacklist support (#390)

* Initial mpris blacklist support * Fix merge conflict * Simplify blacklist type and parse * Fix man * Trim whitespaces * Fix blacklisting when a new player appears * Remove flake.nix * Remove log * Remove comment * Address review suggestions * Fixed linter errors --------- Co-authored-by: 's avatar12thgenpenguin <cjgibb@protonmail.com> Co-authored-by: 's avatarMrPenguin07 <127086564+MrPenguin07@users.noreply.github.com> Co-authored-by: 's avatarErik Reider <35975961+ErikReider@users.noreply.github.com>
parent 653058be
......@@ -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 ++
......@@ -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"]
},
"menubar": {
"menu#power": {
......
......@@ -74,6 +74,7 @@
"mpris": {
"image-size": 96,
"image-radius": 12
"blacklist": []
},
"buttons-grid": {
"actions": [
......
......@@ -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,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 ();
......@@ -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;
MprisSource ? source = MprisSource.get_player (name);
if (source != null) add_player (name, source);
......@@ -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);
......@@ -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;
}
}
}
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