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 parity: window dragging from the top of webpages (on by default, as in Arc)
Victor3b6b27d7a9e2
diff --git a/Packages/CraCore/Sources/CraCore/PageTopDrag.swift b/Packages/CraCore/Sources/CraCore/PageTopDrag.swiftnew file mode 100644index 0000000..3d07265--- /dev/null+++ b/Packages/CraCore/Sources/CraCore/PageTopDrag.swift@@ -0,0 +1,21 @@+import Foundation++/// Arc's Settings ▸ Advanced "Allow window dragging from the top of webpages" (on by default; Arc+/// 1.172.1, measured with real drags on 7 Nov 2026): with the toolbar hidden, a drag that starts in+/// the top 56 pt of the page moves the window (58 pt in it no longer does). A press there waits: if+/// the pointer moves past the drag slop the window moves; if it lifts first, the page gets the click.+public enum PageTopDrag {+ /// How far into the page the band reaches (Arc: 56 pt drags, 58 pt doesn't).+ public static let band: Double = 56+ /// How far the pointer moves before a press is a drag (AppKit's and Cra's window-drag slop).+ public static let slop: Double = 3++ /// Whether a press is held back as a possible window drag: a plain single left click in the+ /// band of a page that has no bar above it, with the setting on.+ public static func holds(enabled: Bool, barAbovePage: Bool, depthIntoPage: Double, clickCount: Int, modifiers: Bool) -> Bool {+ enabled && !barAbovePage && clickCount == 1 && !modifiers && depthIntoPage >= 0 && depthIntoPage < band+ }++ /// Whether the pointer has moved far enough from the press to move the window.+ public static func isDrag(dx: Double, dy: Double) -> Bool { (dx * dx + dy * dy).squareRoot() > slop }+}diff --git a/Packages/CraCore/Sources/CraCore/SidebarModel.swift b/Packages/CraCore/Sources/CraCore/SidebarModel.swiftindex 5b05a9f..acb88d9 100644--- a/Packages/CraCore/Sources/CraCore/SidebarModel.swift+++ b/Packages/CraCore/Sources/CraCore/SidebarModel.swift@@ -527,6 +527,8 @@ public struct AppSettings: Codable, Equatable {public var blockCookieBanners: Bool = false/// Arc's View ▸ Developer ▸ "Allow JavaScript from Apple Events": AppleScript's `execute`, off by default.public var allowAppleEventsJavaScript: Bool = false+ /// Arc's Settings ▸ Advanced "Allow window dragging from the top of webpages" (PageTopDrag), on by default.+ public var pageTopWindowDrag: Bool = true/// Arc's searchSuggestEnabled: the command bar asks the search engine for suggestions/// as you type and fills its rows with them.public var searchSuggestions: Bool = true@@ -739,6 +741,7 @@ extension AppSettings {shareThemeWithWebsites = try c.decodeIfPresent(Bool.self, forKey: .shareThemeWithWebsites) ?? trueblockCookieBanners = try c.decodeIfPresent(Bool.self, forKey: .blockCookieBanners) ?? falseallowAppleEventsJavaScript = try c.decodeIfPresent(Bool.self, forKey: .allowAppleEventsJavaScript) ?? false+ pageTopWindowDrag = try c.decodeIfPresent(Bool.self, forKey: .pageTopWindowDrag) ?? truesearchSuggestions = try c.decodeIfPresent(Bool.self, forKey: .searchSuggestions) ?? trueshowSpaceHeaderOnSingleSpace = try c.decodeIfPresent(Bool.self, forKey: .showSpaceHeaderOnSingleSpace) ?? truesharedFavorites = try c.decodeIfPresent(Bool.self, forKey: .sharedFavorites) ?? falsediff --git a/Packages/CraCore/Tests/CraCoreTests/PageTopDragTests.swift b/Packages/CraCore/Tests/CraCoreTests/PageTopDragTests.swiftnew file mode 100644index 0000000..c7d387b--- /dev/null+++ b/Packages/CraCore/Tests/CraCoreTests/PageTopDragTests.swift@@ -0,0 +1,22 @@+import CraCore+import Testing++/// Arc 1.172.1 (measured 7 Nov 2026): with the toolbar hidden, drags from the top 56 pt of a page move the window.+struct PageTopDragTests {+ @Test(arguments: [(0.0, true), (55.9, true), (56.0, false), (58.0, false), (-1.0, false)])+ func theBandIsArcs56Points(depth: Double, holds: Bool) {+ #expect(PageTopDrag.holds(enabled: true, barAbovePage: false, depthIntoPage: depth, clickCount: 1, modifiers: false) == holds)+ }++ @Test func onlyPlainSingleClicksWithNoBarAndTheSettingOn() {+ #expect(!PageTopDrag.holds(enabled: false, barAbovePage: false, depthIntoPage: 10, clickCount: 1, modifiers: false))+ #expect(!PageTopDrag.holds(enabled: true, barAbovePage: true, depthIntoPage: 10, clickCount: 1, modifiers: false))+ #expect(!PageTopDrag.holds(enabled: true, barAbovePage: false, depthIntoPage: 10, clickCount: 2, modifiers: false), "double-clicks go straight to the page")+ #expect(!PageTopDrag.holds(enabled: true, barAbovePage: false, depthIntoPage: 10, clickCount: 1, modifiers: true), "⌘-click opens links as always")+ }++ @Test func aDragIsMoreThanTheSlop() {+ #expect(!PageTopDrag.isDrag(dx: 2, dy: 2))+ #expect(PageTopDrag.isDrag(dx: 3, dy: 1))+ }+}diff --git a/Sources/Cra/UI/Settings/AdvancedPane.swift b/Sources/Cra/UI/Settings/AdvancedPane.swiftindex e9e3624..263d925 100644--- a/Sources/Cra/UI/Settings/AdvancedPane.swift+++ b/Sources/Cra/UI/Settings/AdvancedPane.swift@@ -35,6 +35,8 @@ struct AdvancedPane: View {SettingsFormRow(label: "Websites:") {// Arc: Settings ▸ Advanced "Allow websites to get your theme data" (--arc-palette-* variables).SettingsCheckbox(title: "Allow websites to get your theme data", isOn: $store.settings.shareThemeWithWebsites)+ // Arc: "Allow window dragging from the top of webpages" (with the toolbar hidden).+ SettingsCheckbox(title: "Allow window dragging from the top of webpages", isOn: $store.settings.pageTopWindowDrag)}SettingsFormRow(label: "When quitting Cra:") {SettingsCheckbox(title: "Warn before quitting", isOn: $store.settings.warnBeforeQuitting)diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swiftindex 9aa91dc..f9090d5 100644--- a/Sources/Cra/UI/Windows/MainWindowController.swift+++ b/Sources/Cra/UI/Windows/MainWindowController.swift@@ -21,6 +21,8 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMprivate var spaceEditor: NSWindow?private var importWindow: ImportWindowController?private var scrollMonitor: Any?+ private var pageTopDragMonitor: Any?+ private var replayingPageClick = falseprivate var childClickMonitor: Any?private var middleClickMonitor: Any?private enum SwipeAxis { case undecided, horizontal, vertical }@@ -198,6 +200,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMinstallSwipeMonitor()installChildClickMonitor()+ installPageTopDragMonitor()installFloatingSidebar()observeStore()refresh()@@ -2083,6 +2086,61 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM}}+ /// Arc's "Allow window dragging from the top of webpages" (PageTopDrag): with no bar above the+ /// page, a plain click in its top 56 pt waits. Moved past the slop, the window moves with the+ /// pointer; let go first, the page gets the click as it was, from the press on.+ private func installPageTopDragMonitor() {+ pageTopDragMonitor = NSEvent.addLocalMonitorForEvents(matching: .leftMouseDown) { [weak self] event in+ guard let self, !self.replayingPageClick, let window = self.window, let target = event.window,+ !window.styleMask.contains(.fullScreen), let depth = self.depthIntoPage(event, in: target, of: window) else { return event }+ let modifiers = !event.modifierFlags.intersection([.command, .shift, .option, .control]).isEmpty+ guard PageTopDrag.holds(enabled: self.store.settings.pageTopWindowDrag,+ barAbovePage: self.store.settings.showToolbar || self.shell.panesShowBars,+ depthIntoPage: depth, clickCount: event.clickCount, modifiers: modifiers) else { return event }+ self.trackPageTopPress(event, page: target, owner: window)+ return nil+ }+ }++ /// How far below the top of the page under it a press is, or nil when it isn't on a page:+ /// a Chrome-style page's own child window, or a page view inside this window.+ private func depthIntoPage(_ event: NSEvent, in target: NSWindow, of window: NSWindow) -> Double? {+ if target.parent === window {+ return CraCEFRuntime.isPageWindow(target) ? target.frame.height - event.locationInWindow.y : nil+ }+ guard target === window, let content = window.contentView,+ var view = content.hitTest(content.convert(event.locationInWindow, from: nil)) else { return nil }+ // Chromium's page view, reparented into the pane card (Chrome-style hosting): its+ // WebContentsViewCocoa is the page's frame.+ while NSStringFromClass(type(of: view)) != "WebContentsViewCocoa" {+ guard let up = view.superview else { return nil }+ view = up+ }+ return view.convert(view.bounds, to: nil).maxY - event.locationInWindow.y+ }++ private func trackPageTopPress(_ down: NSEvent, page: NSWindow, owner: NSWindow) {+ let start = NSEvent.mouseLocation+ var last = start, dragging = false+ var up: NSEvent?+ page.trackEvents(matching: [.leftMouseDragged, .leftMouseUp], timeout: NSEvent.foreverDuration, mode: .eventTracking) { event, stop in+ guard let event else { stop.pointee = true; return }+ if event.type == .leftMouseUp { up = event; stop.pointee = true; return }+ let now = NSEvent.mouseLocation+ if !dragging, PageTopDrag.isDrag(dx: now.x - start.x, dy: now.y - start.y) { dragging = true }+ if dragging { owner.setFrameOrigin(NSPoint(x: owner.frame.minX + now.x - last.x, y: owner.frame.minY + now.y - last.y)) }+ last = now+ }+ CraLog.note("page-top press: \(dragging ? "moved the window" : "a click for the page")")+ guard !dragging else { return }+ // A click after all: the page gets the press and the release, in its own window.+ replayingPageClick = true+ if !page.isKeyWindow, page.canBecomeKey { page.makeKey() }+ page.sendEvent(down)+ if let up { page.sendEvent(up) }+ replayingPageClick = false+ }+/// What the row's hover button does: close every picked tab when this is one of them;/// the open pinned tab unloads and stays pinned, another pinned tab is archived.private func middleClickClose(_ id: UUID) {@@ -3465,7 +3523,8 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMother.takePage(rt)}browsers.closeAll()- for monitor in [scrollMonitor, childClickMonitor, middleClickMonitor].compactMap({ $0 }) { NSEvent.removeMonitor(monitor) }+ for monitor in [scrollMonitor, childClickMonitor, middleClickMonitor, pageTopDragMonitor].compactMap({ $0 }) { NSEvent.removeMonitor(monitor) }+ pageTopDragMonitor = nilscrollMonitor = nilchildClickMonitor = nilmiddleClickMonitor = nildiff --git a/docs/arc-parity.md b/docs/arc-parity.mdindex 518b38c..fbc6615 100644--- a/docs/arc-parity.md+++ b/docs/arc-parity.md@@ -30,7 +30,7 @@ or Arc-only service), per CONTRIBUTING.md.| Find and Replace, Use Selection to Find, Jump to Selection | Edit ▸ Find | partial | Use Selection to Find and Jump to Selection (⌘J) done; Find and Replace is for Arc's Notes/Easels text, which Cra doesn't have. || Sound effects | Settings ▸ Advanced "Play Arc sound effects" | done | Settings ▸ Advanced ▸ Play Cra sound effects gates the capture shutter. || Theme data for websites | Settings ▸ Advanced "Allow websites to get your theme data" | done | `--arc-palette-*` and `--arc-background-*` as #RRGGBBAA, from the space's theme (ArcThemeData; fitted to Arc's stored palette, checked live). |-| Window dragging from the top of webpages | Settings ▸ Advanced | measured | With the toolbar hidden, Arc drags the window from the top 56 pt of the page (66 pt below the window's top); 58 pt in, the page gets the drag. Cra's strip reaches 4 pt into the page. Needs clicks in that band held until the pointer moves, across Chromium's page windows. |+| Window dragging from the top of webpages | Settings ▸ Advanced | done | With the toolbar hidden, a drag from the top 56 pt of a page moves the window; a click there still reaches the page (PageTopDrag). Settings ▸ Advanced, on by default as in Arc. || Restore windows from previous session | Settings ▸ Advanced | done | Settings ▸ Advanced; off keeps the window in use last. || Block Cookie Banners | Settings ▸ General | done | Settings ▸ Privacy; hides the common consent managers' banners (CookieBanners), off by default as in Arc. || Archive Little Arcs after | Settings ▸ Links (6 hours default) | done | Settings ▸ Tabs ▸ Links; a Little Window left alone that long closes into the archive. |@@ -86,7 +86,7 @@ gains "New Profile".| General | Previews Settings… (Block Cookie Banners done, under Privacy) || Profiles | "New documents" app (Arc's Notes/Easels); Privacy, Passwords, Credit Cards and Notifications done || Links | "Open Little Arc when clicking on links with ⌥⌘ held"; Archive Little Windows after done |-| Advanced | window dragging from the top of webpages (measured), Shared Quotes (arc.net), Enable Boosts (sound effects, restore windows and theme data done) |+| Advanced | Shared Quotes (arc.net), Enable Boosts (the rest done) || Icon | Cra has its own icon picker |## 5. Animations and styling@@ -126,6 +126,7 @@ in this sweep (Essential Shortcuts window, Library pages).measured live in Arc (names, #RRGGBBAA format, no trace in the page's markup) and fitted to thesemantic palette Arc stores per space.- Edit ▸ Find ▸ Use Selection to Find and Jump to Selection (⌘J).+- Window dragging from the top of webpages (Victor's choice, 7 Nov: on, as in Arc).- AppleScript, Arc's dictionary (Victor's choice, 7 Nov: like Arc, JavaScript off by default).- Settings ▸ Privacy ▸ Block cookie banners (Arc's "Block Cookie Banners", off by default).- Easels, first version: File ▸ New Easel (⌃⇧E) opens a canvas in the tab (EaselBrowser, a page@@ -150,5 +151,4 @@ in this sweep (Essential Shortcuts window, Library pages).- Boosts: the offline Arc has no network and a local server is blocked in this session, so its Boosteditor couldn't be put on screen to copy. Needs a site in Arc (Victor's OK to run the real Arc, ora localhost server).-- Window dragging from the top of pages (measured, above), Previews and- Join Meeting: not started.+- Previews and Join Meeting: not started (they need a live Google session in Arc to measure).