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
hidden, always visible, or only visible ++
when a valid album art is provided. ++
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. ++
*menubar*++
type: object ++
......@@ -615,7 +620,8 @@ config file to be able to detect config errors
"mpris": {
"blacklist": ["playerctld"],
"autohide": true,
"show-album-art": "always"
"show-album-art": "always",
"loop-carousel": false
},
"menubar": {
"menu#power": {
......
......@@ -75,7 +75,8 @@
"mpris": {
"blacklist": [],
"autohide": false,
"show-album-art": "always"
"show-album-art": "always",
"loop-carousel": false
},
"buttons-grid": {
"actions": [
......
......@@ -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.",
"default": "always",
"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 {
AlbumArtState show_album_art;
bool autohide;
string[] blacklist;
bool loop_carousel;
}
public class Mpris : BaseWidget {
......@@ -48,6 +49,7 @@ namespace SwayNotificationCenter.Widgets.Mpris {
image_size = -1,
show_album_art = AlbumArtState.ALWAYS,
autohide = false,
loop_carousel = false,
};
public Mpris (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
......@@ -82,8 +84,8 @@ namespace SwayNotificationCenter.Widgets.Mpris {
button_next.sensitive = false;
return;
}
button_prev.sensitive = index > 0;
button_next.sensitive = index < carousel.n_pages - 1;
button_prev.sensitive = (index > 0) || mpris_config.loop_carousel;
button_next.sensitive = (index < carousel.n_pages - 1) || mpris_config.loop_carousel;
});
carousel_box.append (button_prev);
......@@ -128,6 +130,11 @@ namespace SwayNotificationCenter.Widgets.Mpris {
bool autohide_found;
bool? autohide = get_prop<bool> (config, "autohide", out autohide_found);
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 ();
......@@ -253,8 +260,13 @@ namespace SwayNotificationCenter.Widgets.Mpris {
private void change_carousel_position (int delta) {
uint children_length = carousel.n_pages;
if (children_length == 0) return;
uint position = ((uint) carousel.position + delta)
.clamp (0, (children_length - 1));
uint position;
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);
}
......
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