mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-03 20:18:31 -04:00
qs: numerous performance optimizations
- ClippingRectangle usages - Asynchronous loader usages - Replace cava visualizers with shaders
This commit is contained in:
@@ -7,15 +7,24 @@ Item {
|
||||
id: root
|
||||
|
||||
readonly property MprisPlayer activePlayer: MprisController.activePlayer
|
||||
readonly property bool hasActiveMedia: activePlayer !== null
|
||||
readonly property bool isPlaying: hasActiveMedia && activePlayer && activePlayer.playbackState === MprisPlaybackState.Playing
|
||||
readonly property bool isPlaying: activePlayer !== null && activePlayer.playbackState === MprisPlaybackState.Playing
|
||||
readonly property bool live: visible && isPlaying
|
||||
|
||||
width: 20
|
||||
height: Theme.iconSize
|
||||
|
||||
Loader {
|
||||
active: isPlaying
|
||||
readonly property real maxBarHeight: Theme.iconSize - 2
|
||||
readonly property real minBarHeight: 3
|
||||
|
||||
onLiveChanged: {
|
||||
if (!live) {
|
||||
bars.bandsA = Qt.vector4d(0, 0, 0, 0);
|
||||
bars.bandsB = Qt.vector2d(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
active: root.live
|
||||
sourceComponent: Component {
|
||||
Ref {
|
||||
service: CavaService
|
||||
@@ -23,15 +32,8 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
readonly property real maxBarHeight: Theme.iconSize - 2
|
||||
readonly property real minBarHeight: 3
|
||||
readonly property real heightRange: maxBarHeight - minBarHeight
|
||||
property var barHeights: [minBarHeight, minBarHeight, minBarHeight, minBarHeight, minBarHeight, minBarHeight]
|
||||
|
||||
Timer {
|
||||
id: fallbackTimer
|
||||
|
||||
running: !CavaService.cavaAvailable && isPlaying
|
||||
running: !CavaService.cavaAvailable && root.live
|
||||
interval: 500
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
@@ -41,54 +43,32 @@ Item {
|
||||
|
||||
Connections {
|
||||
target: CavaService
|
||||
enabled: root.live
|
||||
function onValuesChanged() {
|
||||
if (!root.isPlaying) {
|
||||
root.barHeights = [root.minBarHeight, root.minBarHeight, root.minBarHeight, root.minBarHeight, root.minBarHeight, root.minBarHeight];
|
||||
const v = CavaService.values;
|
||||
if (v.length < 6)
|
||||
return;
|
||||
}
|
||||
|
||||
const newHeights = [];
|
||||
for (let i = 0; i < 6; i++) {
|
||||
if (CavaService.values.length <= i) {
|
||||
newHeights.push(root.minBarHeight);
|
||||
continue;
|
||||
}
|
||||
|
||||
const rawLevel = CavaService.values[i];
|
||||
if (rawLevel <= 0) {
|
||||
newHeights.push(root.minBarHeight);
|
||||
} else if (rawLevel >= 100) {
|
||||
newHeights.push(root.maxBarHeight);
|
||||
} else {
|
||||
newHeights.push(root.minBarHeight + Math.sqrt(rawLevel * 0.01) * root.heightRange);
|
||||
}
|
||||
}
|
||||
root.barHeights = newHeights;
|
||||
const n = i => {
|
||||
const x = v[i];
|
||||
return x <= 0 ? 0 : x >= 100 ? 1 : Math.sqrt(x * 0.01);
|
||||
};
|
||||
bars.bandsA = Qt.vector4d(n(0), n(1), n(2), n(3));
|
||||
bars.bandsB = Qt.vector2d(n(4), n(5));
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
anchors.centerIn: parent
|
||||
spacing: 1.5
|
||||
ShaderEffect {
|
||||
id: bars
|
||||
anchors.fill: parent
|
||||
|
||||
Repeater {
|
||||
model: 6
|
||||
property real widthPx: width
|
||||
property real heightPx: height
|
||||
property real minH: root.minBarHeight
|
||||
property real maxH: root.maxBarHeight
|
||||
property vector4d bandsA: Qt.vector4d(0, 0, 0, 0)
|
||||
property vector2d bandsB: Qt.vector2d(0, 0)
|
||||
property vector4d fillColor: Qt.vector4d(Theme.primary.r, Theme.primary.g, Theme.primary.b, Theme.primary.a)
|
||||
|
||||
Rectangle {
|
||||
width: 2
|
||||
height: root.barHeights[index]
|
||||
radius: 1.5
|
||||
color: Theme.primary
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
Behavior on height {
|
||||
enabled: root.isPlaying && !CavaService.cavaAvailable
|
||||
NumberAnimation {
|
||||
duration: 100
|
||||
easing.type: Easing.Linear
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fragmentShader: Qt.resolvedUrl("../../../Shaders/qsb/viz_bars.frag.qsb")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import QtQuick
|
||||
import QtQuick.Effects
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import Quickshell.Wayland
|
||||
import Quickshell.Widgets
|
||||
@@ -234,16 +233,19 @@ BasePill {
|
||||
color: Theme.widgetTextColor
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Row {
|
||||
id: contentRow
|
||||
anchors.centerIn: parent
|
||||
spacing: Theme.spacingS
|
||||
visible: !root.isVerticalOrientation
|
||||
|
||||
readonly property real iconSize: Theme.barIconSize(root.barThickness, undefined, root.barConfig?.maximizeWidgetIcons, root.barConfig?.iconScale)
|
||||
|
||||
IconImage {
|
||||
id: horizontalAppIcon
|
||||
Layout.preferredWidth: Theme.barIconSize(root.barThickness, undefined, root.barConfig?.maximizeWidgetIcons, root.barConfig?.iconScale)
|
||||
Layout.preferredHeight: Layout.preferredWidth
|
||||
width: contentRow.iconSize
|
||||
height: contentRow.iconSize
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: root.showIcon && activeWindow && status === Image.Ready
|
||||
source: {
|
||||
if (!activeWindow || !activeWindow.appId)
|
||||
@@ -264,8 +266,10 @@ BasePill {
|
||||
}
|
||||
|
||||
DankIcon {
|
||||
Layout.preferredWidth: Theme.barIconSize(root.barThickness, undefined, root.barConfig?.maximizeWidgetIcons, root.barConfig?.iconScale)
|
||||
size: Layout.preferredWidth
|
||||
id: horizontalSteamIcon
|
||||
width: contentRow.iconSize
|
||||
size: contentRow.iconSize
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
name: "sports_esports"
|
||||
color: Theme.widgetTextColor
|
||||
visible: root.showIcon && activeWindow && activeWindow.appId && horizontalAppIcon.status !== Image.Ready && Paths.isSteamApp(activeWindow.appId)
|
||||
@@ -280,9 +284,11 @@ BasePill {
|
||||
}
|
||||
font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText)
|
||||
color: Theme.widgetTextColor
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
wrapMode: Text.NoWrap
|
||||
elide: Text.ElideRight
|
||||
maximumLineCount: 1
|
||||
Layout.maximumWidth: compactMode ? 80 : 180
|
||||
width: Math.min(implicitWidth, compactMode ? 80 : 180)
|
||||
visible: text.length > 0
|
||||
}
|
||||
|
||||
@@ -291,6 +297,7 @@ BasePill {
|
||||
text: compactMode ? "" : "•"
|
||||
font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText)
|
||||
color: Theme.outlineButton
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: !compactMode && appText.text && titleText.text
|
||||
}
|
||||
|
||||
@@ -318,9 +325,24 @@ BasePill {
|
||||
}
|
||||
font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText)
|
||||
color: Theme.widgetTextColor
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
wrapMode: Text.NoWrap
|
||||
elide: Text.ElideRight
|
||||
maximumLineCount: 1
|
||||
Layout.maximumWidth: maxWidth - appText.implicitWidth - appSeparator.implicitWidth
|
||||
width: {
|
||||
const sp = contentRow.spacing;
|
||||
let used = 0;
|
||||
if (horizontalAppIcon.visible)
|
||||
used += horizontalAppIcon.width + sp;
|
||||
else if (horizontalSteamIcon.visible)
|
||||
used += horizontalSteamIcon.width + sp;
|
||||
if (appText.visible)
|
||||
used += appText.width + sp;
|
||||
if (appSeparator.visible)
|
||||
used += appSeparator.width + sp;
|
||||
const budget = root.maxWidth - root.horizontalPadding * 2 - used;
|
||||
return Math.min(implicitWidth, Math.max(0, budget));
|
||||
}
|
||||
visible: text.length > 0
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user