diff --git a/modules/bar/Bar.qml b/modules/bar/Bar.qml index 961775d..01c92e2 100644 --- a/modules/bar/Bar.qml +++ b/modules/bar/Bar.qml @@ -5,7 +5,6 @@ import Quickshell import "components" import "components/bluetooth" import "components/hyprland" -import "components/mpris" import "components/tray" Scope { diff --git a/modules/bar/components/Mpris.qml b/modules/bar/components/Mpris.qml new file mode 100644 index 0000000..675a1b9 --- /dev/null +++ b/modules/bar/components/Mpris.qml @@ -0,0 +1,48 @@ +pragma ComponentBehavior: Bound + +import qs.config +import qs.services +import qs.widgets +import QtQuick + +StyledButton { + id: root + + onClicked: { + if (!Mpris.active.canTogglePlaying) { + return; + } + if (Mpris.active.isPlaying) { + Mpris.active.pause(); + } else { + Mpris.active.play(); + } + } + + content: StyledText { + id: text + text: `${Mpris.active?.isPlaying ? "" : ""} ${Mpris.active?.trackTitle} - ${Mpris.active?.trackArtist}` + + font.pixelSize: Dimensions.mpris.fontSize + + states: State { + name: "hovered" + when: root.containsMouse + PropertyChanges { + text { + color: Theme.palette.base300 + } + } + } + transitions: Transition { + from: "" + to: "hovered" + reversible: true + ColorAnimation { + properties: "color" + duration: 200 + easing.type: Easing.InOutCubic + } + } + } +} diff --git a/modules/bar/components/mpris/Mpris.qml b/modules/bar/components/mpris/Mpris.qml deleted file mode 100644 index e9ff3c0..0000000 --- a/modules/bar/components/mpris/Mpris.qml +++ /dev/null @@ -1,29 +0,0 @@ -import Quickshell.Services.Mpris -import QtQuick - -Item { - id: root - - property int currentIndex: 0 - property var players: Mpris.players - - Repeater { - id: players - model: Mpris.players.values.filter(item => item != null) - - Player { - - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter - - visible: index === root.currentIndex && modelData.canControl - - onNextPlayer: { - currentIndex = (currentIndex + 1) % players.count; - } - onPreviousPlayer: { - currentIndex = (currentIndex - 1 + players.count) % players.count; - } - } - } -} diff --git a/modules/bar/components/mpris/Player.qml b/modules/bar/components/mpris/Player.qml deleted file mode 100644 index 131b0f1..0000000 --- a/modules/bar/components/mpris/Player.qml +++ /dev/null @@ -1,64 +0,0 @@ -import qs.config -import qs.widgets -import Quickshell.Services.Mpris -import QtQuick - -Loader { - id: root - required property MprisPlayer modelData - required property int index - - signal nextPlayer - signal previousPlayer - - sourceComponent: player - property Component player: StyledButton { - id: button - - onClicked: { - if (!root.modelData.canTogglePlaying) { - return; - } - if (root.modelData.isPlaying) { - root.modelData.pause(); - } else { - root.modelData.play(); - } - } - - onWheel: event => { - if (event.angleDelta.y > 0) { - root.nextPlayer(); - } else if (event.angleDelta.y < 0) { - root.previousPlayer(); - } - } - - content: StyledText { - id: text - text: `${root.modelData.isPlaying ? "" : ""} ${root.modelData.trackTitle} - ${root.modelData.trackArtist}` - - font.pixelSize: Dimensions.mpris.fontSize - - states: State { - name: "hovered" - when: button.containsMouse - PropertyChanges { - text { - color: Theme.palette.base300 - } - } - } - transitions: Transition { - from: "" - to: "hovered" - reversible: true - ColorAnimation { - properties: "color" - duration: 200 - easing.type: Easing.InOutCubic - } - } - } - } -} diff --git a/services/Mpris.qml b/services/Mpris.qml new file mode 100644 index 0000000..54648ae --- /dev/null +++ b/services/Mpris.qml @@ -0,0 +1,12 @@ +pragma Singleton + +import QtQuick +import Quickshell +import Quickshell.Services.Mpris + +Singleton { + id: root + + property list players: Mpris.players.values + property MprisPlayer active: players.filter(player => player.isPlaying)[0] ?? players[0] +}