Unverified Commit f0268d71 authored by Aidan Epstein's avatar Aidan Epstein Committed by GitHub

Add loop-carousel option to mpris. (#570)

parent d93d60e4
...@@ -354,6 +354,11 @@ config file to be able to detect config errors ...@@ -354,6 +354,11 @@ config file to be able to detect config errors
hidden, always visible, or only visible ++ hidden, always visible, or only visible ++
when a valid album art is provided. ++ when a valid album art is provided. ++
enum: ["right", "left"] ++ enum: ["right", "left"] ++
loop-carousel: ++
type: bool ++
optional: true ++
default: false ++
description: Whether to loop through the mpris carousel. ++
description: A widget that displays multiple music players. ++ description: A widget that displays multiple music players. ++
*menubar*++ *menubar*++
type: object ++ type: object ++
...@@ -615,7 +620,8 @@ config file to be able to detect config errors ...@@ -615,7 +620,8 @@ config file to be able to detect config errors
"mpris": { "mpris": {
"blacklist": ["playerctld"], "blacklist": ["playerctld"],
"autohide": true, "autohide": true,
"show-album-art": "always" "show-album-art": "always",
"loop-carousel": false
}, },
"menubar": { "menubar": {
"menu#power": { "menu#power": {
......
...@@ -75,7 +75,8 @@ ...@@ -75,7 +75,8 @@
"mpris": { "mpris": {
"blacklist": [], "blacklist": [],
"autohide": false, "autohide": false,
"show-album-art": "always" "show-album-art": "always",
"loop-carousel": false
}, },
"buttons-grid": { "buttons-grid": {
"actions": [ "actions": [
......
...@@ -421,6 +421,11 @@ ...@@ -421,6 +421,11 @@
"description": "Whether or not the album art should be hidden, always visible, or only visible when a valid album art is provided.", "description": "Whether or not the album art should be hidden, always visible, or only visible when a valid album art is provided.",
"default": "always", "default": "always",
"enum": ["always", "when-available", "never"] "enum": ["always", "when-available", "never"]
},
"loop-carousel": {
"type": "boolean",
"description": "Whether to loop through the mpris carousel.",
"default": "false"
} }
} }
}, },
......
...@@ -21,6 +21,7 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -21,6 +21,7 @@ namespace SwayNotificationCenter.Widgets.Mpris {
AlbumArtState show_album_art; AlbumArtState show_album_art;
bool autohide; bool autohide;
string[] blacklist; string[] blacklist;
bool loop_carousel;
} }
public class Mpris : BaseWidget { public class Mpris : BaseWidget {
...@@ -48,6 +49,7 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -48,6 +49,7 @@ namespace SwayNotificationCenter.Widgets.Mpris {
image_size = -1, image_size = -1,
show_album_art = AlbumArtState.ALWAYS, show_album_art = AlbumArtState.ALWAYS,
autohide = false, autohide = false,
loop_carousel = false,
}; };
public Mpris (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) { public Mpris (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
...@@ -82,8 +84,8 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -82,8 +84,8 @@ namespace SwayNotificationCenter.Widgets.Mpris {
button_next.sensitive = false; button_next.sensitive = false;
return; return;
} }
button_prev.sensitive = index > 0; button_prev.sensitive = (index > 0) || mpris_config.loop_carousel;
button_next.sensitive = index < carousel.n_pages - 1; button_next.sensitive = (index < carousel.n_pages - 1) || mpris_config.loop_carousel;
}); });
carousel_box.append (button_prev); carousel_box.append (button_prev);
...@@ -128,6 +130,11 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -128,6 +130,11 @@ namespace SwayNotificationCenter.Widgets.Mpris {
bool autohide_found; bool autohide_found;
bool? autohide = get_prop<bool> (config, "autohide", out autohide_found); bool? autohide = get_prop<bool> (config, "autohide", out autohide_found);
if (autohide_found) mpris_config.autohide = autohide; if (autohide_found) mpris_config.autohide = autohide;
// Get loop
bool loop_carousel_found;
bool? loop_carousel = get_prop<bool> (config, "loop-carousel", out loop_carousel_found);
if (loop_carousel_found) mpris_config.loop_carousel = loop_carousel;
} }
hide (); hide ();
...@@ -253,8 +260,13 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -253,8 +260,13 @@ namespace SwayNotificationCenter.Widgets.Mpris {
private void change_carousel_position (int delta) { private void change_carousel_position (int delta) {
uint children_length = carousel.n_pages; uint children_length = carousel.n_pages;
if (children_length == 0) return; if (children_length == 0) return;
uint position = ((uint) carousel.position + delta) uint position;
.clamp (0, (children_length - 1)); if (mpris_config.loop_carousel) {
position = ((uint) carousel.position + delta) % children_length;
} else {
position = ((uint) carousel.position + delta)
.clamp (0, (children_length - 1));
}
carousel.scroll_to (carousel.get_nth_page (position), true); carousel.scroll_to (carousel.get_nth_page (position), true);
} }
......
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