Players.qml
1 pragma Singleton 2 3 import "root:/widgets" 4 import Quickshell 5 import Quickshell.Io 6 import Quickshell.Services.Mpris 7 8 Singleton { 9 id: root 10 11 readonly property list<MprisPlayer> list: Mpris.players.values 12 readonly property MprisPlayer active: manualActive ?? list.find(p => p.identity === "Spotify") ?? list[0] ?? null 13 property MprisPlayer manualActive 14 15 CustomShortcut { 16 name: "mediaToggle" 17 description: "Toggle media playback" 18 onPressed: { 19 const active = root.active; 20 if (active && active.canTogglePlaying) 21 active.togglePlaying(); 22 } 23 } 24 25 CustomShortcut { 26 name: "mediaPrev" 27 description: "Previous track" 28 onPressed: { 29 const active = root.active; 30 if (active && active.canGoPrevious) 31 active.previous(); 32 } 33 } 34 35 CustomShortcut { 36 name: "mediaNext" 37 description: "Next track" 38 onPressed: { 39 const active = root.active; 40 if (active && active.canGoNext) 41 active.next(); 42 } 43 } 44 45 CustomShortcut { 46 name: "mediaStop" 47 description: "Stop media playback" 48 onPressed: root.active?.stop() 49 } 50 51 IpcHandler { 52 target: "mpris" 53 54 function getActive(prop: string): string { 55 const active = root.active; 56 return active ? active[prop] ?? "Invalid property" : "No active player"; 57 } 58 } 59 }