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.

A Peek keeps the browser window's shadow and leaves its edges to resizing, as in Arc (#222)

Grigoriy3b57e7f8aed1
diff --git a/Packages/CraCore/Sources/CraCore/PeekLayout.swift b/Packages/CraCore/Sources/CraCore/PeekLayout.swift
index da00c6c..7fb6829 100644
--- a/Packages/CraCore/Sources/CraCore/PeekLayout.swift
+++ b/Packages/CraCore/Sources/CraCore/PeekLayout.swift
@@ -31,6 +31,18 @@ public enum PeekLayout {
/// window edge to edge (no margins to widen) (PR #221).
public static let pageScale: CGFloat = 0.985
+ /// Arc's Peek is a card inside the browser window, so the window's own resize band beats the click
+ /// that closes it. Arc 1.172.1 (offline Arc, HID clicks on a 1100 × 760 pt window, 6 Nov 2026, PR
+ /// #222): a click 1–3 pt inside the right or bottom edge (1–2 at the top) keeps the Peek and a drag
+ /// from there resizes the window, the card following; 4 pt in (3 at the top), a click closes it.
+ public static let dismissInset: CGFloat = 3
+
+ /// The part of a browser window (`window`, its frame) where a click closes the Peek over it: all
+ /// of it but the band along its edges that macOS keeps for resizing.
+ public static func dismissArea(covering window: CGRect) -> CGRect {
+ window.insetBy(dx: dismissInset, dy: dismissInset)
+ }
+
public struct Backdrop: Sendable, Equatable {
public let alpha: CGFloat
public let scale: CGFloat
diff --git a/Packages/CraCore/Tests/CraCoreTests/PeekLayoutTests.swift b/Packages/CraCore/Tests/CraCoreTests/PeekLayoutTests.swift
index a9a8a76..03ab59b 100644
--- a/Packages/CraCore/Tests/CraCoreTests/PeekLayoutTests.swift
+++ b/Packages/CraCore/Tests/CraCoreTests/PeekLayoutTests.swift
@@ -23,6 +23,24 @@ struct PeekLayoutTests {
#expect(PeekLayout.column(beside: card) == CGRect(x: 1603, y: buttons[2].minY, width: 34, height: buttons[0].maxY - buttons[2].minY))
}
+ @Test func clicksNearTheEdgeResizeLikeArc() {
+ // Arc 1.172.1, a 1100 × 760 pt window: 1–3 pt inside an edge resize and keep the Peek, 4 pt
+ // in closes it.
+ let window = CGRect(x: 100, y: 80, width: 1100, height: 760)
+ let area = PeekLayout.dismissArea(covering: window)
+ for d: CGFloat in [1, 2, 3 - 0.01] {
+ for p in [CGPoint(x: window.maxX - d, y: window.midY), CGPoint(x: window.minX + d, y: window.midY),
+ CGPoint(x: window.midX, y: window.maxY - d), CGPoint(x: window.midX, y: window.minY + d)] {
+ #expect(!area.contains(p), "\(d) pt in")
+ }
+ }
+ for p in [CGPoint(x: window.maxX - 4, y: window.midY), CGPoint(x: window.minX + 4, y: window.midY),
+ CGPoint(x: window.midX, y: window.maxY - 4), CGPoint(x: window.midX, y: window.minY + 4)] {
+ #expect(area.contains(p))
+ }
+ #expect(window.contains(area))
+ }
+
@Test func hiddenSidebarCentresOnTheWindow() {
let card = PeekLayout.card(in: PeekLayout.area(window: Self.window, contentMinX: 0))
#expect(card.midX == Self.window.width / 2)
diff --git a/Sources/Cra/UI/Windows/ChromiumChildFocus.swift b/Sources/Cra/UI/Windows/ChromiumChildFocus.swift
new file mode 100644
index 0000000..1a128a0
--- /dev/null
+++ b/Sources/Cra/UI/Windows/ChromiumChildFocus.swift
@@ -0,0 +1,44 @@
+import AppKit
+import ObjectiveC
+
+/// Chromium keeps its own child windows from becoming main ("Dialogs and bubbles shouldn't take
+/// large shadows away from their parent", -[NativeWidgetMacNSWindow canBecomeMainWindow]), but it
+/// only knows the parents it made. A Peek's or Little Window's page is a Chromium window Cra hangs
+/// on its window with addChildWindow, so a click in the page made it main: the browser window
+/// under a Peek lost its active shadow and coloured traffic lights. Arc's Peek is a card inside
+/// the browser window, which stays main. For windows attached here the rule covers AppKit parents
+/// too; they still take the keyboard.
+@MainActor
+enum ChromiumChildFocus {
+ private static let pages = NSHashTable<NSWindow>.weakObjects()
+ private static var patchedClasses = Set<ObjectIdentifier>()
+ private typealias MainIMP = @convention(c) (NSWindow, Selector) -> Bool
+
+ /// Registers a page window hung on a Cra window; if it is main already, hands main back to
+ /// the nearest ancestor that can take it.
+ static func attach(_ window: NSWindow) {
+ pages.add(window)
+ patch(type(of: window))
+ guard window.isMainWindow else { return }
+ var ancestor = window.parent
+ while let parent = ancestor {
+ if parent.canBecomeMain { parent.makeMain(); return }
+ ancestor = parent.parent
+ }
+ }
+
+ private static func patch(_ cls: AnyClass) {
+ guard patchedClasses.insert(ObjectIdentifier(cls)).inserted else { return }
+ let sel = #selector(getter: NSWindow.canBecomeMain)
+ guard let method = class_getInstanceMethod(cls, sel), let types = method_getTypeEncoding(method) else { return }
+ let original = unsafeBitCast(method_getImplementation(method), to: MainIMP.self)
+ let block: @convention(block) (NSWindow) -> Bool = { window in
+ MainActor.assumeIsolated {
+ if pages.contains(window), window.parent != nil { return false }
+ return original(window, sel)
+ }
+ }
+ let imp = imp_implementationWithBlock(block)
+ if !class_addMethod(cls, sel, imp, types) { method_setImplementation(method, imp) }
+ }
+}
diff --git a/Sources/Cra/UI/Windows/LittleWindowController.swift b/Sources/Cra/UI/Windows/LittleWindowController.swift
index a5b0254..35e65c4 100644
--- a/Sources/Cra/UI/Windows/LittleWindowController.swift
+++ b/Sources/Cra/UI/Windows/LittleWindowController.swift
@@ -322,6 +322,7 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
// flashed as a black block in the corner.
if openingPeek { w.contentView?.isHidden = true }
window.addChildWindow(w, ordered: .above)
+ ChromiumChildFocus.attach(w)
positionHostWindow(shell.convert(shell.page.frame, to: nil))
w.orderFront(nil)
rejoinPage()
@@ -446,6 +447,7 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
shell.layoutSubtreeIfNeeded()
pw.addChildWindow(window, ordered: .above)
pw.addChildWindow(controls, ordered: .above)
+ pw.makeMain()
controls.orderFront(nil)
window.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)
@@ -492,7 +494,7 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
func repositionPeek() {
guard let window, let parent = peekParent, let pw = parent.window, !closingPeek else { return }
- dim?.setFrame(pw.frame, display: true)
+ dim?.reposition(covering: pw)
window.setFrame(parent.peekFrame(), display: true)
controls?.place(parent.peekButtonFrames(), theme: parent.focusedSpace.theme)
}
@@ -1395,40 +1397,6 @@ final class LittleWindow: NSPanel {
}
}
-/// 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 = {}
- override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
- override func mouseDown(with event: NSEvent) { onClick() }
- override func rightMouseDown(with event: NSEvent) { onClick() }
- }
-
- init(covering parent: NSWindow, onClick: @escaping () -> Void) {
- super.init(contentRect: parent.frame, styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
- isOpaque = false
- backgroundColor = .clear
- hasShadow = false
- isMovable = false
- hidesOnDeactivate = false
- isReleasedWhenClosed = false
- let shade = Shade(frame: NSRect(origin: .zero, size: parent.frame.size))
- shade.onClick = onClick
- shade.wantsLayer = true
- // The page fades instead (MainWindowController.showPeekVeil); 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
- }
-
- override var canBecomeKey: Bool { false }
- override var canBecomeMain: Bool { false }
-
-}
-
/// Borderless, non-activating tooltip panel (never takes key status).
final class LittleTooltipPanel: NSPanel {
override var canBecomeKey: Bool { false }
diff --git a/Sources/Cra/UI/Windows/PeekDimPanel.swift b/Sources/Cra/UI/Windows/PeekDimPanel.swift
new file mode 100644
index 0000000..b422e8e
--- /dev/null
+++ b/Sources/Cra/UI/Windows/PeekDimPanel.swift
@@ -0,0 +1,42 @@
+import AppKit
+
+/// Covers a browser window while a Peek shows on it; a click on it ends the Peek. It leaves the
+/// window's edge band uncovered (PeekLayout.dismissArea), so a press there resizes the window
+/// and the Peek stays, as in Arc, where the Peek is a card inside the window.
+final class PeekDimPanel: NSPanel {
+ private final class Shade: NSView {
+ var onClick: () -> Void = {}
+ override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
+ override func mouseDown(with event: NSEvent) { onClick() }
+ override func rightMouseDown(with event: NSEvent) { onClick() }
+ }
+
+ init(covering parent: NSWindow, onClick: @escaping () -> Void) {
+ let frame = PeekLayout.dismissArea(covering: parent.frame)
+ super.init(contentRect: frame, styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
+ isOpaque = false
+ backgroundColor = .clear
+ hasShadow = false
+ isMovable = false
+ hidesOnDeactivate = false
+ isReleasedWhenClosed = false
+ let shade = Shade(frame: NSRect(origin: .zero, size: frame.size))
+ shade.onClick = onClick
+ shade.wantsLayer = true
+ // The page fades instead (MainWindowController.showPeekVeil); 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
+ }
+
+ /// Follows the browser window as it moves or resizes under the Peek.
+ func reposition(covering parent: NSWindow) {
+ setFrame(PeekLayout.dismissArea(covering: parent.frame), display: true)
+ }
+
+ override var canBecomeKey: Bool { false }
+ override var canBecomeMain: Bool { false }
+}
diff --git a/Tests/PeekDimPanelTests.swift b/Tests/PeekDimPanelTests.swift
new file mode 100644
index 0000000..a21f946
--- /dev/null
+++ b/Tests/PeekDimPanelTests.swift
@@ -0,0 +1,103 @@
+import AppKit
+
+@main
+enum PeekDimPanelTests {
+ private static var checks = 0
+
+ @MainActor
+ static func main() {
+ _ = NSApplication.shared
+ NSApp.setActivationPolicy(.prohibited)
+ let parent = NSWindow(contentRect: NSRect(x: -10000, y: -10000, width: 1000, height: 700),
+ styleMask: [.titled, .resizable, .fullSizeContentView], backing: .buffered, defer: false)
+ parent.isReleasedWhenClosed = false
+ var dismissed = 0
+ let panel = PeekDimPanel(covering: parent) { dismissed += 1 }
+ parent.addChildWindow(panel, ordered: .above)
+ checkResizeEdges(parent, panel)
+ expect(!panel.canBecomeKey && !panel.canBecomeMain, "the dismiss panel must not take focus")
+
+ for size in [NSSize(width: 640, height: 420), NSSize(width: 1500, height: 1000)] {
+ parent.setFrame(NSRect(origin: parent.frame.origin, size: size), display: false)
+ panel.reposition(covering: parent)
+ checkResizeEdges(parent, panel)
+ expect(panel.contentView?.frame.size == panel.frame.size, "the click catcher follows the resized panel")
+ }
+ parent.setFrameOrigin(NSPoint(x: -12000, y: -9000))
+ checkResizeEdges(parent, panel)
+ expect(dismissed == 0, "resizing and moving the parent keep Peek open")
+
+ let view = panel.contentView!
+ let point = NSPoint(x: view.bounds.midX, y: view.bounds.midY)
+ let hit = view.hitTest(point)!
+ expect(hit.acceptsFirstMouse(for: nil), "a background click dismisses Peek on the first click")
+ for type in [NSEvent.EventType.leftMouseDown, .rightMouseDown] {
+ let event = NSEvent.mouseEvent(with: type, location: point, modifierFlags: [], timestamp: 1,
+ windowNumber: panel.windowNumber, context: nil, eventNumber: 0,
+ clickCount: 1, pressure: 0)!
+ if type == .leftMouseDown { hit.mouseDown(with: event) } else { hit.rightMouseDown(with: event) }
+ }
+ expect(dismissed == 2, "both left and right background clicks dismiss Peek")
+ checkPageFocus(parent)
+ parent.removeChildWindow(panel)
+ panel.close()
+ parent.close()
+ print("Peek dismiss panel: \(checks) checks passed")
+ }
+
+ @MainActor
+ private static func checkPageFocus(_ parent: NSWindow) {
+ let peek = NSPanel(contentRect: parent.frame.insetBy(dx: 100, dy: 100), styleMask: [.borderless], backing: .buffered, defer: false)
+ let page: NSWindow = FocusTestPage(contentRect: peek.frame, styleMask: [.borderless], backing: .buffered, defer: false)
+ let other: NSWindow = FocusTestPage(contentRect: peek.frame, styleMask: [.borderless], backing: .buffered, defer: false)
+ for window in [peek, page, other] { window.isReleasedWhenClosed = false }
+ parent.addChildWindow(peek, ordered: .above)
+ peek.addChildWindow(page, ordered: .above)
+ ChromiumChildFocus.attach(page)
+ expect(page.canBecomeKey, "the page in Peek keeps keyboard focus")
+ expect(!page.canBecomeMain, "the page in Peek must not take the parent's main-window status and shadow")
+ expect(other.canBecomeMain, "unregistered Chromium windows keep their original focus rules")
+ ChromiumChildFocus.attach(page)
+ expect(!page.canBecomeMain, "reattaching keeps the page from becoming main")
+ peek.removeChildWindow(page)
+ expect(page.canBecomeMain, "a detached page regains its original main-window eligibility")
+ parent.addChildWindow(page, ordered: .above)
+ expect(!page.canBecomeMain, "a page promoted from Peek still belongs to its browser window")
+ parent.removeChildWindow(page)
+ parent.removeChildWindow(peek)
+ for window in [page, other, peek] { window.close() }
+ }
+
+ @MainActor
+ private static func checkResizeEdges(_ parent: NSWindow, _ panel: PeekDimPanel) {
+ let frame = parent.frame
+ let xs = [frame.minX + 1, frame.midX, frame.maxX - 1]
+ let ys = [frame.minY + 1, frame.midY, frame.maxY - 1]
+ for x in xs {
+ for y in ys where x != frame.midX || y != frame.midY {
+ expect(!panel.frame.contains(NSPoint(x: x, y: y)), "Peek must leave the parent's resize edges and corners uncovered")
+ }
+ }
+ expect(panel.frame.contains(NSPoint(x: frame.midX, y: frame.midY)), "the panel still catches clicks inside the parent")
+ // Arc: 4 pt in, a click closes the Peek.
+ for p in [NSPoint(x: frame.maxX - 4, y: frame.midY), NSPoint(x: frame.minX + 4, y: frame.midY),
+ NSPoint(x: frame.midX, y: frame.maxY - 4), NSPoint(x: frame.midX, y: frame.minY + 4)] {
+ expect(panel.frame.contains(p), "a click 4 pt inside an edge closes the Peek, as in Arc")
+ }
+ expect(frame.contains(panel.frame), "the dismiss panel stays inside the parent")
+ }
+
+ private static func expect(_ condition: @autoclosure () -> Bool, _ message: String) {
+ guard condition() else { fatalError(message) }
+ checks += 1
+ }
+}
+
+enum LittleWindow {
+ static func cornerRadius(of window: NSWindow) -> CGFloat { 16 }
+}
+
+final class FocusTestPage: NSWindow {
+ override var canBecomeKey: Bool { true }
+ override var canBecomeMain: Bool { true }
+}
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index 87adf26..170c896 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -3050,6 +3050,29 @@ links, A near the top left and B near the bottom right, real HID Shift-clicks (`
.77, .84, .91, .93, .98 of the way a frame apart (Arc .60, .77, .85, .91, .95, .97), its bottom edge .34,
.59, .71, .80, .87, .91 (Arc .31, .54, .73, .82, .89, .94), and it closed back into the link.
+### Peek, the window's shadow and its edges (Arc 1.172.1, 6 Nov 2026, PR #222, offline Arc)
+Offline Arc (fake home, network blocked) in a 1100 × 760 pt window at 100,80, a Peek opened by a HID
+Shift-click on a lab page's link, then HID clicks and drags; Peek open or closed read from AX (its Close button,
+`confirmCloseModal`), the window's state from AX and `screencapture -l` with the shadow.
+- [O] The Peek is a card inside the browser window: no second CGWindow or AX window while it shows (the
+ `ModalContent.ModalWindow` class is a plain NSWindow subclass with no focus overrides, but none was on
+ screen). The browser window stays main and keeps its full shadow, before and after a click into the
+ Peek's page (capture 2424 × 1744 px both times).
+- [O] Clicks near the edge, outside the card: 1–3 pt inside the right or bottom edge and 1–2 pt inside the
+ top keep the Peek (macOS's resize band takes them); 4 pt in (3 at the top) closes it. Left: the sidebar
+ is there, and 1–6 pt in kept it.
+- [O] A drag from 2 pt inside the right edge, or 2 pt below the bottom edge, resizes the window with the
+ Peek open, and the card grows with the window.
+- [O, Cra] 0.1.32 lost the browser window's active look as soon as a Peek opened (grey traffic lights,
+ capture 2336 × 1656 px): Chromium keeps only the child windows it made itself from becoming main
+ (-[NativeWidgetMacNSWindow canBecomeMainWindow]), and the Peek's page window hangs on Cra's window
+ through AppKit. Its click catcher covered the whole window, so every click 1–12 pt in closed the Peek
+ and a drag from 2 pt inside closed it instead of resizing (from outside it resized).
+- Cra: ChromiumChildFocus keeps a Peek's or Little Window's page from becoming main; PeekDimPanel covers
+ PeekLayout.dismissArea, the window minus a 3 pt band. Checked on a test copy like Arc above: full shadow
+ and coloured traffic lights after a click in the Peek, edge clicks 1–3 pt in keep it and 4 pt in close it,
+ and a drag from 2 pt inside resizes with the Peek open.
+
## Capture (Arc 1.171, 4 Nov 2026, X request, Swift metadata + strings + offline Arc at 2x, 120 fps recordings)
- [O metadata] Module `Capture`: ContentCaptureViewController holds ContentCaptureView (grayscale and darkened layers with
shape masks, a lens ShadowView, a camera cursor view, single/double click and pan recognizers, an Esc monitor,
diff --git a/docs/release-checklist.md b/docs/release-checklist.md
index 1660574..d32dcaa 100644
--- a/docs/release-checklist.md
+++ b/docs/release-checklist.md
@@ -71,6 +71,10 @@ built release app with a test profile. Note anything that fails in the release's
Window over it, and doesn't when Settings ▸ Tabs ▸ Links is off.
- **#202:** in a Peek, ⌘-click a `target=_blank` link: a background tab opens and the Peek
stays. A plain click on it closes the Peek and selects the new tab below the source tab.
+- **PR #222:** with a Peek open, the browser window keeps its full shadow and coloured traffic
+ lights, also after a click in the Peek, as in Arc. A drag from every edge and corner resizes the
+ window with the Peek open and the card follows; a click on the background 4 pt or more inside
+ the window closes it.
- **#186:** send a link from a full-screen app. The Little Window opens centred on that Space
with no switch to the desktop, and a video in it can still go full screen.
- **#172:** with a space on its own profile, a Little Window from that space and a Peek from its
diff --git a/scripts/test-peek-dim-panel.sh b/scripts/test-peek-dim-panel.sh
new file mode 100755
index 0000000..c18d070
--- /dev/null
+++ b/scripts/test-peek-dim-panel.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+# The click catcher behind a Peek (PeekDimPanel) and the focus rule for page windows hung on Cra windows (ChromiumChildFocus).
+set -euo pipefail
+cd "$(dirname "$0")/.."
+TEST_DIR="$(mktemp -d "${TMPDIR:-/tmp}/cra-peek-panel.XXXXXX")"
+trap 'rm -rf "$TEST_DIR"' EXIT
+xcrun swiftc -swift-version 5 -parse-as-library ${CRA_TEST_SWIFTC_FLAGS:-} \
+ Packages/CraCore/Sources/CraCore/PeekLayout.swift Sources/Cra/UI/Windows/PeekDimPanel.swift \
+ Sources/Cra/UI/Windows/ChromiumChildFocus.swift Tests/PeekDimPanelTests.swift \
+ -o "$TEST_DIR/peek-panel-tests"
+"$TEST_DIR/peek-panel-tests"
+[ -z "${CRA_TEST_KEEP:-}" ] || cp "$TEST_DIR/peek-panel-tests" "$CRA_TEST_KEEP/"
diff --git a/scripts/test.sh b/scripts/test.sh
index dc68f2d..d0c4080 100755
--- a/scripts/test.sh
+++ b/scripts/test.sh
@@ -21,6 +21,7 @@ if [ "${1:-}" != core ]; then
suite "Floating sidebar" scripts/test-floating-sidebar.sh
suite "Extension popup candidate" scripts/test-extension-popup-candidate.sh
suite "Extension popup window" scripts/test-extension-popup-window.sh
+ suite "Peek dismiss panel" scripts/test-peek-dim-panel.sh
suite "Extension state" scripts/test-extension-state.sh
suite "Extension store migration" scripts/test-extension-store-migration.sh
suite "Store and importers" scripts/test-store.sh