background: add vertical parallax

This commit is contained in:
end-4
2025-08-20 19:35:33 +07:00
parent 75f749dbe0
commit 7c8068b2bd
3 changed files with 40 additions and 13 deletions
@@ -161,22 +161,34 @@ Variants {
Behavior on opacity { Behavior on opacity {
animation: Appearance.animation.elementMoveEnter.numberAnimation.createObject(this) animation: Appearance.animation.elementMoveEnter.numberAnimation.createObject(this)
} }
property real value // 0 to 1, for offset
cache: false cache: false
asynchronous: true asynchronous: true
value: { // Range = groups that workspaces span on
// Range = groups that workspaces span on property int chunkSize: Config?.options.bar.workspaces.shown ?? 10;
const chunkSize = Config?.options.bar.workspaces.shown ?? 10; property int lower: Math.floor(bgRoot.firstWorkspaceId / chunkSize) * chunkSize;
const lower = Math.floor(bgRoot.firstWorkspaceId / chunkSize) * chunkSize; property int upper: Math.ceil(bgRoot.lastWorkspaceId / chunkSize) * chunkSize;
const upper = Math.ceil(bgRoot.lastWorkspaceId / chunkSize) * chunkSize; property int range: upper - lower;
const range = upper - lower; property real valueX: {
return (Config.options.background.parallax.enableWorkspace ? ((bgRoot.monitor.activeWorkspace?.id - lower) / range) : 0.5) let result = 0.5;
+ (0.15 * GlobalStates.sidebarRightOpen * Config.options.background.parallax.enableSidebar) if (Config.options.background.parallax.enableWorkspace && !Config.options.background.parallax.vertical) {
- (0.15 * GlobalStates.sidebarLeftOpen * Config.options.background.parallax.enableSidebar) result = ((bgRoot.monitor.activeWorkspace?.id - lower) / range);
}
if (Config.options.background.parallax.enableSidebar) {
result += (0.15 * GlobalStates.sidebarRightOpen - 0.15 * GlobalStates.sidebarLeftOpen);
}
return result;
} }
property real effectiveValue: Math.max(0, Math.min(1, value)) property real valueY: {
x: -(bgRoot.movableXSpace) - (effectiveValue - 0.5) * 2 * bgRoot.movableXSpace let result = 0.5;
y: -(bgRoot.movableYSpace) if (Config.options.background.parallax.enableWorkspace && Config.options.background.parallax.vertical) {
result = ((bgRoot.monitor.activeWorkspace?.id - lower) / range);
}
return result;
}
property real effectiveValueX: Math.max(0, Math.min(1, valueX))
property real effectiveValueY: Math.max(0, Math.min(1, valueY))
x: -(bgRoot.movableXSpace) - (effectiveValueX - 0.5) * 2 * bgRoot.movableXSpace
y: -(bgRoot.movableYSpace) - (effectiveValueY - 0.5) * 2 * bgRoot.movableYSpace
source: bgRoot.wallpaperPath source: bgRoot.wallpaperPath
fillMode: Image.PreserveAspectCrop fillMode: Image.PreserveAspectCrop
Behavior on x { Behavior on x {
@@ -185,6 +197,12 @@ Variants {
easing.type: Easing.OutCubic easing.type: Easing.OutCubic
} }
} }
Behavior on y {
NumberAnimation {
duration: 600
easing.type: Easing.OutCubic
}
}
sourceSize { sourceSize {
width: bgRoot.screen.width * bgRoot.effectiveWallpaperScale width: bgRoot.screen.width * bgRoot.effectiveWallpaperScale
height: bgRoot.screen.height * bgRoot.effectiveWallpaperScale height: bgRoot.screen.height * bgRoot.effectiveWallpaperScale
@@ -122,6 +122,7 @@ Singleton {
property string wallpaperPath: "" property string wallpaperPath: ""
property string thumbnailPath: "" property string thumbnailPath: ""
property JsonObject parallax: JsonObject { property JsonObject parallax: JsonObject {
property bool vertical: false
property bool enableWorkspace: true property bool enableWorkspace: true
property real workspaceZoom: 1.07 // Relative to your screen, not wallpaper size property real workspaceZoom: 1.07 // Relative to your screen, not wallpaper size
property bool enableSidebar: true property bool enableSidebar: true
@@ -212,6 +212,14 @@ ContentPage {
ContentSubsection { ContentSubsection {
title: Translation.tr("Wallpaper parallax") title: Translation.tr("Wallpaper parallax")
ConfigSwitch {
text: Translation.tr("Vertical")
checked: Config.options.background.parallax.vertical
onCheckedChanged: {
Config.options.background.parallax.vertical = checked;
}
}
ConfigRow { ConfigRow {
uniform: true uniform: true
ConfigSwitch { ConfigSwitch {