mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-08 14:38:30 -04:00
media: further optimizations for bar widget animations
related #2863 port 1.5
This commit is contained in:
@@ -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;
|
|
||||||
holdTicks = 33;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (next <= 0) {
|
|
||||||
mediaText.scrollOffset = 0;
|
Timer {
|
||||||
direction = 1;
|
id: cavaTickWatch
|
||||||
holdTicks = 33;
|
interval: 150
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
mediaText.scrollOffset = next;
|
|
||||||
|
Connections {
|
||||||
|
target: CavaService
|
||||||
|
enabled: mediaText.scrollActive && SettingsData.audioVisualizerEnabled && CavaService.cavaAvailable
|
||||||
|
function onValuesChanged() {
|
||||||
|
cavaTickWatch.restart();
|
||||||
|
mediaText.stepScroll(40);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user