Skip to content
Open
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
28 changes: 24 additions & 4 deletions shell/services/BackgroundIntro.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Item {
// A finished switch whose wallpaper is still hidden or decoding keeps its
// cover until the wallpaper is on screen, so the fade never reveals a gap.
property bool themeFinishing: false
// A finished switch onto a video while OWE already holds the desktop. The
// shell's background stays hidden under the new video too, so it never
// turns ready; the cover waits for OWE to show this video instead.
property string themeVideo: ""
// A switch to a still without an intro of its own opens the cover with the
// same slanted cut as an ordinary background transition, not the intro fade.
property bool themeCut: false
Expand Down Expand Up @@ -93,12 +97,14 @@ Item {
themeShell = shell
themeOpacity = 1
themeFinishing = false
themeVideo = ""
themeFallback.restart()
}

function revealTheme() {
if (!themeToken && !cover) return
themeFinishing = false
themeVideo = ""
framePoll.stop()
themeFallback.stop()
// A background change keeps the theme, so it hands over no palette.
Expand All @@ -123,11 +129,19 @@ Item {

// OWE hands the desktop back to the shell when an intro ends or is cut
// short, and the new still may still be decoding then.
function finishTheme(token, cut) {
function finishTheme(token, cut, background) {
if (token !== themeToken) return
themeCut = !!cut
if (backgroundReady || !backgroundService) revealTheme()
else themeFinishing = true
if (backgroundReady || !backgroundService) {
revealTheme()
} else if (!backgroundActive && Util.isVideoPath(background)) {
themeFinishing = true
themeVideo = background
framePoll.start()
if (!frameStatus.running) frameStatus.running = true
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
} else {
themeFinishing = true
}
}

function themeStatus(token) {
Expand All @@ -146,6 +160,7 @@ Item {

function cancelTheme() {
themeFinishing = false
themeVideo = ""
framePoll.stop()
themeFallback.stop()
themeFade.stop()
Expand Down Expand Up @@ -247,8 +262,13 @@ Item {
if (exitCode !== 0 || token !== root.themeToken || (!token && !root.cover)) return
try {
var status = JSON.parse(frameStatusOut.text)
if (status.kind === "video" && status.ready && !status.has_transition && status.time_pos > 0)
// The outgoing video is playing too, so a background switch waits
// for its own path. A paused video holds its first frame at 0.
if (root.themeVideo) {
if (status.path === root.themeVideo && status.ready && !status.has_transition) root.revealTheme()
} else if (status.kind === "video" && status.ready && !status.has_transition && status.time_pos > 0) {
root.revealTheme()
}
} catch (e) {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion shell/services/BackgroundSwitch.qml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Item {
: ["bash", "-c", 'owe refresh >/dev/null && exec owe intro --start first-frame "$1"', "_", clip]
playProc.running = true
} else {
intro.finishTheme(token, !clip)
intro.finishTheme(token, !clip, still)
}
}

Expand Down
63 changes: 63 additions & 0 deletions test/shell.d/background-video-handoff-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
require_quickshell "background video handoff test"

# A video replacing a video: OWE holds the desktop throughout, so the shell's
# background never turns ready. The cover must stay while OWE still shows the
# outgoing video, and open once it shows the new one, paused on frame zero.
stage=$(mktemp -d)
trap 'rm -rf "$stage"' EXIT
mkdir -p "$stage/services" "$stage/bin"
cp "$ROOT/shell/services/BackgroundIntro.qml" "$stage/services/"
ln -s "$ROOT/shell/Commons" "$stage/Commons"
printf 'P6\n1 1\n255\n\377\377\377' >"$stage/cover.ppm"
printf '{"path":"/media/old.mp4","kind":"video","ready":true,"has_transition":false,"time_pos":4.2}\n' >"$stage/shown"
printf '{"path":"/media/new.mp4","kind":"video","ready":true,"has_transition":false,"time_pos":0}\n' >"$stage/new"
printf '#!/bin/bash\ncat "$VIDEO_TEST_DIR/shown"\n' >"$stage/bin/owe"
printf '#!/bin/bash\necho %s\n' "'{\"bool\":true}'" >"$stage/bin/hyprctl"
chmod +x "$stage/bin/"*

cat >"$stage/shell.qml" <<'QML'
import QtQuick
import Quickshell
import Quickshell.Io
import "services"

ShellRoot {
id: test
property var services: ({})
readonly property string dir: Quickshell.env("VIDEO_TEST_DIR")
function firstPartyServiceFor(id) { return services[id] || null }

QtObject { id: background; property bool suspended: true; property bool ready: true }
BackgroundIntro { id: intro; host: test }
Process { id: showNew; command: ["cp", test.dir + "/new", test.dir + "/shown"] }

Timer { interval: 100; running: true; onTriggered: {
test.services = ({ "omarchy.background": background })
intro.prepareTheme(test.dir + "/cover.ppm", "switch", "", "")
intro.finishTheme("switch", true, "/media/new.mp4")
held.start()
} }
Timer { id: held; interval: 500; onTriggered: {
console.log("HELD " + (intro.themeToken === "switch"))
showNew.running = true
opened.start()
} }
Timer { id: opened; interval: 600; onTriggered: {
console.log("OPENED " + (intro.themeToken === ""))
Qt.quit()
} }
}
QML

output=$(PATH="$stage/bin:$PATH" HOME="$stage" VIDEO_TEST_DIR="$stage" timeout 10 quickshell -p "$stage" --no-color 2>&1) || fail "video handoff fixture exits cleanly" "$output"
if rg -q 'ReferenceError|TypeError|Error:|Unable to assign|Binding loop' <<<"$output"; then
fail "video handoff fixture has no QML errors" "$output"
fi
[[ $output == *"HELD true"* ]] || fail "the cover stays while OWE still shows the outgoing video" "$output"
[[ $output == *"OPENED true"* ]] || fail "the cover opens once OWE shows the new video, paused on its first frame" "$output"
pass "a video-to-video switch lifts its cover once OWE shows the new video"