mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-30 00:12:50 -05:00
Added per app volume control (#801)
* Added per app volume control * format and lint fixes
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Services.Pipewire
|
import Quickshell.Services.Pipewire
|
||||||
import qs.Common
|
import qs.Common
|
||||||
@@ -10,8 +9,8 @@ Rectangle {
|
|||||||
id: root
|
id: root
|
||||||
|
|
||||||
property bool hasVolumeSliderInCC: {
|
property bool hasVolumeSliderInCC: {
|
||||||
const widgets = SettingsData.controlCenterWidgets || []
|
const widgets = SettingsData.controlCenterWidgets || [];
|
||||||
return widgets.some(widget => widget.id === "volumeSlider")
|
return widgets.some(widget => widget.id === "volumeSlider");
|
||||||
}
|
}
|
||||||
|
|
||||||
implicitHeight: headerRow.height + (!hasVolumeSliderInCC ? volumeSlider.height : 0) + audioContent.height + Theme.spacingM
|
implicitHeight: headerRow.height + (!hasVolumeSliderInCC ? volumeSlider.height : 0) + audioContent.height + Theme.spacingM
|
||||||
@@ -66,7 +65,7 @@ Rectangle {
|
|||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (AudioService.sink && AudioService.sink.audio) {
|
if (AudioService.sink && AudioService.sink.audio) {
|
||||||
AudioService.sink.audio.muted = !AudioService.sink.audio.muted
|
AudioService.sink.audio.muted = !AudioService.sink.audio.muted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,13 +73,17 @@ Rectangle {
|
|||||||
DankIcon {
|
DankIcon {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
name: {
|
name: {
|
||||||
if (!AudioService.sink || !AudioService.sink.audio) return "volume_off"
|
if (!AudioService.sink || !AudioService.sink.audio)
|
||||||
let muted = AudioService.sink.audio.muted
|
return "volume_off";
|
||||||
let volume = AudioService.sink.audio.volume
|
let muted = AudioService.sink.audio.muted;
|
||||||
if (muted || volume === 0.0) return "volume_off"
|
let volume = AudioService.sink.audio.volume;
|
||||||
if (volume <= 0.33) return "volume_down"
|
if (muted || volume === 0.0)
|
||||||
if (volume <= 0.66) return "volume_up"
|
return "volume_off";
|
||||||
return "volume_up"
|
if (volume <= 0.33)
|
||||||
|
return "volume_down";
|
||||||
|
if (volume <= 0.66)
|
||||||
|
return "volume_up";
|
||||||
|
return "volume_up";
|
||||||
}
|
}
|
||||||
size: Theme.iconSize
|
size: Theme.iconSize
|
||||||
color: AudioService.sink && AudioService.sink.audio && !AudioService.sink.audio.muted && AudioService.sink.audio.volume > 0 ? Theme.primary : Theme.surfaceText
|
color: AudioService.sink && AudioService.sink.audio && !AudioService.sink.audio.muted && AudioService.sink.audio.volume > 0 ? Theme.primary : Theme.surfaceText
|
||||||
@@ -101,13 +104,13 @@ Rectangle {
|
|||||||
valueOverride: actualVolumePercent
|
valueOverride: actualVolumePercent
|
||||||
thumbOutlineColor: Theme.surfaceVariant
|
thumbOutlineColor: Theme.surfaceVariant
|
||||||
|
|
||||||
onSliderValueChanged: function(newValue) {
|
onSliderValueChanged: function (newValue) {
|
||||||
if (AudioService.sink && AudioService.sink.audio) {
|
if (AudioService.sink && AudioService.sink.audio) {
|
||||||
AudioService.sink.audio.volume = newValue / 100
|
AudioService.sink.audio.volume = newValue / 100;
|
||||||
if (newValue > 0 && AudioService.sink.audio.muted) {
|
if (newValue > 0 && AudioService.sink.audio.muted) {
|
||||||
AudioService.sink.audio.muted = false
|
AudioService.sink.audio.muted = false;
|
||||||
}
|
}
|
||||||
AudioService.volumeChanged()
|
AudioService.volumeChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,22 +136,26 @@ Rectangle {
|
|||||||
model: ScriptModel {
|
model: ScriptModel {
|
||||||
values: {
|
values: {
|
||||||
const nodes = Pipewire.nodes.values.filter(node => {
|
const nodes = Pipewire.nodes.values.filter(node => {
|
||||||
return node.audio && node.isSink && !node.isStream
|
return node.audio && node.isSink && !node.isStream;
|
||||||
})
|
});
|
||||||
const pins = SettingsData.audioOutputDevicePins || {}
|
const pins = SettingsData.audioOutputDevicePins || {};
|
||||||
const pinnedName = pins["preferredOutput"]
|
const pinnedName = pins["preferredOutput"];
|
||||||
|
|
||||||
let sorted = [...nodes]
|
let sorted = [...nodes];
|
||||||
sorted.sort((a, b) => {
|
sorted.sort((a, b) => {
|
||||||
// Pinned device first
|
// Pinned device first
|
||||||
if (a.name === pinnedName && b.name !== pinnedName) return -1
|
if (a.name === pinnedName && b.name !== pinnedName)
|
||||||
if (b.name === pinnedName && a.name !== pinnedName) return 1
|
return -1;
|
||||||
|
if (b.name === pinnedName && a.name !== pinnedName)
|
||||||
|
return 1;
|
||||||
// Then active device
|
// Then active device
|
||||||
if (a === AudioService.sink && b !== AudioService.sink) return -1
|
if (a === AudioService.sink && b !== AudioService.sink)
|
||||||
if (b === AudioService.sink && a !== AudioService.sink) return 1
|
return -1;
|
||||||
return 0
|
if (b === AudioService.sink && a !== AudioService.sink)
|
||||||
})
|
return 1;
|
||||||
return sorted
|
return 0;
|
||||||
|
});
|
||||||
|
return sorted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,13 +179,13 @@ Rectangle {
|
|||||||
DankIcon {
|
DankIcon {
|
||||||
name: {
|
name: {
|
||||||
if (modelData.name.includes("bluez"))
|
if (modelData.name.includes("bluez"))
|
||||||
return "headset"
|
return "headset";
|
||||||
else if (modelData.name.includes("hdmi"))
|
else if (modelData.name.includes("hdmi"))
|
||||||
return "tv"
|
return "tv";
|
||||||
else if (modelData.name.includes("usb"))
|
else if (modelData.name.includes("usb"))
|
||||||
return "headset"
|
return "headset";
|
||||||
else
|
else
|
||||||
return "speaker"
|
return "speaker";
|
||||||
}
|
}
|
||||||
size: Theme.iconSize - 4
|
size: Theme.iconSize - 4
|
||||||
color: modelData === AudioService.sink ? Theme.primary : Theme.surfaceText
|
color: modelData === AudioService.sink ? Theme.primary : Theme.surfaceText
|
||||||
@@ -188,9 +195,9 @@ Rectangle {
|
|||||||
Column {
|
Column {
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
width: {
|
width: {
|
||||||
const iconWidth = Theme.iconSize
|
const iconWidth = Theme.iconSize;
|
||||||
const pinButtonWidth = pinOutputRow.width + Theme.spacingS * 4 + Theme.spacingM
|
const pinButtonWidth = pinOutputRow.width + Theme.spacingS * 4 + Theme.spacingM;
|
||||||
return parent.parent.width - iconWidth - parent.spacing - pinButtonWidth - Theme.spacingM * 2
|
return parent.parent.width - iconWidth - parent.spacing - pinButtonWidth - Theme.spacingM * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
@@ -222,8 +229,8 @@ Rectangle {
|
|||||||
height: 28
|
height: 28
|
||||||
radius: height / 2
|
radius: height / 2
|
||||||
color: {
|
color: {
|
||||||
const isThisDevicePinned = (SettingsData.audioOutputDevicePins || {})["preferredOutput"] === modelData.name
|
const isThisDevicePinned = (SettingsData.audioOutputDevicePins || {})["preferredOutput"] === modelData.name;
|
||||||
return isThisDevicePinned ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : Theme.withAlpha(Theme.surfaceText, 0.05)
|
return isThisDevicePinned ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : Theme.withAlpha(Theme.surfaceText, 0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
@@ -235,21 +242,21 @@ Rectangle {
|
|||||||
name: "push_pin"
|
name: "push_pin"
|
||||||
size: 16
|
size: 16
|
||||||
color: {
|
color: {
|
||||||
const isThisDevicePinned = (SettingsData.audioOutputDevicePins || {})["preferredOutput"] === modelData.name
|
const isThisDevicePinned = (SettingsData.audioOutputDevicePins || {})["preferredOutput"] === modelData.name;
|
||||||
return isThisDevicePinned ? Theme.primary : Theme.surfaceText
|
return isThisDevicePinned ? Theme.primary : Theme.surfaceText;
|
||||||
}
|
}
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
text: {
|
text: {
|
||||||
const isThisDevicePinned = (SettingsData.audioOutputDevicePins || {})["preferredOutput"] === modelData.name
|
const isThisDevicePinned = (SettingsData.audioOutputDevicePins || {})["preferredOutput"] === modelData.name;
|
||||||
return isThisDevicePinned ? "Pinned" : "Pin"
|
return isThisDevicePinned ? "Pinned" : "Pin";
|
||||||
}
|
}
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
color: {
|
color: {
|
||||||
const isThisDevicePinned = (SettingsData.audioOutputDevicePins || {})["preferredOutput"] === modelData.name
|
const isThisDevicePinned = (SettingsData.audioOutputDevicePins || {})["preferredOutput"] === modelData.name;
|
||||||
return isThisDevicePinned ? Theme.primary : Theme.surfaceText
|
return isThisDevicePinned ? Theme.primary : Theme.surfaceText;
|
||||||
}
|
}
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
}
|
}
|
||||||
@@ -259,16 +266,16 @@ Rectangle {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
const pins = JSON.parse(JSON.stringify(SettingsData.audioOutputDevicePins || {}))
|
const pins = JSON.parse(JSON.stringify(SettingsData.audioOutputDevicePins || {}));
|
||||||
const isCurrentlyPinned = pins["preferredOutput"] === modelData.name
|
const isCurrentlyPinned = pins["preferredOutput"] === modelData.name;
|
||||||
|
|
||||||
if (isCurrentlyPinned) {
|
if (isCurrentlyPinned) {
|
||||||
delete pins["preferredOutput"]
|
delete pins["preferredOutput"];
|
||||||
} else {
|
} else {
|
||||||
pins["preferredOutput"] = modelData.name
|
pins["preferredOutput"] = modelData.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingsData.set("audioOutputDevicePins", pins)
|
SettingsData.set("audioOutputDevicePins", pins);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,12 +288,186 @@ Rectangle {
|
|||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (modelData) {
|
if (modelData) {
|
||||||
Pipewire.preferredDefaultAudioSink = modelData
|
Pipewire.preferredDefaultAudioSink = modelData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Row {
|
||||||
|
id: playbackHeaderRow
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.leftMargin: Theme.spacingM
|
||||||
|
anchors.rightMargin: Theme.spacingM
|
||||||
|
height: 28
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
id: playbackHeaderText
|
||||||
|
text: I18n.tr("Playback")
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
color: Theme.surfaceVariantText
|
||||||
|
font.weight: Font.Medium
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Repeater {
|
||||||
|
model: ScriptModel {
|
||||||
|
values: {
|
||||||
|
const nodes = Pipewire.nodes.values.filter(node => {
|
||||||
|
return node.audio && node.isSink && node.isStream;
|
||||||
|
});
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delegate: Rectangle {
|
||||||
|
required property var modelData
|
||||||
|
required property int index
|
||||||
|
|
||||||
|
width: parent.width
|
||||||
|
height: 50
|
||||||
|
radius: Theme.cornerRadius
|
||||||
|
color: Theme.withAlpha(Theme.surfaceContainerHighest, Theme.popupTransparency)
|
||||||
|
border.color: modelData === AudioService.sink ? Theme.primary : Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.12)
|
||||||
|
border.width: 0
|
||||||
|
|
||||||
|
Row {
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
anchors.leftMargin: Theme.spacingM
|
||||||
|
spacing: Theme.spacingS
|
||||||
|
|
||||||
|
DankIcon {
|
||||||
|
name: "album"
|
||||||
|
size: Theme.iconSize - 4
|
||||||
|
color: !modelData.audio.muted ? Theme.primary : Theme.surfaceText
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
}
|
||||||
|
|
||||||
|
Column {
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
width: {
|
||||||
|
const iconWidth = Theme.iconSize;
|
||||||
|
return parent.parent.width - iconWidth - parent.spacing - Theme.spacingM * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
text: AudioService.displayName(modelData)
|
||||||
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
|
color: Theme.surfaceText
|
||||||
|
font.weight: modelData === AudioService.sink ? Font.Medium : Font.Normal
|
||||||
|
elide: Text.ElideRight
|
||||||
|
width: parent.width
|
||||||
|
wrapMode: Text.NoWrap
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Rectangle {
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: 120
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
width: appVolumeRow.width
|
||||||
|
height: 28
|
||||||
|
radius: height / 2
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: appVolumeRow
|
||||||
|
property color sliderTrackColor: "transparent"
|
||||||
|
anchors.centerIn: parent
|
||||||
|
|
||||||
|
height: 40
|
||||||
|
width: parent.width
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: Theme.spacingM
|
||||||
|
width: Theme.iconSize + Theme.spacingS * 2
|
||||||
|
height: Theme.iconSize + Theme.spacingS * 2
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
radius: Theme.cornerRadius
|
||||||
|
color: appIconArea.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : Theme.withAlpha(Theme.primary, 0)
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
id: appIconArea
|
||||||
|
anchors.fill: parent
|
||||||
|
visible: modelData !== null
|
||||||
|
hoverEnabled: true
|
||||||
|
cursorShape: Qt.PointingHandCursor
|
||||||
|
onClicked: {
|
||||||
|
if (modelData) {
|
||||||
|
AudioService.suppressOSD = true;
|
||||||
|
modelData.audio.muted = !modelData.audio.muted;
|
||||||
|
AudioService.suppressOSD = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DankIcon {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
name: {
|
||||||
|
if (!modelData)
|
||||||
|
return "volume_off";
|
||||||
|
|
||||||
|
let volume = modelData.audio.volume;
|
||||||
|
let muted = modelData.audio.muted;
|
||||||
|
|
||||||
|
if (muted || volume === 0.0)
|
||||||
|
return "volume_off";
|
||||||
|
if (volume <= 0.33)
|
||||||
|
return "volume_down";
|
||||||
|
if (volume <= 0.66)
|
||||||
|
return "volume_up";
|
||||||
|
return "volume_up";
|
||||||
|
}
|
||||||
|
size: Theme.iconSize
|
||||||
|
color: modelData && !modelData.audio.muted && modelData.audio.volume > 0 ? Theme.primary : Theme.surfaceText
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DankSlider {
|
||||||
|
readonly property real actualVolumePercent: modelData ? Math.round(modelData.audio.volume * 100) : 0
|
||||||
|
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
width: 100
|
||||||
|
enabled: modelData !== null
|
||||||
|
minimum: 0
|
||||||
|
maximum: 100
|
||||||
|
value: modelData ? Math.min(100, Math.round(modelData.audio.volume * 100)) : 0
|
||||||
|
showValue: true
|
||||||
|
unit: "%"
|
||||||
|
valueOverride: actualVolumePercent
|
||||||
|
thumbOutlineColor: Theme.surfaceContainer
|
||||||
|
trackColor: appVolumeRow.sliderTrackColor.a > 0 ? appVolumeRow.sliderTrackColor : Theme.withAlpha(Theme.surfaceContainerHigh, Theme.popupTransparency)
|
||||||
|
|
||||||
|
onIsDraggingChanged: {
|
||||||
|
if (isDragging) {
|
||||||
|
AudioService.suppressOSD = true;
|
||||||
|
} else {
|
||||||
|
Qt.callLater(() => {
|
||||||
|
AudioService.suppressOSD = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onSliderValueChanged: function (newValue) {
|
||||||
|
if (modelData) {
|
||||||
|
modelData.audio.volume = newValue / 100.0;
|
||||||
|
if (newValue > 0 && modelData.audio.muted) {
|
||||||
|
modelData.audio.muted = false;
|
||||||
|
}
|
||||||
|
AudioService.playVolumeChangeSoundIfEnabled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PwObjectTracker {
|
||||||
|
objects: [modelData]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user