Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ad26e9c
test: reproduce missing per-display wallpaper rotation (#27075)
teamleaderleo Oct 28, 2026
b8cbdf7
feat: add per-display wallpaper rotation overrides (#27075)
teamleaderleo Oct 28, 2026
c8ed39e
feat: bind window wallpaper to its display (#27075)
teamleaderleo Oct 28, 2026
186d3bf
refactor: coalesce display wallpaper notifications
teamleaderleo Oct 28, 2026
d40d897
chore: document display wallpaper observer lifecycle
teamleaderleo Oct 28, 2026
f30f5b3
fix: use shuffle turn timing for display overrides
teamleaderleo Oct 28, 2026
248c779
Fix per-display backdrop rotation scheduling
teamleaderleo Oct 29, 2026
b76a210
Call backdrop shuffle calendar provider
teamleaderleo Oct 29, 2026
b9a12cf
Import display backdrop binding in window controller
teamleaderleo Oct 29, 2026
c9789bc
test: cover display fallback previews and room background priority
teamleaderleo Oct 29, 2026
affe181
fix: preserve wallpaper inheritance and stable display identity
teamleaderleo Oct 29, 2026
dae340a
test: use current backdrop catalog entries in display tests
teamleaderleo Oct 29, 2026
a6978fb
test: expose display folder enumeration on the UI thread
teamleaderleo Oct 29, 2026
9ff847f
fix: keep display backdrop I/O and notifications off the UI thread
teamleaderleo Oct 29, 2026
76213f9
test: probe folder reader thread from a synchronous helper
teamleaderleo Oct 29, 2026
462d076
test: reproduce stale display folder cache after cadence and screen c…
teamleaderleo Oct 29, 2026
cdac73e
fix: expire folder snapshots independently of the active display
teamleaderleo Oct 29, 2026
93a6651
test: advance past folder cache deadlines
teamleaderleo Oct 29, 2026
e2fcd5d
fix: detach display backdrop observers during deinit
teamleaderleo Oct 29, 2026
5d0883b
test: cover named display observer delivery and teardown
teamleaderleo Oct 29, 2026
e2259dc
fix: assume main actor for display binding destruction
teamleaderleo Oct 29, 2026
77c0bb2
fix: discard folder reads that cross their expiry
teamleaderleo Oct 29, 2026
de9f883
fix: expose display binding teardown to lifecycle adapter
teamleaderleo Oct 29, 2026
460fd19
fix: dispatch display binding teardown safely
teamleaderleo Oct 29, 2026
9ccc1b2
fix: make teardown adapter sendable
teamleaderleo Oct 29, 2026
44e7893
fix: retain main actor teardown state
teamleaderleo Oct 29, 2026
45379eb
fix: inherit global wallpaper cadence per display
teamleaderleo Oct 29, 2026
860b642
fix: expose per-display settings and applied previews
teamleaderleo Oct 29, 2026
f0e765b
Merge remote-tracking branch 'origin/feat-cmux-next' into wallpaper-r…
teamleaderleo Oct 29, 2026
50b3332
fix: let agents set per-display backgrounds like the global ones
teamleaderleo Oct 29, 2026
7f9c46d
fix: give the per-display background settings their catalog strings
teamleaderleo Oct 30, 2026
1a78fb8
chore: regenerate settings exports for per-display backgrounds
teamleaderleo Oct 30, 2026
c7683dc
Merge remote-tracking branch 'origin/feat-cmux-next' into wallpaper-r…
teamleaderleo Oct 31, 2026
6ce977f
arch-ratchet: reviewed exceptions for the per-display backdrop binding
teamleaderleo Oct 31, 2026
1d1b97c
chore: regenerate settings exports after the base merge
teamleaderleo Oct 31, 2026
c0993de
Merge remote-tracking branch 'origin/feat-cmux-next' into wallpaper-r…
teamleaderleo Oct 31, 2026
0fd6b9f
chore: settings reference rows for the per-display backgrounds after …
teamleaderleo Oct 31, 2026
0086413
Merge remote-tracking branch 'origin/feat-cmux-next' into wallpaper-r…
teamleaderleo Nov 2, 2026
0f10394
Merge remote-tracking branch 'origin/feat-cmux-next' into wallpaper-r…
teamleaderleo Nov 2, 2026
5fb0364
chore: settings reference rows for the per-display backgrounds
teamleaderleo Nov 2, 2026
22aac0c
Merge branch 'feat-cmux-next' into wallpaper-rotation
cmux-bot[bot] Nov 2, 2026
95e09f2
Merge remote-tracking branch 'origin/feat-cmux-next' into wallpaper-r…
teamleaderleo Nov 2, 2026
178a449
chore: settings reference rows for the per-display backgrounds
teamleaderleo Nov 2, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import CmuxNextBrowser
import CmuxNextDaemon
import CmuxNextDesign
import CmuxNextLayout
import CmuxNextSettings
import Observation

/// One window: sidebar, titlebar, and the content of the workspace it shows.
Expand Down Expand Up @@ -47,6 +48,8 @@ final class WindowController: NSWindowController, NSWindowDelegate {
/// it (with the color transition).
let themeScope = ThemeScope(level: .room)
private var roomObservation: Task<Void, Never>?
private var displayBackdropObservation: Task<Void, Never>?
private var displayBackdrop: DisplayBackdropBinding?
private var roomBrowserProfileObservation: Task<Void, Never>?
/// Shown while the window has no workspace (first connect, or failure).
private(set) var connectingView: DaemonConnectingView?
Expand Down Expand Up @@ -112,6 +115,20 @@ final class WindowController: NSWindowController, NSWindowDelegate {
// contentRect grows by the titlebar; restore the saved frame exactly.
if let frame { window.setFrame(frame, display: false) } else { window.center() }
window.delegate = self
let displayBackdrop = DisplayBackdropBinding(window: window, scope: themeScope,
displayID: { [weak window] in
window?.screen.flatMap(WindowPlacementFallback.displayID(of:))
})
self.displayBackdrop = displayBackdrop
if let settings = services.settings {
displayBackdrop.apply(settings.snapshot.root)
displayBackdropObservation = Task { [weak self, weak settings] in
guard let settings else { return }
for await root in ObservationStream({ settings.applied.root }) {
self?.displayBackdrop?.apply(root)
}
}
}
window.focus = focus
focus.applier = focusApplier
focus.window = window
Expand Down Expand Up @@ -139,6 +156,9 @@ final class WindowController: NSWindowController, NSWindowDelegate {
startupObservation?.cancel()
previewFeaturesObservation?.cancel()
roomObservation?.cancel()
displayBackdropObservation?.cancel()
displayBackdrop?.stop()
displayBackdrop = nil
roomBrowserProfileObservation?.cancel()
state.roomBrowserProfileOf = nil
content?.teardown()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
public import AppKit
public import CmuxNextDesign
import CmuxNextWakeups

/// Keeps destruction's main-actor hop in a small AppKit lifecycle seam.
@MainActor
private final class DisplayBackdropLifecycle {
let scope: ThemeScope
let displayScope: ThemeScope
let inheritedScope: ThemeScope
let center: NotificationCenter
let recordRemoval: (() -> Void)?
let timer = DemandTimer(owner: "display-backdrop")
var observers: [NSObjectProtocol] = []
var stopped = false
var generation = 0
var folders: [String: (task: Task<[BackdropSelection], Never>, expires: Date, pictures: [BackdropSelection]?)] = [:]
var folderRefresh: Task<Void, Never>?

init(scope: ThemeScope, displayScope: ThemeScope, inheritedScope: ThemeScope, center: NotificationCenter,
recordRemoval: (() -> Void)?) {
self.scope = scope
self.displayScope = displayScope
self.inheritedScope = inheritedScope
self.center = center
self.recordRemoval = recordRemoval
}

func teardown() {
guard !stopped else { return }
stopped = true
generation += 1
timer.cancel()
folderRefresh?.cancel()
folderRefresh = nil
for folder in folders.values { folder.task.cancel() }
folders.removeAll()
observers.forEach { center.removeObserver($0); recordRemoval?() }
observers.removeAll()
displayScope.pinBackdrop(.inherit)
if scope.parent === displayScope { scope.setParent(inheritedScope) }
}
}

private struct DisplayBackdropDeinitAdapter: Sendable {
private let cleanup: @MainActor @Sendable () -> Void

init(lifecycle: DisplayBackdropLifecycle) {
cleanup = { lifecycle.teardown() }
}

nonisolated func run() {
MainDelivery().run(cleanup)
}
}

/// Applies a display background between the app and room scopes. Explicit window and workspace
/// choices still win. The window owner calls ``stop()`` when it tears down.
@MainActor
public final class DisplayBackdropBinding {
private let scope: ThemeScope
private let displayScope: ThemeScope
private let inheritedScope: ThemeScope
private let displayID: () -> String?
private let now: () -> Date
private let calendar: () -> Calendar
private let listFolder: @Sendable (String) async -> [BackdropSelection]
private let lifecycle: DisplayBackdropLifecycle
private let deinitAdapter: DisplayBackdropDeinitAdapter
private let recordObserver: ((Notification.Name, AnyObject?, OperationQueue?) -> Void)?
private var root: JSONValue = [:]
private var stopped: Bool { lifecycle.stopped }
private var generation: Int { get { lifecycle.generation } set { lifecycle.generation = newValue } }
private var folders: [String: (task: Task<[BackdropSelection], Never>, expires: Date, pictures: [BackdropSelection]?)] {
get { lifecycle.folders }
set { lifecycle.folders = newValue }
}
private(set) var folderRefresh: Task<Void, Never>? {
get { lifecycle.folderRefresh }
set { lifecycle.folderRefresh = newValue }
}

public init(window: NSWindow, scope: ThemeScope, center: NotificationCenter = .default,
displayID: @escaping () -> String?, now: @escaping () -> Date = Date.init,
calendar: @escaping () -> Calendar = { .current },
listFolder: @escaping @Sendable (String) async -> [BackdropSelection] = DisplayBackdropBinding.readFolder,
recordObserver: ((Notification.Name, AnyObject?, OperationQueue?) -> Void)? = nil,
recordRemoval: (() -> Void)? = nil) {
self.scope = scope; self.displayID = displayID; self.now = now; self.calendar = calendar
self.listFolder = listFolder
self.recordObserver = recordObserver
inheritedScope = scope.parent ?? .app
displayScope = ThemeScope(level: .room, parent: inheritedScope)
scope.setParent(displayScope)
lifecycle = DisplayBackdropLifecycle(scope: scope, displayScope: displayScope, inheritedScope: inheritedScope,
center: center, recordRemoval: recordRemoval)
deinitAdapter = DisplayBackdropDeinitAdapter(lifecycle: lifecycle)
let names: [Notification.Name] = [NSWindow.didChangeScreenNotification, .NSSystemClockDidChange,
.NSCalendarDayChanged, .NSSystemTimeZoneDidChange]
for name in names {
// Never make a notification's posting thread wait for the UI actor (SwiftUI can hold its render lock).
recordObserver?(name, name == NSWindow.didChangeScreenNotification ? window : nil, nil)
lifecycle.observers.append(center.addObserver(forName: name, object: name == NSWindow.didChangeScreenNotification ? window : nil,
queue: nil) { [weak self] _ in
Task { @MainActor [weak self] in self?.refresh() }
})
}
}

nonisolated deinit {
deinitAdapter.run()
}

/// Resolves and lists a folder on the global executor, including all symlink and metadata reads.
@concurrent public nonisolated static func readFolder(_ path: String) async -> [BackdropSelection] {
guard !Task.isCancelled else { return [] }
return BackdropUserImages(folder: URL(fileURLWithPath: path, isDirectory: true)).list().sorted { $0.id < $1.id }
}

public func apply(_ root: JSONValue) {
self.root = root
// Bound cached/in-flight listings to configured folders; a removed folder cannot keep work alive.
let paths = Set((root.value(at: ["appearance", "displayBackgrounds"])?.objectValue ?? [:]).values
.compactMap { $0.stringValue.flatMap(BackdropSelectionSetting.folderPath) })
for path in Array(folders.keys) where !paths.contains(path) {
folders.removeValue(forKey: path)?.task.cancel()
}
refresh()
}

public func stop() {
teardown()
}

fileprivate func teardown() {
lifecycle.teardown()
}

private func refresh() {
guard !stopped else { return }
generation += 1
lifecycle.timer.cancel()
folderRefresh?.cancel()
folderRefresh = nil
let values = root.value(at: ["appearance", "displayBackgrounds"])?.objectValue
guard let id = displayID(), let raw = values?[id]?.stringValue else {
displayScope.pinBackdrop(.inherit)
return
}
guard raw != "none" else { displayScope.pinBackdrop(.none); return }
let rotation = root.value(at: ["appearance", "displayBackgroundRotations"])?.objectValue?[id]?.stringValue
.flatMap(BackdropRotation.init(rawValue:))
?? root.value(at: ["appearance", "backgroundRotation"])?.stringValue.flatMap(BackdropRotation.init(rawValue:))
?? .defaultRotation
if let path = BackdropSelectionSetting.folderPath(raw) {
refreshFolder(path, rotation: rotation)
} else if raw == BackdropSelectionSetting.dailyID {
let turn = BackdropShuffle(source: .paintings, rotation: rotation).turn(at: now(), calendar: calendar())
displayScope.pinBackdrop(turn.picture.map(BackdropPin.selection) ?? .none)
schedule(after: turn.wait)
} else {
displayScope.pinBackdrop(BackdropSelection(id: raw).map(BackdropPin.selection) ?? .inherit)
}
}

private func refreshFolder(_ path: String, rotation: BackdropRotation) {
// A pending read is shared across refreshes. Completed listings expire at the next rotation,
// so screen/settings changes reuse them while additions and removals appear on the next turn.
if let expires = folders[path]?.expires, expires <= now() {
folders.removeValue(forKey: path)?.task.cancel()
}
if folders[path] == nil {
let listFolder = listFolder
folders[path] = (Task.detached(priority: .utility) { await listFolder(path) },
rotation.nextTurn(after: now(), calendar: calendar()), nil)
}
guard let request = folders[path] else { return }
// Freshness belongs to the read, not to whichever display eventually consumes it.
// A shorter cadence also shortens the lifetime of an already cached/in-flight read.
folders[path]?.expires = min(request.expires, rotation.nextTurn(after: now(), calendar: calendar()))
if let pictures = request.pictures {
applyFolder(pictures, rotation: rotation)
return
}
let requestedGeneration = generation
displayScope.pinBackdrop(.none)
folderRefresh = Task { [weak self] in
let pictures = await request.task.value
guard !Task.isCancelled, let self, !self.stopped, self.generation == requestedGeneration else { return }
guard let expires = self.folders[path]?.expires, expires > self.now() else {
self.folders.removeValue(forKey: path)
self.generation += 1
self.refreshFolder(path, rotation: rotation)
return
}
self.folders[path]?.pictures = pictures
self.applyFolder(pictures, rotation: rotation)
}
}

private func applyFolder(_ pictures: [BackdropSelection], rotation: BackdropRotation) {
let date = now(), calendar = calendar()
let picture = rotation.index(count: pictures.count, on: date, calendar: calendar).map { pictures[$0] }
displayScope.pinBackdrop(picture.map(BackdropPin.selection) ?? .none)
schedule(after: max(1, rotation.nextTurn(after: date, calendar: calendar).timeIntervalSince(date) + 1))
}

private func schedule(after wait: TimeInterval) {
lifecycle.timer.schedule(after: .seconds(wait)) { @MainActor [weak self] in self?.refresh() }
}
}
Loading