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.

Developer bar like Arc's, one-click toolbar after DevTools, steady Extensions popover (#42) (#56)

Victor Kildahl9456c3942b42
diff --git a/Sources/Cra/UI/AppKitControls.swift b/Sources/Cra/UI/AppKitControls.swift
index c07d815..e270384 100644
--- a/Sources/Cra/UI/AppKitControls.swift
+++ b/Sources/Cra/UI/AppKitControls.swift
@@ -61,3 +61,15 @@ final class MaterialCardView: NSVisualEffectView {
}
}
}
+
+extension NSView {
+ /// DevTools (and a page) are Chromium child windows of the main window. After a click in one,
+ /// AppKit treated the next click on the main window as the one that activates it, and a toolbar
+ /// button needed a second click (GitHub #42), even once AppKit itself already had the main window
+ /// key. Chrome draws all of it in one window, so buttons take that click while focus is in this
+ /// window or its children; a click into an inactive Cra still only activates it.
+ var takesClickFromChildWindow: Bool {
+ guard NSApp.isActive, let window, let key = NSApp.keyWindow else { return false }
+ return key === window || key.parent === window
+ }
+}
diff --git a/Sources/Cra/UI/PaneToolbarView.swift b/Sources/Cra/UI/PaneToolbarView.swift
index 378f614..e41b5da 100644
--- a/Sources/Cra/UI/PaneToolbarView.swift
+++ b/Sources/Cra/UI/PaneToolbarView.swift
@@ -39,6 +39,14 @@ final class PaneToolbarView: NSView {
var closeTint = NSColor.secondaryLabelColor
var hairline: NSColor?
var dividerColor = NSColor.clear
+ /// Icon hover fill. White everywhere, as in Arc, where it doesn't show on a white bar either;
+ /// the developer bar is no longer white (GitHub #42).
+ var hover = NSColor.white.withAlphaComponent(0.1)
+ /// Arc's diagonal stripes behind the developer bar.
+ var stripes = false
+ /// The developer address field's selected text.
+ var selection = NSColor.selectedTextBackgroundColor
+ var tabID: UUID?
}
private var model = Model()
@@ -51,6 +59,9 @@ final class PaneToolbarView: NSView {
private let placeholderLabel = NSTextField.sidebarLabel(size: 13)
private let hairline = NSView()
private let devDivider = NSView()
+ private let stripes = DeveloperStripesView()
+ /// Arc lifts the whole developer bar ~9% toward white while its address field is edited.
+ private let editVeil = NSView()
private var press = WindowDragGesture()
init(paneTabID: UUID?, store: SidebarStore, ui: SidebarUIState, actions: SidebarActions) {
@@ -62,9 +73,15 @@ final class PaneToolbarView: NSView {
wantsLayer = true
hairline.wantsLayer = true
devDivider.wantsLayer = true
+ stripes.isHidden = true
+ addSubview(stripes)
placeholderLabel.stringValue = "Search or Enter URL…"
urlButton.action = { [weak self] in self?.editURL() }
- for v in [hairline, devDivider, urlButton, placeholderLabel] as [NSView] {
+ urlButton.onCommit = { [weak self] in self?.actions.loadTyped($0) }
+ urlButton.onEditingChange = { [weak self] in self?.editVeil.isHidden = !$0 }
+ editVeil.wantsLayer = true
+ editVeil.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.09).cgColor
+ for v in [hairline, editVeil, devDivider, urlButton, placeholderLabel] as [NSView] {
v.isHidden = true
addSubview(v)
}
@@ -75,6 +92,11 @@ final class PaneToolbarView: NSView {
override var isFlipped: Bool { true }
+ override func viewDidMoveToSuperview() {
+ super.viewDidMoveToSuperview()
+ (superview as? PaneCardView)?.developerBar = model.kind == .developer ? model.fill : nil
+ }
+
// MARK: Model
private func scheduleSync() {
@@ -109,7 +131,8 @@ final class PaneToolbarView: NSView {
m.sidebarVisible = store.window(ui.windowID).sidebarVisible
if let item, item.isEmptyTab {
m.kind = .emptyPane
- } else if let t = item?.tab {
+ } else if let item, let t = item.tab {
+ m.tabID = item.id
m.kind = !m.inSplit && store.settings.isDeveloperMode(url: t.url) ? .developer : .normal
m.url = t.url
let human = SuggestionEngine.humanURL(t.url)
@@ -143,6 +166,21 @@ final class PaneToolbarView: NSView {
m.placeholder = NSColor(palette.textTertiary)
m.closeTint = m.kind == .emptyPane ? NSColor(palette.textSecondary) : m.fgDim
m.dividerColor = light ? NSColor.black.withAlphaComponent(0.15) : NSColor.white.withAlphaComponent(0.22)
+ if m.kind == .developer {
+ // Arc's developer bar (GitHub #42): the space's colour under faint stripes, whatever the
+ // page's theme-color, with near-white ink (Arc's foregroundPrimary, JYSK 236/237/254),
+ // a white 10% rule along the bottom and a white 8% hover.
+ let theme = store.focusedSpace(window: ui.windowID).theme
+ m.fill = theme.developerBarColor
+ let ink = NSColor.white.blended(withFraction: 0.07, of: m.fill) ?? .white
+ m.fg = ink
+ m.fgDim = ink
+ m.hairline = NSColor.white.withAlphaComponent(0.1)
+ m.dividerColor = theme.developerSecondaryColor.withAlphaComponent(0.45)
+ m.selection = theme.developerSecondaryColor.withAlphaComponent(0.6)
+ m.hover = NSColor.white.withAlphaComponent(0.08)
+ m.stripes = true
+ }
return m
}
@@ -166,7 +204,7 @@ final class PaneToolbarView: NSView {
tint: NSColor? = nil, animated: Bool = false, action: @escaping (PaneToolbarView) -> Void) -> ToolbarGlyphButton {
let b = button(key) { ToolbarGlyphButton() }
b.configure(symbol: symbol, image: nil, help: help, enabled: enabled, width: width, iconSize: iconSize, tint: tint ?? model.fgDim,
- animated: animated)
+ hover: model.hover, animated: animated)
b.action = { [weak self] in if let self { action(self) } }
return b
}
@@ -174,6 +212,9 @@ final class PaneToolbarView: NSView {
private func apply(old: Model) {
let m = model
layer?.backgroundColor = m.fill.cgColor
+ stripes.isHidden = !m.stripes
+ // The card under the bar takes its colour and height (Arc's developer bar is 40 pt, 32 otherwise).
+ (superview as? PaneCardView)?.developerBar = m.kind == .developer ? m.fill : nil
hairline.isHidden = m.hairline == nil
hairline.layer?.backgroundColor = m.hairline?.cgColor
var l: [ToolbarGlyphButton] = []
@@ -201,16 +242,16 @@ final class PaneToolbarView: NSView {
}
case .developer:
if !m.inSplit { l.append(toggle()) }
- r.append(glyph("copy", "link", help: "Copy URL (⇧⌘C)") { $0.actions.performAction("copyURL") })
+ r.append(glyph("copy", "link", help: "Copy URL (⇧⌘C)", width: 28) { $0.actions.performAction("copyURL") })
r.append(devDivider)
- r.append(glyph("devtools", "terminal", help: "Developer Tools (⌥⌘I)") { $0.actions.performAction("devTools") })
+ r.append(glyph("devtools", "terminal", help: "Developer Tools (⌥⌘I)", width: 28) { $0.actions.performAction("devTools") })
}
// Arc's right end of the bar: pinned extensions, the Extensions button, then Split View;
// also on the no-tab bar. A split pane has its options (focused pane only) and close.
if !m.inSplit, m.kind != .emptyPane {
for e in m.pinned {
let b = button("ext:" + e.id) { ToolbarGlyphButton() }
- b.configure(symbol: nil, image: e.icon, help: e.name, enabled: true, width: 34, iconSize: 18, tint: m.fgDim)
+ b.configure(symbol: nil, image: e.icon, help: e.name, enabled: true, width: 34, iconSize: 18, tint: m.fgDim, hover: m.hover)
let id = e.id
b.action = { [weak self] in self?.actions.runExtension(id) }
b.menuProvider = { ExtensionStore.shared.entries.first { $0.extensionID == id }.map(ExtensionsMenu.iconMenu) }
@@ -237,12 +278,16 @@ final class PaneToolbarView: NSView {
left = l
right = r
+ if m.kind != .developer || m.tabID != old.tabID { urlButton.endEditing(commit: false) }
switch m.kind {
case .normal, .developer:
urlButton.isHidden = false
placeholderLabel.isHidden = true
+ // Arc's developer URL has no hover fill (it edits in place on a click).
+ let urlHover = m.kind == .developer ? NSColor.clear : NSColor.white.withAlphaComponent(0.08)
urlButton.show(host: m.host, path: m.path, url: m.url, developer: m.kind == .developer, status: m.status,
- fg: m.fg, fgDim: m.fgDim, animated: old.status?.id != m.status?.id && window != nil)
+ fg: m.fg, fgDim: m.fgDim, hover: urlHover, animated: old.status?.id != m.status?.id && window != nil)
+ urlButton.selection = m.selection
case .noTab, .emptyPane:
urlButton.isHidden = true
placeholderLabel.isHidden = false
@@ -256,10 +301,18 @@ final class PaneToolbarView: NSView {
let h = bounds.height, w = bounds.width
let m = model
hairline.frame = NSRect(x: 0, y: h - 1, width: w, height: 1)
+ stripes.frame = bounds
+ editVeil.frame = bounds
+ // Buttons are 26 pt boxes on the 32 pt bar, 28 pt on the 40 pt developer bar (Arc).
+ let bh: CGFloat = m.kind == .developer ? 28 : 26
+ for b in buttons.values {
+ b.cornerRadius = m.kind == .developer ? 6 : 7
+ b.iconRowHeight = bh
+ }
// Left group: icons edge to edge.
var x: CGFloat = m.kind == .emptyPane ? 1 : (m.inSplit ? 2.5 : 11.5)
for b in left {
- b.frame = NSRect(x: x, y: (h - 26) / 2, width: b.width, height: 26)
+ b.frame = NSRect(x: x, y: (h - bh) / 2, width: b.width, height: bh)
x += b.width
}
let leftEnd = left.isEmpty ? 0 : x
@@ -275,7 +328,7 @@ final class PaneToolbarView: NSView {
for v in trailing.reversed() {
let bw = (v as? ToolbarGlyphButton)?.width ?? 26
rx -= bw
- v.frame = NSRect(x: rx, y: (h - 26) / 2, width: bw, height: 26)
+ v.frame = NSRect(x: rx, y: (h - bh) / 2, width: bw, height: bh)
}
if !devGroup.isEmpty {
if !trailing.isEmpty { rx -= 6 }
@@ -285,8 +338,9 @@ final class PaneToolbarView: NSView {
v.frame = NSRect(x: rx, y: (h - 14) / 2, width: 1, height: 14)
rx -= 5 + 6
} else {
- rx -= 26
- v.frame = NSRect(x: rx, y: (h - 26) / 2, width: 26, height: 26)
+ let bw = (v as? ToolbarGlyphButton)?.width ?? 26
+ rx -= bw
+ v.frame = NSRect(x: rx, y: (h - bh) / 2, width: bw, height: bh)
}
}
}
@@ -324,7 +378,10 @@ final class PaneToolbarView: NSView {
}
}
+ /// Arc: the developer bar edits its full URL in place (ContentPanelTextField, GitHub #42); every
+ /// other bar opens the command bar.
private func editURL() {
+ if model.kind == .developer, !urlButton.isHidden { urlButton.beginEditing(); return }
if let id = paneTabID { actions.editPaneURL(id) } else { actions.openCommandBar(model.kind == .noTab ? .newTab : .editURL) }
}
@@ -349,6 +406,7 @@ final class PaneToolbarView: NSView {
// A click anywhere on the bar edits the URL (a pane's click also focuses it); a drag moves
// the window, as on Arc's toolbar.
override var mouseDownCanMoveWindow: Bool { false }
+ override func acceptsFirstMouse(for event: NSEvent?) -> Bool { takesClickFromChildWindow }
override func mouseDown(with event: NSEvent) { press.begin(event) }
override func mouseDragged(with event: NSEvent) { press.drag(event) }
override func mouseUp(with event: NSEvent) {
@@ -384,6 +442,12 @@ final class ToolbarGlyphButton: NSView {
private var turnsOnPress = false
private var hovering = false { didSet { if hovering != oldValue { refreshFill() } } }
private var shown: (String?, NSImage?, CGFloat, NSColor, Bool)?
+ private var hover = NSColor.white.withAlphaComponent(0.1)
+ private var iconBox: NSSize?
+ var cornerRadius: CGFloat = 7 { didSet { layer?.cornerRadius = cornerRadius } }
+ /// The height an extension icon is centred in, from the bottom (the toolbar sets its button height;
+ /// the sidebar pill keeps the 26 pt it was laid out with).
+ var iconRowHeight: CGFloat = 26 { didSet { needsLayout = true } }
override init(frame: NSRect) {
super.init(frame: frame)
@@ -398,9 +462,10 @@ final class ToolbarGlyphButton: NSView {
/// `animated` swaps another symbol in the way Arc swaps refresh and stop.
func configure(symbol: String?, image: NSImage?, help: String, enabled: Bool, width: CGFloat, iconSize: CGFloat, tint: NSColor,
- animated: Bool = false) {
+ hover: NSColor = .white.withAlphaComponent(0.1), animated: Bool = false) {
self.width = width
self.enabled = enabled
+ self.hover = hover
if shown == nil || shown!.0 != symbol || shown!.1 !== image || shown!.2 != iconSize || shown!.3 != tint || shown!.4 != enabled {
let was = shown?.0
shown = (symbol, image, iconSize, tint, enabled)
@@ -417,9 +482,8 @@ final class ToolbarGlyphButton: NSView {
imageView.contentTintColor = image == nil || image?.isTemplate == true ? tint : nil
}
}
- let iconBox = symbol == nil ? NSSize(width: iconSize, height: iconSize) : nil
- imageView.frame = iconBox.map { NSRect(x: (width - $0.width) / 2, y: (26 - $0.height) / 2, width: $0.width, height: $0.height) }
- ?? NSRect(x: 0, y: 0, width: width, height: 26)
+ iconBox = symbol == nil ? NSSize(width: iconSize, height: iconSize) : nil
+ needsLayout = true
if help.isEmpty {
tip?.removeFromSuperview()
tip = nil
@@ -431,11 +495,22 @@ final class ToolbarGlyphButton: NSView {
refreshFill()
}
+ override func layout() {
+ super.layout()
+ let h = bounds.height
+ imageView.frame = iconBox.map { NSRect(x: (width - $0.width) / 2, y: (iconRowHeight - $0.height) / 2, width: $0.width, height: $0.height) }
+ ?? NSRect(x: 0, y: 0, width: width, height: h)
+ }
+
private func refreshFill() {
- layer?.backgroundColor = (hovering && enabled ? NSColor.white.withAlphaComponent(0.1) : .clear).cgColor
+ layer?.backgroundColor = (hovering && enabled ? hover : .clear).cgColor
}
override var mouseDownCanMoveWindow: Bool { false }
+ override func acceptsFirstMouse(for event: NSEvent?) -> Bool { takesClickFromChildWindow }
+ /// The button takes its clicks itself: AppKit asks the hit view about the first click, and
+ /// that was the glyph's image view.
+ override func hitTest(_ point: NSPoint) -> NSView? { frame.contains(point) ? self : nil }
override func updateTrackingAreas() {
super.updateTrackingAreas()
@@ -462,14 +537,24 @@ final class ToolbarGlyphButton: NSView {
/// The URL in the middle of the bar: link glyph, host bright and path dimmer (the full URL in
/// monospace after a lock in developer mode), or the nav-bar status in its place.
-final class ToolbarURLButton: NSView {
+final class ToolbarURLButton: NSView, NSTextFieldDelegate {
var action: () -> Void = {}
+ /// Developer mode's in-place address field: the text Return submits, and editing starting/ending.
+ var onCommit: (String) -> Void = { _ in }
+ var onEditingChange: (Bool) -> Void = { _ in }
+ var selection = NSColor.selectedTextBackgroundColor
+ private var field: NSTextField?
+ private var savedSelectionAttributes: [NSAttributedString.Key: Any]?
+ private var resignObserver: NSObjectProtocol?
+ private var url = ""
+ private var ink = NSColor.white
private var press = WindowDragGesture()
private let content = NSView()
private let icon = NSImageView()
private let label = NSTextField.sidebarLabel(size: 13)
private let tip: ArcTooltipAnchorView
private var developer = false
+ private var hover = NSColor.white.withAlphaComponent(0.08)
private var hovering = false { didSet { refreshFill() } }
override init(frame: NSRect) {
@@ -492,6 +577,13 @@ final class ToolbarURLButton: NSView {
override var isFlipped: Bool { true }
override var mouseDownCanMoveWindow: Bool { false }
+ override func acceptsFirstMouse(for event: NSEvent?) -> Bool { takesClickFromChildWindow }
+ /// Clicks land on the button, not its label (AppKit asks the hit view about the first click);
+ /// the address field takes its own while editing.
+ override func hitTest(_ point: NSPoint) -> NSView? {
+ guard frame.contains(point) else { return nil }
+ return field == nil ? self : super.hitTest(point)
+ }
/// The text's natural width plus padding; the bar centres and clips the button to it.
var idealWidth: CGFloat {
@@ -501,8 +593,14 @@ final class ToolbarURLButton: NSView {
/// The glyph's own width, as SwiftUI lays an Image out; developer mode boxes it at 14 pt.
private var iconWidth: CGFloat { developer ? 14 : ceil(icon.image?.size.width ?? 12) }
- func show(host: String, path: String, url: String, developer: Bool, status: ToolbarStatus?, fg: NSColor, fgDim: NSColor, animated: Bool) {
+ func show(host: String, path: String, url: String, developer: Bool, status: ToolbarStatus?, fg: NSColor, fgDim: NSColor, hover: NSColor,
+ animated: Bool) {
self.developer = developer
+ self.hover = hover
+ self.url = url
+ ink = fg
+ field?.textColor = fg
+ refreshFill()
tip.text = url
if animated {
// SwiftUI's .transition(.opacity) on the status swap.
@@ -542,10 +640,75 @@ final class ToolbarURLButton: NSView {
let lh = label.intrinsicContentSize.height
let lx = pad + iconW + gap
label.frame = NSRect(x: lx - SidebarText.inset, y: (h - lh) / 2, width: max(0, bounds.width - lx - pad) + 2 * SidebarText.inset, height: lh)
+ field?.frame = label.frame
+ }
+
+ var isEditing: Bool { field != nil }
+
+ /// The full URL becomes editable where it is drawn, all of it selected, in Arc's selection tint.
+ func beginEditing() {
+ guard field == nil, let window else { return }
+ let f = NSTextField(string: url)
+ f.isBordered = false
+ f.drawsBackground = false
+ f.focusRingType = .none
+ f.font = NSFont.monospacedSystemFont(ofSize: 12, weight: .regular)
+ f.textColor = ink
+ f.cell?.isScrollable = true
+ f.cell?.wraps = false
+ f.delegate = self
+ f.frame = label.frame
+ content.addSubview(f)
+ field = f
+ label.isHidden = true
+ tip.isHidden = true
+ window.makeKey()
+ window.makeFirstResponder(f)
+ if let editor = f.currentEditor() as? NSTextView {
+ // The window's field editor is shared: put its selection colours back afterwards.
+ savedSelectionAttributes = editor.selectedTextAttributes
+ editor.selectedTextAttributes = [.backgroundColor: selection, .foregroundColor: ink]
+ editor.insertionPointColor = ink
+ editor.selectAll(nil)
+ }
+ // A click into the page (its own window) ends the edit, like a click elsewhere on the bar.
+ resignObserver = NotificationCenter.default.addObserver(forName: NSWindow.didResignKeyNotification, object: window, queue: .main) { [weak self] _ in
+ MainActor.assumeIsolated { self?.endEditing(commit: false) }
+ }
+ onEditingChange(true)
}
+ /// Return loads what was typed; anything else puts the URL back.
+ func endEditing(commit: Bool) {
+ guard let f = field else { return }
+ field = nil
+ if let resignObserver { NotificationCenter.default.removeObserver(resignObserver) }
+ resignObserver = nil
+ let text = f.stringValue
+ if let editor = f.currentEditor() as? NSTextView, let saved = savedSelectionAttributes { editor.selectedTextAttributes = saved }
+ savedSelectionAttributes = nil
+ if f.currentEditor() != nil { f.window?.makeFirstResponder(nil) }
+ f.removeFromSuperview()
+ label.isHidden = false
+ tip.isHidden = false
+ onEditingChange(false)
+ if commit { onCommit(text) }
+ }
+
+ func control(_ control: NSControl, textView: NSTextView, doCommandBy selector: Selector) -> Bool {
+ switch selector {
+ case #selector(NSResponder.insertNewline(_:)): endEditing(commit: true)
+ // A field editor reads Esc as complete: (word completion), ⌘. as cancelOperation:.
+ case #selector(NSResponder.cancelOperation(_:)), #selector(NSResponder.complete(_:)): endEditing(commit: false)
+ default: return false
+ }
+ return true
+ }
+
+ func controlTextDidEndEditing(_ obj: Notification) { endEditing(commit: false) }
+
private func refreshFill() {
- layer?.backgroundColor = (hovering ? NSColor.white.withAlphaComponent(0.08) : .clear).cgColor
+ layer?.backgroundColor = (hovering ? hover : .clear).cgColor
}
override func updateTrackingAreas() {
@@ -563,3 +726,33 @@ final class ToolbarURLButton: NSView {
if press.finish(), bounds.contains(convert(event.locationInWindow, from: nil)) { action() }
}
}
+
+/// Arc's developer-bar stripes (GitHub #42), measured on Arc 1.170 at 2x: white 2% bands at 45°
+/// running down to the right, 21 pt wide along the bar every 45 pt, the first band starting
+/// 14.5 pt from the bar's left edge at its top.
+final class DeveloperStripesView: NSView {
+ private static let pitch: CGFloat = 45, band: CGFloat = 21, phase: CGFloat = 14.5
+
+ override var isFlipped: Bool { true }
+ override func hitTest(_ point: NSPoint) -> NSView? { nil }
+ override func setFrameSize(_ newSize: NSSize) {
+ super.setFrameSize(newSize)
+ needsDisplay = true
+ }
+
+ override func draw(_ dirtyRect: NSRect) {
+ let h = bounds.height, w = bounds.width
+ let path = NSBezierPath()
+ var x = Self.phase - (floor((Self.phase + h) / Self.pitch) + 1) * Self.pitch
+ while x < w {
+ path.move(to: NSPoint(x: x, y: 0))
+ path.line(to: NSPoint(x: x + Self.band, y: 0))
+ path.line(to: NSPoint(x: x + Self.band + h, y: h))
+ path.line(to: NSPoint(x: x + h, y: h))
+ path.close()
+ x += Self.pitch
+ }
+ NSColor.white.withAlphaComponent(0.02).setFill()
+ path.fill()
+ }
+}
diff --git a/Sources/Cra/UI/ShellView.swift b/Sources/Cra/UI/ShellView.swift
index fdd89a7..2e910ff 100644
--- a/Sources/Cra/UI/ShellView.swift
+++ b/Sources/Cra/UI/ShellView.swift
@@ -280,6 +280,7 @@ final class ShellView: NSView {
card.toolbarColor = toolbarColors[id]
card.transparent = id == ShellView.noTabID
card.showToolbar = showToolbar && !contentFullscreen
+ card.onToolbarHeightChange = { [weak self] in self?.needsLayout = true }
contentContainer.addSubview(card, positioned: .below, relativeTo: placeholderHost)
cards.append(card)
}
@@ -365,9 +366,9 @@ final class ShellView: NSView {
/// Each pane's page area in window coordinates, for the given card frames.
private func paneWebFrames(_ layout: SplitPaneLayout.Result) -> [UUID: NSRect] {
var out: [UUID: NSRect] = [:]
- let th: CGFloat = (showToolbar && !contentFullscreen) ? CraMetrics.toolbarHeight : 0
for c in paneCards where c.tabID != ShellView.noTabID {
guard let f = layout.frames[c.tabID] else { continue }
+ let th: CGFloat = (showToolbar && !contentFullscreen) ? c.toolbarHeight : 0
var web = NSRect(x: f.minX, y: f.minY, width: f.width, height: max(0, f.height - th))
if c.tabID == focusedPaneID, devToolsVisible, !devToolsFrontendDocked, f.width > 640 {
web.size.width -= min(max(320, devToolsWidth), f.width * 0.7)
@@ -550,7 +551,7 @@ final class ShellView: NSView {
// DevTools docks inside the focused card, right of its page.
let focus = focusedCard
let fb = focus?.bounds ?? .zero
- let th: CGFloat = toolbarVisible ? CraMetrics.toolbarHeight : 0
+ let th: CGFloat = toolbarVisible ? focus?.toolbarHeight ?? CraMetrics.toolbarHeight : 0
let bodyH = max(0, fb.height - th)
let selfDock = devToolsFrontendDocked
let showDev = devToolsVisible && hasTab && focus != nil && (selfDock || fb.width > 640)
@@ -622,13 +623,13 @@ final class ShellView: NSView {
func animateSidebar(visible: Bool, floating: Bool, fullscreen: Bool, width: CGFloat, duration: TimeInterval = 0.085) {
let target = frames(sidebarVisible: visible, floating: floating, fullscreen: fullscreen, width: width)
// Size the pages for their destination once, up front; the cards then just slide over them.
- let toolbarH: CGFloat = (showToolbar && !fullscreen) ? CraMetrics.toolbarHeight : 0
let targetLayout = paneLayout(in: NSRect(origin: .zero, size: target.content.size))
var webTargets: [UUID: NSRect] = [:]
for c in paneCards where c.tabID != ShellView.noTabID {
guard let f = targetLayout.frames[c.tabID] else { continue }
var w = f.width
if c.tabID == focusedPaneID, devToolsVisible, !devToolsFrontendDocked, f.width > 640 { w -= min(max(320, devToolsWidth), f.width * 0.7) }
+ let toolbarH: CGFloat = (showToolbar && !fullscreen) ? c.toolbarHeight : 0
c.frozenWebBounds = NSRect(x: 0, y: 0, width: w, height: max(0, f.height - toolbarH))
webTargets[c.tabID] = convert(NSRect(x: target.content.minX + f.minX, y: target.content.minY + f.minY, width: w, height: max(0, f.height - toolbarH)), to: nil)
}
diff --git a/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift b/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift
index d9d7e0d..b548b1d 100644
--- a/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift
+++ b/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift
@@ -294,6 +294,8 @@ final class SidebarGlyphButton: NSView {
}
override var mouseDownCanMoveWindow: Bool { false }
+ override func acceptsFirstMouse(for event: NSEvent?) -> Bool { takesClickFromChildWindow }
+ override func hitTest(_ point: NSPoint) -> NSView? { frame.contains(point) ? self : nil }
override func updateTrackingAreas() {
super.updateTrackingAreas()
diff --git a/Sources/Cra/UI/SidebarUIState.swift b/Sources/Cra/UI/SidebarUIState.swift
index e48cae4..a43f71e 100644
--- a/Sources/Cra/UI/SidebarUIState.swift
+++ b/Sources/Cra/UI/SidebarUIState.swift
@@ -212,6 +212,8 @@ final class SidebarActions {
var runExtension: (String) -> Void = { _ in }
/// Toolbar Extensions button: the extensions menu, under the pointer.
var showExtensionsMenu: () -> Void = {}
+ /// The developer bar's address field: a typed URL or search, in the selected tab.
+ var loadTyped: (String) -> Void = { _ in }
}
private struct SidebarActionsKey: EnvironmentKey {
diff --git a/Sources/Cra/UI/SiteControlCenter.swift b/Sources/Cra/UI/SiteControlCenter.swift
index 371eee1..93650bc 100644
--- a/Sources/Cra/UI/SiteControlCenter.swift
+++ b/Sources/Cra/UI/SiteControlCenter.swift
@@ -536,11 +536,22 @@ final class BlockMenuItem: NSMenuItem {
@MainActor
final class SiteControlCenterPopover: NSObject, NSPopoverDelegate {
private var popover: NSPopover?
+ /// When the mouse-down that closed the popover from outside happened (event time).
+ private var closingClick: TimeInterval?
var isShown: Bool { popover?.isShown == true }
func show(relativeTo rect: NSRect, of view: NSView, url: String, dark: Bool, profile: String, store: SidebarStore, actions: SiteControlCenterActions) {
+ // A transient popover closes on the mouse-down outside it; the button fires on that
+ // click's mouse-up. The same click on the sliders button closes it, as in Arc,
+ // however long the press took (GitHub #42): the latest mouse-down is the closing one.
+ let closedByThisClick = closingClick.map { t in
+ NSApp.currentEvent?.type == .leftMouseUp
+ && abs(ProcessInfo.processInfo.systemUptime - CGEventSource.secondsSinceLastEventType(.combinedSessionState, eventType: .leftMouseDown) - t) < 0.05
+ } ?? false
+ closingClick = nil
if let popover, popover.isShown { popover.performClose(nil); return }
+ if closedByThisClick { return }
let p = NSPopover()
p.behavior = .transient
p.animates = true
@@ -571,5 +582,9 @@ final class SiteControlCenterPopover: NSObject, NSPopoverDelegate {
func close() { popover?.performClose(nil) }
+ func popoverWillClose(_ notification: Notification) {
+ if let e = NSApp.currentEvent, e.type == .leftMouseDown { closingClick = e.timestamp }
+ }
+
func popoverDidClose(_ notification: Notification) { popover = nil }
}
diff --git a/Sources/Cra/UI/SplitView/PaneCardView.swift b/Sources/Cra/UI/SplitView/PaneCardView.swift
index 66c4370..1aed91d 100644
--- a/Sources/Cra/UI/SplitView/PaneCardView.swift
+++ b/Sources/Cra/UI/SplitView/PaneCardView.swift
@@ -21,7 +21,19 @@ final class PaneCardView: NSView {
/// them as a light rim in every rounded corner.
private let pageBackground = NSView()
var showToolbar = true { didSet { needsLayout = true } }
- var toolbarHeight: CGFloat = CraMetrics.toolbarHeight { didSet { needsLayout = true } }
+ var toolbarHeight: CGFloat = CraMetrics.toolbarHeight {
+ didSet { if toolbarHeight != oldValue { needsLayout = true; onToolbarHeightChange?() } }
+ }
+ /// The shell lays the page windows out again when the bar's height changes.
+ var onToolbarHeightChange: (() -> Void)?
+ /// Arc's developer bar (PaneToolbarView): its colour behind the bar, and its 40 pt height.
+ var developerBar: NSColor? {
+ didSet {
+ guard developerBar != oldValue else { return }
+ toolbarHeight = developerBar == nil ? CraMetrics.toolbarHeight : CraMetrics.developerToolbarHeight
+ refreshBackground()
+ }
+ }
var cornerRadius: CGFloat = CraMetrics.contentCornerRadius { didSet { layer?.cornerRadius = cornerRadius; needsLayout = true } }
/// White page card, or Arc's tinted translucent empty pane.
var hasPage = true { didSet { refreshBackground() } }
@@ -94,7 +106,7 @@ final class PaneCardView: NSView {
// Measured on Arc 1.170 (Victor theme, 2x): the empty pane is the
// gradient plus about +9/+11/+12 per channel, i.e. a white veil at ~0.2.
layer?.backgroundColor = transparent || hasPage ? NSColor.clear.cgColor : NSColor(white: 1, alpha: isDark ? 0.08 : 0.2).cgColor
- let bar = toolbarColor.map { NSColor(Color(hex: $0)) } ?? .white
+ let bar = developerBar ?? toolbarColor.map { NSColor(Color(hex: $0)) } ?? .white
toolbarBackground.layer?.backgroundColor = (hasPage && !transparent ? bar : NSColor.clear).cgColor
let page = pageColor.map { NSColor(Color(hex: $0)) } ?? .white
pageBackground.layer?.backgroundColor = (hasPage && !transparent ? page : NSColor.clear).cgColor
diff --git a/Sources/Cra/UI/TabSwitcher/TabSwitcherView.swift b/Sources/Cra/UI/TabSwitcher/TabSwitcherView.swift
index 004f7a1..f69dc83 100644
--- a/Sources/Cra/UI/TabSwitcher/TabSwitcherView.swift
+++ b/Sources/Cra/UI/TabSwitcher/TabSwitcherView.swift
@@ -247,6 +247,36 @@ extension SpaceTheme {
let rgb = OKLab.toRGB(L: L, a: target * cos(hue), b: target * sin(hue))
return Color(.sRGB, red: rgb.r, green: rgb.g, blue: rgb.b, opacity: dark ? 0.48 : 1)
}
+
+ /// Arc's developer-mode toolbar: the space's semantic "focus" colour (dark) over black, opaque.
+ /// Arc 1.170, JYSK, 1 Nov 2026: focus (0.294, 0.329, 1.021) at α 0.8075 → sRGB 61/67/210, the bar
+ /// measured 61/67/210 after undoing the display's P3. Focus sits a little darker than hover at the
+ /// sRGB gamut edge in the theme's hue; fitted on JYSK as OKLab L 0.552 at full chroma. Arc's palette
+ /// hue drifts ~5° from its base colour's, so JYSK lands at 44/72/206 (one space measured so far).
+ var developerBarColor: NSColor {
+ let hex = accent ?? colors.first ?? "#808080"
+ let c = HexColor.components(hex) ?? (0.5, 0.5, 0.5)
+ let lab = OKLab.from(r: c.r, g: c.g, b: c.b)
+ let chroma = (lab.a * lab.a + lab.b * lab.b).squareRoot()
+ let hue = atan2(lab.b, lab.a)
+ let L = 0.552
+ let target = OKLab.maxChroma(L: L, hue: hue) * min(1, chroma / 0.03)
+ let rgb = OKLab.toRGB(L: L, a: target * cos(hue), b: target * sin(hue))
+ let k = 0.8075
+ return NSColor(srgbRed: rgb.r * k, green: rgb.g * k, blue: rgb.b * k, alpha: 1)
+ }
+
+ /// Arc's foregroundSecondary (JYSK 131/137/255, OKLab L 0.68): the developer bar's dividers at 45%,
+ /// its selected text at 60%.
+ var developerSecondaryColor: NSColor {
+ let c = HexColor.components(accent ?? colors.first ?? "#808080") ?? (0.5, 0.5, 0.5)
+ let lab = OKLab.from(r: c.r, g: c.g, b: c.b)
+ let hue = atan2(lab.b, lab.a)
+ let L = 0.68
+ let target = OKLab.maxChroma(L: L, hue: hue) * min(1, (lab.a * lab.a + lab.b * lab.b).squareRoot() / 0.03)
+ let rgb = OKLab.toRGB(L: L, a: target * cos(hue), b: target * sin(hue))
+ return NSColor(srgbRed: rgb.r, green: rgb.g, blue: rgb.b, alpha: 1)
+ }
}
/// Björn Ottosson's OKLab, for colours that keep the same perceived lightness across hues.
diff --git a/Sources/Cra/UI/Theme.swift b/Sources/Cra/UI/Theme.swift
index 91bc6e1..21f9154 100644
--- a/Sources/Cra/UI/Theme.swift
+++ b/Sources/Cra/UI/Theme.swift
@@ -495,6 +495,8 @@ enum CraMetrics {
static let contentInset: CGFloat = 10
static let contentCornerRadius: CGFloat = 6
static let toolbarHeight: CGFloat = 32
+ /// Arc's developer-mode bar is taller (Arc 1.170 at 2x: 80 px against 64).
+ static let developerToolbarHeight: CGFloat = 40
/// Traffic lights, sidebar toggle and nav buttons share this centre line.
static let titleRowCenter: CGFloat = 24
static let titleAreaHeight: CGFloat = 44
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index e704962..06125ca 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -216,6 +216,12 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
guard let self else { return }
self.store.createTab(url: url, window: self.windowID)
}
+ sidebarActions.loadTyped = { [weak self] typed in
+ guard let self else { return }
+ let t = typed.trimmingCharacters(in: .whitespacesAndNewlines)
+ guard !t.isEmpty else { return }
+ self.loadInSelectedTab(SuggestionEngine.looksLikeURL(t) ? SuggestionEngine.urlFromInput(t) : self.store.settings.searchEngine.searchURL(t))
+ }
sidebarActions.focusPane = { [weak self] id in
guard let self, self.selectedTabID != id else { return }
self.store.selectTab(id, window: windowID)
@@ -1619,7 +1625,8 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
let card = shell.focusedCard.map { shell.contentContainer.convert($0.frame, to: nil) }
?? shell.convert(shell.contentContainer.frame, to: nil)
let onScreen = window.convertToScreen(card)
- return (onScreen.maxY - (store.settings.showToolbar ? CraMetrics.toolbarHeight : 0), onScreen.maxX)
+ let bar = shell.focusedCard?.toolbarHeight ?? CraMetrics.toolbarHeight
+ return (onScreen.maxY - (store.settings.showToolbar ? bar : 0), onScreen.maxX)
}
/// Where a popup from a URL-bar button hangs: under the toolbar, or, with the toolbar
@@ -1670,15 +1677,18 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
/// toolbar or the sidebar's URL pill (also in the floating sidebar's panel), so a popup
/// hangs from the same place wherever the button was clicked (GitHub #8).
private static func extensionButtonRightX() -> CGFloat {
+ buttonFrameUnderPointer { $0 is ToolbarGlyphButton }?.maxX ?? NSEvent.mouseLocation.x + 17
+ }
+
+ /// The button under the pointer (screen rect): the one just clicked.
+ private static func buttonFrameUnderPointer(_ isButton: (NSView) -> Bool) -> NSRect? {
let mouse = NSEvent.mouseLocation
let number = NSWindow.windowNumber(at: mouse, belowWindowWithWindowNumber: 0)
- if let w = NSApp.window(withWindowNumber: number), let content = w.contentView {
- let p = w.convertPoint(fromScreen: mouse)
- var v = content.hitTest(content.superview?.convert(p, from: nil) ?? p)
- while let view = v, !(view is ToolbarGlyphButton) { v = view.superview }
- if let button = v { return w.convertToScreen(button.convert(button.bounds, to: nil)).maxX }
- }
- return mouse.x + 17
+ guard let w = NSApp.window(withWindowNumber: number), let content = w.contentView else { return nil }
+ let p = w.convertPoint(fromScreen: mouse)
+ var v = content.hitTest(content.superview?.convert(p, from: nil) ?? p)
+ while let view = v, !isButton(view) { v = view.superview }
+ return v.map { w.convertToScreen($0.convert($0.bounds, to: nil)) }
}
/// No page for Chrome's popup to attach to (no tab open, no DevTools pipe, a page it
@@ -1710,13 +1720,13 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
}
/// Arc's sliders button (toolbar and URL pill): the Site Control Center, hung under the
- /// button the pointer is on (buttons are 32 × 28).
+ /// button that was clicked (buttons are 32 × 28), not wherever the pointer is in it.
private func showToolbarExtensionsMenu() {
guard let window, let content = window.contentView, let y = urlBarBottomOnScreen() else { return }
ExtensionStore.shared.reload()
- let mouse = NSEvent.mouseLocation
+ let midX = Self.buttonFrameUnderPointer { $0 is ToolbarGlyphButton || $0 is SidebarGlyphButton }?.midX ?? NSEvent.mouseLocation.x
// Arc's popover overlaps the bar by 4 pt (popover top 71 under a bar ending at 75).
- let onScreen = NSRect(x: mouse.x - 16, y: y + 4, width: 32, height: 28)
+ let onScreen = NSRect(x: midX - 16, y: y + 4, width: 32, height: 28)
let rect = content.convert(window.convertFromScreen(onScreen), from: nil)
let url = selectedTabID.flatMap { store.item($0)?.tab?.url } ?? ""
var actions = SiteControlCenterActions()
diff --git a/Sources/CraCEF/CraCEF.mm b/Sources/CraCEF/CraCEF.mm
index 800ea4a..2a8a2fe 100644
--- a/Sources/CraCEF/CraCEF.mm
+++ b/Sources/CraCEF/CraCEF.mm
@@ -707,7 +707,12 @@ public:
return true;
}
void OnLoadStart(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, TransitionType transition_type) override {
- if (frame->IsMain()) CraDevToolsLog(@"OnLoadStart %s", frame->GetURL().ToString().c_str());
+ if (!frame->IsMain()) return;
+ CraDevToolsLog(@"OnLoadStart %s", frame->GetURL().ToString().c_str());
+ // Chrome picks the frontend URL (OnBeforeBrowse never sees it), so the earliest
+ // point to swap in can_dock=true is the first load's start: the frontend app then
+ // loads once instead of twice (GitHub #42).
+ if (host_) MakeDockable(browser, frame);
}
void OnLoadEnd(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int httpStatusCode) override {
if (!frame->IsMain()) return;
@@ -715,21 +720,31 @@ public:
if (host_) Prepare(browser, frame);
}
- // Docked mode: make a Chrome-style frontend dockable (one reload), then hook it.
+ static bool IsFrontend(const std::string& url) {
+ // Only the main frontend; helper pages it opens (device_mode_emulation_frame.html
+ // when undocked) must not report dock state or page bounds.
+ return url.rfind("devtools://", 0) == 0
+ && (url.find("/devtools_app.html") != std::string::npos || url.find("/inspector.html") != std::string::npos);
+ }
+
+ // A Chrome-style frontend opens undockable; load it again with can_dock=true (once).
+ bool MakeDockable(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame) {
+ std::string url = frame->GetURL().ToString();
+ if (reloaded_ || !IsFrontend(url) || !browser->GetHost()->HasView() || url.find("can_dock=") != std::string::npos) return false;
+ reloaded_ = true;
+ std::string docked = url + (url.find('?') == std::string::npos ? "?" : "&") + "can_dock=true";
+ CraDevToolsLog(@"reloading as dockable: %s", docked.c_str());
+ frame->LoadURL(docked);
+ return true;
+ }
+
+ // Docked mode: make a Chrome-style frontend dockable, then hook it.
// Alloy frontends (can_dock=false, no close button) only get the close button.
void Prepare(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame) {
std::string url = frame->GetURL().ToString();
- if (url.rfind("devtools://", 0) != 0) return;
- // Only the main frontend; helper pages it opens (device_mode_emulation_frame.html
- // when undocked) must not report dock state or page bounds.
- if (url.find("/devtools_app.html") == std::string::npos && url.find("/inspector.html") == std::string::npos) return;
- if (browser->GetHost()->HasView() && url.find("can_dock=") == std::string::npos && !reloaded_) {
- reloaded_ = true;
- std::string docked = url + (url.find('?') == std::string::npos ? "?" : "&") + "can_dock=true";
- CraDevToolsLog(@"reloading as dockable: %s", docked.c_str());
- frame->LoadURL(docked);
- return;
- }
+ if (!IsFrontend(url) || MakeDockable(browser, frame)) return;
+ // The undockable load that MakeDockable replaced still reports its end.
+ if (reloaded_ && url.find("can_dock=") == std::string::npos) return;
frame->ExecuteJavaScript(kCraDevToolsHooks, frame->GetURL(), 0);
}
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index ea7a819..6701be8 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -1774,3 +1774,34 @@ Theme palettes in a hand-built space can be borrowed; only the `background` styl
rest (17.5 / 13 / 9 pt with 12 / 16 / 22 spaces); icon-less spaces are dots, small when squeezed. Cra
(`SpaceDockView.cellWidths`) follows the widths and shrinks emoji in narrow cells; it has no icon-less spaces
yet (imported ones get 🗂️).
+
+## Developer bar (Arc 1.170, 1 Nov 2026, issue #42, live window captures at 2x)
+
+Arc's toolbar module ContentPanel carries `ContentPanelTextField`/`ContentPanelTextView` (the in-place
+address field) and `Stripes`/`StripesConfig` (drawn in code; `StripeIcon` in Assets.car is the payment
+company's logo). Measured on example.com (a developer host) in the JYSK space, captures in Display P3,
+converted to sRGB where noted:
+
+- Height 40 pt (80 px) against 32 for the normal bar; a 1 pt rule along the bottom, white ~10% over the fill.
+- Fill: not the page's theme-color. JYSK's bar is P3 62/67/202 = sRGB 61/67/210, which is Arc's semantic
+ dark `focus` colour (0.294, 0.329, 1.021, α 0.8075, from StorableSidebar.json) over black. Cra derives
+ it from the accent (SpaceTheme.developerBarColor: OKLab L 0.552 at the sRGB chroma edge × 0.8075) and
+ lands at 44/72/206 for JYSK: Arc's palette hues drift from the base colour's (+5.6° for JYSK, +1.6° for
+ Victor), so one more space would be needed to model that.
+- Stripes: white ~2% bands at 45° running down to the right, 21 pt wide along the bar every 45 pt; at the
+ bar's top the first band starts 14.5 pt from its left edge.
+- Ink: icons and the lock P3 236/237/254 (Arc's foregroundPrimary), URL text the same antialiased.
+ Dividers P3 93/99/230 = foregroundSecondary (131/137/255) at ~45%.
+- Icon hover: a 28 × 28 pt rounded rect (radius ~5–6 pt), centred in the bar, white 8%. The URL has no hover.
+- Click on the URL: the full URL becomes editable in place (same monospaced text), all of it selected;
+ selection P3 111/117/251 (foregroundSecondary at ~60%), text 226/227/254, and the whole bar lifts by a
+ white ~9% veil while editing. One Esc left it editing (it may only revert the text); Cra ends the edit.
+- Arc's developer bar also has buttons Cra doesn't: Capture, Screenshot | DevTools, Network, Inspect |
+ extensions … Split View, with dividers between the groups.
+
+DevTools in Cra: Chrome picks the frontend URL (DevToolsClient::OnBeforeBrowse never sees the first
+navigation), so the dockable `can_dock=true` load now replaces it at the first OnLoadStart instead of
+after OnLoadEnd: open → page bounds 185–200 ms instead of 265–290 ms. A click inside DevTools makes its
+child window key; AppKit then spent the next toolbar click on making the main window key, so toolbar
+buttons accept first mouse while a child window is key. Clicks after the page had focus were not affected
+(real HID test).