code cleanup: deduplicate volume icon logic, mpris time format, sink list
This commit is contained in:
parent
5dc966c916
commit
5dcea32dc3
3 changed files with 30 additions and 49 deletions
|
|
@ -14,13 +14,10 @@ Text {
|
||||||
text: _displayIcon
|
text: _displayIcon
|
||||||
|
|
||||||
onIconChanged: {
|
onIconChanged: {
|
||||||
if (_crossfade.running) {
|
|
||||||
_pendingIcon = icon;
|
|
||||||
} else {
|
|
||||||
_pendingIcon = icon;
|
_pendingIcon = icon;
|
||||||
|
if (!_crossfade.running)
|
||||||
_crossfade.start();
|
_crossfade.start();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
SequentialAnimation {
|
SequentialAnimation {
|
||||||
id: _crossfade
|
id: _crossfade
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,12 @@ M.PopupPanel {
|
||||||
|
|
||||||
required property MprisPlayer player
|
required property MprisPlayer player
|
||||||
|
|
||||||
// Album art
|
function _fmtTime(ms) {
|
||||||
|
const s = Math.floor(ms / 1000);
|
||||||
|
const m = Math.floor(s / 60);
|
||||||
|
return m + ":" + String(s % 60).padStart(2, "0");
|
||||||
|
}
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
width: menuWindow.panelWidth
|
width: menuWindow.panelWidth
|
||||||
height: _artImg.status === Image.Ready ? 140 : 60
|
height: _artImg.status === Image.Ready ? 140 : 60
|
||||||
|
|
@ -28,7 +33,6 @@ M.PopupPanel {
|
||||||
visible: status === Image.Ready
|
visible: status === Image.Ready
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gradient fade at the bottom so art blends into the panel
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
|
|
@ -41,7 +45,6 @@ M.PopupPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback icon when no art
|
|
||||||
Text {
|
Text {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
text: "\uF001"
|
text: "\uF001"
|
||||||
|
|
@ -52,7 +55,6 @@ M.PopupPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track info
|
|
||||||
Item {
|
Item {
|
||||||
width: menuWindow.panelWidth
|
width: menuWindow.panelWidth
|
||||||
height: titleCol.implicitHeight + 8
|
height: titleCol.implicitHeight + 8
|
||||||
|
|
@ -82,7 +84,7 @@ M.PopupPanel {
|
||||||
const p = menuWindow.player;
|
const p = menuWindow.player;
|
||||||
if (!p) return "";
|
if (!p) return "";
|
||||||
const artist = Array.isArray(p.trackArtists) ? p.trackArtists.join(", ") : (p.trackArtists || "");
|
const artist = Array.isArray(p.trackArtists) ? p.trackArtists.join(", ") : (p.trackArtists || "");
|
||||||
return [artist, p.trackAlbum].filter(s => s).join(" — ");
|
return [artist, p.trackAlbum].filter(s => s).join(" \u2014 ");
|
||||||
}
|
}
|
||||||
color: M.Theme.base04
|
color: M.Theme.base04
|
||||||
font.pixelSize: M.Theme.fontSize - 1
|
font.pixelSize: M.Theme.fontSize - 1
|
||||||
|
|
@ -93,7 +95,6 @@ M.PopupPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Progress bar
|
|
||||||
Item {
|
Item {
|
||||||
width: menuWindow.panelWidth
|
width: menuWindow.panelWidth
|
||||||
height: 20
|
height: 20
|
||||||
|
|
@ -102,39 +103,25 @@ M.PopupPanel {
|
||||||
readonly property real dur: menuWindow.player?.length ?? 0
|
readonly property real dur: menuWindow.player?.length ?? 0
|
||||||
readonly property real frac: dur > 0 ? pos / dur : 0
|
readonly property real frac: dur > 0 ? pos / dur : 0
|
||||||
|
|
||||||
// Time labels
|
|
||||||
Text {
|
Text {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: 12
|
anchors.leftMargin: 12
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
text: _fmt(parent.pos)
|
text: menuWindow._fmtTime(parent.pos)
|
||||||
color: M.Theme.base04
|
color: M.Theme.base04
|
||||||
font.pixelSize: M.Theme.fontSize - 2
|
font.pixelSize: M.Theme.fontSize - 2
|
||||||
font.family: M.Theme.fontFamily
|
font.family: M.Theme.fontFamily
|
||||||
|
|
||||||
function _fmt(ms) {
|
|
||||||
const s = Math.floor(ms / 1000);
|
|
||||||
const m = Math.floor(s / 60);
|
|
||||||
return m + ":" + String(s % 60).padStart(2, "0");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Text {
|
Text {
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.rightMargin: 12
|
anchors.rightMargin: 12
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
text: _fmt(parent.dur)
|
text: menuWindow._fmtTime(parent.dur)
|
||||||
color: M.Theme.base04
|
color: M.Theme.base04
|
||||||
font.pixelSize: M.Theme.fontSize - 2
|
font.pixelSize: M.Theme.fontSize - 2
|
||||||
font.family: M.Theme.fontFamily
|
font.family: M.Theme.fontFamily
|
||||||
|
|
||||||
function _fmt(ms) {
|
|
||||||
const s = Math.floor(ms / 1000);
|
|
||||||
const m = Math.floor(s / 60);
|
|
||||||
return m + ":" + String(s % 60).padStart(2, "0");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bar
|
|
||||||
Item {
|
Item {
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|
@ -155,7 +142,6 @@ M.PopupPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transport controls
|
|
||||||
Item {
|
Item {
|
||||||
width: menuWindow.panelWidth
|
width: menuWindow.panelWidth
|
||||||
height: 36
|
height: 36
|
||||||
|
|
@ -164,7 +150,6 @@ M.PopupPanel {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
spacing: 24
|
spacing: 24
|
||||||
|
|
||||||
// Previous
|
|
||||||
Text {
|
Text {
|
||||||
text: "\uF048"
|
text: "\uF048"
|
||||||
color: menuWindow.player?.canGoPrevious ? M.Theme.base05 : M.Theme.base03
|
color: menuWindow.player?.canGoPrevious ? M.Theme.base05 : M.Theme.base03
|
||||||
|
|
@ -180,7 +165,6 @@ M.PopupPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Play/Pause
|
|
||||||
Text {
|
Text {
|
||||||
text: menuWindow.player?.playbackState === MprisPlaybackState.Playing ? "\uF04C" : "\uF04B"
|
text: menuWindow.player?.playbackState === MprisPlaybackState.Playing ? "\uF04C" : "\uF04B"
|
||||||
color: M.Theme.base0E
|
color: M.Theme.base0E
|
||||||
|
|
@ -195,7 +179,6 @@ M.PopupPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next
|
|
||||||
Text {
|
Text {
|
||||||
text: "\uF051"
|
text: "\uF051"
|
||||||
color: menuWindow.player?.canGoNext ? M.Theme.base05 : M.Theme.base03
|
color: menuWindow.player?.canGoNext ? M.Theme.base05 : M.Theme.base03
|
||||||
|
|
@ -213,7 +196,6 @@ M.PopupPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Player name
|
|
||||||
Item {
|
Item {
|
||||||
width: menuWindow.panelWidth
|
width: menuWindow.panelWidth
|
||||||
height: 20
|
height: 20
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import "." as M
|
||||||
M.BarSection {
|
M.BarSection {
|
||||||
id: root
|
id: root
|
||||||
spacing: M.Theme.moduleSpacing
|
spacing: M.Theme.moduleSpacing
|
||||||
// No tooltip — the panel replaces it
|
|
||||||
tooltip: ""
|
tooltip: ""
|
||||||
|
|
||||||
PwObjectTracker {
|
PwObjectTracker {
|
||||||
|
|
@ -17,20 +16,32 @@ M.BarSection {
|
||||||
readonly property var sink: Pipewire.defaultAudioSink
|
readonly property var sink: Pipewire.defaultAudioSink
|
||||||
readonly property real volume: sink?.audio?.volume ?? 0
|
readonly property real volume: sink?.audio?.volume ?? 0
|
||||||
readonly property bool muted: sink?.audio?.muted ?? false
|
readonly property bool muted: sink?.audio?.muted ?? false
|
||||||
|
readonly property string _volumeIcon: muted ? "\uF026" : (volume > 0.5 ? "\uF028" : (volume > 0 ? "\uF027" : "\uF026"))
|
||||||
|
readonly property color _volumeColor: muted ? M.Theme.base04 : M.Theme.base0E
|
||||||
|
|
||||||
|
readonly property var _sinkList: {
|
||||||
|
const sinks = [];
|
||||||
|
if (Pipewire.nodes) {
|
||||||
|
for (const node of Pipewire.nodes.values)
|
||||||
|
if (!node.isStream && node.isSink)
|
||||||
|
sinks.push(node);
|
||||||
|
}
|
||||||
|
return sinks;
|
||||||
|
}
|
||||||
|
|
||||||
property bool _expanded: false
|
property bool _expanded: false
|
||||||
property bool _panelHovered: false
|
property bool _panelHovered: false
|
||||||
readonly property bool _showPanel: root._hovered || _panelHovered || _expanded
|
readonly property bool _showPanel: root._hovered || _panelHovered || _expanded
|
||||||
|
|
||||||
M.BarIcon {
|
M.BarIcon {
|
||||||
icon: root.muted ? "\uF026" : (root.volume > 0.5 ? "\uF028" : (root.volume > 0 ? "\uF027" : "\uF026"))
|
icon: root._volumeIcon
|
||||||
color: root.muted ? M.Theme.base04 : M.Theme.base0E
|
color: root._volumeColor
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
}
|
}
|
||||||
M.BarLabel {
|
M.BarLabel {
|
||||||
label: Math.round(root.volume * 100) + "%"
|
label: Math.round(root.volume * 100) + "%"
|
||||||
minText: "100%"
|
minText: "100%"
|
||||||
color: root.muted ? M.Theme.base04 : M.Theme.base0E
|
color: root._volumeColor
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,8 +151,8 @@ M.BarSection {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: 12
|
anchors.leftMargin: 12
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
text: root.muted ? "\uF026" : (root.volume > 0.5 ? "\uF028" : "\uF027")
|
text: root._volumeIcon
|
||||||
color: root.muted ? M.Theme.base04 : M.Theme.base0E
|
color: root._volumeColor
|
||||||
font.pixelSize: M.Theme.fontSize + 2
|
font.pixelSize: M.Theme.fontSize + 2
|
||||||
font.family: M.Theme.iconFontFamily
|
font.family: M.Theme.iconFontFamily
|
||||||
|
|
||||||
|
|
@ -171,7 +182,7 @@ M.BarSection {
|
||||||
Rectangle {
|
Rectangle {
|
||||||
width: parent.width * Math.min(1, Math.max(0, root.volume))
|
width: parent.width * Math.min(1, Math.max(0, root.volume))
|
||||||
height: parent.height
|
height: parent.height
|
||||||
color: root.muted ? M.Theme.base04 : M.Theme.base0E
|
color: root._volumeColor
|
||||||
radius: 3
|
radius: 3
|
||||||
|
|
||||||
Behavior on width { NumberAnimation { duration: 80 } }
|
Behavior on width { NumberAnimation { duration: 80 } }
|
||||||
|
|
@ -249,16 +260,7 @@ M.BarSection {
|
||||||
}
|
}
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
model: {
|
model: root._sinkList
|
||||||
const sinks = [];
|
|
||||||
if (Pipewire.nodes) {
|
|
||||||
for (const node of Pipewire.nodes.values) {
|
|
||||||
if (!node.isStream && node.isSink)
|
|
||||||
sinks.push(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sinks;
|
|
||||||
}
|
|
||||||
|
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
required property var modelData
|
required property var modelData
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue