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
10 changes: 8 additions & 2 deletions shell/plugins/background/Background.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Item {
readonly property string currentThemeBackgrounds: stateHome + "/omarchy/current/theme/backgrounds"

property string currentBackground: ""
// The wallpaper that goes with the palette on screen. A theme switch moves it
// in the same step that applies the new colors, so the transparent bar samples
// its text color once, with both.
property string appliedBackground: ""
property string displayedBackground: ""
property string incomingBackground: ""
property string oldBackground: ""
Expand Down Expand Up @@ -102,7 +106,7 @@ Item {
transitionBackground("", path, path, instant, instant)
}

function transitionBackground(fromPath, path, finalPath, instant, force) {
function transitionBackground(fromPath, path, finalPath, instant, force, withTheme) {
path = String(path || "").trim()
finalPath = String(finalPath || path).trim()
fromPath = String(fromPath || "").trim()
Expand All @@ -115,6 +119,7 @@ Item {
requestNativeSize(fromPath || displayedBackground)
requestNativeSize(finalPath)
currentBackground = finalPath
if (!withTheme) appliedBackground = finalPath
backgroundVersion += 1
failedBackground = ""
revealStartedVersion = -1
Expand Down Expand Up @@ -155,13 +160,14 @@ Item {
// background reveal instead of waiting for a separate reload path.
Commons.Color.loadShell(pendingShellRaw)
Style.scheduleRefresh()
appliedBackground = currentBackground
pendingThemeVersion = -1
pendingColorsRaw = ""
pendingShellRaw = ""
}

function transitionBackgroundWithTheme(fromPath, path, finalPath, colorsB64, shellB64) {
transitionBackground(fromPath, path, finalPath, false, true)
transitionBackground(fromPath, path, finalPath, false, true, true)
setPendingTheme(colorsB64, shellB64)
if (!incomingBackground || revealProgress >= 1) applyPendingTheme()
}
Expand Down
30 changes: 26 additions & 4 deletions shell/plugins/bar/Bar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ Item {
property color themeForeground: Commons.Color.bar.text
property color themeContrastForeground: Commons.Color.background
property color transparentForeground: Commons.Color.bar.text
property bool transparentForegroundRefreshQueued: false
// The background plugin moves this in the same step as a theme's colors, so
// a theme switch samples once, after both have arrived. Watching the state
// directory instead fired when the switch began, before either had.
readonly property var backgroundService: shell && shell.services ? shell.firstPartyServiceFor("omarchy.background") : null
readonly property string appliedBackground: backgroundService ? String(backgroundService.appliedBackground || "") : ""
// No background plugin, or one cloned before appliedBackground existed: fall
// back to the state directory, so a wallpaper-only change still re-samples.
readonly property bool backgroundTracksApplied: !!backgroundService && backgroundService.appliedBackground !== undefined
property color foreground: themeForeground
property color barForeground: useTransparentForeground ? transparentForeground : themeForeground
property bool foregroundAnimationEnabled: true
Expand Down Expand Up @@ -1355,22 +1364,34 @@ Item {
}

function refreshTransparentForeground() {
if (!requestedTransparent || transparentForegroundProc.running) return
if (!requestedTransparent) return
// A sample still running was taken for older inputs: discard its answer and
// sample again when it exits, rather than dropping this request.
if (transparentForegroundProc.running) {
transparentForegroundRefreshQueued = true
return
}
// The discarded answer can still arrive after its process exits, so it
// stays blocked until this replacement sample starts.
transparentForegroundRefreshQueued = false

transparentForegroundProc.command = [
var command = [
"omarchy-bar-text-color",
root.position,
String(root.barSize),
colorHex(root.themeForeground),
colorHex(root.themeContrastForeground)
]
if (root.appliedBackground) command.push("--background", root.appliedBackground)
transparentForegroundProc.command = command
transparentForegroundProc.running = true
}

onRequestedTransparentChanged: scheduleTransparentForegroundRefresh()
onPositionChanged: scheduleTransparentForegroundRefresh()
onThemeForegroundChanged: scheduleTransparentForegroundRefresh()
onThemeContrastForegroundChanged: scheduleTransparentForegroundRefresh()
onAppliedBackgroundChanged: scheduleTransparentForegroundRefresh()

Timer {
id: transparentForegroundTimer
Expand All @@ -1384,7 +1405,7 @@ Item {
stdout: SplitParser {
onRead: function(line) {
var value = String(line || "").trim()
if (!/^#[0-9A-Fa-f]{6}$/.test(value)) return
if (root.transparentForegroundRefreshQueued || !/^#[0-9A-Fa-f]{6}$/.test(value)) return

root.foregroundAnimationEnabled = false
root.transparentForeground = value
Expand All @@ -1395,13 +1416,14 @@ Item {
root.restoreForegroundAnimation()
}
}
onExited: if (root.transparentForegroundRefreshQueued) root.scheduleTransparentForegroundRefresh()
}

FileView {
path: root.stateHome + "/omarchy/current"
watchChanges: true
printErrors: false
onFileChanged: root.scheduleTransparentForegroundRefresh()
onFileChanged: if (!root.backgroundTracksApplied) root.scheduleTransparentForegroundRefresh()
}

function runProcess(process) {
Expand Down
10 changes: 10 additions & 0 deletions test/shell.d/background-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ assert(
'background theme transition applies pending colors even if image reveal stalls'
)

// The transparent bar samples its text color against appliedBackground. A
// theme switch must move it together with the new palette, not when the
// incoming frame starts loading, or the bar samples the old theme's colors.
assert(
/if \(!withTheme\) appliedBackground = finalPath/.test(backgroundQml) &&
/transitionBackground\(fromPath, path, finalPath, false, true, true\)/.test(backgroundQml) &&
/function applyPendingTheme\(\) \{[\s\S]*?Color\.loadShell\(pendingShellRaw\)[\s\S]*?appliedBackground = currentBackground[\s\S]*?pendingThemeVersion = -1/.test(backgroundQml),
'background moves the applied wallpaper with the theme colors, and at once for a plain wallpaper change'
)

const themeSet = fs.readFileSync(path.join(root, 'bin/omarchy-theme-set'), 'utf8')

// The next background decodes while the theme stages, rather than after the
Expand Down
30 changes: 30 additions & 0 deletions test/shell.d/bar-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,36 @@ const shellSource = fs.readFileSync(root + '/shell/shell.qml', 'utf8')

assert(/function toggleBarTransparency\(\): string \{[\s\S]*?shell\.bar\.cycleBackground\(\)/.test(shellSource), 'shell exposes the bar background cycle over IPC')

// A theme switch must not sample the transparent text color before its colors
// and wallpaper reach the shell, and a sample asked for while one runs must not
// be lost, or the bar keeps the previous theme's text color.
assert(
/onFileChanged: if \(!root\.backgroundTracksApplied\) root\.scheduleTransparentForegroundRefresh\(\)/.test(barSource) &&
/backgroundTracksApplied: !!backgroundService && backgroundService\.appliedBackground !== undefined/.test(barSource) &&
/onAppliedBackgroundChanged: scheduleTransparentForegroundRefresh\(\)/.test(barSource) &&
/firstPartyServiceFor\("omarchy\.background"\)/.test(barSource) &&
/command\.push\("--background", root\.appliedBackground\)/.test(barSource),
'transparent bar samples the wallpaper the shell applied, and watches the state directory only without one'
)
const textColorProc = barSource.slice(barSource.indexOf('id: transparentForegroundProc'))
// The whole handler, whether written on one line or as a block: it ends where
// the Process block closes.
const exitedStart = textColorProc.indexOf('onExited:')
const exitedHandler = exitedStart === -1 ? '' : textColorProc.slice(exitedStart, textColorProc.indexOf('\n }', exitedStart))
assert(
/if \(transparentForegroundProc\.running\) \{\s*transparentForegroundRefreshQueued = true\s*return\s*\}[\s\S]*?transparentForegroundRefreshQueued = false\s*var command/.test(barSource) &&
/if \(root\.transparentForegroundRefreshQueued \|\| /.test(textColorProc) &&
exitedHandler.includes('transparentForegroundRefreshQueued') &&
exitedHandler.includes('scheduleTransparentForegroundRefresh()'),
'transparent bar samples again after a run that started before the latest change'
)
// Output can arrive after the process exits, so the outdated answer stays
// blocked until the replacement starts, not just until the old run exits.
assert(
exitedHandler !== '' && !/transparentForegroundRefreshQueued\s*=\s*false/.test(exitedHandler),
'an outdated transparent text color answer stays blocked after its process exits'
)

// put tolerates a placement target the bar does not carry, so the IPC call
// must reach the registry's put rather than route back through enable.
assert(
Expand Down