diff --git a/Sources/ParcelConfig/HoverBarConfiguration.swift b/Sources/ParcelConfig/HoverBarConfiguration.swift index f22c6adf..5ecc4954 100644 --- a/Sources/ParcelConfig/HoverBarConfiguration.swift +++ b/Sources/ParcelConfig/HoverBarConfiguration.swift @@ -5,7 +5,7 @@ public struct HoverBarConfiguration: Codable, Equatable, Sendable { public var isValid: Bool { Self.delays.contains(delay) } - public init(enabled: Bool = true, delay: Double = 0.6) { + public init(enabled: Bool = false, delay: Double = 0.6) { self.enabled = enabled self.delay = delay } diff --git a/Sources/ParcelUI/HoverBar/HoverBarController.swift b/Sources/ParcelUI/HoverBar/HoverBarController.swift index 823db1aa..3f8e4303 100644 --- a/Sources/ParcelUI/HoverBar/HoverBarController.swift +++ b/Sources/ParcelUI/HoverBar/HoverBarController.swift @@ -101,7 +101,8 @@ public final class HoverBarController { if model.phase == .visible, let current = model.target, current.interactionFrame.contains(point) || panel?.isKeyWindow == true || presentingMenu, let target = HoverBarModel.target(for: current.window, state: state), target.workspace == current.workspace, - target.frame == current.frame + target.frame == current.frame, target.windowFrame == current.windowFrame, + target.displayFrame == current.displayFrame { model.show(target, configuration: preferences) render() @@ -195,7 +196,7 @@ public final class HoverBarController { case .toggleFloat, .alwaysFloat: id = .floating } let button = view.buttons[id.rawValue] - guard button.isEnabled else { throw HoverActionError.unavailableAction } + guard button.isEnabled, !button.isHidden else { throw HoverActionError.unavailableAction } button.optionHeld = action == .alwaysFloat button.performClick(nil) button.optionHeld = false @@ -289,6 +290,10 @@ public final class HoverBarController { HoverBarModel.controls(for: target, state: state, optionHeld: optionHeld).map { Self.presentation(for: $0, target: target, state: state, configuration: configuration) }) + guard view.buttons.contains(where: { !$0.isHidden }) else { + hide() + return + } panel.place(target.controlsFrame) panel.orderFront(nil) if showing, let layer = view.layer { @@ -314,8 +319,24 @@ public final class HoverBarController { toolTip = UIStrings.text("No other screen") help = toolTip } + let bound: Bool + if let action = control.action { + bound = hasBinding(for: action, target: target, state: state, configuration: configuration) + } else { + bound = control.destinations.contains { + hasBinding(for: .moveToDisplay($0), target: target, state: state, configuration: configuration) + } + } return HoverControlPresentation( - title: title, shortcut: shortcut.display, enabled: control.enabled, help: help, toolTip: toolTip) + title: title, shortcut: control.action == nil ? "" : shortcut.display, + enabled: control.enabled && bound, help: help, toolTip: toolTip, visible: control.enabled && bound) + } + + private static func hasBinding( + for action: HoverAction, target: HoverTarget, state: State, configuration: ParcelConfiguration + ) -> Bool { + HoverBarModel.shortcutCommands(for: action, target: target, state: state) + .contains { configuration.keybindings[$0] != nil } } static func titledShortcut(title: String, shortcut: (display: String, accessibilityLabel: String)) @@ -343,7 +364,7 @@ public final class HoverBarController { let control = HoverBarModel.controls(for: target, state: state, optionHeld: optionHeld).first(where: { $0.id == id }), - control.enabled + Self.presentation(for: control, target: target, state: state, configuration: configuration).visible else { return } if let action = control.action { dispatch(action) @@ -357,6 +378,10 @@ public final class HoverBarController { private func displayMenu(target: HoverTarget) -> NSMenu { let menu = NSMenu(title: UIStrings.text("Move to…")) for display in HoverBarModel.destinations(for: target, state: state) { + guard + Self.hasBinding( + for: .moveToDisplay(display), target: target, state: state, configuration: configuration) + else { continue } let title = String(format: UIStrings.text("Move to %@"), Self.displayName(display)) let shortcut = Self.shortcutPresentation( action: .moveToDisplay(display), target: target, state: state, configuration: configuration) diff --git a/Sources/ParcelUI/HoverBar/HoverBarModel.swift b/Sources/ParcelUI/HoverBar/HoverBarModel.swift index 82ef13d0..e65af59d 100644 --- a/Sources/ParcelUI/HoverBar/HoverBarModel.swift +++ b/Sources/ParcelUI/HoverBar/HoverBarModel.swift @@ -9,31 +9,42 @@ public struct HoverTarget: Equatable, Sendable { public let workspace: WorkspaceKey public let frame: CGRect public let displayFrame: CGRect + public let windowFrame: CGRect public let isFloating: Bool public let isFocused: Bool public let stackControlsFrame: CGRect? public init( window: WindowID, workspace: WorkspaceKey, frame: CGRect, displayFrame: CGRect, - isFloating: Bool = false, isFocused: Bool = false, stackControlsFrame: CGRect? = nil + isFloating: Bool = false, isFocused: Bool = false, stackControlsFrame: CGRect? = nil, + windowFrame: CGRect? = nil ) { self.window = window self.workspace = workspace self.frame = frame self.displayFrame = displayFrame + self.windowFrame = windowFrame ?? frame self.isFloating = isFloating self.isFocused = isFocused self.stackControlsFrame = stackControlsFrame } public var controlsFrame: CGRect { + guard windowFrame.isFiniteAndPositive, displayFrame.isFiniteAndPositive else { return .zero } let width = min(520, displayFrame.width) let height = min(56, displayFrame.height) - let top = stackControlsFrame.map { max($0.maxY, frame.maxY + 28) } ?? frame.maxY - return CGRect( - x: min(max(stackControlsFrame?.minX ?? frame.minX, displayFrame.minX), displayFrame.maxX - width), - y: min(max(top, displayFrame.minY), displayFrame.maxY - height), - width: width, height: height) + let x = min(max(frame.minX, displayFrame.minX), displayFrame.maxX - width) + let y = min(max(frame.minY, displayFrame.minY), displayFrame.maxY - height) + let candidates = [ + CGRect(x: x, y: windowFrame.minY - height - 4, width: width, height: height), + CGRect(x: x, y: windowFrame.maxY + 4, width: width, height: height), + CGRect(x: windowFrame.maxX + 4, y: y, width: width, height: height), + CGRect(x: windowFrame.minX - width - 4, y: y, width: width, height: height), + ] + return candidates.first { + displayFrame.contains($0) && !$0.intersects(windowFrame) + && !(stackControlsFrame?.intersects($0) ?? false) + } ?? .zero } var interactionFrame: CGRect { frame.union(controlsFrame).union(stackControlsFrame ?? frame) } @@ -63,14 +74,15 @@ public struct HoverBarModel: Sendable { if preferences != configuration { hide() } preferences = configuration guard configuration.enabled, let target, target.frame.isFiniteAndPositive, - target.displayFrame.isFiniteAndPositive, + target.displayFrame.isFiniteAndPositive, target.controlsFrame.isFiniteAndPositive, target.stackControlsFrame.map(\.isFiniteAndPositive) ?? true else { hide() return } if self.target?.window != target.window || self.target?.workspace != target.workspace - || self.target?.frame != target.frame + || self.target?.frame != target.frame || self.target?.windowFrame != target.windowFrame + || self.target?.displayFrame != target.displayFrame { phase = .pending deadline = time + configuration.delay @@ -85,7 +97,7 @@ public struct HoverBarModel: Sendable { public mutating func show(_ target: HoverTarget, configuration: HoverBarConfiguration) { precondition(configuration.isValid) guard configuration.enabled, target.frame.isFiniteAndPositive, target.displayFrame.isFiniteAndPositive, - target.stackControlsFrame.map(\.isFiniteAndPositive) ?? true + target.controlsFrame.isFiniteAndPositive, target.stackControlsFrame.map(\.isFiniteAndPositive) ?? true else { hide() return @@ -135,16 +147,17 @@ public struct HoverBarModel: Sendable { let strip = CGRect(x: rect.minX, y: rect.minY, width: rect.width, height: min(28, rect.height)) return HoverTarget( window: window, workspace: key, frame: grip?.frame ?? strip, displayFrame: screen, - isFloating: managed.isFloating, isFocused: focused == window, stackControlsFrame: chipRow) + isFloating: managed.isFloating, isFocused: focused == window, stackControlsFrame: chipRow, + windowFrame: rect) } - public static func controlFrames(in frame: CGRect) -> [CGRect] { - guard frame.isFiniteAndPositive else { return [] } + public static func controlFrames(in frame: CGRect, count: Int = HoverControlID.allCases.count) -> [CGRect] { + guard frame.isFiniteAndPositive, count > 0 else { return [] } let inset = min(4, frame.width / 16, frame.height / 4) let bounds = frame.insetBy(dx: inset, dy: inset) - let width = bounds.width / Double(HoverControlID.allCases.count) - return HoverControlID.allCases.map { - CGRect(x: bounds.minX + Double($0.rawValue) * width, y: bounds.minY, width: width, height: bounds.height) + let width = bounds.width / Double(count) + return (0.. Bool { true } @objc private func pressed() { diff --git a/Sources/ParcelUI/HoverBar/README.md b/Sources/ParcelUI/HoverBar/README.md index 96e11a64..d0856dc0 100644 --- a/Sources/ParcelUI/HoverBar/README.md +++ b/Sources/ParcelUI/HoverBar/README.md @@ -1,10 +1,15 @@ # Hover bar -The hover bar offers window actions near an eligible window without permanently -covering its content. A stacked tile has a compact grip: the selected segment is -longer, and inactive stacks show dots. Hover over the grip to reveal the chip row -and window actions. The stack's VoiceOver action or Stacked Windows menu item -opens the chips without a pointer. Single windows retain their title-strip trigger. +The hover bar is opt-in. It offers bound window actions wholly outside the +observed window, never over its title bar or toolbar. If the display has no safe +space for the bar, it stays hidden. Unbound actions and unavailable screens are +omitted from drawing, keyboard navigation, and VoiceOver. + +A stacked tile has a compact grip: the selected segment is longer, and inactive +stacks show dots. Hover over the grip to reveal the chip row. The stack's VoiceOver +action or Stacked Windows menu item opens the chips without a pointer. Stack chips +remain available with the hover bar off. Single windows retain their title-strip +trigger after hover controls are enabled. Its controller owns presentation and dismissal; actions flow through the engine's command path. Chips stay available while dragging or using the keyboard. diff --git a/Tests/ParcelConfigTests/HoverBarConfigurationTests.swift b/Tests/ParcelConfigTests/HoverBarConfigurationTests.swift index 1cb02ece..ce2f1a85 100644 --- a/Tests/ParcelConfigTests/HoverBarConfigurationTests.swift +++ b/Tests/ParcelConfigTests/HoverBarConfigurationTests.swift @@ -5,7 +5,7 @@ import Testing @Suite struct HoverBarConfigurationTests { @Test func omittedValuesKeepDefaults() throws { let result = ConfigValidator.validate(try TOMLDocument(parsing: "")) - #expect(result.configuration?.hoverBar == HoverBarConfiguration(enabled: true, delay: 0.6)) + #expect(result.configuration?.hoverBar == HoverBarConfiguration(enabled: false, delay: 0.6)) #expect(result.diagnostics.isEmpty) } @@ -41,7 +41,7 @@ import Testing let enabled = try #require(hover.properties?["enabled"]) let delay = try #require(hover.properties?["delay"]) #expect(enabled.type == "boolean") - #expect(enabled.defaultBool == true) + #expect(enabled.defaultBool == false) #expect(delay.type == "number") #expect(delay.minimum == 0.1) #expect(delay.maximum == 3) diff --git a/Tests/ParcelE2ETests/HoverControlsEndToEndTests.swift b/Tests/ParcelE2ETests/HoverControlsEndToEndTests.swift index c2b736b0..bf067d64 100644 --- a/Tests/ParcelE2ETests/HoverControlsEndToEndTests.swift +++ b/Tests/ParcelE2ETests/HoverControlsEndToEndTests.swift @@ -15,7 +15,9 @@ extension RealAppEndToEndTests { var configuration = E2EConfiguration() configuration.layout = .side configuration.ratio = 0.6 + configuration.outerGap = 64 try await withSession(configuration: configuration) { session in + try Data((configuration.source + "[hover-bar]\nenabled=true\n").utf8).write(to: session.configURL) let (fixture, opened) = try await session.addFixture(arguments: [ "--windows", "2", "--title", "Hover Controls Fixture", ]) @@ -76,7 +78,10 @@ extension RealAppEndToEndTests { } @Test func hoverOptionAlwaysFloatPersistsOnlyMatchingWindowsAndSupportsUndo() async throws { - try await withSession { session in + var configuration = E2EConfiguration() + configuration.outerGap = 64 + try await withSession(configuration: configuration) { session in + try Data((configuration.source + "[hover-bar]\nenabled=true\n").utf8).write(to: session.configURL) let title = "Always Float Hover Fixture" let (fixture, opened) = try await session.addFixture(arguments: [ "--windows", "2", "--titles", #"["Always Float Hover Fixture", "Unmatched Hover Fixture"]"#, diff --git a/Tests/ParcelUITests/HoverBar/HoverBarTests.swift b/Tests/ParcelUITests/HoverBar/HoverBarTests.swift index bdf410fe..138cccc3 100644 --- a/Tests/ParcelUITests/HoverBar/HoverBarTests.swift +++ b/Tests/ParcelUITests/HoverBar/HoverBarTests.swift @@ -17,7 +17,7 @@ struct HoverBarTests { @Test(arguments: [0.1, 0.6, 3.0]) func dwellOnlyShowsAtDeadline(delay: Double) { var model = HoverBarModel() - let preferences = HoverBarConfiguration(delay: delay) + let preferences = HoverBarConfiguration(enabled: true, delay: delay) model.receive(target, at: 10, configuration: preferences) #expect(model.phase == .pending) #expect(model.deadline == 10 + delay) @@ -30,17 +30,17 @@ struct HoverBarTests { @Test func delayChangesRestartDwellAndUnobservedWindowsHaveNoTarget() { var model = HoverBarModel() - model.receive(target, at: 0, configuration: .init()) - model.receive(target, at: 0.3, configuration: .init(delay: 1)) + model.receive(target, at: 0, configuration: .init(enabled: true)) + model.receive(target, at: 0.3, configuration: .init(enabled: true, delay: 1)) #expect(model.deadline == 1.3) - var state = LearningScene.state() + var state = hoverState() state.observedFrames = [:] #expect(HoverBarModel.target(at: CGPoint(x: 24, y: 24), state: state) == nil) } @MainActor @Test func hoverFadesNeverScaleAndMotionOffIsInstant() { let layer = CALayer() - LearningMotion.show(layer, token: .fade, configuration: .init()) + LearningMotion.show(layer, token: .fade, configuration: .init(enabled: true)) #expect(layer.animation(forKey: "learningScale") == nil) LearningMotion.show(layer, token: .drop, configuration: .init(enabled: false)) #expect(layer.animationKeys() == nil) @@ -48,32 +48,32 @@ struct HoverBarTests { @Test func departureMovingWindowsAndSpaceChangesCancelDwell() { var model = HoverBarModel() - model.receive(target, at: 0, configuration: .init()) - model.receive(nil, at: 0.4, configuration: .init()) + model.receive(target, at: 0, configuration: .init(enabled: true)) + model.receive(nil, at: 0.4, configuration: .init(enabled: true)) #expect(model.phase == .hidden) #expect(model.target == nil) - model.receive(target, at: 1, configuration: .init()) + model.receive(target, at: 1, configuration: .init(enabled: true)) let moved = HoverTarget( window: target.window, workspace: target.workspace, frame: target.frame.offsetBy(dx: 4, dy: 0), displayFrame: target.displayFrame) - model.receive(moved, at: 1.5, configuration: .init()) + model.receive(moved, at: 1.5, configuration: .init(enabled: true)) #expect(model.deadline == 2.1) let otherSpace = HoverTarget( window: target.window, workspace: WorkspaceKey(display: target.workspace.display, space: SpaceID(rawValue: 2)), frame: moved.frame, displayFrame: target.displayFrame) - model.receive(otherSpace, at: 1.7, configuration: .init()) + model.receive(otherSpace, at: 1.7, configuration: .init(enabled: true)) #expect(model.deadline == 2.3) } @Test func floatingAndFocusChangesUpdateWithoutRestartingDwell() { var model = HoverBarModel() - model.receive(target, at: 0, configuration: .init()) - model.receive(target, at: 1, configuration: .init()) + model.receive(target, at: 0, configuration: .init(enabled: true)) + model.receive(target, at: 1, configuration: .init(enabled: true)) let next = HoverTarget( window: target.window, workspace: target.workspace, frame: target.frame, displayFrame: target.displayFrame, isFloating: true) - model.receive(next, at: 1.1, configuration: .init()) + model.receive(next, at: 1.1, configuration: .init(enabled: true)) #expect(model.phase == .visible) #expect(model.target == next) } @@ -82,14 +82,14 @@ struct HoverBarTests { var model = HoverBarModel() model.receive(target, at: 1, configuration: .init(enabled: false)) #expect(model.phase == .hidden) - model.receive(target, at: 2, configuration: .init()) - model.receive(target, at: 1.5, configuration: .init()) + model.receive(target, at: 2, configuration: .init(enabled: true)) + model.receive(target, at: 1.5, configuration: .init(enabled: true)) #expect(model.phase == .hidden) - model.receive(target, at: .infinity, configuration: .init()) + model.receive(target, at: .infinity, configuration: .init(enabled: true)) #expect(model.phase == .hidden) let invalid = HoverTarget( window: target.window, workspace: target.workspace, frame: .zero, displayFrame: target.displayFrame) - model.show(invalid, configuration: .init()) + model.show(invalid, configuration: .init(enabled: true)) #expect(model.phase == .hidden) #expect(!HoverBarConfiguration.delays.contains(.nan)) } @@ -108,7 +108,7 @@ struct HoverBarTests { } @Test func floatingTitleStripTargetsItsWindowButItsBodyBlocksTiles() throws { - var state = LearningScene.state() + var state = hoverState() let frame = try #require(state.frames[LearningScene.first]) state.windows[LearningScene.second]?.isFloating = true state.observedFrames[LearningScene.second] = frame @@ -123,7 +123,7 @@ struct HoverBarTests { } @Test func overlappingFloatingFramesNeverGuessTheFocusedWindowIsOnTop() throws { - var state = LearningScene.state() + var state = hoverState() let frame = try #require(state.observedFrames[LearningScene.first]) state.windows[LearningScene.first]?.isFloating = true state.windows[LearningScene.second]?.isFloating = true @@ -133,7 +133,7 @@ struct HoverBarTests { } @Test func everyControlHasAnIndependentHitRegionAndTitleStripPassesThrough() { - #expect(target.controlsFrame == CGRect(x: 20, y: 48, width: 520, height: 56)) + #expect(target.controlsFrame == CGRect(x: 20, y: 52, width: 520, height: 56)) for (id, x) in zip(HoverControlID.allCases, [88.0, 216, 344, 472]) { #expect(HoverBarModel.hitTest(CGPoint(x: x, y: 76), target: target) == id) } @@ -143,11 +143,11 @@ struct HoverBarTests { let edge = HoverTarget( window: target.window, workspace: target.workspace, frame: CGRect(x: 790, y: 590, width: 200, height: 28), displayFrame: target.displayFrame) - #expect(edge.controlsFrame == CGRect(x: 280, y: 544, width: 520, height: 56)) + #expect(edge.controlsFrame == CGRect(x: 280, y: 530, width: 520, height: 56)) } @Test func displayControlUsesOneExplicitDestinationOrAMenuAndNeverUnknownScreens() throws { - var state = LearningScene.state() + var state = hoverState() var controls = HoverBarModel.controls(for: target, state: state) #expect(!controls[2].enabled) let second = addDisplay("second", x: 800, state: &state) @@ -169,7 +169,7 @@ struct HoverBarTests { } @Test func targetSpecificRequestsRejectStaleWindowsSpacesAndActions() throws { - var state = LearningScene.state() + var state = hoverState() state.focusedWindow = LearningScene.second let request = try HoverBarModel.request(.makePrimary, target: target, state: state) #expect(request.window == LearningScene.first) @@ -180,13 +180,13 @@ struct HoverBarTests { #expect(try HoverBarModel.request(.alwaysFloat, target: target, state: state).window == LearningScene.first) state.activeSpaces[LearningScene.display.id] = SpaceID(rawValue: 2) #expect(throws: HoverActionError.self) { try HoverBarModel.request(.toggleFloat, target: target, state: state) } - state = LearningScene.state() + state = hoverState() state.windows[LearningScene.first] = nil #expect(throws: HoverActionError.self) { try HoverBarModel.request(.toggleFloat, target: target, state: state) } } @MainActor @Test func labelsReadCurrentBindingsWithoutInventingDisplayShortcuts() throws { - var state = LearningScene.state() + var state = hoverState() var configuration = ParcelConfiguration.defaults configuration.keybindings[.makePrimary] = try KeyChord(parsing: "ctrl-shift-p") #expect( @@ -218,7 +218,7 @@ struct HoverBarTests { } @MainActor @Test func shortcutPresentationSeparatesVisibleAndSpokenLabels() throws { - let state = LearningScene.state() + let state = hoverState() var configuration = ParcelConfiguration.defaults configuration.keybindings[.makePrimary] = try KeyChord(parsing: "ctrl-shift-p") let shortcut = HoverBarController.shortcutPresentation( @@ -247,6 +247,84 @@ struct HoverBarTests { #expect(unbound.accessibilityLabel == "Not bound") } + @Test(arguments: [ + (CGRect(x: 20, y: 100, width: 240, height: 200), CGRect(x: 20, y: 40, width: 520, height: 56)), + (CGRect(x: 20, y: 20, width: 240, height: 200), CGRect(x: 20, y: 224, width: 520, height: 56)), + (CGRect(x: 20, y: 0, width: 200, height: 600), CGRect(x: 224, y: 0, width: 520, height: 56)), + (CGRect(x: 560, y: 0, width: 240, height: 600), CGRect(x: 36, y: 0, width: 520, height: 56)), + ]) + func barStaysOutsideTheEntireObservedWindow(window: CGRect, expected: CGRect) { + let target = HoverTarget( + window: LearningScene.first, workspace: LearningScene.key, + frame: CGRect(x: window.minX, y: window.minY, width: window.width, height: 28), + displayFrame: self.target.displayFrame, windowFrame: window) + #expect(target.controlsFrame == expected) + #expect(!target.controlsFrame.intersects(window)) + #expect(target.displayFrame.contains(target.controlsFrame)) + } + + @Test func noClearanceNeverFallsBackOverWindowControls() { + let window = target.displayFrame + let blocked = HoverTarget( + window: target.window, workspace: target.workspace, + frame: CGRect(x: 0, y: 0, width: 800, height: 28), displayFrame: window, windowFrame: window) + #expect(blocked.controlsFrame == .zero) + var model = HoverBarModel() + model.receive(blocked, at: 0, configuration: .init(enabled: true)) + #expect(model.phase == .hidden) + #expect(model.deadline == nil) + model.show(blocked, configuration: .init(enabled: true)) + #expect(model.phase == .hidden) + } + + @Test func fullWindowGeometryChangesRestartDwell() { + var model = HoverBarModel() + model.receive(target, at: 0, configuration: .init(enabled: true)) + let resized = HoverTarget( + window: target.window, workspace: target.workspace, frame: target.frame, + displayFrame: target.displayFrame, windowFrame: CGRect(x: 20, y: 20, width: 240, height: 200)) + model.receive(resized, at: 0.5, configuration: .init(enabled: true)) + #expect(model.phase == .pending) + #expect(model.deadline == 1.1) + } + + @MainActor @Test func singleDisplayAndUnboundActionsAreNotOffered() { + var state = hoverState() + var configuration = ParcelConfiguration.defaults + let controls = HoverBarModel.controls(for: target, state: state) + #expect( + !HoverBarController.presentation( + for: controls[2], target: target, state: state, configuration: configuration + ).visible) + configuration.keybindings[.makePrimary] = nil + #expect( + !HoverBarController.presentation( + for: controls[0], target: target, state: state, configuration: configuration + ).visible) + let second = addDisplay("second", x: 800, state: &state) + let display = HoverBarModel.controls(for: target, state: state)[2] + #expect(display.action == .moveToDisplay(second)) + #expect( + HoverBarController.presentation( + for: display, target: target, state: state, configuration: configuration + ).visible) + configuration.keybindings[.displayMoveRight] = nil + #expect( + !HoverBarController.presentation( + for: display, target: target, state: state, configuration: configuration + ).visible) + } + + @Test func defaultHoverIsOffUntilExplicitlyEnabled() { + var model = HoverBarModel() + model.receive(target, at: 0, configuration: .init()) + model.receive(target, at: 3, configuration: .init()) + #expect(model.phase == .hidden) + #expect(model.deadline == nil) + model.show(target, configuration: .init(enabled: true)) + #expect(model.phase == .visible) + } + @MainActor @Test func monitorFailureIsSurfacedAndPartialInstallationIsRemoved() { var removed = 0 let failedLocal = HoverBarController(installMonitor: { _, _ in nil }, removeMonitor: { _ in removed += 1 }) @@ -261,6 +339,14 @@ struct HoverBarTests { } +private func hoverState() -> State { + var state = LearningScene.state() + state.observedFrames = state.observedFrames.mapValues { + Rect(x: $0.minX, y: $0.minY, width: $0.size.width, height: 200) + } + return state +} + private func addDisplay(_ name: String, x: Double, state: inout State) -> DisplayID { let id = DisplayID(rawValue: name) let space = SpaceID(rawValue: 1) @@ -277,7 +363,7 @@ extension AppKitTestSuite { init() { _ = NSApplication.shared } @Test func controlsExposeSpokenHelpAndGlyphTooltipsWithoutAWindow() throws { - let state = LearningScene.state() + let state = hoverState() let target = try #require(HoverBarModel.target(for: LearningScene.first, state: state)) var configuration = ParcelConfiguration.defaults configuration.keybindings[.makePrimary] = try KeyChord(parsing: "ctrl-shift-p") @@ -302,8 +388,8 @@ extension AppKitTestSuite { @MainActor @Test func clickablePanelUsesVoiceOverLabelsAndNormalClicksNeverNeedKeyFocus() throws { let controller = HoverBarController() defer { controller.stop() } - let state = LearningScene.state() - controller.update(state: state, configuration: .defaults, preferences: .init()) + let state = hoverState() + controller.update(state: state, configuration: .defaults, preferences: .init(enabled: true)) let point = CGPoint(x: 24, y: 24) let time = CACurrentMediaTime() controller.pointerMoved(to: point, at: time) @@ -314,13 +400,15 @@ extension AppKitTestSuite { #expect(!panel.canBecomeMain) #expect(panel.styleMask.contains(.nonactivatingPanel)) #expect(!panel.isKeyWindow) - #expect(view.buttons.map { $0.accessibilityLabel() } == ["Primary", "Focus", "Next screen", "Float"]) + #expect( + view.buttons.filter { !$0.isHidden }.map { $0.accessibilityLabel() } == ["Primary", "Focus", "Float"]) #expect(view.buttons.allSatisfy { !$0.needsPanelToBecomeKey && $0.acceptsFirstMouse(for: nil) }) + #expect(!view.buttons[2].acceptsFirstResponder) #expect(view.buttons[3].accessibilityHelp()?.contains("Hold Option") == true) #expect(view.buttons[3].accessibilityCustomActions()?.first?.name == "Always float") - controller.pointerMoved(to: CGPoint(x: 88, y: 76), at: time + 1.1) + controller.pointerMoved(to: CGPoint(x: 88, y: 250), at: time + 1.1) #expect(controller.model.phase == .visible) - controller.pointerMoved(to: CGPoint(x: 88, y: 200), at: time + 1.2) + controller.pointerMoved(to: CGPoint(x: 88, y: 400), at: time + 1.2) #expect(controller.model.phase == .hidden) } @@ -328,21 +416,16 @@ extension AppKitTestSuite { let controller = HoverBarController() defer { controller.stop() } #expect(controller.controlFrame(for: LearningScene.first, control: .primary) == nil) - controller.update(state: LearningScene.state(), configuration: .defaults, preferences: .init()) + controller.update(state: hoverState(), configuration: .defaults, preferences: .init(enabled: true)) let point = CGPoint(x: 24, y: 24) let time = CACurrentMediaTime() controller.pointerMoved(to: point, at: time) #expect(controller.controlFrame(for: LearningScene.first, control: .primary) == nil) controller.pointerMoved(to: point, at: time + 1) - #expect( - controller.controlFrame(for: LearningScene.first, control: .primary) - == CGRect(x: 24, y: 52, width: 128, height: 48)) - #expect( - controller.controlFrame(for: LearningScene.first, control: .focus) - == CGRect(x: 152, y: 52, width: 128, height: 48)) - #expect( - controller.controlFrame(for: LearningScene.first, control: .floating) - == CGRect(x: 408, y: 52, width: 128, height: 48)) + let frames = HoverBarModel.controlFrames(in: CGRect(x: 20, y: 224, width: 520, height: 56), count: 3) + #expect(controller.controlFrame(for: LearningScene.first, control: .primary) == frames[0]) + #expect(controller.controlFrame(for: LearningScene.first, control: .focus) == frames[1]) + #expect(controller.controlFrame(for: LearningScene.first, control: .floating) == frames[2]) #expect(controller.controlFrame(for: LearningScene.first, control: .display) == nil) #expect(controller.controlFrame(for: LearningScene.second, control: .primary) == nil) controller.hide() @@ -352,9 +435,9 @@ extension AppKitTestSuite { @MainActor @Test func keyboardReachesEveryEnabledControlAndEscapeDismisses() throws { let controller = HoverBarController() defer { controller.stop() } - var state = LearningScene.state() + var state = hoverState() _ = addDisplay("second", x: 800, state: &state) - controller.update(state: state, configuration: .defaults, preferences: .init()) + controller.update(state: state, configuration: .defaults, preferences: .init(enabled: true)) #expect(controller.focusControls(window: LearningScene.first)) let panel = try #require(controller.panel) let buttons = try #require(controller.controlsView).buttons @@ -376,9 +459,9 @@ extension AppKitTestSuite { defer { controller.stop() } var requests: [HoverActionRequest] = [] controller.onAction = { requests.append($0) } - var state = LearningScene.state() + var state = hoverState() state.focusedWindow = LearningScene.second - controller.update(state: state, configuration: .defaults, preferences: .init()) + controller.update(state: state, configuration: .defaults, preferences: .init(enabled: true)) try await controller.fixtureInput(action: .makePrimary, window: LearningScene.first) #expect( requests == [ @@ -390,7 +473,7 @@ extension AppKitTestSuite { #expect(requests.last?.window == LearningScene.first) await Task.yield() state.windows[LearningScene.first]?.isFloating = true - controller.update(state: state, configuration: .defaults, preferences: .init()) + controller.update(state: state, configuration: .defaults, preferences: .init(enabled: true)) try await controller.fixtureInput(action: .toggleFloat, window: LearningScene.first) #expect(requests.last?.action == .toggleFloat) #expect(requests.count == 3) @@ -401,17 +484,18 @@ extension AppKitTestSuite { defer { controller.stop() } var requests: [HoverActionRequest] = [] controller.onAction = { requests.append($0) } - var state = LearningScene.state() + var state = hoverState() state.focusedWindow = LearningScene.second let second = addDisplay("second", x: 800, state: &state) - controller.update(state: state, configuration: .defaults, preferences: .init()) + controller.update(state: state, configuration: .defaults, preferences: .init(enabled: true)) try await controller.fixtureInput(action: .moveToDisplay(second), window: LearningScene.first) #expect( requests.last == HoverActionRequest( window: LearningScene.first, workspace: LearningScene.key, action: .moveToDisplay(second))) - let third = addDisplay("third", x: 1600, state: &state) - controller.update(state: state, configuration: .defaults, preferences: .init()) + let third = addDisplay("third", x: 0, state: &state) + state.displays[third]?.frame = Rect(x: 0, y: -600, width: 800, height: 600) + controller.update(state: state, configuration: .defaults, preferences: .init(enabled: true)) try await controller.fixtureInput(action: .moveToDisplay(third), window: LearningScene.first) #expect( requests.last @@ -425,7 +509,7 @@ extension AppKitTestSuite { defer { controller.stop() } var requests: [HoverActionRequest] = [] controller.onAction = { requests.append($0) } - controller.update(state: LearningScene.state(), configuration: .defaults, preferences: .init()) + controller.update(state: hoverState(), configuration: .defaults, preferences: .init(enabled: true)) #expect(controller.focusControls(window: LearningScene.second)) let button = try #require(controller.controlsView).buttons[3] button.keyDown(with: try keyEvent(" ", flags: .option)) @@ -441,9 +525,9 @@ extension AppKitTestSuite { let controller = HoverBarController() defer { controller.stop() } controller.update( - state: LearningScene.state(), configuration: .defaults, preferences: .init(enabled: false)) + state: hoverState(), configuration: .defaults, preferences: .init(enabled: false)) #expect(!controller.focusControls()) - controller.update(state: State(), configuration: .defaults, preferences: .init()) + controller.update(state: State(), configuration: .defaults, preferences: .init(enabled: true)) #expect(!controller.focusControls(window: LearningScene.first)) } diff --git a/Tests/ParcelUITests/Overlays/StackGripTests.swift b/Tests/ParcelUITests/Overlays/StackGripTests.swift index a8dd7e8e..7735ac6f 100644 --- a/Tests/ParcelUITests/Overlays/StackGripTests.swift +++ b/Tests/ParcelUITests/Overlays/StackGripTests.swift @@ -78,7 +78,7 @@ extension StackControlsTests { #expect(StackGrip.groups(in: LearningScene.state()).isEmpty) } - @Test func hoverDwellStartsAtGripAndContinuesAcrossChipRow() throws { + @Test func fullSizeStackKeepsChipsWithoutCoveringItsWindowWithHoverControls() throws { let state = LearningScene.state(count: 3, cap: 1) let grip = try #require(StackGrip.groups(in: state).first) let point = CGPoint(x: grip.frame.midX, y: grip.frame.midY) @@ -87,19 +87,17 @@ extension StackControlsTests { #expect(target.frame == grip.frame) let row = try #require(target.stackControlsFrame) #expect(target.interactionFrame.contains(row)) - #expect(target.controlsFrame.minY >= row.maxY) + #expect(target.controlsFrame == .zero) let titleBar = try #require(state.observedFrames[grip.visible]) let titlePoint = CGPoint(x: titleBar.minX + 4, y: titleBar.minY + 4) - #expect(target.controlsFrame.minY >= titleBar.minY + 28) - #expect(target.interactionFrame.contains(titlePoint)) + #expect(target.windowFrame == titleBar.learningRect) #expect(!target.containsControl(at: titlePoint)) #expect(target.containsControl(at: CGPoint(x: row.midX, y: row.midY))) var model = HoverBarModel() - model.receive(target, at: 0, configuration: .init(delay: 0.6)) - #expect(model.phase == .pending) - model.receive(target, at: 0.6, configuration: .init(delay: 0.6)) - #expect(model.phase == .visible) - model.receive(nil, at: 0.7, configuration: .init()) + model.receive(target, at: 0, configuration: .init(enabled: true, delay: 0.6)) + #expect(model.phase == .hidden) + #expect(model.deadline == nil) + model.receive(target, at: 0.6, configuration: .init(enabled: true, delay: 0.6)) #expect(model.phase == .hidden) } diff --git a/Tests/ParcelUITests/Overlays/WindowControlsTests.swift b/Tests/ParcelUITests/Overlays/WindowControlsTests.swift index 68a5f902..cc52718e 100644 --- a/Tests/ParcelUITests/Overlays/WindowControlsTests.swift +++ b/Tests/ParcelUITests/Overlays/WindowControlsTests.swift @@ -21,7 +21,11 @@ extension AppKitTestSuite { defer { controller.stop() } var config = ParcelConfiguration.defaults config.motion.enabled = false - let state = LearningScene.state(cap: 1) + config.hoverBar.enabled = true + var state = LearningScene.state(cap: 1) + state.observedFrames = state.observedFrames.mapValues { + Rect(x: $0.minX, y: $0.minY, width: $0.size.width, height: 200) + } controller.update(state: state, configuration: config, active: true) #expect(controller.chips.groups.count == 1) let frame = try #require(HoverBarModel.target(for: LearningScene.first, state: state)).frame @@ -94,7 +98,10 @@ extension AppKitTestSuite.WindowControlsTests { let controller = try WindowControlsController( settingsModel: settings, focus: { _ in }, close: { _ in }, onFailure: { Issue.record($0) }) defer { controller.stop() } - let state = LearningScene.state(cap: 1) + var state = LearningScene.state(cap: 1) + state.observedFrames = state.observedFrames.mapValues { + Rect(x: $0.minX, y: $0.minY, width: $0.size.width, height: 200) + } var configuration = settings.configuration configuration.motion.enabled = false controller.update(state: state, configuration: configuration, active: true) diff --git a/docs/parcel.schema.json b/docs/parcel.schema.json index 2792c9c2..f2b60955 100644 --- a/docs/parcel.schema.json +++ b/docs/parcel.schema.json @@ -337,7 +337,7 @@ "type" : "number" }, "enabled" : { - "default" : true, + "default" : false, "type" : "boolean" } },