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
|
|
@ -7,7 +7,6 @@ import "." as M
|
|||
M.BarSection {
|
||||
id: root
|
||||
spacing: M.Theme.moduleSpacing
|
||||
// No tooltip — the panel replaces it
|
||||
tooltip: ""
|
||||
|
||||
PwObjectTracker {
|
||||
|
|
@ -17,20 +16,32 @@ M.BarSection {
|
|||
readonly property var sink: Pipewire.defaultAudioSink
|
||||
readonly property real volume: sink?.audio?.volume ?? 0
|
||||
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 _panelHovered: false
|
||||
readonly property bool _showPanel: root._hovered || _panelHovered || _expanded
|
||||
|
||||
M.BarIcon {
|
||||
icon: root.muted ? "\uF026" : (root.volume > 0.5 ? "\uF028" : (root.volume > 0 ? "\uF027" : "\uF026"))
|
||||
color: root.muted ? M.Theme.base04 : M.Theme.base0E
|
||||
icon: root._volumeIcon
|
||||
color: root._volumeColor
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
M.BarLabel {
|
||||
label: Math.round(root.volume * 100) + "%"
|
||||
minText: "100%"
|
||||
color: root.muted ? M.Theme.base04 : M.Theme.base0E
|
||||
color: root._volumeColor
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
|
|
@ -140,8 +151,8 @@ M.BarSection {
|
|||
anchors.left: parent.left
|
||||
anchors.leftMargin: 12
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: root.muted ? "\uF026" : (root.volume > 0.5 ? "\uF028" : "\uF027")
|
||||
color: root.muted ? M.Theme.base04 : M.Theme.base0E
|
||||
text: root._volumeIcon
|
||||
color: root._volumeColor
|
||||
font.pixelSize: M.Theme.fontSize + 2
|
||||
font.family: M.Theme.iconFontFamily
|
||||
|
||||
|
|
@ -171,7 +182,7 @@ M.BarSection {
|
|||
Rectangle {
|
||||
width: parent.width * Math.min(1, Math.max(0, root.volume))
|
||||
height: parent.height
|
||||
color: root.muted ? M.Theme.base04 : M.Theme.base0E
|
||||
color: root._volumeColor
|
||||
radius: 3
|
||||
|
||||
Behavior on width { NumberAnimation { duration: 80 } }
|
||||
|
|
@ -249,16 +260,7 @@ M.BarSection {
|
|||
}
|
||||
|
||||
Repeater {
|
||||
model: {
|
||||
const sinks = [];
|
||||
if (Pipewire.nodes) {
|
||||
for (const node of Pipewire.nodes.values) {
|
||||
if (!node.isStream && node.isSink)
|
||||
sinks.push(node);
|
||||
}
|
||||
}
|
||||
return sinks;
|
||||
}
|
||||
model: root._sinkList
|
||||
|
||||
delegate: Item {
|
||||
required property var modelData
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue