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.
Space dock: wide space buttons, hover/press fill, drag to reorder spaces
Victor94c3034b13fe
diff --git a/Sources/Cra/Services/BrowserManager.swift b/Sources/Cra/Services/BrowserManager.swiftindex 16e4277..ecea866 100644--- a/Sources/Cra/Services/BrowserManager.swift+++ b/Sources/Cra/Services/BrowserManager.swift@@ -209,25 +209,16 @@ final class BrowserManager: NSObject, @preconcurrency CraBrowserDelegate {}/// The visible viewport, cropped to the switcher's thumbnail shape from the top.+ /// No `clip`: a clipped screenshot makes Chromium emulate the clip's size and scale on+ /// the live page, which drew the page shrunk into its corner for a few frames, a+ /// second after every tab switch and page load. Without one it copies the frame+ /// already on screen, and the crop and downscale happen here instead.func captureSnapshot(_ id: UUID, completion: (() -> Void)? = nil) {guard let rt = runtimes[id], visibleTabIDs.contains(id) else { completion?(); return }- let b = rt.browser- b.sendDevToolsMethod("Page.getLayoutMetrics", params: "{}") { result, _ in- guard let result, let m = try? JSONSerialization.jsonObject(with: Data(result.utf8)) as? [String: Any],- let vp = m["cssVisualViewport"] as? [String: Any],- let x = vp["pageX"] as? Double, let y = vp["pageY"] as? Double,- let w = vp["clientWidth"] as? Double, let h = vp["clientHeight"] as? Double, w > 0, h > 0 else {- DispatchQueue.main.async { completion?() }- return- }- let thumb = TabSwitcherMetrics.thumbnail- let aspect = Double(thumb.width / thumb.height)- let cw = min(w, h * aspect), ch = cw / aspect- let scale = min(1, Double(thumb.width) * 2 / cw)- let params = #"{"format":"jpeg","quality":80,"clip":{"x":\#(x + (w - cw) / 2),"y":\#(y),"width":\#(cw),"height":\#(ch),"scale":\#(scale)}}"#- b.sendDevToolsMethod("Page.captureScreenshot", params: params) { [weak self] shot, _ in+ rt.browser.sendDevToolsMethod("Page.captureScreenshot", params: #"{"format":"jpeg","quality":80,"optimizeForSpeed":true}"#) { [weak self] shot, _ in+ DispatchQueue.global(qos: .utility).async {let image = shot.flatMap { try? JSONSerialization.jsonObject(with: Data($0.utf8)) as? [String: Any] }- .flatMap { $0["data"] as? String }.flatMap { Data(base64Encoded: $0) }.flatMap(NSImage.init(data:))+ .flatMap { $0["data"] as? String }.flatMap { Data(base64Encoded: $0) }.flatMap(Self.thumbnail(fromViewport:))DispatchQueue.main.async {if let image { self?.runtimes[id]?.snapshot = image }completion?()@@ -236,6 +227,25 @@ final class BrowserManager: NSObject, @preconcurrency CraBrowserDelegate {}}+ /// The top of the viewport at the thumbnail's aspect ratio, centred horizontally,+ /// at most twice the thumbnail's width in pixels.+ nonisolated private static func thumbnail(fromViewport data: Data) -> NSImage? {+ guard let source = CGImageSourceCreateWithData(data as CFData, nil),+ let full = CGImageSourceCreateImageAtIndex(source, 0, nil), full.width > 0, full.height > 0 else { return nil }+ let thumb = TabSwitcherMetrics.thumbnail+ let aspect = thumb.width / thumb.height+ let w = CGFloat(full.width), h = CGFloat(full.height)+ let cw = min(w, h * aspect), ch = cw / aspect+ guard let crop = full.cropping(to: CGRect(x: ((w - cw) / 2).rounded(), y: 0, width: cw.rounded(), height: ch.rounded())) else { return nil }+ let outW = Int(min(cw, thumb.width * 2).rounded()), outH = Int((CGFloat(outW) / aspect).rounded())+ guard outW > 0, outH > 0,+ let ctx = CGContext(data: nil, width: outW, height: outH, bitsPerComponent: 8, bytesPerRow: 0,+ space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue) else { return nil }+ ctx.interpolationQuality = .high+ ctx.draw(crop, in: CGRect(x: 0, y: 0, width: outW, height: outH))+ return ctx.makeImage().map { NSImage(cgImage: $0, size: NSSize(width: outW, height: outH)) }+ }+func browser(_ browser: CraBrowser, didCreateHostWindow window: NSWindow) {delegate?.browserManagerPageWindowsChanged(focus: tabID(of: browser) == visibleTabID)}diff --git a/Sources/Cra/UI/Sidebar/SpaceDock.swift b/Sources/Cra/UI/Sidebar/SpaceDock.swiftindex 757ac7d..5016bde 100644--- a/Sources/Cra/UI/Sidebar/SpaceDock.swift+++ b/Sources/Cra/UI/Sidebar/SpaceDock.swift@@ -7,6 +7,14 @@ struct SpaceDock: View {@Environment(SidebarStore.self) private var store@Environment(SidebarUIState.self) private var ui@Environment(\.sidebarActions) private var actions+ @State private var reorder: SpaceReorder?+ @GestureState private var pressing: UUID?++ /// Arc 1.170 (SidebarDock, an NSCollectionView): 34×32 pt cells side by side with no+ /// gap, so a press anywhere between two icons still lands on a space.+ static let cell = CGSize(width: 34, height: 32)+ /// Marks the strip as draggable content so a press there never moves the window.+ private static let stripID = UUID()var body: some View {HStack(spacing: 0) {@@ -14,40 +22,125 @@ struct SpaceDock: View {Spacer(minLength: 0)// An incognito window has one space of its own: nothing to switch to or add.if !store.window(ui.windowID).isIncognito {- HStack(spacing: 6) {- ForEach(store.orderedSpaces) { space in- SpaceDockButton(space: space, palette: palette, selected: space.id == store.focusedSpaceID(window: ui.windowID))+ let spaces = store.orderedSpaces+ HStack(spacing: 0) {+ ForEach(Array(spaces.enumerated()), id: \.element.id) { index, space in+ SpaceDockButton(space: space, palette: palette,+ selected: space.id == store.focusedSpaceID(window: ui.windowID),+ pressed: reorder?.id == space.id)+ .offset(x: offset(of: space.id, at: index))+ .zIndex(reorder?.id == space.id ? 1 : 0)+ .gesture(press(space, at: index, count: spaces.count))}}+ .coordinateSpace(name: Self.stripID)+ .background(SpaceDockStripAnchor(ui: ui).allowsHitTesting(false))+ .onHover { ui.hoverDraggable(Self.stripID, $0) }+ // A cancelled gesture never reaches onEnded; don't leave a cell pressed.+ .onChange(of: pressing) { _, now in+ guard now == nil else { return }+ DispatchQueue.main.async { if reorder?.settling == false { reorder = nil } }+ }Spacer(minLength: 0)SidebarIconButton(symbol: "plus", palette: palette, help: "New Space") { actions.editSpace(nil) }}}.frame(height: 36)}++ /// The dragged space follows the pointer; the ones it passes slide a cell the other way,+ /// like the gap Arc's collection view opens at the proposed drop index.+ private func offset(of id: UUID, at index: Int) -> CGFloat {+ guard let r = reorder else { return 0 }+ if r.id == id { return r.dx }+ if r.from < index && index <= r.to { return -Self.cell.width }+ if r.to <= index && index < r.from { return Self.cell.width }+ return 0+ }++ /// Arc's dock item handles mouseDown/mouseUp itself: the cell fills on press, a release+ /// switches space, and dragging reorders. A release inside the pressed cell that didn't+ /// move the space still switches, so a shaky click never ends up as a window drag or a no-op.+ private func press(_ space: Space, at index: Int, count: Int) -> some Gesture {+ let cell = CGRect(x: CGFloat(index) * Self.cell.width, y: 0, width: Self.cell.width, height: Self.cell.height)+ return DragGesture(minimumDistance: 0, coordinateSpace: .named(Self.stripID))+ .updating($pressing) { _, state, _ in state = space.id }+ .onChanged { g in+ var r = reorder ?? SpaceReorder(id: space.id, from: index, to: index)+ guard r.id == space.id else { return }+ if !r.moved && abs(g.translation.width) < 3 && abs(g.translation.height) < 3 {+ reorder = r+ return+ }+ r.moved = true+ let w = Self.cell.width+ r.dx = min(max(g.translation.width, -CGFloat(index) * w), CGFloat(count - 1 - index) * w)+ let to = min(max(index + Int((r.dx / w).rounded()), 0), count - 1)+ if to != r.to {+ reorder?.dx = r.dx+ withAnimation(.easeOut(duration: 0.2)) { r.to = to; reorder = r }+ } else {+ reorder = r+ }+ }+ .onEnded { g in+ guard let r = reorder, r.id == space.id, r.to != r.from else {+ if cell.contains(g.location) { store.focusSpace(space.id, window: ui.windowID) }+ if reorder?.id == space.id { withAnimation(.easeOut(duration: 0.15)) { reorder = nil } }+ return+ }+ reorder?.settling = true+ withAnimation(.easeOut(duration: 0.15)) {+ reorder?.dx = CGFloat(r.to - r.from) * Self.cell.width+ } completion: {+ withTransaction(Transaction(animation: nil)) {+ store.moveSpace(r.id, to: r.to)+ reorder = nil+ }+ }+ }+ }+}++private struct SpaceReorder {+ let id: UUID+ let from: Int+ var to: Int+ var dx: CGFloat = 0+ var moved = false+ /// Released; the space is sliding into its new cell.+ var settling = false}struct SpaceDockButton: View {let space: Spacelet palette: SpacePalettelet selected: Bool+ var pressed = false@Environment(SidebarStore.self) private var store@Environment(SidebarUIState.self) private var ui@Environment(\.sidebarActions) private var actions@State private var hover = false@State private var targeted = false+ /// Arc's hovered/pressed cell on a dark space: white at ~7.8% (39,33,51 over 21,14,34), 6 pt corners.+ private var cellFill: Color { palette.isDark ? .white.opacity(0.078) : .black.opacity(0.05) }+var body: some View {Text(space.emoji).font(.system(size: 13))- .frame(width: 26, height: 26)- .opacity(selected || hover ? 1 : 0.45)- .saturation(selected || hover ? 1 : 0.2)- .background(RoundedRectangle(cornerRadius: 7, style: .continuous).fill(targeted ? palette.hoverFill : .clear))+ .frame(width: SpaceDock.cell.width, height: SpaceDock.cell.height)+ .opacity(selected || hover || pressed ? 1 : 0.45)+ .saturation(selected || hover || pressed ? 1 : 0.2)+ .background(RoundedRectangle(cornerRadius: 6).fill(targeted || hover || pressed ? cellFill : .clear)).contentShape(Rectangle()).onHover { hover = $0 }- .onTapGesture { store.focusSpace(space.id, window: ui.windowID) }.arcTooltip(space.title)+ // Arc exposes each cell as a button named after the space.+ .accessibilityElement()+ .accessibilityLabel(space.title)+ .accessibilityAddTraits(.isButton)+ .accessibilityAction { store.focusSpace(space.id, window: ui.windowID) }.dropDestination(for: SidebarDragItem.self) { items, _ inguard let d = items.first else { return false }store.moveTab(d.id, toSpace: space.id)@@ -174,6 +267,17 @@ private struct BinMotion {var opacity: Double = 1}+/// Hands the strip of space cells to the window, which keeps presses there from dragging it.+private struct SpaceDockStripAnchor: NSViewRepresentable {+ let ui: SidebarUIState+ func makeNSView(context: Context) -> NSView {+ let v = NSView()+ ui.spaceDockStrip = v+ return v+ }+ func updateNSView(_ nsView: NSView, context: Context) { ui.spaceDockStrip = nsView }+}+/// Hands the Library button's NSView to the window controller, which aims download/// flights at it (the sidebar can live in the window or in the floating sidebar panel).private struct LibraryAnchor: NSViewRepresentable {diff --git a/Sources/Cra/UI/SidebarUIState.swift b/Sources/Cra/UI/SidebarUIState.swiftindex c2f285c..cd5cffc 100644--- a/Sources/Cra/UI/SidebarUIState.swift+++ b/Sources/Cra/UI/SidebarUIState.swift@@ -30,6 +30,8 @@ final class SidebarUIState {var recentDownload: RecentDownload?/// The Library button's view, where download flights land.@ObservationIgnored weak var libraryAnchor: NSView?+ /// The space dock's strip of space cells; a press there never drags the window.+ @ObservationIgnored weak var spaceDockStrip: NSView?/// Arc's downloads list over the bottom of the sidebar, open while the Library/// button (or the list) is hovered.var downloadsListOpen = falsediff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swiftindex c91c925..b70ec67 100644--- a/Sources/Cra/UI/Windows/MainWindowController.swift+++ b/Sources/Cra/UI/Windows/MainWindowController.swift@@ -112,7 +112,15 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM// AppKit asks the view under a press whether it may move the window. In the// sidebar's list that is SwiftUI's scroll container, which always says yes,// so the window's own flag is what keeps a row press for the row's drag.- sidebarUI.onPointerOverDraggableChange = { [weak window] over in window?.isMovableByWindowBackground = !over }+ sidebarUI.onPointerOverDraggableChange = { [weak window] over in+ guard let window, !window.holdingPress else { return }+ window.isMovableByWindowBackground = !over+ }+ window.holdsPress = { [weak window, weak sidebarUI] point in+ guard let strip = sidebarUI?.spaceDockStrip, strip.window === window else { return false }+ return strip.bounds.contains(strip.convert(point, from: nil))+ }+ window.movableAfterPress = { [weak sidebarUI] in !(sidebarUI?.pointerOverDraggable ?? false) }browsers.paneHost = { [weak self] id in self?.shell.card(for: id)?.webArea }shell.makeToolbar = { [weak self] id inguard let self else { return AnyView(EmptyView()) }@@ -1672,7 +1680,25 @@ final class CraWindow: NSWindow {/// here: a double-click runs the title bar action, anything else drags the window.private static let titleStripHeight = CraMetrics.contentInset + 4+ /// Presses that belong to sidebar controls and must never drag the window (the space+ /// dock). The sidebar's hover flag alone misses a pointer that left a control mid-drag+ /// and jumped back in, so these are checked where the press lands.+ var holdsPress: (NSPoint) -> Bool = { _ in false }+ /// Movable-by-background once a held press ends.+ var movableAfterPress: () -> Bool = { true }+ private(set) var holdingPress = false+override func sendEvent(_ event: NSEvent) {+ if event.type == .leftMouseDown, holdsPress(event.locationInWindow) {+ holdingPress = true+ isMovableByWindowBackground = false+ }+ defer {+ if event.type == .leftMouseUp, holdingPress {+ holdingPress = false+ isMovableByWindowBackground = movableAfterPress()+ }+ }if event.type == .leftMouseDown, !styleMask.contains(.fullScreen),let content = contentView, event.locationInWindow.y >= content.bounds.height - Self.titleStripHeight,isTitleStrip(content.hitTest(content.convert(event.locationInWindow, from: nil))) {diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.mdindex 38e7bec..f2c99f2 100644--- a/docs/arc-reverse-engineering.md+++ b/docs/arc-reverse-engineering.md@@ -1486,3 +1486,29 @@ strings "Opens the tab switcher, where you can cycle through recent tabs like Co- **Cra test (CraTK, pid-targeted keys):** geometry, borders, text and favicon position match Arc's captures to thepixel. Thumbnails come from `Page.captureScreenshot` of the visible viewport (Chromium draws nothing for hiddenpages), taken 1 s after a tab shows or finishes loading and again for the current tab when the switcher opens.++### Space dock: press area, fills and reordering (Arc 1.170, 27 Oct 2026, ObjC metadata + AX tree + captures)++- [O static] `SidebarDock.SidebarDockView` holds an NSCollectionView (`SidebarDockCollectionViewLayout`, with+ `draggingIndexPaths`, `proposedDropIndexPath`, `dropTargets`, `layoutAttributesForInterItemGapBeforeIndexPath:`,+ `layoutAttributesForDropTargetAtPoint:`), so spaces reorder through the collection view's own drag and drop+ with a gap opening at the proposed index. `SidebarDockItemView` overrides `mouseDown:`/`mouseUp:` and has a+ `backgroundLayer`, `_controlState`, `activeIconView`/`inactiveIconView`, a `pageIndicator` and `menuForEvent:`.+ It has no tracking-area methods of its own.+- [O static] "Drag to Reorder Space" ("Tooltip; Drag target to reorder a space.") belongs to `Arc.SpaceControlsView`+ (the space header controls), not to the dock.+- [O AX, 1728×1084 window] each space is an AXButton (role description "Space", title = space name), frame 36×34 on+ a 34 pt pitch inside a 68×32 section for two spaces, so the hit cells (34×32) touch with no gap. The strip is a+ 263×50 scroll area centred between the 32×32 Library button (x 8, 9 pt above the bottom) and the 32×32 "+" button+ (8 pt from the sidebar edge).+- [O capture, Victor's screenshot] pressed cell: 34×32, ~6 pt circular corners, fill 39,33,51 over 21,14,34, i.e. white+ at ~7.8%.+- [U] Arc's hover fill could not be recorded (live pointer runs were cut short while Victor was at the Mac); the pressed+ value is used for hover too, and the light-theme fill (black 5%) is a guess. Arc's drag image follows the pointer+ freely (system drag session); Cra keeps the dragged icon on the dock's row.+- Cra: `SpaceDock` uses 34×32 contiguous cells with one `DragGesture` per cell: fill on hover and press, release inside+ the cell switches space, a horizontal drag reorders (neighbours slide a cell aside, the icon settles, then+ `moveSpace`). `CraWindow.holdsPress` turns movable-by-background off for any press inside the strip until mouse-up,+ because the hover flag (`hoverDraggable`) missed a pointer that left the strip mid-drag and jumped back in. Verified+ on a renamed test bundle: presses, shaky clicks and drags in the strip never move the window; a drag on empty+ sidebar background still does.