Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 59 additions & 17 deletions shell/plugins/background/Background.qml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Item {
if (!instant && !root.suspended && displayedBackground && isVideo(path) && !isVideo(displayedBackground)) return

revealAnimation.stop()
revealGraceTimer.stop()
finishingTransition = false

// Video frames are not fed through the image-only reveal stack. Switching
Expand Down Expand Up @@ -172,15 +173,50 @@ Item {
if (!incomingBackground || revealProgress >= 1) applyPendingTheme()
}

// Every screen slides together, so the reveal waits until each one has
// decoded its incoming frame. A screen that cannot decode in time, or at
// all, does not hold the others past a short grace; it joins the running
// reveal once its frame is ready.
function startReveal(panel) {
if (!incomingBackground) return
panel.maskReady = true
if (revealStartedVersion === backgroundVersion) return
if (revealStartedVersion === backgroundVersion) {
panel.maskReady = true
return
}
for (var other of backgrounds.instances) {
if (!other.incomingReady()) {
revealGraceTimer.start()
return
}
}
beginReveal()
Comment on lines +186 to +192

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Wallpaper timing lacks regression coverage

The new multi-monitor timing and cleanup logic has no regression test. AGENTS.md requires: “A bug fix with logic in it gets the one test that fails on the base branch and passes with the fix.” Before merging, add focused coverage showing that staggered incoming frames share the reveal, the grace timer releases a slow screen, and cleanup waits for every base image.

File Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in ab79506: a second fixture run in background-pending-theme-test.sh drives the real plugin on the live screens with 4000x2500 wallpapers, which decode at each screen's own size, so screens finish at different times. It checks:

  • once the slide ends, every screen has joined it, including one whose frame decoded after the slide started
  • when the transition comes down, every screen has already drawn its new base (backgroundReady)

On the base branch it fails with "screen 0 sat out the reveal" on a 6K + laptop desk. With the reveal-start check removed, it fails with "the transition ended before every screen drew its new background". The cleanup check fails on one screen too, because the old code cleared the transition before the base had drawn a frame. The 250ms grace for a screen that never decodes has no check: it would need a screen that never finishes decoding, which the fixture cannot make without a stub.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks—this addresses the regression-coverage concern. The fixture exercises the real plugin on live screens, covers staggered frame readiness and waits for every screen’s new base to be drawn before cleanup; the reported base-branch failures also demonstrate that the checks catch the original behavior.

The 250 ms never-decodes timeout remains untested, as you note, but that’s a separate edge case requiring a controllable decode stub. I’m withdrawing the request to block merging on additional coverage.

}

function beginReveal() {
if (!incomingBackground || revealStartedVersion === backgroundVersion) return
revealGraceTimer.stop()
revealStartedVersion = backgroundVersion
for (var panel of backgrounds.instances) {
if (panel.incomingReady()) panel.maskReady = true
}
applyPendingTheme()
revealAnimation.restart()
}

// The incoming frame stays over the base until the base has drawn the new
// background on every screen. Ending it when the first screen is ready
// left a larger screen, still decoding, black for a moment.
function maybeFinishTransition() {
if (!finishingTransition || !ready) return
incomingBackground = ""
oldBackground = ""
preparedBackground = ""
finishingTransition = false
pruneNativeSizes()
}

onReadyChanged: maybeFinishTransition()

function prepareBackground(path) {
path = String(path || "").trim()
// Only a still that is not already on screen is worth decoding ahead.
Expand Down Expand Up @@ -315,6 +351,13 @@ Item {
onTriggered: root.preparedBackground = ""
}

Timer {
id: revealGraceTimer
interval: 250
repeat: false
onTriggered: root.beginReveal()
}

Timer {
id: pendingThemeFallbackTimer
interval: 300
Expand All @@ -339,6 +382,9 @@ Item {
root.finishingTransition = true
}
root.revealProgress = 1
// A base already holding the new background stays ready, so no
// change of ready would end the transition.
Qt.callLater(root.maybeFinishTransition)
}
}

Expand Down Expand Up @@ -368,6 +414,11 @@ Item {
updatesEnabled: true

property bool maskReady: false
// A function, not a binding: onStatusChanged can run before a binding
// on the same status has caught up.
function incomingReady() {
return root.incomingBackground !== "" && incomingFrame.status === Image.Ready
}
property int readyFrames: 0
readonly property bool backgroundReady: base.ready && readyFrames >= 2

Expand Down Expand Up @@ -398,11 +449,9 @@ Item {
}

function maybeStartReveal() {
if (!root.incomingBackground || root.revealProgress !== 0 || maskReady) return
if (incomingFrame.status !== Image.Ready) return
if (!incomingReady() || root.revealProgress >= 1 || maskReady) return
Qt.callLater(function() {
if (!root.incomingBackground || root.revealProgress !== 0 || maskReady) return
if (incomingFrame.status !== Image.Ready) return
if (!incomingReady() || root.revealProgress >= 1 || maskReady) return
root.startReveal(panel)
})
}
Expand All @@ -423,16 +472,7 @@ Item {
constrainDecode: true
decodeSize: panel.decodeSize(root.displayedBackground)
onFailedChanged: if (failed) root.recoverBackground(path)
onReadyChanged: {
panel.readyFrames = 0
if (ready && root.finishingTransition) {
root.incomingBackground = ""
root.oldBackground = ""
root.preparedBackground = ""
root.finishingTransition = false
root.pruneNativeSizes()
}
}
onReadyChanged: panel.readyFrames = 0
}

Image {
Expand All @@ -455,7 +495,9 @@ Item {
id: incomingLayer
anchors.fill: parent
visible: root.incomingBackground !== "" && incomingFrame.status === Image.Ready && (root.revealProgress >= 1 || panel.maskReady)
layer.enabled: root.incomingBackground !== "" && root.revealProgress < 1
// The mask stays on until the base takes over: turning the layer off
// as the reveal ends redraws the frame unmasked mid-transition.
layer.enabled: root.incomingBackground !== "" && panel.maskReady
layer.smooth: true
layer.effect: MultiEffect {
maskEnabled: true
Expand Down
17 changes: 17 additions & 0 deletions test/shell.d/background-pending-theme-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,20 @@ output=$(HOME="$stage/home" timeout 10 quickshell -p "$stage" --no-color 2>&1) |
[[ $output == *"RESULT pass"* && $output != *"RESULT fail"* ]] || fail "the palette survives the fallback timer, and a still covers the desktop until OWE takes a video" "$output"
pass "a pending still transition cannot restore old colors after the current theme is applied"
pass "a video chosen during a reveal keeps the stills on screen, and the reveal ends on its still"

# Wallpapers larger than any screen decode at each screen's own size, so a
# larger screen finishes later than a smaller one, as on a real desk.
reveal=$(mktemp -d)
trap 'rm -rf "$stage" "$reveal"' EXIT
mkdir -p "$reveal/home/.local/state/omarchy/current"
ln -s "$ROOT/shell/plugins/background" "$reveal/background"
ln -s "$ROOT/shell/Commons" "$reveal/Commons"
ln -s "$ROOT/shell/Ui" "$reveal/Ui"
magick -size 4000x2500 gradient:magenta-navy "$reveal/still.png"
magick -size 4000x2500 gradient:cyan-orange "$reveal/home/next.png"
ln -s "$reveal/still.png" "$reveal/home/.local/state/omarchy/current/background"
cp "$SHELL_TEST_DIR/fixtures/background-reveal/shell.qml" "$reveal/shell.qml"
output=$(HOME="$reveal/home" timeout 10 quickshell -p "$reveal" --no-color 2>&1) || fail "background reveal fixture exits cleanly" "$output"
[[ $output == *"RESULT pass"* && $output != *"RESULT fail"* ]] || fail "every screen slides together and keeps its frame until its new background is drawn" "$output"
pass "every screen joins the reveal, also one that decoded after it started"
pass "the reveal comes down only after every screen has drawn its new background"
71 changes: 71 additions & 0 deletions test/shell.d/fixtures/background-reveal/shell.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import QtQuick
import Quickshell
import "background" as BackgroundPlugin

ShellRoot {
id: shell
property bool failed: false
property bool revealed: false
property bool started: false

function check(ok, message) {
if (!ok && !failed) {
failed = true
console.log("RESULT fail " + message)
}
}

// One panel per screen, built by the plugin's own Variants.
function panels() {
for (var child of background.data)
if (child && child.instances !== undefined) return child.instances
return []
}

BackgroundPlugin.Background { id: background }

Timer {
interval: 800
running: true
onTriggered: {
shell.check(background.ready, "the first background is on screen before the switch")
background.setBackground(Quickshell.env("HOME") + "/next.png", false)
shell.started = true
}
}

FrameAnimation {
running: shell.started
onTriggered: {
var screens = shell.panels()
if (background.incomingBackground) {
shell.revealed = true
// Every screen slides, including one whose frame decoded after the
// others had started. One left out would jump to the new background
// when the slide ends.
if (background.revealProgress >= 1) {
for (var i = 0; i < screens.length; i++)
shell.check(screens[i].maskReady, "screen " + i + " sat out the reveal")
}
return
}
if (!shell.revealed) return
// The incoming frame comes down only once every screen has drawn the new
// background underneath it, or that screen shows nothing for a moment.
for (var panel of screens)
shell.check(panel.backgroundReady, "the transition ended before every screen drew its new background")
shell.check(background.displayedBackground.endsWith("/next.png"), "the reveal ends on the new background: " + background.displayedBackground)
if (!shell.failed) console.log("RESULT pass")
Qt.quit()
}
}

Timer {
interval: 5000
running: true
onTriggered: {
shell.check(false, "the reveal finishes")
Qt.quit()
}
}
}
Loading