Skip to content

Commit 01c9841

Browse files
committed
Add loop option to mpris.
1 parent f55b433 commit 01c9841

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

man/swaync.5.scd

+7-1
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ config file to be able to detect config errors
345345
default: false ++
346346
description: Whether to hide the widget when the ++
347347
player has no metadata. ++
348+
loop: ++
349+
type: bool ++
350+
optional: true ++
351+
default: false ++
352+
description: Whether to loop through the mpris carousel. ++
348353
description: A widget that displays multiple music players. ++
349354
*menubar*++
350355
type: object ++
@@ -611,7 +616,8 @@ config file to be able to detect config errors
611616
"mpris": {
612617
"image-size": 96,
613618
"blacklist": ["playerctld"],
614-
"autohide": true
619+
"autohide": true,
620+
"loop": false
615621
},
616622
"menubar": {
617623
"menu#power": {

src/config.json.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
"mpris": {
7777
"image-size": 96,
7878
"blacklist": [],
79-
"autohide": false
79+
"autohide": false,
80+
"loop": false
8081
},
8182
"buttons-grid": {
8283
"actions": [

src/controlCenter/widgets/mpris/mpris.vala

+16-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace SwayNotificationCenter.Widgets.Mpris {
33
int image_size;
44
bool autohide;
55
string[] blacklist;
6+
bool loop;
67
}
78

89
public class Mpris : BaseWidget {
@@ -29,6 +30,7 @@ namespace SwayNotificationCenter.Widgets.Mpris {
2930
Config mpris_config = Config () {
3031
image_size = 96,
3132
autohide = false,
33+
loop = false,
3234
};
3335

3436
public Mpris (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
@@ -63,8 +65,8 @@ namespace SwayNotificationCenter.Widgets.Mpris {
6365
button_next.sensitive = false;
6466
return;
6567
}
66-
button_prev.sensitive = index > 0;
67-
button_next.sensitive = index < carousel.n_pages - 1;
68+
button_prev.sensitive = (index > 0) || mpris_config.loop;
69+
button_next.sensitive = (index < carousel.n_pages - 1) || mpris_config.loop;
6870
});
6971

7072
carousel_box.append (button_prev);
@@ -100,6 +102,11 @@ namespace SwayNotificationCenter.Widgets.Mpris {
100102
bool autohide_found;
101103
bool? autohide = get_prop<bool> (config, "autohide", out autohide_found);
102104
if (autohide_found) mpris_config.autohide = autohide;
105+
106+
// Get loop
107+
bool loop_found;
108+
bool? loop = get_prop<bool> (config, "loop", out loop_found);
109+
if (loop_found) mpris_config.loop = loop;
103110
}
104111

105112
hide ();
@@ -225,8 +232,13 @@ namespace SwayNotificationCenter.Widgets.Mpris {
225232
private void change_carousel_position (int delta) {
226233
uint children_length = carousel.n_pages;
227234
if (children_length == 0) return;
228-
uint position = ((uint) carousel.position + delta)
229-
.clamp (0, (children_length - 1));
235+
uint position;
236+
if (mpris_config.loop) {
237+
position = ((uint) carousel.position + delta) % children_length;
238+
} else {
239+
position = ((uint) carousel.position + delta)
240+
.clamp (0, (children_length - 1));
241+
}
230242
carousel.scroll_to (carousel.get_nth_page (position), true);
231243
}
232244

0 commit comments

Comments
 (0)