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.
Arc's sidebar toggle placement and command bar glyph (#50) (#65)
Victor Kildahl7a9774c1d183
diff --git a/Sources/Cra/UI/CommandBar/CommandBarController.swift b/Sources/Cra/UI/CommandBar/CommandBarController.swiftindex 4319e7b..5d11a42 100644--- a/Sources/Cra/UI/CommandBar/CommandBarController.swift+++ b/Sources/Cra/UI/CommandBar/CommandBarController.swift@@ -33,7 +33,8 @@ final class CommandBarController {private(set) var scope: CommandBarScope?/// What was typed when Tab entered the scope; Backspace puts it back.private var scopeTyped = ""- private var openedPrefill: String?+ /// The URL ⌘L opened with (the page's), nil for ⌘T.+ private(set) var openedPrefill: String?unowned let engine: SuggestionEngineunowned let store: SidebarStorediff --git a/Sources/Cra/UI/CommandBar/CommandBarGlyph.swift b/Sources/Cra/UI/CommandBar/CommandBarGlyph.swiftnew file mode 100644index 0000000..8ea771f--- /dev/null+++ b/Sources/Cra/UI/CommandBar/CommandBarGlyph.swift@@ -0,0 +1,24 @@+/// The glyph before the command bar's text (Arc 1.171, GitHub #50): the highlighted row's icon,+/// so it says what Return does: a site's favicon, a globe for a URL without one, a magnifier+/// for a search. Before anything is typed, ⌘L shows the page's favicon and ⌘T a magnifier.+enum CommandBarGlyph: Equatable {+ case favicon(String)+ case symbol(String)++ /// `untouched`: the field is empty, or still holds the URL ⌘L opened with, and no row is+ /// arrowed to. `row` is the highlighted row (the arrowed one, else the top one).+ static func resolve(editingURL: Bool, untouched: Bool, scoped: Bool, pageFaviconKey: String?,+ row: (faviconKey: String?, symbol: String?)?, hasFavicon: (String) -> Bool) -> CommandBarGlyph {+ // Scoped to a site or to the open tabs (a pill before the field): a search.+ if scoped { return .symbol("magnifyingglass") }+ if untouched {+ guard editingURL else { return .symbol("magnifyingglass") }+ if let key = pageFaviconKey, hasFavicon(key) { return .favicon(key) }+ return .symbol("globe")+ }+ guard let row else { return .symbol("magnifyingglass") }+ if let key = row.faviconKey, hasFavicon(key) { return .favicon(key) }+ // A row without a favicon draws its symbol, a globe when it has none (CommandBarRowView).+ return .symbol(row.symbol ?? "globe")+ }+}diff --git a/Sources/Cra/UI/CommandBar/CommandBarView.swift b/Sources/Cra/UI/CommandBar/CommandBarView.swiftindex 105fe4e..9eb0e3e 100644--- a/Sources/Cra/UI/CommandBar/CommandBarView.swift+++ b/Sources/Cra/UI/CommandBar/CommandBarView.swift@@ -128,11 +128,15 @@ final class CommandBarView: NSView {keycap.layer?.backgroundColor = NSColor.labelColor.withAlphaComponent(0.04).cgColor}- // Follows the row the arrows moved to; otherwise the completing top match.+ // Follows the row the arrows moved to; otherwise the top one.let previewing = c.previewText != nil && items.indices.contains(c.selectedIndex)let row = previewing ? items[c.selectedIndex] : items.first- if scope == nil, let s = row, let key = s.faviconKey, s.id != "typed", let img = favicons.image(forKey: key),- previewing || c.result.inlineCompletion != nil || c.mode == .editURL {+ let typed = c.query.trimmingCharacters(in: .whitespaces)+ let glyph = CommandBarGlyph.resolve(+ editingURL: c.mode == .editURL, untouched: !previewing && (typed.isEmpty || typed == c.openedPrefill),+ scoped: scope != nil, pageFaviconKey: c.openedPrefill.flatMap(FaviconCache.key(for:)),+ row: row.map { ($0.faviconKey, $0.symbol) }, hasFavicon: { [favicons] in favicons.image(forKey: $0) != nil })+ if case .favicon(let key) = glyph, let img = favicons.image(forKey: key) {leadingIcon.imageScaling = .scaleProportionallyUpOrDownleadingIcon.image = imgleadingIcon.contentTintColor = nil@@ -141,7 +145,7 @@ final class CommandBarView: NSView {leadingIcon.frame.size = NSSize(width: 20, height: 20)} else {leadingIcon.imageScaling = .scaleNone- leadingIcon.image = SidebarSymbols.image(c.mode == .editURL ? "info.circle" : "magnifyingglass", size: 17, weight: .medium)+ if case .symbol(let name) = glyph { leadingIcon.image = SidebarSymbols.image(name, size: 17, weight: .medium) }leadingIcon.contentTintColor = .secondaryLabelColorleadingIcon.layer?.masksToBounds = falseleadingIcon.frame.size = NSSize(width: 22, height: 22)diff --git a/Sources/Cra/UI/PaneToolbarView.swift b/Sources/Cra/UI/PaneToolbarView.swiftindex 47b00b2..f3743ce 100644--- a/Sources/Cra/UI/PaneToolbarView.swift+++ b/Sources/Cra/UI/PaneToolbarView.swift@@ -217,9 +217,9 @@ final class PaneToolbarView: NSView {(superview as? PaneCardView)?.developerBar = m.kind == .developer ? m.fill : nilhairline.isHidden = m.hairline == nilhairline.layer?.backgroundColor = m.hairline?.cgColor- let bar = ToolbarComposition(kind: m.kind, inSplit: m.inSplit, focusedPane: m.focusedPane, canGoBack: m.canGoBack,- canGoForward: m.canGoForward, isLoading: m.isLoading, pinnedExtensions: m.pinned.map(\.id),- hasExtensions: m.hasExtensions)+ let bar = ToolbarComposition(kind: m.kind, inSplit: m.inSplit, sidebarVisible: m.sidebarVisible, focusedPane: m.focusedPane,+ canGoBack: m.canGoBack, canGoForward: m.canGoForward, isLoading: m.isLoading,+ pinnedExtensions: m.pinned.map(\.id), hasExtensions: m.hasExtensions)// The no-tab bar and an empty pane show navigation that does nothing (Arc greys it out).let wide = m.kind == .noTab || m.kind == .emptyPanefunc view(_ item: ToolbarComposition.Item) -> NSView {@@ -303,8 +303,8 @@ final class PaneToolbarView: NSView {b.cornerRadius = m.kind == .developer ? 6 : 7b.iconRowHeight = bh}- // Left group: icons edge to edge.- var x: CGFloat = m.kind == .emptyPane ? 1 : (m.inSplit ? 2.5 : 11.5)+ // Left group: icons edge to edge, the first (toggle or ←) centred 21 pt from the card edge (Arc 1.171).+ var x: CGFloat = m.kind == .emptyPane ? 1 : 2.5for b in left {b.frame = NSRect(x: x, y: (h - bh) / 2, width: b.width, height: bh)x += b.widthdiff --git a/Sources/Cra/UI/Sidebar/List/SidebarView.swift b/Sources/Cra/UI/Sidebar/List/SidebarView.swiftindex c4ed191..d75b614 100644--- a/Sources/Cra/UI/Sidebar/List/SidebarView.swift+++ b/Sources/Cra/UI/Sidebar/List/SidebarView.swift@@ -190,6 +190,7 @@ final class SidebarTopBarView: NSView {private var colors = SidebarColors()private var compact = falseprivate var devNav = false+ private var fullscreen = falseprivate var buttons: [String: SidebarGlyphButton] = [:]private var rowButtons: [SidebarGlyphButton] = []private var chevron: NSView?@@ -213,6 +214,12 @@ final class SidebarTopBarView: NSView {override var isFlipped: Bool { true }+ // The floating panel and the window place the toggle differently in fullscreen.+ override func viewDidMoveToWindow() {+ super.viewDidMoveToWindow()+ needsLayout = true+ }+private func sync() {syncQueued = falsewithObservationTracking { apply() } onChange: { [weak self] in@@ -249,10 +256,12 @@ final class SidebarTopBarView: NSView {devNav = !compact && (tab?.tab.map { store.settings.isDeveloperMode(url: $0.url) } ?? false)let active = ui.appActivelet reloadSymbol = ui.isLoading ? "xmark" : "arrow.clockwise"- var shown: [SidebarGlyphButton] = []+ fullscreen = ui.windowFullscreen+ // Arc 1.171: the header always carries the sidebar toggle; the toolbar has one only while the+ // sidebar is hidden (PaneToolbarView), so a floating sidebar shows both.+ let help = store.window(ui.windowID).sidebarVisible ? "Hide Sidebar (⌘S)" : "Show Sidebar (⌘S)"+ var shown = [button("toggle", symbol: "sidebar.left", help: help, size: 32, height: 32, iconSize: 15.5, active: active) { [weak self] in self?.actions.toggleSidebar() }]if compact {- // The toolbar carries the sidebar toggle; this one only stands in while the toolbar is hidden.- shown.append(button("toggle", symbol: "sidebar.left", help: "Hide Sidebar (⌘S)", size: 32, height: 32, iconSize: 15.5, active: active) { [weak self] in self?.actions.toggleSidebar() })shown.append(button("back", symbol: "arrow.left", help: "Go Back (⌘[)", size: 32, height: 32, iconSize: 15, active: active, enabled: ui.canGoBack) { [weak self] in self?.actions.goBack() })shown.append(button("forward", symbol: "arrow.right", help: "Go Forward (⌘])", size: 32, height: 32, iconSize: 15, active: active, enabled: ui.canGoForward) { [weak self] in self?.actions.goForward() })shown.append(button("reload", symbol: reloadSymbol, help: "Refresh (⌘R)", size: 32, height: 32, iconSize: 15, active: active, animated: true) { [weak self] in self?.actions.reload() })@@ -294,10 +303,13 @@ final class SidebarTopBarView: NSView {override func layout() {super.layout()let w = bounds.width+ // Row 1: 71 pt for the traffic lights, then the toggle. In fullscreen the lights are gone and+ // Arc draws it from 20 pt in (glyph 20–38.5 pt); the floating panel draws stand-in lights.+ let lights = !fullscreen || window?.parent != nil+ if let t = rowButtons.first { t.frame = NSRect(x: lights ? 6 + 71 + 2 : 13, y: CraMetrics.titleRowCenter - 17, width: 32, height: 32) }if compact {- // Row 1: 71 pt for the traffic lights, the toggle, then ← → ↻ 2 pt apart, 6 pt from the edge.+ // ← → ↻ 2 pt apart, 6 pt from the edge.let y = CraMetrics.titleRowCenter - 17- if let t = rowButtons.first { t.frame = NSRect(x: 6 + 71 + 2, y: y, width: 32, height: 32) }var x = w - 6for b in rowButtons.dropFirst().reversed() {x -= 32@@ -312,7 +324,7 @@ final class SidebarTopBarView: NSView {x -= 12c.frame = NSRect(x: x, y: y, width: 12, height: 28)}- for b in rowButtons.reversed() {+ for b in rowButtons.dropFirst().reversed() {x -= b.size.widthb.frame = NSRect(x: x, y: y + (28 - b.size.height) / 2, width: b.size.width, height: b.size.height)}diff --git a/Sources/Cra/UI/SidebarUIState.swift b/Sources/Cra/UI/SidebarUIState.swiftindex ff3d3cf..04e38ef 100644--- a/Sources/Cra/UI/SidebarUIState.swift+++ b/Sources/Cra/UI/SidebarUIState.swift@@ -28,6 +28,8 @@ final class SidebarUIState {var canGoForward = falsevar isLoading = falsevar isCompact = false+ /// The window is in macOS fullscreen (no traffic lights), not a page's element fullscreen.+ var windowFullscreen = false/// Cra is the frontmost app (Arc darkens the sidebar header's glyphs then).var appActive = true/// Page theme colour of the visible tab ("#RRGGBB" or "").diff --git a/Sources/Cra/UI/ToolbarComposition.swift b/Sources/Cra/UI/ToolbarComposition.swiftindex 56247ff..c50a8a5 100644--- a/Sources/Cra/UI/ToolbarComposition.swift+++ b/Sources/Cra/UI/ToolbarComposition.swift@@ -4,7 +4,8 @@ import Foundation/// and places the views. Measured against Arc 1.170: the full bar is sidebar toggle ← → ↻ on/// the left and pinned extensions, Extensions, Split View on the right; a split pane has only/// ← → and its options (focused pane) and close; the developer bar swaps the navigation for-/// copy · divider · DevTools.+/// copy · divider · DevTools. The toggle is there only while the sidebar is hidden or floating:+/// otherwise the sidebar's header carries it (Arc 1.171, GitHub #50).struct ToolbarComposition: Equatable {enum Kind: Equatable { case noTab, emptyPane, normal, developer }@@ -27,20 +28,20 @@ struct ToolbarComposition: Equatable {var left: [Item] = []var right: [Item] = []- init(kind: Kind, inSplit: Bool, focusedPane: Bool, canGoBack: Bool, canGoForward: Bool, isLoading: Bool,+ init(kind: Kind, inSplit: Bool, sidebarVisible: Bool, focusedPane: Bool, canGoBack: Bool, canGoForward: Bool, isLoading: Bool,pinnedExtensions: [String], hasExtensions: Bool) {+ // Never in a split pane (Arc 1.170: only ← → in a pane) or an empty one.+ if !inSplit, !sidebarVisible, kind != .emptyPane { left.append(.toggleSidebar) }switch kind {case .noTab:- left = [.toggleSidebar, .back(enabled: false), .forward(enabled: false), .reload(loading: false, enabled: false)]+ left += [.back(enabled: false), .forward(enabled: false), .reload(loading: false, enabled: false)]case .emptyPane:left = [.back(enabled: false), .forward(enabled: false)]case .normal:- // Split panes drop the toggle and refresh (Arc 1.170: only ← → in a pane).- if !inSplit { left.append(.toggleSidebar) }+ // Split panes drop refresh too.left += [.back(enabled: canGoBack), .forward(enabled: canGoForward)]if !inSplit { left.append(.reload(loading: isLoading, enabled: true)) }case .developer:- if !inSplit { left.append(.toggleSidebar) }right += [.copyURL, .divider, .devTools]}// Arc's right end: pinned extensions, the Extensions button, then Split View; also ondiff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swiftindex f6bc4aa..7429e70 100644--- a/Sources/Cra/UI/Windows/MainWindowController.swift+++ b/Sources/Cra/UI/Windows/MainWindowController.swift@@ -2138,6 +2138,9 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMcommandBar.close()}+ // The sidebar header's toggle moves into the traffic lights' place while they are gone (Arc).+ func windowWillEnterFullScreen(_ notification: Notification) { sidebarUI.windowFullscreen = true }+ func windowWillExitFullScreen(_ notification: Notification) { sidebarUI.windowFullscreen = false }func windowDidEnterFullScreen(_ notification: Notification) { shell.needsLayout = true }func windowDidExitFullScreen(_ notification: Notification) {// Left with the green button or ⌃⌘F while a video was fullscreen: the page leaves too.diff --git a/Tests/CommandBarGlyphTests.swift b/Tests/CommandBarGlyphTests.swiftnew file mode 100644index 0000000..955fde7--- /dev/null+++ b/Tests/CommandBarGlyphTests.swift@@ -0,0 +1,43 @@+import Foundation++/// The command bar's leading glyph against what Arc 1.171 showed (GitHub #50).+@main+enum CommandBarGlyphTests {+ private static var checks = 0++ static func main() {+ let cached: Set<String> = ["github.com", "youtube.com", "x.com"]+ func glyph(editingURL: Bool = false, untouched: Bool = false, site: Bool = false, page: String? = nil,+ row: (String?, String?)?) -> CommandBarGlyph {+ CommandBarGlyph.resolve(editingURL: editingURL, untouched: untouched, scoped: site, pageFaviconKey: page,+ row: row.map { (faviconKey: $0.0, symbol: $0.1) }, hasFavicon: cached.contains)+ }+ let recentTab = ("github.com", nil as String?)++ // Nothing typed: ⌘L shows the page's favicon (a globe without one), ⌘T a magnifier.+ expect(glyph(editingURL: true, untouched: true, page: "github.com", row: recentTab) == .favicon("github.com"), "⌘L, page favicon")+ expect(glyph(editingURL: true, untouched: true, page: "example.com", row: recentTab) == .symbol("globe"), "⌘L, page without favicon")+ expect(glyph(untouched: true, row: recentTab) == .symbol("magnifyingglass"), "⌘T, empty")++ // Typed: the highlighted row's icon, in both modes.+ for editing in [false, true] {+ expect(glyph(editingURL: editing, row: (nil, "magnifyingglass")) == .symbol("magnifyingglass"), "hello world → search row")+ expect(glyph(editingURL: editing, row: ("example.org", "globe")) == .symbol("globe"), "example.org → URL row, no favicon")+ expect(glyph(editingURL: editing, row: ("youtube.com", "globe")) == .favicon("youtube.com"), "youtube.com → URL row's favicon")+ expect(glyph(editingURL: editing, row: ("x.com", nil)) == .favicon("x.com"), "x.com → completing tab")+ expect(glyph(editingURL: editing, row: ("jira.example", nil)) == .symbol("globe"), "tab row without a cached favicon")+ }+ expect(glyph(site: true, row: ("youtube.com", nil)) == .symbol("magnifyingglass"), "site search or the tabs scope")+ expect(glyph(row: nil) == .symbol("magnifyingglass"), "no rows")++ print("CommandBarGlyph: \(checks) checks passed")+ }++ private static func expect(_ ok: Bool, _ what: String) {+ checks += 1+ if !ok {+ print("FAIL: \(what)")+ exit(1)+ }+ }+}diff --git a/Tests/PolicyTests.swift b/Tests/PolicyTests.swiftindex 9fc69af..972d8f0 100644--- a/Tests/PolicyTests.swift+++ b/Tests/PolicyTests.swift@@ -17,10 +17,10 @@ enum PolicyTests {private static func toolbar() {typealias T = ToolbarComposition- func bar(_ kind: T.Kind, split: Bool = false, focused: Bool = true, back: Bool = false, forward: Bool = false,- loading: Bool = false, pinned: [String] = [], extensions: Bool = false) -> T {- T(kind: kind, inSplit: split, focusedPane: focused, canGoBack: back, canGoForward: forward, isLoading: loading,- pinnedExtensions: pinned, hasExtensions: extensions)+ func bar(_ kind: T.Kind, split: Bool = false, sidebar: Bool = false, focused: Bool = true, back: Bool = false,+ forward: Bool = false, loading: Bool = false, pinned: [String] = [], extensions: Bool = false) -> T {+ T(kind: kind, inSplit: split, sidebarVisible: sidebar, focusedPane: focused, canGoBack: back, canGoForward: forward,+ isLoading: loading, pinnedExtensions: pinned, hasExtensions: extensions)}let full = bar(.normal, back: true, loading: true, pinned: ["a", "b"], extensions: true)expect(full.left == [.toggleSidebar, .back(enabled: true), .forward(enabled: false), .reload(loading: true, enabled: true)],@@ -28,6 +28,9 @@ enum PolicyTests {expect(full.right == [.pinnedExtension("a"), .pinnedExtension("b"), .extensions, .addSplit],"the right end: pinned extensions, Extensions, Split View")expect(bar(.normal).right == [.addSplit], "no Extensions button without extensions")+ expect(bar(.normal, sidebar: true).left == [.back(enabled: false), .forward(enabled: false), .reload(loading: false, enabled: true)]+ && bar(.noTab, sidebar: true).left.first == .back(enabled: false) && bar(.developer, sidebar: true).left.isEmpty,+ "the sidebar shown: its header carries the toggle, the bar has none (Arc 1.171, #50)")let pane = bar(.normal, split: true, back: true, pinned: ["a"], extensions: true)expect(pane.left == [.back(enabled: true), .forward(enabled: false)] && pane.right == [.splitOptions, .closePane],"a focused split pane: only ← →, then its options and close")diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.mdindex 5d93c58..706aa31 100644--- a/docs/arc-reverse-engineering.md+++ b/docs/arc-reverse-engineering.md@@ -1943,3 +1943,26 @@ CEF still draws the first page of a new renderer transparent (chromiumembedded/ccanvas, an unstyled page (no background, no color-scheme) showed black text on black until its load ended(4 s with a slow image). The page now reports its background on every frame while it is parsed(kLoadingBackgroundProbe; frames wait for render-blocking stylesheets), so it turns white with its first paint.++## Sidebar toggle and the command bar's leading glyph (Arc 1.171, 1 Nov 2026, issue #50, live captures at 2x)++Victor's Arc (toolbar shown, full URLs on), window captures by id; Little Arc with keys posted to its pid for+the command bar (posted keys do not reach the main window's ⌘L while Arc is in the background, and Arc's menus+are disabled then).++- [O] Sidebar toggle: the sidebar's title row always has it; the toolbar has one only while the sidebar is+ hidden, floating included (then both show). Windowed: lights 20/43/66, toggle glyph 84–102 (centre 93.25,+ y 23.75). Fullscreen (no lights): glyph 20–38.5 (centre 29.25). Floating panel: lights 25/48/71, toggle 98.25,+ y 28.75 (the panel sits 5 pt in). Cra keeps the toggle 27 pt after its last light (its lights are 20/44/68)+ and draws it at 20–38 in fullscreen; Cra's floating panel sits 8 pt in, so its header is 3 pt right of Arc's.+- [O] Toolbar left group, sidebar shown: ← → ↻ centred 21/58/95 pt from the card edge (the sidebar is 347 pt wide in+ this capture). Sidebar hidden: toggle ← → ↻ at 31.25/68/105/142.25 from the window edge, card 10 pt in, so+ the first glyph is 21 pt from the card edge either way (the old "30 pt" figure was from the window edge).+ Developer mode follows the same rule (Arc 1.168 above: toggle at 93 + ← → ↻⌄ in the title row, URL text 40 pt+ from the card edge, i.e. no toggle in the bar).+- [O] At rest the default toolbar keeps its link glyph before the URL, not the page's favicon.+- [O] Command bar leading glyph = the highlighted row's icon: favicon when it has one (jira → Atlassian from+ history, x.com → X via completion, youtube.com typed → YouTube), globe for a URL row without one+ (example.org), magnifier for a search row ("hello world", "x", "youtulocalhost:3000"). ⌘L untouched or+ emptied: the page's favicon (GitHub), a globe on a page without one (example.com). ⌘T empty: magnifier,+ though its top row is a tab with a favicon. Cra: CommandBarGlyph; `info.circle` is gone.diff --git a/scripts/test-command-bar-glyph.sh b/scripts/test-command-bar-glyph.shnew file mode 100755index 0000000..97018a2--- /dev/null+++ b/scripts/test-command-bar-glyph.sh@@ -0,0 +1,9 @@+#!/bin/bash+# The command bar's leading glyph rule (CommandBarGlyph); no AppKit window or CEF.+set -euo pipefail+cd "$(dirname "$0")/.."+TEST_DIR="$(mktemp -d /tmp/cra-glyph-tests.XXXXXX)"+trap 'rm -rf "$TEST_DIR"' EXIT+xcrun swiftc -parse-as-library Sources/Cra/UI/CommandBar/CommandBarGlyph.swift Tests/CommandBarGlyphTests.swift \+ -o "$TEST_DIR/glyph-tests"+"$TEST_DIR/glyph-tests"diff --git a/scripts/test.sh b/scripts/test.shindex c6771fa..9b86af7 100755--- a/scripts/test.sh+++ b/scripts/test.sh@@ -22,6 +22,7 @@ if [ "${1:-}" != core ]; thensuite "Extension state" scripts/test-extension-state.shsuite "Store and importers" scripts/test-store.shsuite "Policies" scripts/test-policies.sh+ suite "Command bar glyph" scripts/test-command-bar-glyph.shsuite "Lint" scripts/lint.pyfi