Add media source switcher

This commit is contained in:
David Heinemeier Hansson
2026-05-22 09:46:17 +02:00
parent 72ee480599
commit d0795793a3
+92 -4
View File
@@ -9,6 +9,7 @@ BarWidget {
readonly property var mediaService: bar && bar.shell ? bar.shell.firstPartyServiceFor("omarchy.media") : null
readonly property var activePlayer: mediaService ? mediaService.activePlayer : null
readonly property var sourcePlayers: mediaService ? mediaService.sourcePlayers : []
readonly property bool hasMedia: activePlayer !== null && (activePlayer.trackTitle || activePlayer.trackArtist)
readonly property string playIcon: activePlayer && activePlayer.isPlaying ? "󰏤" : "󰐊"
@@ -187,7 +188,7 @@ BarWidget {
verticalPadding: Style.spacing.controlPaddingY
enabled: root.activePlayer && root.activePlayer.canGoPrevious
opacity: enabled ? 1.0 : 0.4
onClicked: if (root.mediaService) root.mediaService.runAction("previous", false)
onClicked: if (root.mediaService) root.mediaService.runAction("previous", false, root.mediaService.playerKey(root.activePlayer))
}
Button {
@@ -196,9 +197,9 @@ BarWidget {
horizontalPadding: Style.spacing.panelGap
verticalPadding: Style.spacing.controlPaddingY
iconSize: Style.font.iconLarge
enabled: root.activePlayer && root.activePlayer.canTogglePlaying
enabled: root.activePlayer && (root.activePlayer.canTogglePlaying || root.activePlayer.canPlay || root.activePlayer.canPause)
opacity: enabled ? 1.0 : 0.4
onClicked: if (root.mediaService) root.mediaService.runAction("playPause", false)
onClicked: if (root.mediaService) root.mediaService.runAction("playPause", false, root.mediaService.playerKey(root.activePlayer))
}
Button {
@@ -208,7 +209,94 @@ BarWidget {
verticalPadding: Style.spacing.controlPaddingY
enabled: root.activePlayer && root.activePlayer.canGoNext
opacity: enabled ? 1.0 : 0.4
onClicked: if (root.mediaService) root.mediaService.runAction("next", false)
onClicked: if (root.mediaService) root.mediaService.runAction("next", false, root.mediaService.playerKey(root.activePlayer))
}
}
PanelSeparator {
visible: root.sourcePlayers.length > 1
foreground: root.bar.foreground
}
Column {
id: sourceList
visible: root.sourcePlayers.length > 1
width: parent.width
spacing: Style.space(4)
Repeater {
model: root.sourcePlayers
Rectangle {
id: sourceRow
required property var modelData
readonly property var player: modelData
readonly property bool selected: root.activePlayer && player
&& root.mediaService.playerKey(root.activePlayer) === root.mediaService.playerKey(player)
readonly property string sourceTitle: player ? (player.trackTitle || player.identity || player.desktopEntry || "Media source") : "Media source"
readonly property string sourceDetail: player && player.trackArtist ? player.trackArtist : (player && player.identity ? player.identity : "")
width: sourceList.width
height: sourceInner.implicitHeight + Style.space(10)
radius: Style.spacing.labelGap
color: selected ? Style.selectedFillFor(root.bar.foreground, Color.accent) : "transparent"
border.color: selected ? Style.selectedBorderFor(root.bar.foreground, Color.accent) : "transparent"
border.width: selected ? Style.normalBorderWidth : 0
Row {
id: sourceInner
anchors.left: parent.left
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: Style.space(8)
anchors.rightMargin: Style.space(8)
spacing: Style.space(8)
Text {
text: sourceRow.player && sourceRow.player.isPlaying ? "󰏤" : "󰐊"
color: root.bar.foreground
font.family: root.bar.fontFamily
font.pixelSize: Style.font.body
width: Style.space(18)
horizontalAlignment: Text.AlignHCenter
anchors.verticalCenter: parent.verticalCenter
}
Column {
width: parent.width - Style.space(26)
spacing: Style.space(1)
anchors.verticalCenter: parent.verticalCenter
Text {
text: sourceRow.sourceTitle
color: root.bar.foreground
font.family: root.bar.fontFamily
font.pixelSize: Style.font.bodySmall
font.bold: sourceRow.selected
elide: Text.ElideRight
width: parent.width
}
Text {
text: sourceRow.sourceDetail
color: Qt.darker(root.bar.foreground, 1.5)
font.family: root.bar.fontFamily
font.pixelSize: Style.font.caption
elide: Text.ElideRight
width: parent.width
visible: text !== ""
}
}
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: if (root.mediaService) root.mediaService.selectPlayer(root.mediaService.playerKey(sourceRow.player))
}
}
}
}
}