smoother animations

This commit is contained in:
ari committed 2026-09-23 16:57:18 -04:00
1 parent bcf70106e2
commit f67d7f1c55
6 files changed
+357 -156

No files matched your search

+69 -24
View File
@@ -21,10 +21,16 @@ Rectangle {
required property string previewFile
// Changes whenever the screenshot files are rewritten.
required property int previewVersion
// Grow the preview out from the icon once it is ready.
required property bool growPreview
signal activated
readonly property string iconSource: Quickshell.iconPath(root.app, "application-x-executable")
readonly property bool hasLive: root.toplevel !== null && liveView.hasContent
readonly property bool hasShot: shotView.status === Image.Ready
// A picture is showing, live or still.
readonly property bool hasPicture: root.hasLive || root.hasShot
width: root.theme.loopCardWidth
height: root.theme.loopCardHeight
@@ -45,35 +51,64 @@ Rectangle {
color: root.theme.loopPreviewBg
clip: true
ScreencopyView {
id: liveView
// Holds the live view and the snapshot. Once a picture is ready it
// grows out from the icon's size to fill the preview area.
Item {
id: picture
// Keeps the window's own shape inside the preview area.
readonly property real aspect: liveView.sourceSize.height > 0 ? liveView.sourceSize.width / liveView.sourceSize.height : 16 / 9
// Size of the icon next to the full preview area.
readonly property real startScale: previewArea.width > 0 ? Math.min(1, root.theme.loopIconSize / previewArea.width) : 1
anchors.centerIn: parent
width: Math.min(parent.width, parent.height * liveView.aspect)
height: liveView.width / liveView.aspect
captureSource: root.live ? root.toplevel : null
live: true
visible: root.toplevel !== null && liveView.hasContent
}
Image {
id: shotView
anchors.fill: parent
source: root.previewFile.length > 0 ? "file://" + root.previewFile + "?v=" + root.previewVersion : ""
// The file is rewritten in place, so never reuse an old copy.
cache: false
asynchronous: true
sourceSize.width: root.theme.loopCardWidth * 2
fillMode: Image.PreserveAspectFit
smooth: true
mipmap: true
visible: shotView.status === Image.Ready
scale: root.hasPicture ? 1 : picture.startScale
opacity: root.hasPicture ? 1 : 0
Behavior on scale {
enabled: root.growPreview
NumberAnimation {
duration: root.theme.loopPreviewGrowDuration
easing.type: Easing.InOutCubic
}
}
Behavior on opacity {
enabled: root.growPreview
NumberAnimation {
duration: root.theme.loopPreviewGrowDuration
easing.type: Easing.InOutCubic
}
}
ScreencopyView {
id: liveView
// Keeps the window's own shape inside the preview area.
readonly property real aspect: liveView.sourceSize.height > 0 ? liveView.sourceSize.width / liveView.sourceSize.height : 16 / 9
anchors.centerIn: parent
width: Math.min(parent.width, parent.height * liveView.aspect)
height: liveView.width / liveView.aspect
captureSource: root.live ? root.toplevel : null
live: true
visible: root.hasLive
}
Image {
id: shotView
anchors.fill: parent
source: root.previewFile.length > 0 ? "file://" + root.previewFile + "?v=" + root.previewVersion : ""
// The file is rewritten in place, so never reuse an old copy.
cache: false
asynchronous: true
sourceSize.width: root.theme.loopCardWidth * 2
fillMode: Image.PreserveAspectFit
smooth: true
mipmap: true
visible: root.hasShot
}
}
Image {
id: previewIcon
anchors.centerIn: parent
width: root.theme.loopIconSize
height: root.theme.loopIconSize
@@ -83,7 +118,17 @@ Rectangle {
fillMode: Image.PreserveAspectFit
smooth: true
mipmap: true
visible: !liveView.visible && !shotView.visible
// Fades out as the picture grows in.
opacity: root.hasPicture ? 0 : 1
visible: previewIcon.opacity > 0
Behavior on opacity {
enabled: root.growPreview
NumberAnimation {
duration: root.theme.loopPreviewGrowDuration
easing.type: Easing.InOutCubic
}
}
}
}