Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

Peek as in Arc: a card with its own bar and Close, Expand and Add To Split beside it; the copy toast's Share button (#166)

Victor Kildahl51edf6df08eb
diff --git a/Packages/CraCore/Sources/CraCore/PeekLayout.swift b/Packages/CraCore/Sources/CraCore/PeekLayout.swift
new file mode 100644
index 0000000..5843c3f
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/PeekLayout.swift
@@ -0,0 +1,52 @@
+import CoreGraphics
+
+/// Where Arc's Peek card and its buttons go in a browser window (y up, as in AppKit).
+///
+/// Arc 1.171 (offline Arc, 1728 × 1084 pt window with a 347 pt sidebar, AX frames, 3 Nov 2026): the
+/// card is centred on the area right of the sidebar (sidebar edge to the window's edge, not the page
+/// card's), 80 % of its width (1105 of 1381 pt), 12 pt in from the window's top and bottom. Close,
+/// Expand and Add To Split are 34 × 33 pt round buttons in a column 13 pt right of the card, the
+/// first 7 pt below its top, 43.5 pt apart. The page behind fades to 28 %, the card has 8 pt corners
+/// and a 32 pt bar. It opens from the area's full size to its own in 0.12 s and closes the same way
+/// back in 0.22 s, fading as it goes.
+public enum PeekLayout {
+ public static let widthFraction: CGFloat = 0.8
+ public static let verticalInset: CGFloat = 12
+ public static let cornerRadius: CGFloat = 8
+ public static let barHeight: CGFloat = 32
+ public static let buttonSize = CGSize(width: 34, height: 33)
+ public static let buttonGap: CGFloat = 13
+ public static let buttonTop: CGFloat = 7
+ public static let buttonPitch: CGFloat = 43.5
+ public static let buttonCount = 3
+ /// The page under a Peek (Arc: 233/240/254 → 178/172/151 over the window's background).
+ public static let pageAlpha: CGFloat = 0.28
+ public static let openDuration: Double = 0.12
+ public static let closeDuration: Double = 0.22
+
+ /// The area a Peek covers: right of the sidebar (`contentMinX`, window coordinates) to the
+ /// window's right edge, its full height.
+ public static func area(window: CGSize, contentMinX: CGFloat) -> CGRect {
+ CGRect(x: contentMinX, y: 0, width: max(0, window.width - contentMinX), height: window.height)
+ }
+
+ public static func card(in area: CGRect) -> CGRect {
+ let w = (area.width * widthFraction).rounded()
+ return CGRect(x: (area.midX - w / 2).rounded(), y: area.minY + verticalInset,
+ width: w, height: max(0, area.height - 2 * verticalInset))
+ }
+
+ /// The column's buttons, top first, beside `card`.
+ public static func buttons(beside card: CGRect) -> [CGRect] {
+ (0..<buttonCount).map { i in
+ let top = card.maxY - buttonTop - CGFloat(i) * buttonPitch
+ return CGRect(x: card.maxX + buttonGap, y: ((top - buttonSize.height) * 2).rounded() / 2,
+ width: buttonSize.width, height: buttonSize.height)
+ }
+ }
+
+ /// The column itself: all the buttons in one frame.
+ public static func column(beside card: CGRect) -> CGRect {
+ buttons(beside: card).reduce(CGRect.null) { $0.union($1) }
+ }
+}
diff --git a/Packages/CraCore/Tests/CraCoreTests/PeekLayoutTests.swift b/Packages/CraCore/Tests/CraCoreTests/PeekLayoutTests.swift
new file mode 100644
index 0000000..e69aec5
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/PeekLayoutTests.swift
@@ -0,0 +1,31 @@
+import CoreGraphics
+import CraCore
+import Testing
+
+/// Arc's Peek as measured (docs/arc-reverse-engineering.md, "Peek and the copy toast's Share
+/// button"): a 1728 × 1084 pt window, sidebar edge at 347, AX frames turned y-up.
+struct PeekLayoutTests {
+ static let window = CGSize(width: 1728, height: 1084)
+
+ @Test func cardMatchesArc() {
+ let card = PeekLayout.card(in: PeekLayout.area(window: Self.window, contentMinX: 347))
+ // Arc: x 485…1590, 12 pt under the window's top, 12.5 above its bottom.
+ #expect(card == CGRect(x: 485, y: 12, width: 1105, height: 1060))
+ }
+
+ @Test func buttonsMatchArc() {
+ let card = PeekLayout.card(in: PeekLayout.area(window: Self.window, contentMinX: 347))
+ let buttons = PeekLayout.buttons(beside: card)
+ // Arc's tops, 19 / 63 / 106 pt under the window's top (y down).
+ let topsFromWindowTop = buttons.map { Self.window.height - $0.maxY }
+ #expect(buttons.allSatisfy { $0.minX == 1603 && $0.size == PeekLayout.buttonSize })
+ #expect(zip(topsFromWindowTop, [19.0, 63, 106]).allSatisfy { abs($0 - $1) <= 0.5 })
+ #expect(PeekLayout.column(beside: card) == CGRect(x: 1603, y: buttons[2].minY, width: 34, height: buttons[0].maxY - buttons[2].minY))
+ }
+
+ @Test func hiddenSidebarCentresOnTheWindow() {
+ let card = PeekLayout.card(in: PeekLayout.area(window: Self.window, contentMinX: 0))
+ #expect(card.midX == Self.window.width / 2)
+ #expect(card.width == (Self.window.width * 0.8).rounded())
+ }
+}
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swift
index 12a102f..cd1f3f6 100644
--- a/Sources/Cra/App/AppDelegate.swift
+++ b/Sources/Cra/App/AppDelegate.swift
@@ -941,7 +941,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
case "copyURL":
if let url = current.flatMap({ store.item($0)?.tab?.url }) {
copy(url)
- main.showToast("Copied Current URL")
+ main.showToast("Copied Current URL", action: .share(url))
}
case "copyURLMarkdown":
if let c = current, let it = store.item(c), let url = it.tab?.url {
diff --git a/Sources/Cra/UI/Windows/LittleWindowController.swift b/Sources/Cra/UI/Windows/LittleWindowController.swift
index 6074058..db0d0be 100644
--- a/Sources/Cra/UI/Windows/LittleWindowController.swift
+++ b/Sources/Cra/UI/Windows/LittleWindowController.swift
@@ -130,6 +130,11 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
let isPeek: Bool
private(set) weak var peekParent: MainWindowController?
private var dim: PeekDimPanel?
+ private var controls: PeekControlsPanel?
+ /// The Peek is on its way out (closePeekAnimated).
+ private var closingPeek = false
+ /// The Peek is shrinking into place; a page window attaching now waits for the end.
+ private var openingPeek = false
private var commandPanel: CommandBarPanel!
private var commandHost: CommandBarView!
private var commandBarOpenedAt = Date.distantPast
@@ -159,7 +164,7 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
.map { NSSize(width: max(LittleMetrics.minSize.width, $0.width), height: max(LittleMetrics.minSize.height, $0.height)) }
?? LittleMetrics.defaultSize
let window = LittleWindow(contentRect: NSRect(origin: .zero, size: size),
- styleMask: parent != nil ? [.titled, .closable, .fullSizeContentView]
+ styleMask: parent != nil ? [.borderless]
: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
backing: .buffered, defer: false)
shell = LittleShellView(frame: window.contentView!.bounds)
@@ -175,7 +180,25 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
window.appearance = NSAppearance(named: .darkAqua)
window.backgroundColor = LittlePalette.barNS
window.contentView = shell
- shell.setToolbar(LittleToolbarView(state: state, actions: actions, store: app.store))
+ if parent != nil {
+ // Arc's Peek is a card: no title bar or traffic lights, 8 pt corners, a shadow.
+ shell.isPeek = true
+ window.isOpaque = false
+ window.backgroundColor = .clear
+ window.hasShadow = true
+ let bar = PeekBarView(state: state)
+ bar.onBack = { [weak self] in self?.browser?.goBack() }
+ bar.onForward = { [weak self] in self?.browser?.goForward() }
+ bar.onReload = { [weak self] in
+ guard let b = self?.browser else { return }
+ if b.isLoading { b.stopLoading() } else { b.reload() }
+ }
+ bar.onEditURL = { [weak self] in self?.openCommandBar() }
+ bar.onCopy = { [weak self] in self?.copyURL() }
+ shell.setPeekBar(bar)
+ } else {
+ shell.setToolbar(LittleToolbarView(state: state, actions: actions, store: app.store))
+ }
shell.onHover = { [weak self] h in
guard let self, self.state.hover != h else { return }
self.state.hover = h
@@ -249,6 +272,9 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
cv.layer?.maskedCorners = cv.isFlipped ? [.layerMinXMaxYCorner, .layerMaxXMaxYCorner] : [.layerMinXMinYCorner, .layerMaxXMinYCorner]
cv.layer?.masksToBounds = true
}
+ // CEF hands the page window over at its own small frame: shown during a Peek's open it
+ // flashed as a black block in the corner.
+ if openingPeek { w.alphaValue = 0 }
window.addChildWindow(w, ordered: .above)
positionHostWindow(shell.convert(shell.page.frame, to: nil))
w.orderFront(nil)
@@ -325,26 +351,82 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
// MARK: Peek
- /// The dimming panel and the Peek, in their order above the parent's other children.
- var peekWindows: [NSWindow] { [dim, window].compactMap { $0 } }
+ /// The click catcher, the Peek and its buttons, in their order above the parent's other children.
+ var peekWindows: [NSWindow] { [dim, window, controls].compactMap { $0 } }
- /// Grows out of the pointer like a Little Window, over the page area of its window.
+ /// Arc's Peek: the card shrinks from the whole area right of the sidebar to its own frame as
+ /// it fades in (0.12 s) while the page behind fades to 28 %; the buttons beside it come after.
func showAsPeek() {
guard let window, let parent = peekParent, let pw = parent.window else { return }
let dim = PeekDimPanel(covering: pw) { [weak self] in self?.closeWindow() }
self.dim = dim
pw.addChildWindow(dim, ordered: .above)
dim.orderFront(nil)
- dim.fadeIn()
- window.setFrame(parent.peekFrame(), display: false)
+ let controls = PeekControlsPanel(buttons: [
+ .init(symbol: "xmark", help: "Close (⌘W)") { [weak self] in self?.closeWindow() },
+ .init(symbol: "arrow.up.left.and.arrow.down.right", help: "Expand (⌘O)") { [weak self] in self?.promote(to: nil) },
+ .init(symbol: "square.split.2x1", help: "Add To Split") { [weak self] in self?.promoteToSplit() },
+ ])
+ self.controls = controls
+ controls.place(parent.peekButtonFrames(), theme: parent.focusedSpace.theme)
+ controls.alphaValue = 0
+ let card = parent.peekFrame()
+ // Laid out at the card's size from the start, as Little Windows open; the page window
+ // waits for the end, it can't follow a frame animation.
+ shell.frozenSize = card.size
+ let host = browser?.hostWindow
+ if let host, host.parent === window { host.alphaValue = 0 }
+ window.alphaValue = 0
+ window.setFrame(parent.peekArea(), display: false)
pw.addChildWindow(window, ordered: .above)
- show()
+ window.makeKeyAndOrderFront(nil)
+ NSApp.activate(ignoringOtherApps: true)
+ parent.setPeekVeil(true, duration: PeekLayout.openDuration)
+ openingPeek = true
+ NSAnimationContext.runAnimationGroup({ ctx in
+ ctx.duration = PeekLayout.openDuration
+ ctx.timingFunction = CAMediaTimingFunction(name: .easeOut)
+ window.animator().alphaValue = 1
+ window.animator().setFrame(card, display: true)
+ }, completionHandler: { [weak self] in
+ MainActor.assumeIsolated {
+ guard let self, let window = self.window, !self.closingPeek else { return }
+ self.openingPeek = false
+ self.shell.frozenSize = nil
+ self.shell.needsLayout = true
+ self.shell.layoutSubtreeIfNeeded()
+ if let host = self.browser?.hostWindow, host.parent === window { host.alphaValue = 1 }
+ pw.addChildWindow(controls, ordered: .above)
+ controls.orderFront(nil)
+ NSAnimationContext.runAnimationGroup { $0.duration = 0.1; controls.animator().alphaValue = 1 }
+ }
+ })
+ if hasPage || isPopupHost { focusPage() } else { openCommandBar() }
}
func repositionPeek() {
- guard let window, let parent = peekParent, let pw = parent.window else { return }
+ guard let window, let parent = peekParent, let pw = parent.window, !closingPeek else { return }
dim?.setFrame(pw.frame, display: true)
window.setFrame(parent.peekFrame(), display: true)
+ controls?.place(parent.peekButtonFrames(), theme: parent.focusedSpace.theme)
+ }
+
+ /// Arc closes a Peek the way it opened, backwards: out to the whole area, fading, as the page
+ /// behind comes back (0.22 s). Expand and Add To Split don't animate: the page stays on screen.
+ private func closePeekAnimated(then finish: @escaping () -> Void) {
+ guard let window, let parent = peekParent else { finish(); return }
+ closingPeek = true
+ parent.setPeekVeil(false, duration: PeekLayout.closeDuration)
+ let host = browser?.hostWindow
+ let controls = controls
+ NSAnimationContext.runAnimationGroup({ ctx in
+ ctx.duration = PeekLayout.closeDuration
+ ctx.timingFunction = CAMediaTimingFunction(name: .easeIn)
+ window.animator().alphaValue = 0
+ host?.animator().alphaValue = 0
+ controls?.animator().alphaValue = 0
+ window.animator().setFrame(parent.peekArea(), display: true)
+ }, completionHandler: { MainActor.assumeIsolated { finish() } })
}
private func endPeek() {
@@ -352,10 +434,36 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
self.dim = nil
dim.parent?.removeChildWindow(dim)
dim.orderOut(nil)
+ if let controls {
+ controls.parent?.removeChildWindow(controls)
+ controls.orderOut(nil)
+ self.controls = nil
+ }
if let window, let p = window.parent { p.removeChildWindow(window) }
+ peekParent?.setPeekVeil(false, duration: 0)
if !promoted, let pw = peekParent?.window, NSApp.isActive { pw.makeKeyAndOrderFront(nil) }
}
+ /// Add To Split: the peeked page becomes a tab and joins the tab under the Peek as a split
+ /// pane, live as it is (Arc's openInSplit).
+ func promoteToSplit() {
+ guard let b = browser, hasPage, let parent = peekParent, let source = parent.selectedTabID else { return }
+ guard parent.canAddPane(to: source) else {
+ parent.showToast("Cannot Add New Pane")
+ return
+ }
+ closePopup()
+ commandBar.close()
+ let sid = store.spaceID(ofItem: source) ?? parent.focusedSpaceID
+ let tab = store.createTab(url: b.currentURL, title: b.currentTitle, in: sid, select: false, window: parent.windowID)
+ if let favicon, let key = FaviconKey.key(for: b.currentURL) { app.favicons.store(favicon, forKey: key) }
+ promoted = true
+ browser = nil
+ parent.browsers.adopt(b, for: tab.id)
+ window?.close()
+ parent.joinSplit(tab.id, with: source)
+ }
+
// MARK: Command bar (Arc: clicking the pill or ⌘L opens the command bar in the window)
func openCommandBar() {
@@ -628,19 +736,24 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
/// ⇧⌘C and the link button: Arc's toast over the window's top-right corner, as in a browser window.
private func copyURL() {
copy(currentURL)
- showToast("Copied Current URL")
+ showToast("Copied Current URL", action: .share(currentURL))
}
/// The toast sits 8 pt under the window's top, over the toolbar (Arc's Little Arc).
- private func showToast(_ text: String) {
+ private func showToast(_ text: String, action: ShinyToast.Action? = nil) {
guard let window, let content = window.contentView else { return }
- toast.show(text, page: content.convert(content.bounds, to: nil), in: window, colors: LittlePalette.toast)
+ toast.show(text, action: action, page: content.convert(content.bounds, to: nil), in: window, colors: LittlePalette.toast)
}
/// ⌘W / Close Window: the same path as the close button. (performClose is
/// skipped: it refuses to act while the standard buttons are dimmed.)
func closeWindow() {
- guard let window, window.isVisible, windowShouldClose(window) else { return }
+ guard let window, window.isVisible else { return }
+ if isPeek, !closingPeek {
+ closePeekAnimated { [weak self] in self?.closeWindow() }
+ return
+ }
+ guard windowShouldClose(window) else { return }
window.close()
}
@@ -850,6 +963,16 @@ final class LittleShellView: NSView {
var openButtonWidth: () -> CGFloat = { 160 }
/// While the window grows open, lay out for this (final) size anchored top-left.
var frozenSize: NSSize? { didSet { needsLayout = true } }
+ /// Arc's Peek card: its own 32 pt bar, the page edge to edge, 8 pt corners all round.
+ var isPeek = false {
+ didSet {
+ layer?.cornerRadius = isPeek ? PeekLayout.cornerRadius : 0
+ layer?.cornerCurve = .continuous
+ layer?.masksToBounds = isPeek
+ needsLayout = true
+ }
+ }
+ private var barHeight: CGFloat { isPeek ? PeekLayout.barHeight : LittleMetrics.barHeight }
private var trackingArea: NSTrackingArea?
override init(frame: NSRect) {
@@ -868,6 +991,13 @@ final class LittleShellView: NSView {
required init?(coder: NSCoder) { fatalError() }
+ func setPeekBar(_ bar: PeekBarView) {
+ toolbarHost.removeFromSuperview()
+ toolbarHost = bar
+ addSubview(bar, positioned: .below, relativeTo: page)
+ needsLayout = true
+ }
+
func setToolbar(_ toolbar: LittleToolbarView) {
toolbar.isOverControl = { [weak self] p in
guard let self else { return false }
@@ -891,6 +1021,7 @@ final class LittleShellView: NSView {
override func mouseMoved(with event: NSEvent) {
super.mouseMoved(with: event)
+ guard !isPeek else { return }
let p = convert(event.locationInWindow, from: nil)
let inBar = p.y > bounds.height - LittleMetrics.barHeight
onHover?(inBar ? hoverTarget(x: p.x, y: bounds.height - p.y) : .none)
@@ -923,9 +1054,9 @@ final class LittleShellView: NSView {
let size = frozenSize ?? bounds.size
let b = NSRect(x: 0, y: bounds.height - size.height, width: size.width, height: size.height)
let fullscreen = window?.styleMask.contains(.fullScreen) ?? false
- let barH = LittleMetrics.barHeight
+ let barH = barHeight
toolbarHost.frame = NSRect(x: 0, y: b.maxY - barH, width: b.width, height: barH)
- let inset = fullscreen ? 0 : LittleMetrics.edgeInset
+ let inset = fullscreen || isPeek ? 0 : LittleMetrics.edgeInset
page.frame = NSRect(x: inset, y: b.minY + inset, width: max(0, b.width - 2 * inset), height: max(0, b.height - barH - inset))
page.layer?.cornerRadius = pageCornerRadius
for sub in page.subviews where sub.frame != page.bounds { sub.frame = page.bounds }
@@ -934,6 +1065,7 @@ final class LittleShellView: NSView {
/// The page's bottom corners follow the window's, just inside its rim.
var pageCornerRadius: CGFloat {
+ if isPeek { return PeekLayout.cornerRadius }
guard let window = window as? LittleWindow, !window.styleMask.contains(.fullScreen) else { return 0 }
return max(0, window.systemCornerRadius - LittleMetrics.edgeInset)
}
@@ -947,6 +1079,8 @@ final class LittleWindow: NSWindow {
func hasActiveAppearance(forStandardWindowButton type: UInt) -> Bool { true }
/// Arc's open animation: ~120 ms from a small rectangle to the full frame.
override func animationResizeTime(_ newFrame: NSRect) -> TimeInterval { LittleMetrics.openDuration }
+ /// A Peek is borderless (Arc's card has no title bar) but still takes the keyboard.
+ override var canBecomeKey: Bool { true }
/// macOS's corner radius for this window (16 pt on macOS 26, larger than Arc's
/// 10), read from the frame view's private `_cornerRadius`.
@@ -980,7 +1114,7 @@ final class LittleWindow: NSWindow {
}
}
-/// The shade over a browser window while a Peek shows on it; a click on it ends the Peek.
+/// Covers a browser window while a Peek shows on it; a click on it ends the Peek.
final class PeekDimPanel: NSPanel {
private final class Shade: NSView {
var onClick: () -> Void = {}
@@ -1000,23 +1134,18 @@ final class PeekDimPanel: NSPanel {
let shade = Shade(frame: NSRect(origin: .zero, size: parent.frame.size))
shade.onClick = onClick
shade.wantsLayer = true
- shade.layer?.backgroundColor = NSColor.black.withAlphaComponent(0.25).cgColor
+ // The page fades instead (MainWindowController.setPeekVeil); this only catches the click,
+ // and a window passes clicks through where it is fully clear.
+ shade.layer?.backgroundColor = NSColor.black.withAlphaComponent(0.01).cgColor
shade.layer?.cornerRadius = LittleWindow.cornerRadius(of: parent)
shade.layer?.cornerCurve = .continuous
shade.autoresizingMask = [.width, .height]
contentView = shade
- alphaValue = 0
}
override var canBecomeKey: Bool { false }
override var canBecomeMain: Bool { false }
- func fadeIn() {
- NSAnimationContext.runAnimationGroup { ctx in
- ctx.duration = LittleMetrics.openDuration
- animator().alphaValue = 1
- }
- }
}
/// Borderless, non-activating tooltip panel (never takes key status).
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index 227c587..40e5e8f 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -1301,13 +1301,48 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
return true
}
- /// Arc's Peek covers the page area less a margin, inside this window.
- func peekFrame() -> NSRect {
+ /// The area Arc's Peek is centred on (window coordinates): right of the sidebar to the
+ /// window's edge, top to bottom; the whole window with the sidebar out of the way.
+ private func peekAreaInWindow() -> NSRect {
guard let window else { return .zero }
// Asked from windowDidResize, before the shell has laid out at the new size.
shell.layoutSubtreeIfNeeded()
- let r = window.convertToScreen(shell.convert(shell.contentContainer.frame, to: nil))
- return r.insetBy(dx: max(24, (r.width * 0.06).rounded()), dy: max(20, (r.height * 0.05).rounded()))
+ let content = shell.convert(shell.contentContainer.frame, to: nil)
+ let sidebarShown = store.window(windowID).sidebarVisible && content.minX > CraMetrics.contentInset
+ return PeekLayout.area(window: window.frame.size, contentMinX: sidebarShown ? content.minX : 0)
+ }
+
+ /// The whole area, where a Peek grows from and goes back to (screen coordinates).
+ func peekArea() -> NSRect { window?.convertToScreen(peekAreaInWindow()) ?? .zero }
+
+ /// Arc's Peek card (screen coordinates).
+ func peekFrame() -> NSRect { window?.convertToScreen(PeekLayout.card(in: peekAreaInWindow())) ?? .zero }
+
+ /// Close, Expand and Add To Split beside the card, top first (screen coordinates).
+ func peekButtonFrames() -> [NSRect] {
+ guard let window else { return [] }
+ return PeekLayout.buttons(beside: PeekLayout.card(in: peekAreaInWindow())).map { window.convertToScreen($0) }
+ }
+
+ /// Arc fades the page under a Peek to 28 % over the window's background, its sidebar as it is.
+ func setPeekVeil(_ on: Bool, duration: TimeInterval) {
+ let alpha: CGFloat = on ? PeekLayout.pageAlpha : 1
+ let pages = browsers.runtimes.values.compactMap(\.hostWindow).filter { $0.parent === window }
+ NSAnimationContext.runAnimationGroup { ctx in
+ ctx.duration = duration
+ shell.contentContainer.animator().alphaValue = alpha
+ for w in pages { w.animator().alphaValue = alpha }
+ }
+ }
+
+ /// Add To Split from a Peek: the peeked page, a new tab, joins `source` as a pane (Arc's
+ /// openInSplit), or a toast when the split is full.
+ func canAddPane(to source: UUID) -> Bool { store.paneTabIDs(for: source).count < 4 }
+
+ func joinSplit(_ tabID: UUID, with source: UUID) {
+ let split = store.splitContaining(source).map { sp in store.addToSplit(sp.id, tabID: tabID, at: nil); return store.item(sp.id) }
+ ?? store.createSplit(with: [source, tabID], at: source)
+ store.selectTab(split.flatMap { store.paneID(for: tabID, in: $0) } ?? tabID, window: windowID)
}
private var peeks: [LittleWindowController] { app.littleWindows.filter { $0.peekParent === self } }
diff --git a/Sources/Cra/UI/Windows/PeekChrome.swift b/Sources/Cra/UI/Windows/PeekChrome.swift
new file mode 100644
index 0000000..a3c7db4
--- /dev/null
+++ b/Sources/Cra/UI/Windows/PeekChrome.swift
@@ -0,0 +1,184 @@
+import AppKit
+import SwiftUI
+
+/// Arc's Peek card bar (1.171, 3 Nov 2026): the page card's own 32 pt toolbar, not Little Arc's
+/// strip. Back, forward and refresh from the card's edge as on a browser window's bar, the
+/// address centred with its copy-link glyph, in the page's colour (white until it reports one).
+@MainActor
+final class PeekBarView: NSView {
+ var onBack: () -> Void = {}
+ var onForward: () -> Void = {}
+ var onReload: () -> Void = {}
+ var onEditURL: () -> Void = {}
+ var onCopy: () -> Void = {}
+
+ private let state: LittleWindowState
+ private let back = ToolbarGlyphButton()
+ private let forward = ToolbarGlyphButton()
+ private let reload = ToolbarGlyphButton()
+ private let url = ToolbarURLButton()
+
+ init(state: LittleWindowState) {
+ self.state = state
+ super.init(frame: .zero)
+ wantsLayer = true
+ for b in [back, forward, reload] { addSubview(b) }
+ addSubview(url)
+ back.action = { [weak self] in self?.onBack() }
+ forward.action = { [weak self] in self?.onForward() }
+ reload.action = { [weak self] in self?.onReload() }
+ url.action = { [weak self] in self?.onEditURL() }
+ url.onCopy = { [weak self] in self?.onCopy() }
+ observe()
+ }
+
+ required init?(coder: NSCoder) { fatalError() }
+
+ override var isFlipped: Bool { true }
+ override var mouseDownCanMoveWindow: Bool { false }
+
+ private struct Shown: Equatable {
+ var url = "", themeColor = ""
+ var canGoBack = false, canGoForward = false, isLoading = false
+ }
+
+ private func observe() {
+ observeChanges(of: { [weak state] in
+ state.map { Shown(url: $0.url, themeColor: $0.themeColor, canGoBack: $0.canGoBack, canGoForward: $0.canGoForward, isLoading: $0.isLoading) }
+ }, apply: { [weak self] shown in
+ if let shown { self?.apply(shown) }
+ })
+ }
+
+ /// PaneToolbarView's colours for a page card: the page's report, else white.
+ private func apply(_ state: Shown) {
+ let hex = ToolbarColor.hex(reported: state.themeColor, remembered: nil)
+ let light = (hex.flatMap(HexColor.luminance) ?? 1) > 0.6
+ let fill = hex.map { NSColor(hex: $0) } ?? .white
+ let fg = light ? NSColor.black.withAlphaComponent(0.8) : NSColor(hex: "#E4E0D4")
+ let fgDim = light ? NSColor.black.withAlphaComponent(0.6) : NSColor(hex: "#F0E6CC").withAlphaComponent(0.9)
+ let hover = NSColor.white.withAlphaComponent(0.1)
+ layer?.backgroundColor = fill.cgColor
+ back.configure(symbol: "arrow.left", image: nil, help: "Go Back (⌘[)", enabled: state.canGoBack, width: 37, iconSize: 15, tint: fgDim, hover: hover)
+ forward.configure(symbol: "arrow.right", image: nil, help: "Go Forward (⌘])", enabled: state.canGoForward, width: 37, iconSize: 15,
+ tint: fgDim, hover: hover)
+ reload.configure(symbol: state.isLoading ? "xmark" : "arrow.clockwise", image: nil, help: "Refresh (⌘R)", enabled: true, width: 37,
+ iconSize: 15, tint: fgDim, hover: hover, animated: true)
+ let human = SuggestionEngine.humanURL(state.url)
+ let host = AppSettings.siteKey(for: state.url) ?? human
+ // Arc's Peek shows the path too ("example.com/peek"), dimmed after the host.
+ url.isHidden = state.url.isEmpty
+ url.show(host: host, path: human.hasPrefix(host) ? String(human.dropFirst(host.count)) : "", url: state.url, developer: false,
+ fg: fg, fgDim: fgDim, hover: NSColor.white.withAlphaComponent(0.08), copyHover: hover)
+ needsLayout = true
+ }
+
+ override func layout() {
+ super.layout()
+ let h = bounds.height
+ var x: CGFloat = 2.5
+ for b in [back, forward, reload] {
+ b.iconRowHeight = 26
+ b.frame = NSRect(x: x, y: (h - 26) / 2, width: b.width, height: 26)
+ x += b.width
+ }
+ // Centred on the card, clear of the buttons on either side.
+ let room = max(0, bounds.width - 2 * (x + 6 + 8))
+ let uw = min(url.idealWidth, room)
+ url.frame = NSRect(x: (bounds.width - uw) / 2, y: (h - 28) / 2, width: uw, height: 28)
+ }
+}
+
+/// Close, Expand and Add To Split beside the Peek card (Arc's confirmCloseModal,
+/// openInSpaceExpander and openInSplit): round buttons in the space's darkest tone with its light
+/// foreground for the glyph, each with Arc's tip.
+@MainActor
+final class PeekControlsPanel: NSPanel {
+ struct Button {
+ let symbol: String
+ let help: String
+ let run: () -> Void
+ }
+
+ private let views: [PeekControlButton]
+
+ init(buttons: [Button]) {
+ views = buttons.map { PeekControlButton(symbol: $0.symbol, help: $0.help, run: $0.run) }
+ super.init(contentRect: .zero, styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
+ isOpaque = false
+ backgroundColor = .clear
+ hasShadow = false
+ hidesOnDeactivate = false
+ isReleasedWhenClosed = false
+ animationBehavior = .none
+ let content = NSView()
+ for v in views { content.addSubview(v) }
+ contentView = content
+ }
+
+ override var canBecomeKey: Bool { false }
+ override var canBecomeMain: Bool { false }
+
+ /// `frames`: each button's screen frame, top first.
+ func place(_ frames: [NSRect], theme: SpaceTheme) {
+ let margin: CGFloat = 8 // room for the buttons' shadows
+ let all = frames.reduce(NSRect.null) { $0.union($1) }.insetBy(dx: -margin, dy: -margin)
+ setFrame(all, display: false)
+ let tones = TooltipTones(theme: theme)
+ let fill = NSColor(srgbRed: tones.fill.r, green: tones.fill.g, blue: tones.fill.b, alpha: 1)
+ let ink = NSColor(LittlePalette.spaceName(theme))
+ for (v, f) in zip(views, frames) {
+ v.frame = NSRect(x: f.minX - all.minX, y: f.minY - all.minY, width: f.width, height: f.height)
+ v.paint(fill: fill, ink: ink)
+ }
+ }
+}
+
+final class PeekControlButton: NSView {
+ private let run: () -> Void
+ private let glyph = NSImageView()
+ private let symbol: String
+ private var pressed = false
+
+ init(symbol: String, help: String, run: @escaping () -> Void) {
+ self.run = run
+ self.symbol = symbol
+ super.init(frame: .zero)
+ wantsLayer = true
+ layer?.shadowColor = NSColor.black.cgColor
+ layer?.shadowOpacity = 0.25
+ layer?.shadowRadius = 4
+ layer?.shadowOffset = CGSize(width: 0, height: -1)
+ glyph.imageScaling = .scaleNone
+ addSubview(glyph)
+ _ = ArcTooltipAnchorView.attach(to: self, help: help)
+ }
+
+ required init?(coder: NSCoder) { fatalError() }
+
+ func paint(fill: NSColor, ink: NSColor) {
+ layer?.backgroundColor = fill.cgColor
+ layer?.cornerRadius = min(bounds.width, bounds.height) / 2
+ glyph.image = SidebarSymbols.image(symbol, size: 15, weight: .semibold)
+ glyph.contentTintColor = ink
+ needsLayout = true
+ }
+
+ override func layout() {
+ super.layout()
+ layer?.cornerRadius = min(bounds.width, bounds.height) / 2
+ glyph.frame = bounds
+ }
+
+ override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
+ override func mouseDown(with event: NSEvent) {
+ pressed = true
+ alphaValue = 0.8
+ }
+ override func mouseUp(with event: NSEvent) {
+ alphaValue = 1
+ guard pressed, bounds.contains(convert(event.locationInWindow, from: nil)) else { pressed = false; return }
+ pressed = false
+ run()
+ }
+}
diff --git a/Sources/Cra/UI/Windows/ShinyToast.swift b/Sources/Cra/UI/Windows/ShinyToast.swift
index a22dced..a093761 100644
--- a/Sources/Cra/UI/Windows/ShinyToast.swift
+++ b/Sources/Cra/UI/Windows/ShinyToast.swift
@@ -15,9 +15,29 @@ import QuartzCore
final class ShinyToast {
struct Action {
let title: String
+ /// A glyph button instead of the text capsule, given the button to anchor a menu to
+ /// (Arc's Share on "Copied Current URL").
+ var symbol: String? = nil
let run: () -> Void
+ var anchored: ((NSView, NSRect) -> Void)? = nil
+
+ /// Arc's Share glyph on "Copied Current URL" (Arc 1.171, browser windows and Little Arc):
+ /// the macOS share menu for the address, from the button.
+ static func share(_ url: String) -> Action {
+ Action(title: "Share", symbol: "square.and.arrow.up", run: {}, anchored: { view, rect in
+ guard let u = URL(string: url) else { return }
+ NSSharingServicePicker(items: [u]).show(relativeTo: rect, of: view, preferredEdge: .minY)
+ })
+ }
}
+ /// The glyph button's toast (Arc 1.171, 3 Nov 2026, 2x captures): 47 pt tall, the text 13 pt in,
+ /// 14.5 pt to a 29 × 27 pt button 13 pt from the end and 10 pt from the top and bottom.
+ static let glyphHeight: CGFloat = 47
+ static let glyphButton = CGSize(width: 29, height: 27)
+ static let glyphPadding: CGFloat = 13
+ static let glyphGap: CGFloat = 14.5
+
static let height: CGFloat = 42
static let topInset: CGFloat = 8
static let trailingInset: CGFloat = 9
@@ -40,6 +60,7 @@ final class ShinyToast {
private let label = CATextLayer()
private let button = CALayer()
private let buttonLabel = CATextLayer()
+ private let buttonGlyph = CALayer()
private var hide: DispatchWorkItem?
private var action: Action?
/// The text colour: the button is a wash of it.
@@ -70,6 +91,8 @@ final class ShinyToast {
buttonLabel.fontSize = Self.buttonFont.pointSize
buttonLabel.alignmentMode = .center
button.addSublayer(buttonLabel)
+ buttonGlyph.contentsGravity = .center
+ button.addSublayer(buttonGlyph)
pill.addSublayer(button)
view.layer?.addSublayer(pill)
view.onHover = { [weak self] inside in self?.hovered(inside) }
@@ -87,19 +110,23 @@ final class ShinyToast {
func show(_ text: String, action: Action? = nil, page: NSRect, in window: NSWindow, colors: Colors) {
self.action = action
+ let glyph = action?.symbol
let textWidth = ceil((text as NSString).size(withAttributes: [.font: Self.font]).width)
- let buttonWidth = action.map { ceil(($0.title as NSString).size(withAttributes: [.font: Self.buttonFont]).width) + 2 * Self.buttonPadding }
- let width = textWidth + 2 * Self.padding + (buttonWidth.map { $0 + Self.buttonGap - Self.padding + (Self.height - Self.buttonHeight) / 2 } ?? 0)
- let local = NSRect(x: page.maxX - Self.trailingInset - width, y: page.maxY - Self.topInset - Self.height,
- width: width, height: Self.height)
+ let buttonWidth = glyph != nil ? Self.glyphButton.width
+ : action.map { ceil(($0.title as NSString).size(withAttributes: [.font: Self.buttonFont]).width) + 2 * Self.buttonPadding }
+ let height = glyph != nil ? Self.glyphHeight : Self.height
+ let width = glyph != nil ? Self.glyphPadding + textWidth + Self.glyphGap + Self.glyphButton.width + Self.glyphPadding
+ : textWidth + 2 * Self.padding + (buttonWidth.map { $0 + Self.buttonGap - Self.padding + (Self.height - Self.buttonHeight) / 2 } ?? 0)
+ let local = NSRect(x: page.maxX - Self.trailingInset - width, y: page.maxY - Self.topInset - height,
+ width: width, height: height)
panel.setFrame(window.convertToScreen(local.insetBy(dx: -Self.margin, dy: -Self.margin)), display: false)
let scale = window.backingScaleFactor
CATransaction.begin()
CATransaction.setDisableActions(true)
// Anchored at the top centre, where Arc's toast grows from.
pill.anchorPoint = CGPoint(x: 0.5, y: 1)
- pill.bounds = CGRect(x: 0, y: 0, width: width, height: Self.height)
- pill.position = CGPoint(x: Self.margin + width / 2, y: Self.margin + Self.height)
+ pill.bounds = CGRect(x: 0, y: 0, width: width, height: height)
+ pill.position = CGPoint(x: Self.margin + width / 2, y: Self.margin + height)
// Top to bottom (a layer's y runs up).
pill.colors = [colors.bottom.cgColor, colors.top.cgColor]
pill.borderColor = colors.outline.cgColor
@@ -107,10 +134,28 @@ final class ShinyToast {
label.contentsScale = scale
label.string = text
let lineHeight = ceil(Self.font.ascender - Self.font.descender)
- label.frame = CGRect(x: buttonWidth == nil ? 0 : Self.padding, y: (Self.height - lineHeight) / 2,
+ label.frame = CGRect(x: buttonWidth == nil ? 0 : glyph != nil ? Self.glyphPadding : Self.padding, y: (height - lineHeight) / 2,
width: buttonWidth == nil ? width : textWidth, height: lineHeight)
button.isHidden = buttonWidth == nil
- if let buttonWidth, let action {
+ buttonLabel.isHidden = glyph != nil
+ buttonGlyph.isHidden = glyph == nil
+ if let glyph {
+ // A wash of white over the pill (60 % on a light toast, 15 % on a dark one) with an
+ // outline of the text colour, the glyph in the text colour.
+ let dark = (colors.text.usingColorSpace(.sRGB)?.brightnessComponent ?? 0) > 0.5
+ let b = Self.glyphButton
+ button.frame = CGRect(x: width - Self.glyphPadding - b.width, y: (height - b.height) / 2, width: b.width, height: b.height)
+ button.cornerRadius = 7
+ button.borderWidth = 1
+ button.borderColor = colors.text.withAlphaComponent(dark ? 0.2 : 0.3).cgColor
+ button.backgroundColor = (colors.top.blended(withFraction: dark ? 0.15 : 0.6, of: .white) ?? colors.top).cgColor
+ let config = NSImage.SymbolConfiguration(pointSize: 13, weight: .medium).applying(.init(paletteColors: [colors.text]))
+ buttonGlyph.contents = NSImage(systemSymbolName: glyph, accessibilityDescription: action?.title)?.withSymbolConfiguration(config)
+ buttonGlyph.contentsScale = scale
+ buttonGlyph.frame = CGRect(origin: .zero, size: b)
+ } else if let buttonWidth, let action {
+ button.cornerRadius = Self.buttonHeight / 2
+ button.borderWidth = 0
let inset = (Self.height - Self.buttonHeight) / 2
button.frame = CGRect(x: width - inset - buttonWidth, y: inset, width: buttonWidth, height: Self.buttonHeight)
buttonTint = colors.text
@@ -123,7 +168,7 @@ final class ShinyToast {
}
CATransaction.commit()
panel.ignoresMouseEvents = action == nil
- view.hitRect = action == nil ? .zero : NSRect(x: Self.margin, y: Self.margin, width: width, height: Self.height)
+ view.hitRect = action == nil ? .zero : NSRect(x: Self.margin, y: Self.margin, width: width, height: height)
if !isShown {
// Opening the tab's page holds the main thread for ~0.1 s, so the toast waits for the
// next turn, invisible: started now, its first frame showed it most of the way in.
@@ -156,7 +201,7 @@ final class ShinyToast {
}
CATransaction.begin()
CATransaction.setDisableActions(true)
- button.backgroundColor = buttonTint.withAlphaComponent(inside ? 0.16 : 0.1).cgColor
+ if action?.symbol == nil { button.backgroundColor = buttonTint.withAlphaComponent(inside ? 0.16 : 0.1).cgColor }
CATransaction.commit()
}
@@ -165,6 +210,13 @@ final class ShinyToast {
guard let action, isShown else { return }
let local = NSPoint(x: point.x - Self.margin, y: point.y - Self.margin)
guard button.frame.insetBy(dx: -4, dy: -4).contains(local) else { return }
+ if let anchored = action.anchored, let root = view.layer {
+ // The menu hangs from the button, the toast stays up under it (Arc), then goes on its time.
+ hide?.cancel()
+ anchored(view, root.convert(button.frame, from: pill))
+ scheduleHide()
+ return
+ }
dismiss()
action.run()
}
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index 178ea7a..a5d0077 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -2729,3 +2729,31 @@ events, the window recorded with `screencapture -V`.
- [O] A Shift-click on a link in the Little Arc's page opened it in that Little Arc: no Peek, no second window
(AX and CG window lists before and after). Cra used to open another Little Window. A Shift-clicked link in a
browser window still opens a Peek (`shiftClickModalEntryPointEnabled`).
+
+## Peek and the copy toast's Share button (Arc 1.171, 3 Nov 2026, offline Arc)
+
+Offline Arc in a 1728 × 1084 pt window (sidebar 347 pt), a page that is one big link, Shift-click as a HID
+event with `shiftClickModalEntryPointEnabled` set for the run, AX frames and 60 fps recordings.
+- [O] With `shiftClickModalEntryPointEnabled` unset (Victor's defaults), a Shift-click on a file:// link opened a
+ new tab below, not a Peek. With it on, a Shift-click on an https link opened the Peek.
+- [O] The Peek is a card in the browser window: x 485…1590, 12 pt in from the window's top and bottom, i.e. 80 %
+ of the area from the sidebar's edge to the window's right edge, centred on it. 8 pt continuous corners, a soft
+ shadow. It has its own 32 pt bar (back, forward, refresh from the card edge, the address centred with its
+ copy-link glyph, "example.com/peek", host then dimmed path), white while the page had no colour.
+- [O] Beside it, 13 pt right of the card, a column of 34 × 33 pt round buttons 7 pt below its top, 43.5 pt
+ apart: `confirmCloseModal` "Close ⌘W" (xmark), `openInSpaceExpander` "Expand ⌘O"
+ (arrow.up.left.and.arrow.down.right), `openInSplit` "Add To Split" (square.split.2x1). Fill 16/13/0, glyph
+ 250/238/194 on the fake home's yellow space: the space's tooltip fill (shadedDark at 30 %) and its light
+ foreground. Their tips are the space's ArcTooltip.
+- [O] The page behind fades to about 28 % over the window's background (233/240/254 → 178/172/151); the sidebar
+ stays. Opening, the card starts at the area's full size and shrinks to its frame as it fades in (~0.12 s), the
+ buttons appearing at the end. Escape closes it backwards: out to the full area, fading, as the page comes back
+ (~0.22 s).
+- [O] "Copied Current URL" carries a Share glyph button in browser windows too (AX `square.and.arrow.up`, "Share",
+ 31 × 27). The toast is 195 × 47 pt: text 13 pt in, 14.5 pt to a 29 × 27 pt button 13 pt from the end, 10 pt from
+ top and bottom. The button is a white wash over the pill (≈ 60 % on the light toast, 15 % on Little Arc's dark
+ one) with an outline. A click opens the macOS share menu (AirDrop, Notes…) from the button; the toast stays.
+- Cra: PeekLayout (CraCore) has the geometry; PeekBarView and PeekControlsPanel (PeekChrome.swift) the card's bar
+ and the buttons; MainWindowController.setPeekVeil fades the page; ShinyToast.Action.share the button.
+- [?] Not measured: the card at other window widths (Cra keeps 80 % of the area), and the Peek with Arc's
+ toolbar turned off.