From c87bfdd2b102ac0dce737464894d223b90ee4fe9 Mon Sep 17 00:00:00 2001 From: Quentin Eude Date: Sun, 15 Nov 2026 11:06:03 +0100 Subject: [PATCH 1/3] fix(input): let swipes reach the native fullscreen placeholder --- Sources/DefiCore/WorkspaceScrolling.swift | 33 ++++-------- Sources/DefiDaemon/DaemonScrollGesture.swift | 16 +++--- .../WorkspaceScrollingTests.swift | 11 ---- Tests/DefiDaemonTests/ScrollPanTests.swift | 54 +++++++++++++++++++ 4 files changed, 72 insertions(+), 42 deletions(-) diff --git a/Sources/DefiCore/WorkspaceScrolling.swift b/Sources/DefiCore/WorkspaceScrolling.swift index bc786547..af2b5d0c 100644 --- a/Sources/DefiCore/WorkspaceScrolling.swift +++ b/Sources/DefiCore/WorkspaceScrolling.swift @@ -240,7 +240,6 @@ public func scrollGestureSnap( viewport: Rect, windows: [Window] = [], settings: LayoutSettings, - excludingWindowIDs: Set = [], rest: Double, current: Double, projected: Double @@ -258,7 +257,7 @@ public func scrollGestureSnap( if direction == 1 { let target = focusedColumnScrollTarget( workspace: stepped, viewport: viewport, windows: windows, - settings: settings, excludingWindowIDs: excludingWindowIDs) + settings: settings) rests.append((column, target.offset, target.focus)) } while workspace.columns.indices.contains(column + direction) { @@ -266,14 +265,12 @@ public func scrollGestureSnap( stepped.focusedColumn = column let target = focusedColumnScrollTarget( workspace: stepped, viewport: viewport, windows: windows, - settings: settings, excludingWindowIDs: excludingWindowIDs) + settings: settings) stepped.scrollOffset = target.offset stepped.scrollFocus = target.focus rests.append((column, target.offset, target.focus)) } } - // A native fullscreen column rests where its neighbour does; it is never the landing. - rests.removeAll { isOutOfLayout(workspace.columns[$0.column], excludingWindowIDs) } rests.sort { $0.column < $1.column } let offsets = rests.map(\.offset).sorted() // A flick carries to the next resting place at most, never several columns at once: @@ -303,7 +300,6 @@ public func scrollGestureFreeRest( viewport: Rect, windows: [Window] = [], settings: LayoutSettings, - excludingWindowIDs: Set = [], current: Double, projected: Double ) -> (column: Int, offset: Double, focus: ScrollFocus?)? { @@ -312,26 +308,20 @@ public func scrollGestureFreeRest( revealing.centerFocusedColumn = .never revealing.alwaysCenterSingleColumn = false let extents = scrollGestureExtents(workspace: workspace, viewport: viewport, windows: windows, - settings: revealing, excludingWindowIDs: excludingWindowIDs) - // Columns in the layout, with their centres in strip widths. - let shown = workspace.columns.indices.filter { !isOutOfLayout(workspace.columns[$0], excludingWindowIDs) } - guard let lowest = shown.map({ extents[$0].lowerBound }).min(), - let highest = shown.map({ extents[$0].upperBound }).max() + settings: revealing) + guard let lowest = extents.map(\.lowerBound).min(), let highest = extents.map(\.upperBound).max() else { return nil } let wanted = min(max(projected, lowest), highest) let forward = projected >= current - let widths = columnWidthsInViewports( - workspaceForLayout(workspace, excludingWindowIDs: excludingWindowIDs).columns, viewport: viewport, + let widths = columnWidthsInViewports(workspace.columns, viewport: viewport, windowsByID: Dictionary(uniqueKeysWithValues: windows.map { ($0.id, $0) }), settings: settings) - guard shown.count == widths.count else { return nil } - let centers = Dictionary(uniqueKeysWithValues: shown.indices.map { - (shown[$0], widths.prefix($0).reduce(0, +) + widths[$0] / 2) - }) let distance = { (column: Int) in (max(extents[column].lowerBound - wanted, wanted - extents[column].upperBound, 0), - abs(centers[column]! - (wanted + 0.5)), forward ? -column : column) + abs(widths.prefix(column).reduce(0, +) + widths[column] / 2 - (wanted + 0.5)), + forward ? -column : column) } - guard let column = shown.min(by: { distance($0) < distance($1) }) else { return nil } + guard let column = workspace.columns.indices.min(by: { distance($0) < distance($1) }) + else { return nil } let extent = extents[column] let rows = workspace.columns[column] let windowID = rows.windows.indices.contains(rows.focusedWindow) ? rows.windows[rows.focusedWindow] : nil @@ -339,11 +329,6 @@ public func scrollGestureFreeRest( windowID.map { ScrollFocus(windowID: $0, centered: false, free: true) }) } -/// Whether layout leaves the column out: every window in it is excluded (native fullscreen). -private func isOutOfLayout(_ column: Column, _ excludingWindowIDs: Set) -> Bool { - column.windows.allSatisfy(excludingWindowIDs.contains) -} - /// Each column's resting offsets: the focus policy pushed from the right, then from the /// left. The column is fully in view anywhere between them. public func scrollGestureExtents( diff --git a/Sources/DefiDaemon/DaemonScrollGesture.swift b/Sources/DefiDaemon/DaemonScrollGesture.swift index 0187e4f0..2f519df2 100644 --- a/Sources/DefiDaemon/DaemonScrollGesture.swift +++ b/Sources/DefiDaemon/DaemonScrollGesture.swift @@ -123,9 +123,9 @@ extension Daemon { moving.formUnion(neighbors.keys) } else { guard !workspace.columns.isEmpty else { return } + // The native fullscreen placeholders end the strip, as for key presses. let extents = scrollGestureExtents(workspace: workspace, viewport: viewport, - windows: tiled.compactMap { state.windows[$0] }, settings: state.layout, - excludingWindowIDs: state.nativeFullscreenWindowIDs) + windows: tiled.compactMap { state.windows[$0] }, settings: state.layout) guard let lowest = extents.map(\.lowerBound).min(), let highest = extents.map(\.upperBound).max() else { return } let rest = workspace.targetScrollOffset @@ -180,11 +180,10 @@ extension Daemon { let windows = workspace.columns.flatMap(\.windows).compactMap { state.windows[$0] } guard let snap = config.input.scrollGestureSnap ? scrollGestureSnap(workspace: workspace, viewport: pan.viewport, windows: windows, - settings: state.layout, excludingWindowIDs: state.nativeFullscreenWindowIDs, - rest: pan.rest, current: offset, projected: pan.rest - projected / pan.stripWidth) + settings: state.layout, rest: pan.rest, current: offset, + projected: pan.rest - projected / pan.stripWidth) : scrollGestureFreeRest(workspace: workspace, viewport: pan.viewport, windows: windows, - settings: state.layout, excludingWindowIDs: state.nativeFullscreenWindowIDs, - current: offset, projected: pan.rest - projected / pan.stripWidth), + settings: state.layout, current: offset, projected: pan.rest - projected / pan.stripWidth), settleScrollGesture(monitorID: pan.monitorID, workspaceID: pan.workspaceID, column: snap.column, offset: snap.offset, focus: snap.focus, state: &state) else { @@ -198,7 +197,10 @@ extension Daemon { commandGeneration &+= 1 activeMonitorID = pan.monitorID settleScrollPan(on: pan.monitorID) - if let selected = state.selectedWindowID(on: pan.monitorID) { + // A swipe only selects a placeholder: focusing its window would switch to its Space. + if let selected = state.selectedWindowID(on: pan.monitorID), + !state.nativeFullscreenWindowIDs.contains(selected) + { focus.queueCommand(PendingAnimatedFocus( windowID: selected, previousSelectedWindowID: previouslySelectedWindowID, diff --git a/Tests/DefiCoreTests/WorkspaceScrollingTests.swift b/Tests/DefiCoreTests/WorkspaceScrollingTests.swift index 8c07be19..fbdca6e9 100644 --- a/Tests/DefiCoreTests/WorkspaceScrollingTests.swift +++ b/Tests/DefiCoreTests/WorkspaceScrollingTests.swift @@ -435,17 +435,6 @@ struct ScrollGestureSnapTests { #expect(abs(rest.offset - 0.1) < 1e-9) } - @Test - func `A swipe never lands on a native fullscreen column`() throws { - let hidden: Set = [WindowID(rawValue: 4)] - let snap = try #require(scrollGestureSnap(workspace: workspace(), viewport: viewport, - settings: LayoutSettings(), excludingWindowIDs: hidden, rest: 0, current: 0.6, projected: 9)) - #expect(snap.column == 2) - let free = try #require(scrollGestureFreeRest(workspace: workspace(), viewport: viewport, - settings: LayoutSettings(), excludingWindowIDs: hidden, current: 0.6, projected: 9)) - #expect(free.column == 2) - } - @Test func `A free position holds against the centring policy until focus leaves the column`() { let settings = LayoutSettings(centerFocusedColumn: .always) diff --git a/Tests/DefiDaemonTests/ScrollPanTests.swift b/Tests/DefiDaemonTests/ScrollPanTests.swift index aa3ba400..51d11a53 100644 --- a/Tests/DefiDaemonTests/ScrollPanTests.swift +++ b/Tests/DefiDaemonTests/ScrollPanTests.swift @@ -1,5 +1,9 @@ import CoreGraphics +import DefiConfig +import DefiMacOS import DefiModel +import DefiRuntime +import Foundation import Testing @testable import DefiDaemon @@ -30,4 +34,54 @@ struct ScrollPanTests { #expect(pan.shift(travel: -10_000) > -1440 - 72) #expect(abs(scrollPanProjection - 0.333) < 0.001) } + + /// A swipe reaches the native fullscreen placeholder at the strip's end, as key presses do, + /// and only selects it: the fullscreen Space stays where it is. + @Test @NavigationActor + func `A swipe selects the fullscreen placeholder without focusing its window`() async throws { + let directory = URL(filePath: "/tmp/defi-swipe-\(UUID().uuidString)") + try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true) + defer { try? FileManager.default.removeItem(at: directory) } + let configURL = directory.appending(path: "config.toml") + try "[layout]\ndefault_column_width = 0.5\ngaps = 0\n[animation]\nenabled = false\n" + .write(to: configURL, atomically: true, encoding: .utf8) + let menuBar = await MainActor.run { MenuBarState(accessibilityTrusted: { false }) } + let daemon = try Daemon( + options: DaemonOptions(arguments: [ + "--config", configURL.path, "--socket", directory.appending(path: "daemon.sock").path, + ]), + menuBar: menuBar, + instanceLockURL: directory.appending(path: "daemon.lock"), + topologyStore: WorkspaceTopologyStore(url: directory.appending(path: "topology.json")), + workspaceStatePublisher: { _ in }, + desktopSnapshotOverviewUpdater: { _ in } + ) + defer { daemon.flushPendingTopologyWrite() } + let monitorID = MonitorID(rawValue: 1) + let monitor = MonitorSnapshot(id: monitorID, frame: Rect(x: 0, y: 0, width: 1_000, height: 700)) + daemon.latestMonitors = [monitor] + daemon.activeMonitorID = monitorID + daemon.state.attachMonitor(monitorID) + for id in 1...4 { + try discoverWindow( + Window(id: WindowID(rawValue: UInt64(id)), appID: "app-\(id)", title: "Window \(id)", + frame: Rect(x: 0, y: 0, width: 500, height: 700), monitorID: monitorID), + decision: RuleDecision(followFocus: true), isNativelyFocused: true, state: &daemon.state) + } + // Window 4 went native fullscreen: its column is the placeholder at the end. + daemon.state.nativeFullscreenWindowIDs = [WindowID(rawValue: 4)] + focusWindow(WindowID(rawValue: 3), state: &daemon.state) + synchronizeScrollOffsets(state: &daemon.state, viewports: [monitorID: monitor.frame]) + daemon.state.monitors[0].workspaces[0].scrollOffset = 0.5 + #expect(daemon.state.monitors[0].workspaces[0].targetScrollOffset == 0.5) + + // Half a screen to the left, released at rest. + daemon.handleScrollGesture(.panBegan(id: 1, vertical: false, location: CGPoint(x: 500, y: 350), timestamp: 0)) + daemon.handleScrollGesture(.panEnded(id: 1, travel: -750, velocity: 0, timestamp: 0.3)) + + #expect(daemon.state.monitors[0].workspaces[0].focusedColumn == 3) + #expect(daemon.state.monitors[0].workspaces[0].targetScrollOffset == 1) + #expect(daemon.focus.pendingAnimatedFocus == nil) + #expect(daemon.focus.submittedCommandFocus == nil) + } } From 9e169105e70ed8b60f3c25eadf29272629e855a8 Mon Sep 17 00:00:00 2001 From: Quentin Eude Date: Sun, 15 Nov 2026 17:31:26 +0100 Subject: [PATCH 2/3] fix(overlay): carry the native fullscreen placeholder with the strip The placeholder panel was never on the overlay: during a swipe or an animated move it vanished under the backdrop and popped back once the motion landed. It now travels as an overlay window drawn from the same picture as the panel, built from the daemon's own window state, since macOS lists a window on its fullscreen Space only intermittently. --- Sources/DefiDaemon/DaemonDesktop.swift | 31 +++- Sources/DefiDaemon/DefiDaemon.swift | 2 + .../MacOSPlatform+FrameApplication.swift | 19 +- Sources/DefiMacOS/MacOSPlatform.swift | 29 ++- .../NativeFullscreenPlaceholder.swift | 167 ++++++++++-------- Sources/DefiMacOS/RibbonProxyRenderer.swift | 26 ++- 6 files changed, 182 insertions(+), 92 deletions(-) diff --git a/Sources/DefiDaemon/DaemonDesktop.swift b/Sources/DefiDaemon/DaemonDesktop.swift index 71fa9bdb..0e0f4e4f 100644 --- a/Sources/DefiDaemon/DaemonDesktop.swift +++ b/Sources/DefiDaemon/DaemonDesktop.swift @@ -51,6 +51,7 @@ extension Daemon { var ribbonFrames: [FrameAssignment] = [] var borderAssignments: [FrameAssignment] = [] var nativeFullscreenPlaceholderAssignments: [FrameAssignment] = [] + var nativeFullscreenRibbonFrames: [FrameAssignment] = [] var hiddenWindowIDs = Set() var outOfScopeWindowIDs = Set() var cachedMonitorIDs = Set() @@ -71,6 +72,7 @@ extension Daemon { nativeFullscreenPlaceholderAssignments.append( contentsOf: cached.nativeFullscreenPlaceholderAssignments ) + nativeFullscreenRibbonFrames.append(contentsOf: cached.nativeFullscreenRibbonFrames) hiddenWindowIDs.formUnion(cached.hiddenWindowIDs) outOfScopeWindowIDs.formUnion(cached.assignments.map(\.windowID)) cachedMonitorIDs.insert(monitor.id) @@ -97,6 +99,7 @@ extension Daemon { var monitorAssignments: [FrameAssignment] = [] var monitorBorderAssignments: [FrameAssignment] = [] var monitorNativeFullscreenPlaceholderAssignments: [FrameAssignment] = [] + var monitorNativeFullscreenRibbonFrames: [FrameAssignment] = [] var monitorHiddenWindowIDs = Set() for workspaceIndex in state.monitors[monitorIndex].workspaces.indices { let workspace = state.monitors[monitorIndex].workspaces[workspaceIndex] @@ -124,14 +127,17 @@ extension Daemon { } if !state.nativeFullscreenWindowIDs.isEmpty { + let fullscreenLayout = computeLayout( + workspace: workspace, + viewport: viewport, + windows: workspaceWindows, + settings: state.layout + ) + monitorNativeFullscreenRibbonFrames.append(contentsOf: fullscreenLayout.filter { + state.nativeFullscreenWindowIDs.contains($0.windowID) + }) let fullscreenStrip = continuousStripFramesForActiveWorkspace( - computeLayout( - workspace: workspace, - viewport: viewport, - windows: workspaceWindows, - settings: state.layout - ), - viewport: viewport, park: park + fullscreenLayout, viewport: viewport, park: park ) monitorNativeFullscreenPlaceholderAssignments.append( contentsOf: fullscreenStrip.frames.filter { @@ -167,6 +173,7 @@ extension Daemon { borderAssignments: monitorBorderAssignments, nativeFullscreenPlaceholderAssignments: monitorNativeFullscreenPlaceholderAssignments, + nativeFullscreenRibbonFrames: monitorNativeFullscreenRibbonFrames, hiddenWindowIDs: monitorHiddenWindowIDs ) layoutPlansByMonitor[monitor.id] = plan @@ -182,6 +189,7 @@ extension Daemon { nativeFullscreenPlaceholderAssignments.append( contentsOf: plan.nativeFullscreenPlaceholderAssignments ) + nativeFullscreenRibbonFrames.append(contentsOf: plan.nativeFullscreenRibbonFrames) hiddenWindowIDs.formUnion(plan.hiddenWindowIDs) } let skipped = additionalSkippedWindowIDs.union(outOfScopeWindowIDs) @@ -221,6 +229,15 @@ extension Daemon { laidOut: !cachedMonitorIDs.contains(monitor.id)) } } + platform.nativeFullscreenRibbonPlaceholders = Dictionary( + nativeFullscreenRibbonFrames.compactMap { assignment in + guard let window = state.windows[assignment.windowID], + let monitorID = state.monitorID(containing: assignment.windowID) + else { return nil } + return (window.id, NativeFullscreenPlaceholder(windowID: window.id, monitorID: monitorID, + appID: window.appID, title: window.title, frame: assignment.frame)) + } + ) { first, _ in first } platform.apply( platformAssignments, ribbonFrames: ribbonFrames, diff --git a/Sources/DefiDaemon/DefiDaemon.swift b/Sources/DefiDaemon/DefiDaemon.swift index 196d3667..1352dd32 100644 --- a/Sources/DefiDaemon/DefiDaemon.swift +++ b/Sources/DefiDaemon/DefiDaemon.swift @@ -61,6 +61,8 @@ struct MonitorLayoutPlan { let assignments: [FrameAssignment] let borderAssignments: [FrameAssignment] let nativeFullscreenPlaceholderAssignments: [FrameAssignment] + /// Every placeholder of the active workspace at its ribbon place, on screen or not. + let nativeFullscreenRibbonFrames: [FrameAssignment] let hiddenWindowIDs: Set } diff --git a/Sources/DefiMacOS/MacOSPlatform+FrameApplication.swift b/Sources/DefiMacOS/MacOSPlatform+FrameApplication.swift index 8a95284d..575d87da 100644 --- a/Sources/DefiMacOS/MacOSPlatform+FrameApplication.swift +++ b/Sources/DefiMacOS/MacOSPlatform+FrameApplication.swift @@ -62,6 +62,8 @@ extension MacOSPlatform { previous: previousRibbonFrames, monitors: windowProxyMonitors) for id in deferredRibbonMoves.intersection(skippedWindowIDs) { history[id] = previousRibbonFrames[id] } previousLogicalRibbonFrames = history + let previousPlaceholderFrames = previousNativeFullscreenRibbonFrames + previousNativeFullscreenRibbonFrames = nativeFullscreenRibbonPlaceholders.mapValues(\.frame) deferredRibbonMoves.subtract(resumed) frameSubmissionGeneration &+= 1 let submissionGeneration = frameSubmissionGeneration @@ -70,7 +72,8 @@ extension MacOSPlatform { if windowProxiesEnabled { let resumes = !animates && !resumed.isEmpty applyWindowProxies(assignments: assignments, ribbonFrames: ribbonFrames, - previousRibbonFrames: previousRibbonFrames, skippedWindowIDs: skippedWindowIDs, + previousRibbonFrames: previousRibbonFrames, previousPlaceholderFrames: previousPlaceholderFrames, + skippedWindowIDs: skippedWindowIDs, hiddenWindowIDs: hiddenWindowIDs, source: resumes ? "native-focus-animation" : source, animated: animated || resumes) } @@ -607,7 +610,8 @@ func windowProxyMotion(ribbonTargets: [WindowID: Rect], otherTargets: [WindowID: extension MacOSPlatform { // Runs entirely on the navigation actor: command intake never waits for the main thread. func applyWindowProxies(assignments: [FrameAssignment], ribbonFrames: [FrameAssignment], - previousRibbonFrames: [WindowID: Rect], skippedWindowIDs: Set, + previousRibbonFrames: [WindowID: Rect], previousPlaceholderFrames: [WindowID: Rect], + skippedWindowIDs: Set, hiddenWindowIDs: Set, source: String, animated: Bool) { let allWindows = Dictionary(lastSnapshotWindows.map { ($0.id, $0) }) { first, _ in first } // Each display moves on its own overlay, exactly as a single display does. @@ -627,8 +631,8 @@ extension MacOSPlatform { let ribbon = ribbonFrames.filter { owned.contains($0.windowID) } let shown = applyWindowProxies(on: monitor, presenter: presenter, assignments: assignments.filter { owned.contains($0.windowID) }, ribbonFrames: ribbon, - previousRibbonFrames: previousRibbonFrames, skippedWindowIDs: skippedWindowIDs, - hiddenWindowIDs: hiddenWindowIDs, allWindows: allWindows, + previousRibbonFrames: previousRibbonFrames, previousPlaceholderFrames: previousPlaceholderFrames, + skippedWindowIDs: skippedWindowIDs, hiddenWindowIDs: hiddenWindowIDs, allWindows: allWindows, motion: windowProxyMotionDuration(source: source, animated: animated, hasRibbon: !ribbon.isEmpty, workspaceShift: monitor.workspaceShift)) if released, !shown { presenter.landDrop() } @@ -637,8 +641,8 @@ extension MacOSPlatform { private func applyWindowProxies(on monitor: WindowProxyMonitor, presenter: RibbonProxyPresenter, assignments: [FrameAssignment], ribbonFrames: [FrameAssignment], - previousRibbonFrames: [WindowID: Rect], skippedWindowIDs: Set, - hiddenWindowIDs: Set, allWindows: [WindowID: Window], + previousRibbonFrames: [WindowID: Rect], previousPlaceholderFrames: [WindowID: Rect], + skippedWindowIDs: Set, hiddenWindowIDs: Set, allWindows: [WindowID: Window], motion duration: TimeInterval?) -> Bool { let viewport = monitor.viewport, workspaceShift = monitor.workspaceShift let windows = allWindows.filter { monitor.windowIDs.contains($0.key) } @@ -709,10 +713,11 @@ extension MacOSPlatform { return RibbonProxyWindow(id: plan.id, appID: window.appID, processID: processID, from: from, to: plan.to, appears: appears) } + proxies += nativeFullscreenProxies(monitor, from: previousPlaceholderFrames) // Visible managed windows without a planned motion (skipped writes, floating // windows) are drawn still at their real place instead of blocking the overlay. let moving = Set(proxies.map(\.id)) - for (id, window) in windows where !moving.contains(id) { + for (id, window) in windows where !moving.contains(id) && !nativeFullscreenWindowIDs.contains(id) { guard let processID = window.processID, let frame = observed[id], windowProxyVisibleOverlap(frame, viewport) > 1.01 else { continue } proxies.append(RibbonProxyWindow(id: id, appID: window.appID, processID: processID, diff --git a/Sources/DefiMacOS/MacOSPlatform.swift b/Sources/DefiMacOS/MacOSPlatform.swift index 95e0e822..49fbbf37 100644 --- a/Sources/DefiMacOS/MacOSPlatform.swift +++ b/Sources/DefiMacOS/MacOSPlatform.swift @@ -230,7 +230,7 @@ public final class MacOSPlatform { // Visible windows start exactly where they are (the held one is already under the // pointer); only windows off screen take their logical place. return windows.compactMap { id, window -> RibbonProxyWindow? in - guard let processID = window.processID else { return nil } + guard let processID = window.processID, !nativeFullscreenWindowIDs.contains(id) else { return nil } let logical = previousLogicalRibbonFrames[id] // A window still on its way to or from its parking corner is not on the ribbon yet. if let frame = native[id], windowProxyVisibleOverlap(frame, viewport) > 1.01, @@ -240,9 +240,34 @@ public final class MacOSPlatform { // Parked at a corner, its native y is the display's bottom: the ribbon place is logical. guard let logical else { return nil } return RibbonProxyWindow(id: id, appID: window.appID, processID: processID, from: logical, to: logical) - } + } + nativeFullscreenProxies(monitor, from: previousNativeFullscreenRibbonFrames) } var previousLogicalRibbonFrames: [WindowID: Rect] = [:] + /// Native fullscreen placeholders at their ribbon place, set before each layout. + public var nativeFullscreenRibbonPlaceholders: [WindowID: NativeFullscreenPlaceholder] = [:] + var previousNativeFullscreenRibbonFrames: [WindowID: Rect] = [:] + private var nativeFullscreenPictures: [WindowID: (key: String, image: CGImage)] = [:] + + /// The placeholders of `monitor` as overlay windows, so they travel with the ribbon. + func nativeFullscreenProxies(_ monitor: WindowProxyMonitor, from previous: [WindowID: Rect]) + -> [RibbonProxyWindow] { + nativeFullscreenPictures = nativeFullscreenPictures.filter { nativeFullscreenRibbonPlaceholders[$0.key] != nil } + return nativeFullscreenRibbonPlaceholders.compactMap { id, window -> RibbonProxyWindow? in + guard monitor.windowIDs.contains(id) else { return nil } + let to = window.frame + let scale = RibbonProxyStore.shared.screen(containing: monitor.viewport)?.scale ?? 2 + let selected = id == desiredSelectedWindowID + let accent = RibbonProxyPresenter.borderStyle?.activeColor ?? 0 + let key = "\(window.appID)|\(window.title)|\(to.width)x\(to.height)@\(scale)|\(selected)|\(accent)" + let image = nativeFullscreenPictures[id].flatMap { $0.key == key ? $0.image : nil } + ?? nativeFullscreenPlaceholderImage(appID: window.appID, title: window.title, + size: CGSize(width: to.width, height: to.height), scale: scale, selected: selected, accentColor: accent) + guard let image else { return nil } + nativeFullscreenPictures[id] = (key, image) + return RibbonProxyWindow(id: id, appID: window.appID, processID: 0, + from: previous[id] ?? to, to: to, picture: image) + } + } /// Ribbon moves an animated layout could not write yet; the layout that writes them animates. var deferredRibbonMoves: Set = [] /// When the latest window opening began holding the screen: only its check releases the hold. diff --git a/Sources/DefiMacOS/NativeFullscreenPlaceholder.swift b/Sources/DefiMacOS/NativeFullscreenPlaceholder.swift index c43d28ea..9fc29433 100644 --- a/Sources/DefiMacOS/NativeFullscreenPlaceholder.swift +++ b/Sources/DefiMacOS/NativeFullscreenPlaceholder.swift @@ -191,52 +191,17 @@ private final class NativeFullscreenPlaceholderPanel { @MainActor private final class NativeFullscreenPlaceholderView: NSView { - private let iconView = NSImageView() - private let appLabel = NSTextField(labelWithString: "") - private let statusLabel = NSTextField(labelWithString: "macOS Full Screen") - private var selected: Bool? - private var accentColor: UInt32? + private var appID: String + private var title: String + private var selected = false + private var accentColor: UInt32 = 0 init(appID: String, title: String) { + self.appID = appID + self.title = title super.init(frame: .zero) wantsLayer = true - layer?.backgroundColor = NSColor( - srgbRed: 15 / 255, - green: 15 / 255, - blue: 20 / 255, - alpha: 1 - ).cgColor - layer?.cornerRadius = 10 - layer?.borderWidth = 1 - layer?.borderColor = NSColor.white.withAlphaComponent(0.14).cgColor - layer?.masksToBounds = true - - iconView.imageScaling = .scaleProportionallyUpOrDown - iconView.translatesAutoresizingMaskIntoConstraints = false - appLabel.font = .systemFont(ofSize: 17, weight: .semibold) - appLabel.textColor = .white - appLabel.alignment = .center - appLabel.lineBreakMode = .byTruncatingTail - statusLabel.font = .systemFont(ofSize: 12, weight: .regular) - statusLabel.textColor = NSColor.white.withAlphaComponent(0.68) - statusLabel.alignment = .center - - let stack = NSStackView(views: [iconView, appLabel, statusLabel]) - stack.orientation = .vertical - stack.alignment = .centerX - stack.spacing = 8 - stack.translatesAutoresizingMaskIntoConstraints = false - addSubview(stack) - NSLayoutConstraint.activate([ - iconView.widthAnchor.constraint(equalToConstant: 80), - iconView.heightAnchor.constraint(equalToConstant: 80), - stack.centerXAnchor.constraint(equalTo: centerXAnchor), - stack.centerYAnchor.constraint(equalTo: centerYAnchor), - stack.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor, constant: 24), - stack.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor, constant: -24), - appLabel.widthAnchor.constraint(lessThanOrEqualTo: widthAnchor, constant: -48), - statusLabel.widthAnchor.constraint(lessThanOrEqualTo: widthAnchor, constant: -48), - ]) + layerContentsRedrawPolicy = .onSetNeedsDisplay update(appID: appID, title: title) } @@ -245,22 +210,29 @@ private final class NativeFullscreenPlaceholderView: NSView { nil } + override var wantsUpdateLayer: Bool { true } + + // The same picture the overlay carries during motions, so the handoff is invisible. + override func updateLayer() { + layer?.contents = nativeFullscreenPlaceholderImage(appID: appID, title: title, size: bounds.size, + scale: window?.backingScaleFactor ?? 2, selected: selected, accentColor: accentColor) + } + + override func setFrameSize(_ newSize: NSSize) { + super.setFrameSize(newSize) + needsDisplay = true + } + + override func viewDidChangeBackingProperties() { + super.viewDidChangeBackingProperties() + needsDisplay = true + } + func update(appID: String, title: String) { - let application = NSRunningApplication.runningApplications( - withBundleIdentifier: appID - ).first - let applicationURL = NSWorkspace.shared.urlForApplication( - withBundleIdentifier: appID - ) - let appName = application?.localizedName - ?? applicationURL?.deletingPathExtension().lastPathComponent - ?? appID - iconView.image = application?.icon - ?? applicationURL.map { - NSWorkspace.shared.icon(forFile: $0.path) - } - ?? NSImage(named: NSImage.applicationIconName) - appLabel.stringValue = title.isEmpty ? appName : title + self.appID = appID + self.title = title + needsDisplay = true + let appName = nativeFullscreenPlaceholderAppName(appID) toolTip = title.isEmpty ? appName : title setAccessibilityElement(true) setAccessibilityRole(.group) @@ -272,22 +244,73 @@ private final class NativeFullscreenPlaceholderView: NSView { } func updateAppearance(selected: Bool, accentColor: UInt32) { - guard self.selected != selected || self.accentColor != accentColor else { - return - } + guard self.selected != selected || self.accentColor != accentColor else { return } self.selected = selected self.accentColor = accentColor - CATransaction.begin() - CATransaction.setDisableActions(true) - layer?.borderWidth = selected ? 2 : 1 - layer?.borderColor = selected - ? NSColor( - srgbRed: CGFloat((accentColor >> 16) & 0xff) / 255, - green: CGFloat((accentColor >> 8) & 0xff) / 255, - blue: CGFloat(accentColor & 0xff) / 255, - alpha: 1 - ).cgColor - : NSColor.white.withAlphaComponent(0.14).cgColor - CATransaction.commit() + needsDisplay = true } } + +private func nativeFullscreenPlaceholderAppName(_ appID: String) -> String { + NSRunningApplication.runningApplications(withBundleIdentifier: appID).first?.localizedName + ?? NSWorkspace.shared.urlForApplication(withBundleIdentifier: appID)? + .deletingPathExtension().lastPathComponent + ?? appID +} + +/// The placeholder card: drawn by Defi, so the overlay never needs to capture it. +func nativeFullscreenPlaceholderImage(appID: String, title: String, size: CGSize, scale: CGFloat, + selected: Bool, accentColor: UInt32) -> CGImage? { + let width = Int((size.width * scale).rounded()), height = Int((size.height * scale).rounded()) + guard width > 0, height > 0, + let context = CGContext(data: nil, width: width, height: height, bitsPerComponent: 8, bytesPerRow: 0, + space: CGColorSpace(name: CGColorSpace.sRGB)!, + bitmapInfo: CGImageAlphaInfo.premultipliedFirst.rawValue | CGBitmapInfo.byteOrder32Little.rawValue) + else { return nil } + context.scaleBy(x: scale, y: scale) + let previous = NSGraphicsContext.current + NSGraphicsContext.current = NSGraphicsContext(cgContext: context, flipped: false) + defer { NSGraphicsContext.current = previous } + + let bounds = CGRect(origin: .zero, size: size) + let borderWidth: CGFloat = selected ? 2 : 1 + NSColor(srgbRed: 15 / 255, green: 15 / 255, blue: 20 / 255, alpha: 1).setFill() + NSBezierPath(roundedRect: bounds, xRadius: 10, yRadius: 10).fill() + let border = NSBezierPath(roundedRect: bounds.insetBy(dx: borderWidth / 2, dy: borderWidth / 2), + xRadius: 10 - borderWidth / 2, yRadius: 10 - borderWidth / 2) + border.lineWidth = borderWidth + (selected + ? NSColor(srgbRed: CGFloat((accentColor >> 16) & 0xff) / 255, green: CGFloat((accentColor >> 8) & 0xff) / 255, + blue: CGFloat(accentColor & 0xff) / 255, alpha: 1) + : NSColor.white.withAlphaComponent(0.14)).setStroke() + border.stroke() + + let application = NSRunningApplication.runningApplications(withBundleIdentifier: appID).first + let icon = application?.icon + ?? NSWorkspace.shared.urlForApplication(withBundleIdentifier: appID).map { + NSWorkspace.shared.icon(forFile: $0.path) + } + ?? NSImage(named: NSImage.applicationIconName) + let paragraph = NSMutableParagraphStyle() + paragraph.alignment = .center + paragraph.lineBreakMode = .byTruncatingTail + let name = NSAttributedString(string: title.isEmpty ? nativeFullscreenPlaceholderAppName(appID) : title, + attributes: [.font: NSFont.systemFont(ofSize: 17, weight: .semibold), .foregroundColor: NSColor.white, + .paragraphStyle: paragraph]) + let status = NSAttributedString(string: "macOS Full Screen", + attributes: [.font: NSFont.systemFont(ofSize: 12), .foregroundColor: NSColor.white.withAlphaComponent(0.68), + .paragraphStyle: paragraph]) + let textWidth = max(size.width - 48, 0) + let nameHeight = ceil(name.size().height), statusHeight = ceil(status.size().height) + let spacing: CGFloat = 8, iconSide: CGFloat = 80 + var y = ((size.height + iconSide + spacing + nameHeight + spacing + statusHeight) / 2).rounded() + y -= iconSide + icon?.draw(in: CGRect(x: ((size.width - iconSide) / 2).rounded(), y: y, width: iconSide, height: iconSide)) + y -= spacing + nameHeight + name.draw(with: CGRect(x: 24, y: y, width: textWidth, height: nameHeight), + options: [.usesLineFragmentOrigin, .truncatesLastVisibleLine]) + y -= spacing + statusHeight + status.draw(with: CGRect(x: 24, y: y, width: textWidth, height: statusHeight), + options: [.usesLineFragmentOrigin, .truncatesLastVisibleLine]) + return context.makeImage() +} diff --git a/Sources/DefiMacOS/RibbonProxyRenderer.swift b/Sources/DefiMacOS/RibbonProxyRenderer.swift index dd225228..8fcc989d 100644 --- a/Sources/DefiMacOS/RibbonProxyRenderer.swift +++ b/Sources/DefiMacOS/RibbonProxyRenderer.swift @@ -21,6 +21,8 @@ struct RibbonProxyWindow { let to: Rect /// Just opened: it grows in its slot while its app draws it there under the overlay. var appears = false + /// Drawn by Defi (a native fullscreen placeholder): never captured, no native window to land. + var picture: CGImage? = nil } /// Pictures stay valid only for the native size they were captured at. @@ -637,7 +639,11 @@ final class RibbonProxyPresenter { } if styled.pictured { pictured += 1 } if styled.badged { badged += 1; veiled.insert(window.id) } else { veiled.remove(window.id) } - if pictures.picture(window.id)?.isReduced == true { standIns.insert(window.id) } else { standIns.remove(window.id) } + if window.picture == nil, pictures.picture(window.id)?.isReduced == true { + standIns.insert(window.id) + } else { + standIns.remove(window.id) + } // The active window travels above the windows it crosses, as in Niri. layer.zPosition = window.id == selectedWindowID ? 100_000 : depth[window.id] ?? 0 let launched = ribbonProxyMove(layer, from: from, to: to, velocity: velocity) @@ -696,7 +702,7 @@ final class RibbonProxyPresenter { expectedTargets = ribbonProxyLandingTargets(nativeTargets.filter { $0.key != draggedWindowID }, area: area) requestedTargets = requested.filter { expectedTargets[$0.key] != nil } presentedSubmission = submission - landedRefresh = windows.map { + landedRefresh = windows.filter { $0.picture == nil }.map { RibbonProxyRefresh(id: $0.id, appID: $0.appID, processID: $0.processID, frame: $0.to, distance: ribbonProxyDistance($0.to, area)) } @@ -707,7 +713,7 @@ final class RibbonProxyPresenter { standIns.formIntersection(shownIDs) veiledSince = CACurrentMediaTime() refreshing = Set(windows.filter { window in - window.appID != "" && !veiled.contains(window.id) && window.to.ribbonIntersects(area) + window.appID != "" && window.picture == nil && !veiled.contains(window.id) && window.to.ribbonIntersects(area) && pictures.picture(window.id).map { veiledSince - $0.capturedAt > ribbonProxyPictureFreshness } == true }.map(\.id)) let unpictured = shown.filter { pictures.picture($0.id) == nil }.map(\.id.rawValue) @@ -741,7 +747,7 @@ final class RibbonProxyPresenter { // Windows leaving the screen must be gone too, or a slow app's outgoing window // pops back into view when the overlay lifts. let leaving = Set(windows.filter { - $0.id != draggedWindowID && ribbonProxyLeaves(from: $0.from, to: $0.to, area: area) + $0.id != draggedWindowID && $0.picture == nil && ribbonProxyLeaves(from: $0.from, to: $0.to, area: area) }.map(\.id)).union(unsettledLeaving.subtracting(expected.keys).subtracting([draggedWindowID].compactMap { $0 })) unsettledLeaving = leaving let drawn = Set(shown.map(\.id) + [draggedWindowID].compactMap { $0 }) @@ -1583,6 +1589,18 @@ final class RibbonProxyPresenter { selected: Bool) -> (pictured: Bool, badged: Bool) { let sublayers = Dictionary((layer.sublayers ?? []).compactMap { sublayer in sublayer.name.map { ($0, sublayer) } }) { first, _ in first } + if let own = window.picture { + setContents(sublayers["content"], own) + sublayers["content"]?.contentsScale = CGFloat(own.width) / max(window.to.width, 1) + sublayers["content"]?.masksToBounds = false + sublayers["content"]?.backgroundColor = nil + setContents(sublayers["icon"], nil) + // Its own picture already draws its selection, and the panel has no shadow. + sublayers["border"]?.isHidden = true + sublayers["shadow"]?.isHidden = true + return (true, false) + } + sublayers["shadow"]?.isHidden = false let picture = WindowCaptureStore.shared.picture(window.id) // Any picture reads as the window: an icon popped over an old or reduced one at every // workspace switch, then faded. Only a window without a picture gets its icon. From 9fb197f5a26892bf6dcc643099a576b1541ea3b2 Mon Sep 17 00:00:00 2001 From: Quentin Eude Date: Sun, 15 Nov 2026 18:36:47 +0100 Subject: [PATCH 3/3] fix(fullscreen): keep the placeholder panel on desktop Spaces Ordered in while its window's fullscreen Space was active, the panel stayed on that Space and never showed on the desktop strip. It now joins every desktop Space and no fullscreen one, like the window borders. --- Sources/DefiMacOS/NativeFullscreenPlaceholder.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/DefiMacOS/NativeFullscreenPlaceholder.swift b/Sources/DefiMacOS/NativeFullscreenPlaceholder.swift index 9fc29433..fbafcdd8 100644 --- a/Sources/DefiMacOS/NativeFullscreenPlaceholder.swift +++ b/Sources/DefiMacOS/NativeFullscreenPlaceholder.swift @@ -122,9 +122,8 @@ private final class NativeFullscreenPlaceholderPanel { panel.hasShadow = false panel.sharingType = .readOnly panel.level = .normal - panel.collectionBehavior = [ - .ignoresCycle, - ] + // Like the borders: ordered in while the fullscreen Space is active, it would stay there. + panel.collectionBehavior = [.canJoinAllSpaces, .stationary, .ignoresCycle, .transient] panel.hidesOnDeactivate = false panel.isReleasedWhenClosed = false panel.isExcludedFromWindowsMenu = true