mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-03 20:32:07 -04:00
media: make controls more usable since popout change
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Effects
|
import QtQuick.Effects
|
||||||
import QtQuick.Shapes
|
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import Quickshell.Services.Mpris
|
import Quickshell.Services.Mpris
|
||||||
import Quickshell.Services.Pipewire
|
import Quickshell.Services.Pipewire
|
||||||
@@ -18,7 +17,9 @@ Item {
|
|||||||
property var allPlayers: MprisController.availablePlayers
|
property var allPlayers: MprisController.availablePlayers
|
||||||
|
|
||||||
readonly property bool isRightEdge: (SettingsData.barConfigs[0]?.position ?? SettingsData.Position.Top) === SettingsData.Position.Right
|
readonly property bool isRightEdge: (SettingsData.barConfigs[0]?.position ?? SettingsData.Position.Top) === SettingsData.Position.Right
|
||||||
readonly property bool volumeAvailable: activePlayer && activePlayer.volumeSupported
|
readonly property bool volumeAvailable: (activePlayer && activePlayer.volumeSupported) || (AudioService.sink && AudioService.sink.audio)
|
||||||
|
readonly property bool usePlayerVolume: activePlayer && activePlayer.volumeSupported
|
||||||
|
readonly property real currentVolume: usePlayerVolume ? activePlayer.volume : (AudioService.sink?.audio?.volume ?? 0)
|
||||||
|
|
||||||
// Palette that stays stable across track switches until new colors are ready
|
// Palette that stays stable across track switches until new colors are ready
|
||||||
property color dom: Qt.rgba(Theme.surface.r, Theme.surface.g, Theme.surface.b, 1.0)
|
property color dom: Qt.rgba(Theme.surface.r, Theme.surface.g, Theme.surface.b, 1.0)
|
||||||
@@ -35,9 +36,7 @@ Item {
|
|||||||
// Derived "no players" state: always correct, no timers.
|
// Derived "no players" state: always correct, no timers.
|
||||||
readonly property int _playerCount: allPlayers ? allPlayers.length : 0
|
readonly property int _playerCount: allPlayers ? allPlayers.length : 0
|
||||||
readonly property bool _noneAvailable: _playerCount === 0
|
readonly property bool _noneAvailable: _playerCount === 0
|
||||||
readonly property bool _trulyIdle: activePlayer
|
readonly property bool _trulyIdle: activePlayer && activePlayer.playbackState === MprisPlaybackState.Stopped && !activePlayer.trackTitle && !activePlayer.trackArtist
|
||||||
&& activePlayer.playbackState === MprisPlaybackState.Stopped
|
|
||||||
&& !activePlayer.trackTitle && !activePlayer.trackArtist
|
|
||||||
readonly property bool showNoPlayerNow: (!_switchHold) && (_noneAvailable || _trulyIdle)
|
readonly property bool showNoPlayerNow: (!_switchHold) && (_noneAvailable || _trulyIdle)
|
||||||
|
|
||||||
// Short hold only during track switches (not when players disappear)
|
// Short hold only during track switches (not when players disappear)
|
||||||
@@ -50,49 +49,49 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onActivePlayerChanged: {
|
onActivePlayerChanged: {
|
||||||
isSwitching = true
|
isSwitching = true;
|
||||||
_switchHold = true
|
_switchHold = true;
|
||||||
paletteReady = false
|
paletteReady = false;
|
||||||
_switchHoldTimer.restart()
|
_switchHoldTimer.restart();
|
||||||
if (activePlayer && activePlayer.trackArtUrl) {
|
if (activePlayer && activePlayer.trackArtUrl) {
|
||||||
loadArtwork(activePlayer.trackArtUrl)
|
loadArtwork(activePlayer.trackArtUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
property string activeTrackArtFile: ""
|
property string activeTrackArtFile: ""
|
||||||
|
|
||||||
function loadArtwork(url) {
|
function loadArtwork(url) {
|
||||||
if (!url) return
|
if (!url)
|
||||||
|
return;
|
||||||
if (url.startsWith("http://") || url.startsWith("https://")) {
|
if (url.startsWith("http://") || url.startsWith("https://")) {
|
||||||
const filename = "/tmp/.dankshell/trackart_" + Date.now() + ".jpg"
|
const filename = "/tmp/.dankshell/trackart_" + Date.now() + ".jpg";
|
||||||
activeTrackArtFile = filename
|
activeTrackArtFile = filename;
|
||||||
|
|
||||||
cleanupProcess.command = ["sh", "-c", "mkdir -p /tmp/.dankshell && find /tmp/.dankshell -name 'trackart_*' ! -name '" + filename.split('/').pop() + "' -delete"]
|
cleanupProcess.command = ["sh", "-c", "mkdir -p /tmp/.dankshell && find /tmp/.dankshell -name 'trackart_*' ! -name '" + filename.split('/').pop() + "' -delete"];
|
||||||
cleanupProcess.running = true
|
cleanupProcess.running = true;
|
||||||
|
|
||||||
imageDownloader.command = ["curl", "-L", "-s", "--user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36", "-o", filename, url]
|
imageDownloader.command = ["curl", "-L", "-s", "--user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36", "-o", filename, url];
|
||||||
imageDownloader.targetFile = filename
|
imageDownloader.targetFile = filename;
|
||||||
imageDownloader.running = true
|
imageDownloader.running = true;
|
||||||
} else {
|
} else {
|
||||||
_preloadImage.source = url
|
_preloadImage.source = url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function maybeFinishSwitch() {
|
function maybeFinishSwitch() {
|
||||||
if (activePlayer && activePlayer.trackTitle !== "" && paletteReady) {
|
if (activePlayer && activePlayer.trackTitle !== "" && paletteReady) {
|
||||||
isSwitching = false
|
isSwitching = false;
|
||||||
_switchHold = false
|
_switchHold = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly property real ratio: {
|
readonly property real ratio: {
|
||||||
if (!activePlayer || !activePlayer.length || activePlayer.length <= 0) {
|
if (!activePlayer || !activePlayer.length || activePlayer.length <= 0) {
|
||||||
return 0
|
return 0;
|
||||||
}
|
}
|
||||||
const pos = (activePlayer.position || 0) % Math.max(1, activePlayer.length)
|
const pos = (activePlayer.position || 0) % Math.max(1, activePlayer.length);
|
||||||
const calculatedRatio = pos / activePlayer.length
|
const calculatedRatio = pos / activePlayer.length;
|
||||||
return Math.max(0, Math.min(1, calculatedRatio))
|
return Math.max(0, Math.min(1, calculatedRatio));
|
||||||
}
|
}
|
||||||
|
|
||||||
implicitWidth: 700
|
implicitWidth: 700
|
||||||
@@ -101,13 +100,13 @@ Item {
|
|||||||
Connections {
|
Connections {
|
||||||
target: activePlayer
|
target: activePlayer
|
||||||
function onTrackTitleChanged() {
|
function onTrackTitleChanged() {
|
||||||
_switchHoldTimer.restart()
|
_switchHoldTimer.restart();
|
||||||
maybeFinishSwitch()
|
maybeFinishSwitch();
|
||||||
}
|
}
|
||||||
function onTrackArtUrlChanged() {
|
function onTrackArtUrlChanged() {
|
||||||
if (activePlayer?.trackArtUrl) {
|
if (activePlayer?.trackArtUrl) {
|
||||||
_lastArtUrl = activePlayer.trackArtUrl
|
_lastArtUrl = activePlayer.trackArtUrl;
|
||||||
loadArtwork(activePlayer.trackArtUrl)
|
loadArtwork(activePlayer.trackArtUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,52 +114,61 @@ Item {
|
|||||||
Connections {
|
Connections {
|
||||||
target: MprisController
|
target: MprisController
|
||||||
function onAvailablePlayersChanged() {
|
function onAvailablePlayersChanged() {
|
||||||
const count = (MprisController.availablePlayers?.length || 0)
|
const count = (MprisController.availablePlayers?.length || 0);
|
||||||
if (count === 0) {
|
if (count === 0) {
|
||||||
isSwitching = false
|
isSwitching = false;
|
||||||
_switchHold = false
|
_switchHold = false;
|
||||||
} else {
|
} else {
|
||||||
_switchHold = true
|
_switchHold = true;
|
||||||
_switchHoldTimer.restart()
|
_switchHoldTimer.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAudioDeviceIcon(device) {
|
function getAudioDeviceIcon(device) {
|
||||||
if (!device || !device.name) return "speaker"
|
if (!device || !device.name)
|
||||||
|
return "speaker";
|
||||||
|
|
||||||
const name = device.name.toLowerCase()
|
const name = device.name.toLowerCase();
|
||||||
|
|
||||||
if (name.includes("bluez") || name.includes("bluetooth"))
|
if (name.includes("bluez") || name.includes("bluetooth"))
|
||||||
return "headset"
|
return "headset";
|
||||||
if (name.includes("hdmi"))
|
if (name.includes("hdmi"))
|
||||||
return "tv"
|
return "tv";
|
||||||
if (name.includes("usb"))
|
if (name.includes("usb"))
|
||||||
return "headset"
|
return "headset";
|
||||||
if (name.includes("analog") || name.includes("built-in"))
|
if (name.includes("analog") || name.includes("built-in"))
|
||||||
return "speaker"
|
return "speaker";
|
||||||
|
|
||||||
return "speaker"
|
return "speaker";
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVolumeIcon() {
|
function getVolumeIcon() {
|
||||||
if (!volumeAvailable) return "volume_off"
|
if (!volumeAvailable)
|
||||||
|
return "volume_off";
|
||||||
|
|
||||||
const volume = activePlayer.volume
|
const volume = currentVolume;
|
||||||
|
|
||||||
if (volume === 0.0) return "volume_off"
|
if (volume === 0.0)
|
||||||
if (volume <= 0.33) return "volume_down"
|
return "volume_off";
|
||||||
if (volume <= 0.66) return "volume_up"
|
if (volume <= 0.33)
|
||||||
return "volume_up"
|
return "volume_down";
|
||||||
|
if (volume <= 0.66)
|
||||||
|
return "volume_up";
|
||||||
|
return "volume_up";
|
||||||
}
|
}
|
||||||
|
|
||||||
function adjustVolume(step) {
|
function adjustVolume(step) {
|
||||||
if (!volumeAvailable) return
|
if (!volumeAvailable)
|
||||||
|
return;
|
||||||
|
const current = Math.round(currentVolume * 100);
|
||||||
|
const newVolume = Math.min(100, Math.max(0, current + step));
|
||||||
|
|
||||||
const currentVolume = Math.round(activePlayer.volume * 100)
|
if (usePlayerVolume) {
|
||||||
const newVolume = Math.min(100, Math.max(0, currentVolume + step))
|
activePlayer.volume = newVolume / 100;
|
||||||
|
} else if (AudioService.sink?.audio) {
|
||||||
activePlayer.volume = newVolume / 100
|
AudioService.sink.audio.volume = newVolume / 100;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
@@ -168,9 +176,9 @@ Item {
|
|||||||
running: false
|
running: false
|
||||||
property string targetFile: ""
|
property string targetFile: ""
|
||||||
|
|
||||||
onExited: (exitCode) => {
|
onExited: exitCode => {
|
||||||
if (exitCode === 0 && targetFile) {
|
if (exitCode === 0 && targetFile) {
|
||||||
_preloadImage.source = "file://" + targetFile
|
_preloadImage.source = "file://" + targetFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,11 +196,10 @@ Item {
|
|||||||
visible: false
|
visible: false
|
||||||
onStatusChanged: {
|
onStatusChanged: {
|
||||||
if (status === Image.Ready) {
|
if (status === Image.Ready) {
|
||||||
_cqSource = source
|
_cqSource = source;
|
||||||
colorQuantizer.source = _cqSource
|
colorQuantizer.source = _cqSource;
|
||||||
}
|
} else if (status === Image.Error) {
|
||||||
else if (status === Image.Error) {
|
_cqSource = "";
|
||||||
_cqSource = ""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,37 +210,37 @@ Item {
|
|||||||
depth: 8
|
depth: 8
|
||||||
rescaleSize: 32
|
rescaleSize: 32
|
||||||
onColorsChanged: {
|
onColorsChanged: {
|
||||||
if (!colors || colors.length === 0) return
|
if (!colors || colors.length === 0)
|
||||||
|
return;
|
||||||
function enhanceColor(color) {
|
function enhanceColor(color) {
|
||||||
const satBoost = 1.4
|
const satBoost = 1.4;
|
||||||
const valueBoost = 1.2
|
const valueBoost = 1.2;
|
||||||
return Qt.hsva(color.hsvHue, Math.min(1, color.hsvSaturation * satBoost), Math.min(1, color.hsvValue * valueBoost), color.a)
|
return Qt.hsva(color.hsvHue, Math.min(1, color.hsvSaturation * satBoost), Math.min(1, color.hsvValue * valueBoost), color.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getExtremeColor(startIdx, direction = 1) {
|
function getExtremeColor(startIdx, direction = 1) {
|
||||||
let bestColor = colors[startIdx]
|
let bestColor = colors[startIdx];
|
||||||
let bestScore = 0
|
let bestScore = 0;
|
||||||
|
|
||||||
for (let i = startIdx; i >= 0 && i < colors.length; i += direction) {
|
for (let i = startIdx; i >= 0 && i < colors.length; i += direction) {
|
||||||
const c = colors[i]
|
const c = colors[i];
|
||||||
const saturation = c.hsvSaturation
|
const saturation = c.hsvSaturation;
|
||||||
const brightness = c.hsvValue
|
const brightness = c.hsvValue;
|
||||||
const contrast = Math.abs(brightness - 0.5) * 2
|
const contrast = Math.abs(brightness - 0.5) * 2;
|
||||||
const score = saturation * 0.7 + contrast * 0.3
|
const score = saturation * 0.7 + contrast * 0.3;
|
||||||
|
|
||||||
if (score > bestScore) {
|
if (score > bestScore) {
|
||||||
bestScore = score
|
bestScore = score;
|
||||||
bestColor = c
|
bestColor = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return enhanceColor(bestColor)
|
return enhanceColor(bestColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
_pendingDom = getExtremeColor(Math.floor(colors.length * 0.2), 1)
|
_pendingDom = getExtremeColor(Math.floor(colors.length * 0.2), 1);
|
||||||
_pendingAcc = getExtremeColor(Math.floor(colors.length * 0.8), -1)
|
_pendingAcc = getExtremeColor(Math.floor(colors.length * 0.8), -1);
|
||||||
paletteApplyDelay.restart()
|
paletteApplyDelay.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,25 +252,22 @@ Item {
|
|||||||
repeat: false
|
repeat: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
const dist = (c1, c2) => {
|
const dist = (c1, c2) => {
|
||||||
const dr = c1.r - c2.r, dg = c1.g - c2.g, db = c1.b - c2.b
|
const dr = c1.r - c2.r, dg = c1.g - c2.g, db = c1.b - c2.b;
|
||||||
return Math.sqrt(dr*dr + dg*dg + db*db)
|
return Math.sqrt(dr * dr + dg * dg + db * db);
|
||||||
}
|
};
|
||||||
const domChanged = dist(_pendingDom, dom) > 0.02
|
const domChanged = dist(_pendingDom, dom) > 0.02;
|
||||||
const accChanged = dist(_pendingAcc, acc) > 0.02
|
const accChanged = dist(_pendingAcc, acc) > 0.02;
|
||||||
if (domChanged || accChanged) {
|
if (domChanged || accChanged) {
|
||||||
dom = _pendingDom
|
dom = _pendingDom;
|
||||||
acc = _pendingAcc
|
acc = _pendingAcc;
|
||||||
}
|
}
|
||||||
paletteReady = true
|
paletteReady = true;
|
||||||
maybeFinishSwitch()
|
maybeFinishSwitch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
property bool isSeeking: false
|
property bool isSeeking: false
|
||||||
|
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
@@ -282,11 +286,25 @@ Item {
|
|||||||
color: Qt.rgba(Theme.surface.r, Theme.surface.g, Theme.surface.b, paletteReady ? 0.92 : 0.985)
|
color: Qt.rgba(Theme.surface.r, Theme.surface.g, Theme.surface.b, paletteReady ? 0.92 : 0.985)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Behavior on opacity { NumberAnimation { duration: 160 } }
|
Behavior on opacity {
|
||||||
|
NumberAnimation {
|
||||||
|
duration: 160
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Behavior on dom { ColorAnimation { duration: 220; easing.type: Easing.InOutQuad } }
|
Behavior on dom {
|
||||||
Behavior on acc { ColorAnimation { duration: 220; easing.type: Easing.InOutQuad } }
|
ColorAnimation {
|
||||||
|
duration: 220
|
||||||
|
easing.type: Easing.InOutQuad
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Behavior on acc {
|
||||||
|
ColorAnimation {
|
||||||
|
duration: 220
|
||||||
|
easing.type: Easing.InOutQuad
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
@@ -316,20 +334,19 @@ Item {
|
|||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
enabled: audioDevicesButton.devicesExpanded || volumeButton.volumeExpanded || playerSelectorButton.playersExpanded
|
enabled: audioDevicesButton.devicesExpanded || volumeButton.volumeExpanded || playerSelectorButton.playersExpanded
|
||||||
onClicked: function(mouse) {
|
onClicked: function (mouse) {
|
||||||
const clickOutside = (item) => {
|
const clickOutside = item => {
|
||||||
return mouse.x < item.x || mouse.x > item.x + item.width ||
|
return mouse.x < item.x || mouse.x > item.x + item.width || mouse.y < item.y || mouse.y > item.y + item.height;
|
||||||
mouse.y < item.y || mouse.y > item.y + item.height
|
};
|
||||||
}
|
|
||||||
|
|
||||||
if (playerSelectorButton.playersExpanded && clickOutside(playerSelectorDropdown)) {
|
if (playerSelectorButton.playersExpanded && clickOutside(playerSelectorDropdown)) {
|
||||||
playerSelectorButton.playersExpanded = false
|
playerSelectorButton.playersExpanded = false;
|
||||||
}
|
}
|
||||||
if (audioDevicesButton.devicesExpanded && clickOutside(audioDevicesDropdown)) {
|
if (audioDevicesButton.devicesExpanded && clickOutside(audioDevicesDropdown)) {
|
||||||
audioDevicesButton.devicesExpanded = false
|
audioDevicesButton.devicesExpanded = false;
|
||||||
}
|
}
|
||||||
if (volumeButton.volumeExpanded && clickOutside(volumeSliderPanel) && clickOutside(volumeButton)) {
|
if (volumeButton.volumeExpanded && clickOutside(volumeSliderPanel) && clickOutside(volumeButton)) {
|
||||||
volumeButton.volumeExpanded = false
|
volumeButton.volumeExpanded = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -338,7 +355,7 @@ Item {
|
|||||||
id: audioDevicesDropdown
|
id: audioDevicesDropdown
|
||||||
width: 280
|
width: 280
|
||||||
height: audioDevicesButton.devicesExpanded ? Math.max(200, Math.min(280, audioDevicesDropdown.availableDevices.length * 50 + 100)) : 0
|
height: audioDevicesButton.devicesExpanded ? Math.max(200, Math.min(280, audioDevicesDropdown.availableDevices.length * 50 + 100)) : 0
|
||||||
x: isRightEdge ? -width - Theme.spacingS : root.width + Theme.spacingS
|
x: isRightEdge ? audioDevicesButton.x + audioDevicesButton.width + Theme.spacingS : audioDevicesButton.x - width - Theme.spacingS
|
||||||
y: audioDevicesButton.y - 50
|
y: audioDevicesButton.y - 50
|
||||||
visible: audioDevicesButton.devicesExpanded
|
visible: audioDevicesButton.devicesExpanded
|
||||||
closePolicy: Popup.NoAutoClose
|
closePolicy: Popup.NoAutoClose
|
||||||
@@ -347,7 +364,7 @@ Item {
|
|||||||
padding: 0
|
padding: 0
|
||||||
|
|
||||||
property var availableDevices: Pipewire.nodes.values.filter(node => {
|
property var availableDevices: Pipewire.nodes.values.filter(node => {
|
||||||
return node.audio && node.isSink && !node.isStream
|
return node.audio && node.isSink && !node.isStream;
|
||||||
})
|
})
|
||||||
|
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
@@ -481,13 +498,17 @@ Item {
|
|||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (modelData) {
|
if (modelData) {
|
||||||
Pipewire.preferredDefaultAudioSink = modelData
|
Pipewire.preferredDefaultAudioSink = modelData;
|
||||||
}
|
}
|
||||||
audioDevicesButton.devicesExpanded = false
|
audioDevicesButton.devicesExpanded = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Behavior on border.color { ColorAnimation { duration: Anims.durShort } }
|
Behavior on border.color {
|
||||||
|
ColorAnimation {
|
||||||
|
duration: Anims.durShort
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -499,7 +520,7 @@ Item {
|
|||||||
id: playerSelectorDropdown
|
id: playerSelectorDropdown
|
||||||
width: 240
|
width: 240
|
||||||
height: playerSelectorButton.playersExpanded ? Math.max(180, Math.min(240, (root.allPlayers?.length || 0) * 50 + 80)) : 0
|
height: playerSelectorButton.playersExpanded ? Math.max(180, Math.min(240, (root.allPlayers?.length || 0) * 50 + 80)) : 0
|
||||||
x: isRightEdge ? -width - Theme.spacingS : root.width + Theme.spacingS
|
x: isRightEdge ? playerSelectorButton.x + playerSelectorButton.width + Theme.spacingS : playerSelectorButton.x - width - Theme.spacingS
|
||||||
y: playerSelectorButton.y - 50
|
y: playerSelectorButton.y - 50
|
||||||
visible: playerSelectorButton.playersExpanded
|
visible: playerSelectorButton.playersExpanded
|
||||||
closePolicy: Popup.NoAutoClose
|
closePolicy: Popup.NoAutoClose
|
||||||
@@ -612,16 +633,17 @@ Item {
|
|||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
text: {
|
text: {
|
||||||
if (!modelData) return "Unknown Player"
|
if (!modelData)
|
||||||
|
return "Unknown Player";
|
||||||
|
|
||||||
const identity = modelData.identity || "Unknown Player"
|
const identity = modelData.identity || "Unknown Player";
|
||||||
const trackTitle = modelData.trackTitle || ""
|
const trackTitle = modelData.trackTitle || "";
|
||||||
|
|
||||||
if (trackTitle.length > 0) {
|
if (trackTitle.length > 0) {
|
||||||
return identity + " - " + trackTitle
|
return identity + " - " + trackTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
return identity
|
return identity;
|
||||||
}
|
}
|
||||||
font.pixelSize: Theme.fontSizeMedium
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
color: Theme.surfaceText
|
color: Theme.surfaceText
|
||||||
@@ -633,16 +655,17 @@ Item {
|
|||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
text: {
|
text: {
|
||||||
if (!modelData) return ""
|
if (!modelData)
|
||||||
|
return "";
|
||||||
|
|
||||||
const artist = modelData.trackArtist || ""
|
const artist = modelData.trackArtist || "";
|
||||||
const isActive = modelData === activePlayer
|
const isActive = modelData === activePlayer;
|
||||||
|
|
||||||
if (artist.length > 0) {
|
if (artist.length > 0) {
|
||||||
return artist + (isActive ? " (Active)" : "")
|
return artist + (isActive ? " (Active)" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
return isActive ? "Active" : "Available"
|
return isActive ? "Active" : "Available";
|
||||||
}
|
}
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
color: Theme.surfaceVariantText
|
color: Theme.surfaceVariantText
|
||||||
@@ -661,12 +684,12 @@ Item {
|
|||||||
onClicked: {
|
onClicked: {
|
||||||
if (modelData && modelData.identity) {
|
if (modelData && modelData.identity) {
|
||||||
if (activePlayer && activePlayer !== modelData && activePlayer.canPause) {
|
if (activePlayer && activePlayer !== modelData && activePlayer.canPause) {
|
||||||
activePlayer.pause()
|
activePlayer.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
MprisController.activePlayer = modelData
|
MprisController.activePlayer = modelData;
|
||||||
}
|
}
|
||||||
playerSelectorButton.playersExpanded = false
|
playerSelectorButton.playersExpanded = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -778,13 +801,14 @@ Item {
|
|||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
text: {
|
text: {
|
||||||
if (!activePlayer) return "0:00"
|
if (!activePlayer)
|
||||||
const rawPos = Math.max(0, activePlayer.position || 0)
|
return "0:00";
|
||||||
const pos = activePlayer.length ? rawPos % Math.max(1, activePlayer.length) : rawPos
|
const rawPos = Math.max(0, activePlayer.position || 0);
|
||||||
const minutes = Math.floor(pos / 60)
|
const pos = activePlayer.length ? rawPos % Math.max(1, activePlayer.length) : rawPos;
|
||||||
const seconds = Math.floor(pos % 60)
|
const minutes = Math.floor(pos / 60);
|
||||||
const timeStr = minutes + ":" + (seconds < 10 ? "0" : "") + seconds
|
const seconds = Math.floor(pos % 60);
|
||||||
return timeStr
|
const timeStr = minutes + ":" + (seconds < 10 ? "0" : "") + seconds;
|
||||||
|
return timeStr;
|
||||||
}
|
}
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
color: Theme.surfaceVariantText
|
color: Theme.surfaceVariantText
|
||||||
@@ -794,11 +818,12 @@ Item {
|
|||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
text: {
|
text: {
|
||||||
if (!activePlayer || !activePlayer.length) return "0:00"
|
if (!activePlayer || !activePlayer.length)
|
||||||
const dur = Math.max(0, activePlayer.length || 0) // Length is already in seconds
|
return "0:00";
|
||||||
const minutes = Math.floor(dur / 60)
|
const dur = Math.max(0, activePlayer.length || 0); // Length is already in seconds
|
||||||
const seconds = Math.floor(dur % 60)
|
const minutes = Math.floor(dur / 60);
|
||||||
return minutes + ":" + (seconds < 10 ? "0" : "") + seconds
|
const seconds = Math.floor(dur % 60);
|
||||||
|
return minutes + ":" + (seconds < 10 ? "0" : "") + seconds;
|
||||||
}
|
}
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
color: Theme.surfaceVariantText
|
color: Theme.surfaceVariantText
|
||||||
@@ -841,7 +866,7 @@ Item {
|
|||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (activePlayer && activePlayer.canControl && activePlayer.shuffleSupported) {
|
if (activePlayer && activePlayer.canControl && activePlayer.shuffleSupported) {
|
||||||
activePlayer.shuffle = !activePlayer.shuffle
|
activePlayer.shuffle = !activePlayer.shuffle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -874,13 +899,13 @@ Item {
|
|||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (!activePlayer) {
|
if (!activePlayer) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activePlayer.position > 8 && activePlayer.canSeek) {
|
if (activePlayer.position > 8 && activePlayer.canSeek) {
|
||||||
activePlayer.position = 0
|
activePlayer.position = 0;
|
||||||
} else {
|
} else {
|
||||||
activePlayer.previous()
|
activePlayer.previous();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -971,11 +996,15 @@ Item {
|
|||||||
DankIcon {
|
DankIcon {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
name: {
|
name: {
|
||||||
if (!activePlayer) return "repeat"
|
if (!activePlayer)
|
||||||
switch(activePlayer.loopState) {
|
return "repeat";
|
||||||
case MprisLoopState.Track: return "repeat_one"
|
switch (activePlayer.loopState) {
|
||||||
case MprisLoopState.Playlist: return "repeat"
|
case MprisLoopState.Track:
|
||||||
default: return "repeat"
|
return "repeat_one";
|
||||||
|
case MprisLoopState.Playlist:
|
||||||
|
return "repeat";
|
||||||
|
default:
|
||||||
|
return "repeat";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size: 20
|
size: 20
|
||||||
@@ -989,16 +1018,16 @@ Item {
|
|||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (activePlayer && activePlayer.canControl && activePlayer.loopSupported) {
|
if (activePlayer && activePlayer.canControl && activePlayer.loopSupported) {
|
||||||
switch(activePlayer.loopState) {
|
switch (activePlayer.loopState) {
|
||||||
case MprisLoopState.None:
|
case MprisLoopState.None:
|
||||||
activePlayer.loopState = MprisLoopState.Playlist
|
activePlayer.loopState = MprisLoopState.Playlist;
|
||||||
break
|
break;
|
||||||
case MprisLoopState.Playlist:
|
case MprisLoopState.Playlist:
|
||||||
activePlayer.loopState = MprisLoopState.Track
|
activePlayer.loopState = MprisLoopState.Track;
|
||||||
break
|
break;
|
||||||
case MprisLoopState.Track:
|
case MprisLoopState.Track:
|
||||||
activePlayer.loopState = MprisLoopState.None
|
activePlayer.loopState = MprisLoopState.None;
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1039,29 +1068,9 @@ Item {
|
|||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
parent.playersExpanded = !parent.playersExpanded
|
parent.playersExpanded = !parent.playersExpanded;
|
||||||
}
|
|
||||||
onEntered: {
|
|
||||||
playerTooltipLoader.active = true
|
|
||||||
if (playerTooltipLoader.item) {
|
|
||||||
const p = playerSelectorButton.mapToItem(null, playerSelectorButton.width / 2, 0)
|
|
||||||
playerTooltipLoader.item.show("Media Player", p.x, p.y - 40, null)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onExited: {
|
|
||||||
if (playerTooltipLoader.item) {
|
|
||||||
playerTooltipLoader.item.hide()
|
|
||||||
}
|
|
||||||
playerTooltipLoader.active = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Loader {
|
|
||||||
id: playerTooltipLoader
|
|
||||||
active: false
|
|
||||||
sourceComponent: DankTooltip {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
@@ -1078,7 +1087,7 @@ Item {
|
|||||||
enabled: volumeAvailable
|
enabled: volumeAvailable
|
||||||
|
|
||||||
property bool volumeExpanded: false
|
property bool volumeExpanded: false
|
||||||
property real previousVolume: 1.0
|
property real previousVolume: 0.0
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: volumeHideTimer
|
id: volumeHideTimer
|
||||||
@@ -1090,7 +1099,8 @@ Item {
|
|||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
name: getVolumeIcon()
|
name: getVolumeIcon()
|
||||||
size: 18
|
size: 18
|
||||||
color: volumeAvailable && activePlayer.volume > 0 ? Theme.primary : Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, volumeAvailable ? 1.0 : 0.5) }
|
color: volumeAvailable && currentVolume > 0 ? Theme.primary : Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, volumeAvailable ? 1.0 : 0.5)
|
||||||
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: volumeButtonArea
|
id: volumeButtonArea
|
||||||
@@ -1098,40 +1108,51 @@ Item {
|
|||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onEntered: {
|
onEntered: {
|
||||||
volumeButton.volumeExpanded = true
|
volumeButton.volumeExpanded = true;
|
||||||
volumeHideTimer.stop()
|
volumeHideTimer.stop();
|
||||||
}
|
}
|
||||||
onExited: {
|
onExited: {
|
||||||
volumeHideTimer.restart()
|
volumeHideTimer.restart();
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (activePlayer.volume > 0) {
|
if (currentVolume > 0) {
|
||||||
volumeButton.previousVolume = activePlayer.volume
|
volumeButton.previousVolume = currentVolume;
|
||||||
activePlayer.volume = 0
|
if (usePlayerVolume) {
|
||||||
|
activePlayer.volume = 0;
|
||||||
|
} else if (AudioService.sink?.audio) {
|
||||||
|
AudioService.sink.audio.volume = 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
activePlayer.volume = volumeButton.previousVolume || 1
|
const restoreVolume = volumeButton.previousVolume > 0 ? volumeButton.previousVolume : 0.5;
|
||||||
|
if (usePlayerVolume) {
|
||||||
|
activePlayer.volume = restoreVolume;
|
||||||
|
} else if (AudioService.sink?.audio) {
|
||||||
|
AudioService.sink.audio.volume = restoreVolume;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onWheel: wheelEvent => {
|
onWheel: wheelEvent => {
|
||||||
let delta = wheelEvent.angleDelta.y
|
let delta = wheelEvent.angleDelta.y;
|
||||||
let currentVolume = (activePlayer.volume * 100) || 0
|
let current = (currentVolume * 100) || 0;
|
||||||
let newVolume
|
let newVolume;
|
||||||
|
|
||||||
if (delta > 0) {
|
if (delta > 0) {
|
||||||
newVolume = Math.min(100, currentVolume + 5)
|
newVolume = Math.min(100, current + 5);
|
||||||
} else {
|
} else {
|
||||||
newVolume = Math.max(0, currentVolume - 5)
|
newVolume = Math.max(0, current - 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
activePlayer.volume = newVolume / 100
|
if (usePlayerVolume) {
|
||||||
volumeButton.volumeExpanded = true
|
activePlayer.volume = newVolume / 100;
|
||||||
wheelEvent.accepted = true
|
} else if (AudioService.sink?.audio) {
|
||||||
|
AudioService.sink.audio.volume = newVolume / 100;
|
||||||
|
}
|
||||||
|
volumeButton.volumeExpanded = true;
|
||||||
|
wheelEvent.accepted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: audioDevicesButton
|
id: audioDevicesButton
|
||||||
width: 40
|
width: 40
|
||||||
@@ -1159,38 +1180,17 @@ Item {
|
|||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
parent.devicesExpanded = !parent.devicesExpanded
|
parent.devicesExpanded = !parent.devicesExpanded;
|
||||||
}
|
|
||||||
onEntered: {
|
|
||||||
audioDevicesTooltipLoader.active = true
|
|
||||||
if (audioDevicesTooltipLoader.item) {
|
|
||||||
const p = audioDevicesButton.mapToItem(null, audioDevicesButton.width / 2, 0)
|
|
||||||
audioDevicesTooltipLoader.item.show("Output Device", p.x, p.y - 40, null)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onExited: {
|
|
||||||
if (audioDevicesTooltipLoader.item) {
|
|
||||||
audioDevicesTooltipLoader.item.hide()
|
|
||||||
}
|
}
|
||||||
audioDevicesTooltipLoader.active = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Loader {
|
|
||||||
id: audioDevicesTooltipLoader
|
|
||||||
active: false
|
|
||||||
sourceComponent: DankTooltip {}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Popup {
|
Popup {
|
||||||
id: volumeSliderPanel
|
id: volumeSliderPanel
|
||||||
width: 60
|
width: 60
|
||||||
height: 180
|
height: 180
|
||||||
x: isRightEdge ? -width - Theme.spacingS : root.width + Theme.spacingS
|
x: isRightEdge ? volumeButton.x + volumeButton.width + Theme.spacingS : volumeButton.x - width - Theme.spacingS
|
||||||
y: volumeButton.y - 50
|
y: volumeButton.y - 50
|
||||||
visible: volumeButton.volumeExpanded && volumeAvailable
|
visible: volumeButton.volumeExpanded && volumeAvailable
|
||||||
closePolicy: Popup.NoAutoClose
|
closePolicy: Popup.NoAutoClose
|
||||||
@@ -1265,7 +1265,7 @@ Item {
|
|||||||
Rectangle {
|
Rectangle {
|
||||||
id: sliderFill
|
id: sliderFill
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: volumeAvailable ? (Math.min(1.0, activePlayer.volume) * parent.height) : 0
|
height: volumeAvailable ? (Math.min(1.0, currentVolume) * parent.height) : 0
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
color: Theme.primary
|
color: Theme.primary
|
||||||
@@ -1281,9 +1281,9 @@ Item {
|
|||||||
height: 8
|
height: 8
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
y: {
|
y: {
|
||||||
const ratio = volumeAvailable ? Math.min(1.0, activePlayer.volume) : 0
|
const ratio = volumeAvailable ? Math.min(1.0, currentVolume) : 0;
|
||||||
const travel = parent.height - height
|
const travel = parent.height - height;
|
||||||
return Math.max(0, Math.min(travel, travel * (1 - ratio)))
|
return Math.max(0, Math.min(travel, travel * (1 - ratio)));
|
||||||
}
|
}
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
color: Theme.primary
|
color: Theme.primary
|
||||||
@@ -1308,10 +1308,10 @@ Item {
|
|||||||
opacity: 0
|
opacity: 0
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
opacity = 0.16
|
opacity = 0.16;
|
||||||
width = 0
|
width = 0;
|
||||||
height = 0
|
height = 0;
|
||||||
rippleAnimation.start()
|
rippleAnimation.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
SequentialAnimation {
|
SequentialAnimation {
|
||||||
@@ -1335,7 +1335,7 @@ Item {
|
|||||||
acceptedButtons: Qt.LeftButton
|
acceptedButtons: Qt.LeftButton
|
||||||
onPressedChanged: {
|
onPressedChanged: {
|
||||||
if (pressed) {
|
if (pressed) {
|
||||||
ripple.start()
|
ripple.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1361,43 +1361,47 @@ Item {
|
|||||||
preventStealing: true
|
preventStealing: true
|
||||||
|
|
||||||
onEntered: {
|
onEntered: {
|
||||||
volumeHideTimer.stop()
|
volumeHideTimer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
onExited: {
|
onExited: {
|
||||||
volumeHideTimer.restart()
|
volumeHideTimer.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
onPressed: function(mouse) {
|
onPressed: function (mouse) {
|
||||||
parent.dragging = true
|
parent.dragging = true;
|
||||||
updateVolume(mouse)
|
updateVolume(mouse);
|
||||||
}
|
}
|
||||||
|
|
||||||
onReleased: {
|
onReleased: {
|
||||||
parent.dragging = false
|
parent.dragging = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
onPositionChanged: function(mouse) {
|
onPositionChanged: function (mouse) {
|
||||||
if (pressed) {
|
if (pressed) {
|
||||||
updateVolume(mouse)
|
updateVolume(mouse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onClicked: function(mouse) {
|
onClicked: function (mouse) {
|
||||||
updateVolume(mouse)
|
updateVolume(mouse);
|
||||||
}
|
}
|
||||||
|
|
||||||
onWheel: wheelEvent => {
|
onWheel: wheelEvent => {
|
||||||
const step = 1
|
const step = 1;
|
||||||
adjustVolume(wheelEvent.angleDelta.y > 0 ? step : -step)
|
adjustVolume(wheelEvent.angleDelta.y > 0 ? step : -step);
|
||||||
wheelEvent.accepted = true
|
wheelEvent.accepted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateVolume(mouse) {
|
function updateVolume(mouse) {
|
||||||
if (volumeAvailable) {
|
if (volumeAvailable) {
|
||||||
const ratio = 1.0 - (mouse.y / height)
|
const ratio = 1.0 - (mouse.y / height);
|
||||||
const volume = Math.max(0, Math.min(1, ratio))
|
const volume = Math.max(0, Math.min(1, ratio));
|
||||||
activePlayer.volume = volume
|
if (usePlayerVolume) {
|
||||||
|
activePlayer.volume = volume;
|
||||||
|
} else if (AudioService.sink?.audio) {
|
||||||
|
AudioService.sink.audio.volume = volume;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1407,7 +1411,7 @@ Item {
|
|||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
anchors.bottomMargin: Theme.spacingL
|
anchors.bottomMargin: Theme.spacingL
|
||||||
text: volumeAvailable ? Math.round(activePlayer.volume * 100) + "%" : "0%"
|
text: volumeAvailable ? Math.round(currentVolume * 100) + "%" : "0%"
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
color: Theme.surfaceText
|
color: Theme.surfaceText
|
||||||
font.weight: Font.Medium
|
font.weight: Font.Medium
|
||||||
|
|||||||
Reference in New Issue
Block a user