1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-08-08 06:28:27 -04:00

media: further optimizations for bar widget animations

related #2863
port 1.5

(cherry picked from commit 2986e354e8)
This commit is contained in:
bbedward
2026-07-17 15:48:45 -04:00
committed by dms-ci[bot]
parent 7806cf4a58
commit fc11dfbc57
+57 -35
View File
@@ -317,9 +317,45 @@ BasePill {
id: mediaText id: mediaText
readonly property bool onScreen: Window.window?.visible ?? false readonly property bool onScreen: Window.window?.visible ?? false
property bool needsScrolling: implicitWidth > textContainer.width && SettingsData.scrollTitleEnabled property bool needsScrolling: implicitWidth > textContainer.width && SettingsData.scrollTitleEnabled
readonly property bool scrollActive: needsScrolling && textContainer.visible && onScreen && root._isPlaying
readonly property real maxScrollOffset: Math.max(0, implicitWidth - textContainer.width + 5)
property real scrollOffset: 0 property real scrollOffset: 0
property int scrollDirection: 1
property real scrollHoldMs: 2000
property real textShift: 0 property real textShift: 0
function resetScroll() {
scrollOffset = 0;
scrollDirection = 1;
scrollHoldMs = 2000;
}
function stepScroll(deltaMs) {
if (scrollHoldMs > 0) {
scrollHoldMs -= deltaMs;
return;
}
const next = scrollOffset + scrollDirection * deltaMs / 60;
if (next >= maxScrollOffset) {
scrollOffset = maxScrollOffset;
scrollDirection = -1;
scrollHoldMs = 2000;
return;
}
if (next <= 0) {
scrollOffset = 0;
scrollDirection = 1;
scrollHoldMs = 2000;
return;
}
scrollOffset = next;
}
onScrollActiveChanged: {
if (!scrollActive)
resetScroll();
}
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
text: textContainer.displayText text: textContainer.displayText
font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText) font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText)
@@ -329,52 +365,38 @@ BasePill {
opacity: 1 opacity: 1
onTextChanged: { onTextChanged: {
scrollOffset = 0; resetScroll();
textShift = 0; textShift = 0;
scrollTimer.reset();
textChangeAnimation.restart(); textChangeAnimation.restart();
} }
// Timer stepping, not NumberAnimation — a running animation commits frames every vsync (#2863) // Timer stepping, not NumberAnimation — a running animation commits frames every vsync (#2863).
// When cava frames are already driving renders, scroll steps ride those ticks instead —
// two unsynchronized tick sources nearly double the surface commit rate (#2863).
Timer { Timer {
id: scrollTimer id: scrollTimer
readonly property real maxOffset: Math.max(0, mediaText.implicitWidth - textContainer.width + 5)
property int direction: 1
property int holdTicks: 33
interval: 60 interval: 60
repeat: true repeat: true
running: mediaText.needsScrolling && textContainer.visible && mediaText.onScreen && root._isPlaying running: mediaText.scrollActive
function reset() {
mediaText.scrollOffset = 0;
direction = 1;
holdTicks = 33;
}
onRunningChanged: {
if (!running)
reset();
}
onTriggered: { onTriggered: {
if (holdTicks > 0) { if (cavaTickWatch.running)
holdTicks--;
return; return;
} mediaText.stepScroll(60);
const next = mediaText.scrollOffset + direction; }
if (next >= maxOffset) { }
mediaText.scrollOffset = maxOffset;
direction = -1; Timer {
holdTicks = 33; id: cavaTickWatch
return; interval: 150
} }
if (next <= 0) {
mediaText.scrollOffset = 0; Connections {
direction = 1; target: CavaService
holdTicks = 33; enabled: mediaText.scrollActive && SettingsData.audioVisualizerEnabled && CavaService.cavaAvailable
return; function onValuesChanged() {
} cavaTickWatch.restart();
mediaText.scrollOffset = next; mediaText.stepScroll(40);
} }
} }