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.

Peek moves like Arc's on Core Animation, and opens and closes in Arc's ways (#173)

Victor Kildahla7f7978dd1fe
diff --git a/Packages/CraCore/Sources/CraCore/PeekLayout.swift b/Packages/CraCore/Sources/CraCore/PeekLayout.swift
index 5843c3f..fc1b7bd 100644
--- a/Packages/CraCore/Sources/CraCore/PeekLayout.swift
+++ b/Packages/CraCore/Sources/CraCore/PeekLayout.swift
@@ -7,8 +7,8 @@ import CoreGraphics
/// card's), 80 % of its width (1105 of 1381 pt), 12 pt in from the window's top and bottom. Close,
/// Expand and Add To Split are 34 × 33 pt round buttons in a column 13 pt right of the card, the
/// first 7 pt below its top, 43.5 pt apart. The page behind fades to 28 %, the card has 8 pt corners
-/// and a 32 pt bar. It opens from the area's full size to its own in 0.12 s and closes the same way
-/// back in 0.22 s, fading as it goes.
+/// and a 32 pt bar. It opens from the area's full size to its own and closes the same way back,
+/// fading as it goes (the timings below).
public enum PeekLayout {
public static let widthFraction: CGFloat = 0.8
public static let verticalInset: CGFloat = 12
@@ -21,8 +21,28 @@ public enum PeekLayout {
public static let buttonCount = 3
/// The page under a Peek (Arc: 233/240/254 → 178/172/151 over the window's background).
public static let pageAlpha: CGFloat = 0.28
- public static let openDuration: Double = 0.12
- public static let closeDuration: Double = 0.22
+ /// Arc's open, measured frame by frame at 60 fps (3 Nov 2026): the card's opacity reaches 1 in
+ /// 0.075 s; its scale, from the whole area (1 / widthFraction) to 1 about its centre, follows an
+ /// ease-out cubic over 0.205 s starting a frame in; the page fades to `pageAlpha` on an ease-out
+ /// cubic over 0.18 s. The buttons ride the card's top-right corner and fade with it.
+ public static let openFadeDuration: Double = 0.075
+ public static let openScaleDelay: Double = 0.016
+ public static let openScaleDuration: Double = 0.205
+ public static let openVeilDuration: Double = 0.18
+ /// Arc's close: back out to the whole area in 0.12 s (near linear), fading from 0.07 s for
+ /// 0.09 s, while the page comes back over 0.2 s.
+ public static let closeScaleDuration: Double = 0.12
+ public static let closeFadeDelay: Double = 0.07
+ public static let closeFadeDuration: Double = 0.09
+ public static let closeVeilDuration: Double = 0.2
+ /// The scale that makes the card cover the whole area's width.
+ public static let areaScale: CGFloat = 1 / widthFraction
+
+ /// How far the card's top-right corner (and the buttons with it) is from its place while the
+ /// card is drawn at `scale` about its centre.
+ public static func cornerShift(card: CGRect, scale: CGFloat) -> CGVector {
+ CGVector(dx: (scale - 1) * card.width / 2, dy: (scale - 1) * card.height / 2)
+ }
/// The area a Peek covers: right of the sidebar (`contentMinX`, window coordinates) to the
/// window's right edge, its full height.
diff --git a/Packages/CraCore/Sources/CraCore/PeekTrigger.swift b/Packages/CraCore/Sources/CraCore/PeekTrigger.swift
new file mode 100644
index 0000000..e912c9d
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/PeekTrigger.swift
@@ -0,0 +1,21 @@
+import Foundation
+
+/// Which clicked links open Arc's Peek (Settings ▸ Tabs ▸ Links) instead of loading where they are.
+///
+/// Arc 1.171, offline Arc with both Links settings on (`modalEnabled`, `shiftClickModalEntryPointEnabled`),
+/// HID clicks in a pinned tab (4 Nov 2026): a link to another host peeked, plain or target=_blank; a
+/// same-host link loaded in the tab, but the same link with target=_blank peeked, and so did
+/// window.open; a ⌘-click opened a background tab. A Shift-click peeked from any tab. Links clicked
+/// inside the Peek load in it.
+public enum PeekTrigger {
+ /// `newTab`: the page asked for a new tab (target=_blank, window.open without features).
+ /// `fromPinned`: a pinned tab or favorite.
+ public static func opens(_ url: String, from page: String, shiftClick: Bool, newTab: Bool, fromPinned: Bool,
+ settings: AppSettings) -> Bool {
+ guard SiteKey.site(of: url) != nil else { return false }
+ if shiftClick { return settings.peekOnShiftClick }
+ // Another host, not another site: Arc peeks from pin.lvh.me to away.lvh.me (GitHub #139).
+ return settings.peekLinksToOtherSites && (settings.peekInEveryTab || fromPinned)
+ && (newTab || PinnedNavigation.linkLeavesHost(url, from: page))
+ }
+}
diff --git a/Packages/CraCore/Tests/CraCoreTests/PeekLayoutTests.swift b/Packages/CraCore/Tests/CraCoreTests/PeekLayoutTests.swift
index e69aec5..9b7132c 100644
--- a/Packages/CraCore/Tests/CraCoreTests/PeekLayoutTests.swift
+++ b/Packages/CraCore/Tests/CraCoreTests/PeekLayoutTests.swift
@@ -28,4 +28,13 @@ struct PeekLayoutTests {
#expect(card.midX == Self.window.width / 2)
#expect(card.width == (Self.window.width * 0.8).rounded())
}
+
+ @Test func openStartsAtTheAreasWidth() {
+ let area = PeekLayout.area(window: Self.window, contentMinX: 347)
+ let card = PeekLayout.card(in: area)
+ #expect(abs(card.width * PeekLayout.areaScale - area.width) <= 1)
+ // Arc's first measured frame (scale 1.1675): the corner 93 pt right and 89 pt up of its place.
+ let shift = PeekLayout.cornerShift(card: card, scale: 1.1675)
+ #expect(abs(shift.dx - 92.5) < 0.5 && abs(shift.dy - 88.8) < 0.5)
+ }
}
diff --git a/Packages/CraCore/Tests/CraCoreTests/PeekTriggerTests.swift b/Packages/CraCore/Tests/CraCoreTests/PeekTriggerTests.swift
new file mode 100644
index 0000000..3a87b51
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/PeekTriggerTests.swift
@@ -0,0 +1,44 @@
+import CraCore
+import Testing
+
+/// The links Arc peeked from a pinned tab (docs/arc-reverse-engineering.md, "Peek and the copy
+/// toast's Share button"), on the lab page at 127.0.0.1.
+struct PeekTriggerTests {
+ static let page = "http://127.0.0.1:8765/lab.html"
+ static let other = "http://localhost:8765/other.html"
+ static let same = "http://127.0.0.1:8765/same.html"
+
+ static func opens(_ url: String, shift: Bool = false, newTab: Bool = false, pinned: Bool = true,
+ _ change: (inout AppSettings) -> Void = { _ in }) -> Bool {
+ var s = AppSettings()
+ change(&s)
+ return PeekTrigger.opens(url, from: page, shiftClick: shift, newTab: newTab, fromPinned: pinned, settings: s)
+ }
+
+ @Test func pinnedTabPeeksAtOtherHosts() {
+ #expect(Self.opens(Self.other))
+ #expect(Self.opens(Self.other, newTab: true))
+ #expect(!Self.opens(Self.same))
+ }
+
+ @Test func aNewTabLinkPeeksEvenOnTheSameHost() {
+ #expect(Self.opens(Self.same, newTab: true))
+ }
+
+ @Test func todayTabsLoadUnlessEveryTabIsOn() {
+ #expect(!Self.opens(Self.other, pinned: false))
+ #expect(!Self.opens(Self.same, newTab: true, pinned: false))
+ #expect(Self.opens(Self.other, pinned: false) { $0.peekInEveryTab = true })
+ }
+
+ @Test func shiftClickPeeksFromAnyTab() {
+ #expect(Self.opens(Self.same, shift: true, pinned: false))
+ #expect(!Self.opens(Self.same, shift: true) { $0.peekOnShiftClick = false })
+ }
+
+ @Test func settingsAndSchemes() {
+ #expect(!Self.opens(Self.other) { $0.peekLinksToOtherSites = false })
+ #expect(!Self.opens("file:///tmp/a.html", newTab: true))
+ #expect(!Self.opens("cra://settings", shift: true))
+ }
+}
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swift
index cd1f3f6..48cd4c5 100644
--- a/Sources/Cra/App/AppDelegate.swift
+++ b/Sources/Cra/App/AppDelegate.swift
@@ -937,7 +937,16 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
// Arc: "Close current tab or window".
if current != nil { main.closeCurrentTab() } else { main.window?.performClose(nil) }
case "closeWindow": main.window?.performClose(nil)
- case "reopenClosedTab": if !main.isIncognito { store.reopenLastArchived() } // incognito tabs leave nothing to restore
+ case "reopenClosedTab":
+ guard !main.isIncognito else { break } // incognito tabs leave nothing to restore
+ // Arc: a Peek closed after the last archived tab comes back, over the tab it came from.
+ if let peek = main.closedPeek, peek.at > store.archive.first?.archivedAt ?? .distantPast {
+ main.closedPeek = nil
+ if let id = peek.tabID, store.item(id) != nil { store.selectTab(id, window: main.windowID) }
+ openPeek(url: peek.url, over: main, fromTab: peek.tabID)
+ } else {
+ store.reopenLastArchived()
+ }
case "copyURL":
if let url = current.flatMap({ store.item($0)?.tab?.url }) {
copy(url)
diff --git a/Sources/Cra/Services/BrowserManager.swift b/Sources/Cra/Services/BrowserManager.swift
index 507426d..efd6cc7 100644
--- a/Sources/Cra/Services/BrowserManager.swift
+++ b/Sources/Cra/Services/BrowserManager.swift
@@ -75,7 +75,7 @@ protocol BrowserManagerDelegate: AnyObject {
func browserManagerActivationRequested(_ tabID: UUID, byPage: Bool)
/// Arc's Peek: a link the user clicked (or Shift-clicked) in `tabID`, whose page is at
/// `pageURL`. Return true when it opens in a Peek instead.
- func browserManagerOpensPeek(url: String, fromTab tabID: UUID, pageURL: String, shiftClick: Bool) -> Bool
+ func browserManagerOpensPeek(url: String, fromTab tabID: UUID, pageURL: String, shiftClick: Bool, newTab: Bool) -> Bool
}
/// Creates, shows, hides and tears down CEF browsers inside a container view.
@@ -1002,9 +1002,9 @@ final class BrowserManager: NSObject, @preconcurrency CraBrowserDelegate {
return host
}
- func browser(_ browser: CraBrowser, opensPeekForURL url: String, shiftClick: Bool) -> Bool {
+ func browser(_ browser: CraBrowser, opensPeekForURL url: String, shiftClick: Bool, newTab: Bool) -> Bool {
guard let id = tabID(of: browser), !browser.isIncognito else { return false }
- return delegate?.browserManagerOpensPeek(url: url, fromTab: id, pageURL: browser.currentURL, shiftClick: shiftClick) ?? false
+ return delegate?.browserManagerOpensPeek(url: url, fromTab: id, pageURL: browser.currentURL, shiftClick: shiftClick, newTab: newTab) ?? false
}
func devToolsHostView(for browser: CraBrowser) -> NSView? {
diff --git a/Sources/Cra/UI/Windows/LittleWindowController.swift b/Sources/Cra/UI/Windows/LittleWindowController.swift
index db0d0be..094a5f8 100644
--- a/Sources/Cra/UI/Windows/LittleWindowController.swift
+++ b/Sources/Cra/UI/Windows/LittleWindowController.swift
@@ -135,6 +135,8 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
private var closingPeek = false
/// The Peek is shrinking into place; a page window attaching now waits for the end.
private var openingPeek = false
+ /// The pictures moving while the Peek opens or closes.
+ private var transition: PeekTransition?
private var commandPanel: CommandBarPanel!
private var commandHost: CommandBarView!
private var commandBarOpenedAt = Date.distantPast
@@ -274,7 +276,7 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
}
// CEF hands the page window over at its own small frame: shown during a Peek's open it
// flashed as a black block in the corner.
- if openingPeek { w.alphaValue = 0 }
+ if openingPeek { w.contentView?.isHidden = true }
window.addChildWindow(w, ordered: .above)
positionHostWindow(shell.convert(shell.page.frame, to: nil))
w.orderFront(nil)
@@ -355,7 +357,9 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
var peekWindows: [NSWindow] { [dim, window, controls].compactMap { $0 } }
/// Arc's Peek: the card shrinks from the whole area right of the sidebar to its own frame as
- /// it fades in (0.12 s) while the page behind fades to 28 %; the buttons beside it come after.
+ /// it fades in, its buttons riding its corner, while the page behind fades to 28 %. The motion
+ /// is PeekTransition's pictures on Core Animation; the real card and buttons wait at their
+ /// places, invisible, and take over when it lands.
func showAsPeek() {
guard let window, let parent = peekParent, let pw = parent.window else { return }
let dim = PeekDimPanel(covering: pw) { [weak self] in self?.closeWindow() }
@@ -370,38 +374,44 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
self.controls = controls
controls.place(parent.peekButtonFrames(), theme: parent.focusedSpace.theme)
controls.alphaValue = 0
- let card = parent.peekFrame()
- // Laid out at the card's size from the start, as Little Windows open; the page window
- // waits for the end, it can't follow a frame animation.
- shell.frozenSize = card.size
- let host = browser?.hostWindow
- if let host, host.parent === window { host.alphaValue = 0 }
window.alphaValue = 0
- window.setFrame(parent.peekArea(), display: false)
+ window.setFrame(parent.peekFrame(), display: false)
+ shell.layoutSubtreeIfNeeded()
pw.addChildWindow(window, ordered: .above)
+ pw.addChildWindow(controls, ordered: .above)
+ controls.orderFront(nil)
window.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)
- parent.setPeekVeil(true, duration: PeekLayout.openDuration)
openingPeek = true
- NSAnimationContext.runAnimationGroup({ ctx in
- ctx.duration = PeekLayout.openDuration
- ctx.timingFunction = CAMediaTimingFunction(name: .easeOut)
- window.animator().alphaValue = 1
- window.animator().setFrame(card, display: true)
- }, completionHandler: { [weak self] in
- MainActor.assumeIsolated {
- guard let self, let window = self.window, !self.closingPeek else { return }
- self.openingPeek = false
- self.shell.frozenSize = nil
- self.shell.needsLayout = true
- self.shell.layoutSubtreeIfNeeded()
- if let host = self.browser?.hostWindow, host.parent === window { host.alphaValue = 1 }
- pw.addChildWindow(controls, ordered: .above)
- controls.orderFront(nil)
- NSAnimationContext.runAnimationGroup { $0.duration = 0.1; controls.animator().alphaValue = 1 }
- }
- })
+ // Hidden, not transparent: Chromium sets its page window's alpha back to 1 as it shows it.
+ if let host = browser?.hostWindow, host.parent === window { host.contentView?.isHidden = true }
+ let t = PeekTransition(over: pw, card: pw.convertFromScreen(window.frame), cardImage: PeekTransition.picture(of: shell),
+ column: pw.convertFromScreen(controls.frame), columnImage: controls.contentView.flatMap { PeekTransition.picture(of: $0) })
+ transition = t
if hasPage || isPopupHost { focusPage() } else { openCommandBar() }
+ // Next turn, with the page focused and the panel on its way to the screen.
+ DispatchQueue.main.async { [weak self, weak t] in
+ guard let self, let t, self.transition === t, !self.closingPeek else { return }
+ DispatchQueue.main.asyncAfter(deadline: .now() + PeekTransition.lead) {
+ parent.setPeekVeil(true, duration: PeekLayout.openVeilDuration, timing: PeekTransition.easeOutCubic)
+ }
+ self.landPeek(t)
+ }
+ }
+
+ private func landPeek(_ t: PeekTransition) {
+ t.open { [weak self, weak t] in
+ guard let self, let window = self.window, !self.closingPeek else { return }
+ self.openingPeek = false
+ window.alphaValue = 1
+ if let host = self.browser?.hostWindow, host.parent === window { host.contentView?.isHidden = false }
+ self.controls?.alphaValue = 1
+ // The real card is on screen a frame later; the picture goes after it.
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
+ t?.remove()
+ if self.transition === t { self.transition = nil }
+ }
+ }
}
func repositionPeek() {
@@ -412,26 +422,51 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
}
/// Arc closes a Peek the way it opened, backwards: out to the whole area, fading, as the page
- /// behind comes back (0.22 s). Expand and Add To Split don't animate: the page stays on screen.
+ /// behind comes back. A picture of the card with its page (Chromium's own screenshot, waited
+ /// for at most 80 ms) takes over from the real one. Expand and Add To Split don't animate.
private func closePeekAnimated(then finish: @escaping () -> Void) {
- guard let window, let parent = peekParent else { finish(); return }
+ guard let window, let parent = peekParent, let pw = parent.window else { finish(); return }
closingPeek = true
- parent.setPeekVeil(false, duration: PeekLayout.closeDuration)
- let host = browser?.hostWindow
- let controls = controls
- NSAnimationContext.runAnimationGroup({ ctx in
- ctx.duration = PeekLayout.closeDuration
- ctx.timingFunction = CAMediaTimingFunction(name: .easeIn)
- window.animator().alphaValue = 0
- host?.animator().alphaValue = 0
- controls?.animator().alphaValue = 0
- window.animator().setFrame(parent.peekArea(), display: true)
- }, completionHandler: { MainActor.assumeIsolated { finish() } })
+ transition?.remove()
+ transition = nil
+ var started = false
+ let start: (CGImage?) -> Void = { [weak self] page in
+ guard let self, !started else { return }
+ started = true
+ let card = pw.convertFromScreen(window.frame)
+ let pageRect = self.shell.page.frame
+ let t = PeekTransition(over: pw, card: card,
+ cardImage: PeekTransition.picture(of: self.shell, page: page, pageRect: pageRect),
+ column: self.controls.map { pw.convertFromScreen($0.frame) } ?? .zero,
+ columnImage: self.controls?.contentView.flatMap { PeekTransition.picture(of: $0) })
+ self.transition = t
+ t.close {
+ finish()
+ t.remove()
+ }
+ // The picture is on screen (the same pixels) before the real card goes, so nothing blinks.
+ DispatchQueue.main.asyncAfter(deadline: .now() + PeekTransition.lead) {
+ window.alphaValue = 0
+ if let host = self.browser?.hostWindow { host.alphaValue = 0 }
+ self.controls?.alphaValue = 0
+ parent.setPeekVeil(false, duration: PeekLayout.closeVeilDuration, timing: PeekTransition.easeOutCubic)
+ }
+ }
+ guard let b = browser, hasPage else { start(nil); return }
+ b.sendDevToolsMethod("Page.captureScreenshot", params: #"{"format":"jpeg","quality":85,"optimizeForSpeed":true}"#) { shot, _ in
+ let image = shot.flatMap { try? JSONSerialization.jsonObject(with: Data($0.utf8)) as? [String: Any] }
+ .flatMap { $0["data"] as? String }.flatMap { Data(base64Encoded: $0) }
+ .flatMap { CGImageSourceCreateWithData($0 as CFData, nil) }.flatMap { CGImageSourceCreateImageAtIndex($0, 0, nil) }
+ DispatchQueue.main.async { start(image) }
+ }
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.08) { start(nil) }
}
private func endPeek() {
guard isPeek, let dim else { return }
self.dim = nil
+ transition?.remove()
+ transition = nil
dim.parent?.removeChildWindow(dim)
dim.orderOut(nil)
if let controls {
@@ -455,13 +490,19 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
closePopup()
commandBar.close()
let sid = store.spaceID(ofItem: source) ?? parent.focusedSpaceID
+ // Arc leaves a pinned tab where it is: the split is a new one at the top of Today, a copy
+ // of the pinned tab's page beside the peeked one.
+ var partner = source
+ if store.isPinned(source), store.splitContaining(source) == nil, let page = store.item(source)?.tab {
+ partner = store.createTab(url: page.url, title: page.savedTitle, in: sid, select: false, window: parent.windowID).id
+ }
let tab = store.createTab(url: b.currentURL, title: b.currentTitle, in: sid, select: false, window: parent.windowID)
if let favicon, let key = FaviconKey.key(for: b.currentURL) { app.favicons.store(favicon, forKey: key) }
promoted = true
browser = nil
parent.browsers.adopt(b, for: tab.id)
window?.close()
- parent.joinSplit(tab.id, with: source)
+ parent.joinSplit(tab.id, with: partner)
}
// MARK: Command bar (Arc: clicking the pill or ⌘L opens the command bar in the window)
@@ -750,6 +791,9 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
func closeWindow() {
guard let window, window.isVisible else { return }
if isPeek, !closingPeek {
+ if hasPage, !promoted, let parent = peekParent {
+ parent.closedPeek = (currentURL, parent.sidebarUI.peekBadge?.tabID, store.clock.now)
+ }
closePeekAnimated { [weak self] in self?.closeWindow() }
return
}
@@ -879,7 +923,7 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
/// A Shift-clicked link opens in this window: Arc's Little Arc has no Peek of its own, so its
/// Shift-click is a plain click (1.171, 3 Nov 2026).
- func browser(_ browser: CraBrowser, opensPeekForURL url: String, shiftClick: Bool) -> Bool {
+ func browser(_ browser: CraBrowser, opensPeekForURL url: String, shiftClick: Bool, newTab: Bool) -> Bool {
guard shiftClick, !url.lowercased().hasPrefix("cra:") else { return false }
browser.loadURL(url)
return true
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index 40e5e8f..ab1b39f 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -1284,19 +1284,10 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
}
}
- /// Arc's Peek (Settings ▸ Tabs ▸ Links): a link to another site clicked in a favorite or
- /// pinned tab (any tab with "In every tab" on), or any Shift-clicked link, opens over the
- /// window and the tab stays put.
- func browserManagerOpensPeek(url: String, fromTab tabID: UUID, pageURL: String, shiftClick: Bool) -> Bool {
- guard !isIncognito, SiteKey.site(of: url) != nil else { return false }
- if shiftClick {
- guard store.settings.peekOnShiftClick else { return false }
- } else {
- // Another host, not another site: Arc peeks from pin.lvh.me to away.lvh.me (GitHub #139).
- guard store.settings.peekLinksToOtherSites,
- store.settings.peekInEveryTab || store.isPinned(tabID),
- PinnedNavigation.linkLeavesHost(url, from: pageURL) else { return false }
- }
+ /// Arc's Peek (PeekTrigger): the link opens over the window and the tab stays put.
+ func browserManagerOpensPeek(url: String, fromTab tabID: UUID, pageURL: String, shiftClick: Bool, newTab: Bool) -> Bool {
+ guard !isIncognito, PeekTrigger.opens(url, from: pageURL, shiftClick: shiftClick, newTab: newTab,
+ fromPinned: store.isPinned(tabID), settings: store.settings) else { return false }
app.openPeek(url: url, over: self, fromTab: tabID)
return true
}
@@ -1325,11 +1316,12 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
}
/// Arc fades the page under a Peek to 28 % over the window's background, its sidebar as it is.
- func setPeekVeil(_ on: Bool, duration: TimeInterval) {
+ func setPeekVeil(_ on: Bool, duration: TimeInterval, timing: CAMediaTimingFunction? = nil) {
let alpha: CGFloat = on ? PeekLayout.pageAlpha : 1
let pages = browsers.runtimes.values.compactMap(\.hostWindow).filter { $0.parent === window }
NSAnimationContext.runAnimationGroup { ctx in
ctx.duration = duration
+ ctx.timingFunction = timing
shell.contentContainer.animator().alphaValue = alpha
for w in pages { w.animator().alphaValue = alpha }
}
@@ -1347,6 +1339,10 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
private var peeks: [LittleWindowController] { app.littleWindows.filter { $0.peekParent === self } }
+ /// The Peek closed last over this window and the tab it came from: Arc's ⇧⌘T brings it back
+ /// when nothing was archived after it.
+ var closedPeek: (url: String, tabID: UUID?, at: Date)?
+
// MARK: Tabs
/// cra://debug?devtoolsjs=…: run script in the current tab's DevTools frontend.
diff --git a/Sources/Cra/UI/Windows/PeekChrome.swift b/Sources/Cra/UI/Windows/PeekChrome.swift
index a3c7db4..7efd2fa 100644
--- a/Sources/Cra/UI/Windows/PeekChrome.swift
+++ b/Sources/Cra/UI/Windows/PeekChrome.swift
@@ -182,3 +182,168 @@ final class PeekControlButton: NSView {
run()
}
}
+
+/// Arc's Peek opening and closing, on Core Animation. A picture of the card and of its buttons
+/// rides in a panel over the browser window while the real ones wait, invisible, at their places:
+/// the window server draws every frame, nothing is resized or laid out while it runs, and the
+/// page window (which can't follow a frame animation) is never moved. Curves from PeekLayout.
+@MainActor
+final class PeekTransition {
+ private let panel: NSPanel
+ private let group = CALayer()
+ private let shadow = CALayer()
+ private let card = CALayer()
+ private let buttons = CALayer()
+ /// Arc's ease-out on the card's scale, and the near-linear way back out.
+ static let easeOutCubic = CAMediaTimingFunction(controlPoints: 0.215, 0.61, 0.355, 1)
+ static let closeCurve = CAMediaTimingFunction(controlPoints: 0.25, 0.25, 0.5, 1)
+
+ /// `card` and `column` in `window`'s coordinates; the pictures at the window's scale.
+ init(over window: NSWindow, card frame: NSRect, cardImage: CGImage?, column: NSRect, columnImage: CGImage?) {
+ panel = NSPanel(contentRect: window.frame, styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
+ panel.isOpaque = false
+ panel.backgroundColor = .clear
+ panel.hasShadow = false
+ panel.ignoresMouseEvents = true
+ panel.hidesOnDeactivate = false
+ panel.isReleasedWhenClosed = false
+ panel.animationBehavior = .none
+ let view = NSView(frame: NSRect(origin: .zero, size: window.frame.size))
+ view.wantsLayer = true
+ panel.contentView = view
+ let scale = window.backingScaleFactor
+ CATransaction.begin()
+ CATransaction.setDisableActions(true)
+ group.frame = frame
+ shadow.frame = group.bounds
+ shadow.shadowPath = CGPath(roundedRect: group.bounds, cornerWidth: PeekLayout.cornerRadius, cornerHeight: PeekLayout.cornerRadius, transform: nil)
+ shadow.shadowColor = NSColor.black.cgColor
+ shadow.shadowOpacity = 0.35
+ shadow.shadowRadius = 14
+ shadow.shadowOffset = CGSize(width: 0, height: -6)
+ card.frame = group.bounds
+ card.cornerRadius = PeekLayout.cornerRadius
+ card.cornerCurve = .continuous
+ card.masksToBounds = true
+ card.contents = cardImage
+ card.contentsGravity = .resize
+ card.contentsScale = scale
+ group.addSublayer(shadow)
+ group.addSublayer(card)
+ buttons.frame = column
+ buttons.contents = columnImage
+ buttons.contentsGravity = .resize
+ buttons.contentsScale = scale
+ view.layer?.addSublayer(group)
+ view.layer?.addSublayer(buttons)
+ // Nothing shows until open() or close() animates it: the panel reaches the screen before
+ // the animations do, and its first frame showed the card at its final size.
+ group.opacity = 0
+ buttons.opacity = 0
+ CATransaction.commit()
+ window.addChildWindow(panel, ordered: .above)
+ panel.orderFront(nil)
+ }
+
+ /// From the whole area to the card's frame, fading in; `done` once it has landed.
+ /// A new panel reaches the screen a frame or two after it is ordered in, and the main thread
+ /// still has the page to focus: animations clocked from now lost their first 60 ms. They start
+ /// this far ahead instead, held at their first frame until then.
+ static let lead: CFTimeInterval = 0.03
+
+ func open(done: @escaping () -> Void) {
+ let k = PeekLayout.areaScale
+ let shift = PeekLayout.cornerShift(card: group.frame, scale: k)
+ let now = CACurrentMediaTime() + Self.lead
+ CATransaction.begin()
+ CATransaction.setDisableActions(true)
+ CATransaction.setCompletionBlock { MainActor.assumeIsolated { done() } }
+ for layer in [group, buttons] {
+ layer.opacity = 1
+ let fade = CABasicAnimation(keyPath: "opacity")
+ fade.fromValue = 0
+ fade.toValue = 1
+ fade.duration = PeekLayout.openFadeDuration
+ fade.timingFunction = CAMediaTimingFunction(name: .easeOut)
+ fade.beginTime = now
+ fade.fillMode = .backwards
+ layer.add(fade, forKey: "fade")
+ }
+ let grow = CABasicAnimation(keyPath: "transform.scale")
+ grow.fromValue = k
+ grow.toValue = 1
+ let ride = CABasicAnimation(keyPath: "position")
+ ride.fromValue = NSValue(point: NSPoint(x: buttons.position.x + shift.dx, y: buttons.position.y + shift.dy))
+ ride.toValue = NSValue(point: buttons.position)
+ for (layer, a) in [(group, grow), (buttons, ride)] as [(CALayer, CABasicAnimation)] {
+ a.beginTime = now + PeekLayout.openScaleDelay
+ a.duration = PeekLayout.openScaleDuration
+ a.timingFunction = Self.easeOutCubic
+ a.fillMode = .backwards
+ layer.add(a, forKey: "move")
+ }
+ CATransaction.commit()
+ }
+
+ /// Back out to the whole area, fading partway; `done` once it is gone.
+ func close(done: @escaping () -> Void) {
+ let k = PeekLayout.areaScale
+ let shift = PeekLayout.cornerShift(card: group.frame, scale: k)
+ let now = CACurrentMediaTime() + Self.lead
+ CATransaction.begin()
+ CATransaction.setDisableActions(true)
+ CATransaction.setCompletionBlock { MainActor.assumeIsolated { done() } }
+ let grow = CABasicAnimation(keyPath: "transform.scale")
+ grow.fromValue = 1
+ grow.toValue = k
+ let ride = CABasicAnimation(keyPath: "position")
+ ride.fromValue = NSValue(point: buttons.position)
+ ride.toValue = NSValue(point: NSPoint(x: buttons.position.x + shift.dx, y: buttons.position.y + shift.dy))
+ for (layer, a) in [(group, grow), (buttons, ride)] as [(CALayer, CABasicAnimation)] {
+ a.beginTime = now
+ a.duration = PeekLayout.closeScaleDuration
+ a.timingFunction = Self.closeCurve
+ a.fillMode = .both
+ a.isRemovedOnCompletion = false
+ layer.add(a, forKey: "move")
+ let fade = CABasicAnimation(keyPath: "opacity")
+ fade.fromValue = 1
+ fade.toValue = 0
+ fade.beginTime = now + PeekLayout.closeFadeDelay
+ fade.duration = PeekLayout.closeFadeDuration
+ fade.timingFunction = CAMediaTimingFunction(name: .easeOut)
+ fade.fillMode = .backwards
+ layer.add(fade, forKey: "fade")
+ layer.opacity = 0
+ }
+ CATransaction.commit()
+ }
+
+ func remove() {
+ panel.parent?.removeChildWindow(panel)
+ panel.orderOut(nil)
+ }
+
+ /// A view's own drawing at its window's scale (the layer tree: Cra's views, not a page
+ /// window), with `page` drawn over `pageRect` (the view's coordinates, y up) when given.
+ static func picture(of view: NSView, page: CGImage? = nil, pageRect: NSRect = .zero) -> CGImage? {
+ view.layoutSubtreeIfNeeded()
+ view.displayIfNeeded()
+ guard let layer = view.layer else { return nil }
+ let scale = view.window?.backingScaleFactor ?? 2
+ let w = Int(view.bounds.width * scale), h = Int(view.bounds.height * scale)
+ guard w > 0, h > 0, let ctx = CGContext(data: nil, width: w, height: h, bitsPerComponent: 8, bytesPerRow: 0,
+ space: CGColorSpace(name: CGColorSpace.sRGB)!,
+ bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else { return nil }
+ ctx.scaleBy(x: scale, y: scale)
+ ctx.saveGState()
+ if layer.isGeometryFlipped || view.isFlipped {
+ ctx.translateBy(x: 0, y: view.bounds.height)
+ ctx.scaleBy(x: 1, y: -1)
+ }
+ layer.render(in: ctx)
+ ctx.restoreGState()
+ if let page { ctx.draw(page, in: pageRect) }
+ return ctx.makeImage()
+ }
+}
diff --git a/Sources/CraCEF/CraCEF.mm b/Sources/CraCEF/CraCEF.mm
index 24247ea..d72ccf9 100644
--- a/Sources/CraCEF/CraCEF.mm
+++ b/Sources/CraCEF/CraCEF.mm
@@ -1201,9 +1201,10 @@ public:
// A target=_blank link the user clicked (Shift-clicked: a new window) may open in a
// Peek; window.open with features (a sign-in popup) is CEF_WOD_NEW_POPUP and stays one.
if (user_gesture && (target_disposition == CEF_WOD_NEW_FOREGROUND_TAB || target_disposition == CEF_WOD_NEW_WINDOW)
- && [o.delegate respondsToSelector:@selector(browser:opensPeekForURL:shiftClick:)]
+ && [o.delegate respondsToSelector:@selector(browser:opensPeekForURL:shiftClick:newTab:)]
&& [o.delegate browser:o opensPeekForURL:NSStringFromCef(target_url)
- shiftClick:target_disposition == CEF_WOD_NEW_WINDOW]) return true;
+ shiftClick:target_disposition == CEF_WOD_NEW_WINDOW
+ newTab:target_disposition == CEF_WOD_NEW_FOREGROUND_TAB]) return true;
BOOL background = (target_disposition == CEF_WOD_NEW_BACKGROUND_TAB);
CraBrowser* host = [o.delegate browser:o popupHostForURL:NSStringFromCef(target_url) inBackground:background];
if (!host) return true; // blocked
@@ -1477,8 +1478,8 @@ public:
if (!user_gesture || is_redirect) return false;
cef_transition_type_t tt = request->GetTransitionType();
if ((tt & TT_SOURCE_MASK) != TT_LINK || (tt & TT_FORWARD_BACK_FLAG)) return false;
- if (![o.delegate respondsToSelector:@selector(browser:opensPeekForURL:shiftClick:)]) return false;
- return [o.delegate browser:o opensPeekForURL:NSStringFromCef(request->GetURL()) shiftClick:NO];
+ if (![o.delegate respondsToSelector:@selector(browser:opensPeekForURL:shiftClick:newTab:)]) return false;
+ return [o.delegate browser:o opensPeekForURL:NSStringFromCef(request->GetURL()) shiftClick:NO newTab:NO];
}
bool OnOpenURLFromTab(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& target_url,
@@ -1487,8 +1488,8 @@ public:
if (!o) return false;
// Shift-click (Chrome: a new window).
if (user_gesture && target_disposition == CEF_WOD_NEW_WINDOW
- && [o.delegate respondsToSelector:@selector(browser:opensPeekForURL:shiftClick:)]
- && [o.delegate browser:o opensPeekForURL:NSStringFromCef(target_url) shiftClick:YES]) return true;
+ && [o.delegate respondsToSelector:@selector(browser:opensPeekForURL:shiftClick:newTab:)]
+ && [o.delegate browser:o opensPeekForURL:NSStringFromCef(target_url) shiftClick:YES newTab:NO]) return true;
BOOL background = (target_disposition == CEF_WOD_NEW_BACKGROUND_TAB);
[o.delegate browser:o requestsNewTabWithURL:NSStringFromCef(target_url) inBackground:background];
return true;
diff --git a/Sources/CraCEF/include/CraCEF.h b/Sources/CraCEF/include/CraCEF.h
index bfc70d3..cc0389c 100644
--- a/Sources/CraCEF/include/CraCEF.h
+++ b/Sources/CraCEF/include/CraCEF.h
@@ -110,7 +110,7 @@ typedef NS_ENUM(NSInteger, CraDownloadState) {
/// Arc's Peek: a link the user clicked (`shiftClick` NO: before it navigates the page or
/// opens as a target=_blank tab) or Shift-clicked (YES, instead of a new window). Return
/// YES to show it in a Peek; the page then stays where it is.
-- (BOOL)browser:(CraBrowser *)browser opensPeekForURL:(NSString *)url shiftClick:(BOOL)shiftClick;
+- (BOOL)browser:(CraBrowser *)browser opensPeekForURL:(NSString *)url shiftClick:(BOOL)shiftClick newTab:(BOOL)newTab;
/// The DevTools frontend shows `panel` ("elements", "console", "network", …): on load, and
/// on every switch, from Cra or the frontend's own tab bar.
- (void)browser:(CraBrowser *)browser devToolsShowsPanel:(NSString *)panel;
diff --git a/Tests/BrowserManagerLifecycleTests.swift b/Tests/BrowserManagerLifecycleTests.swift
index fee4acf..ae74657 100644
--- a/Tests/BrowserManagerLifecycleTests.swift
+++ b/Tests/BrowserManagerLifecycleTests.swift
@@ -749,5 +749,5 @@ private final class Observer: BrowserManagerDelegate {
activatedTabs.append(tabID)
activatedByPage.append(byPage)
}
- func browserManagerOpensPeek(url: String, fromTab tabID: UUID, pageURL: String, shiftClick: Bool) -> Bool { false }
+ func browserManagerOpensPeek(url: String, fromTab tabID: UUID, pageURL: String, shiftClick: Bool, newTab: Bool) -> Bool { false }
}
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index a5d0077..2e2a527 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -2753,7 +2753,30 @@ event with `shiftClickModalEntryPointEnabled` set for the run, AX frames and 60
31 × 27). The toast is 195 × 47 pt: text 13 pt in, 14.5 pt to a 29 × 27 pt button 13 pt from the end, 10 pt from
top and bottom. The button is a white wash over the pill (≈ 60 % on the light toast, 15 % on Little Arc's dark
one) with an outline. A click opens the macOS share menu (AirDrop, Notes…) from the button; the toast stays.
+- [O] The motion, frame by frame at 60 fps (card edges on one row, the card's and the page's luminance): opening,
+ the card's opacity reaches 1 in ~0.075 s, and its scale goes from the whole area (1.25, centred) to 1 on an
+ ease-out cubic over ~0.205 s (scale − 1 per frame: .168, .127, .092, .063, .041, .025, .015, .008, .002). The
+ buttons appear with it and ride its top-right corner. The page fades on an ease-out cubic over ~0.18 s.
+ Closing: the card grows to ~1.19 in ~0.09 s (near linear), fading from ~0.07 s, gone by ~0.16 s; the page is
+ back after ~0.2 s.
+- Cra draws the motion on Core Animation (PeekTransition): pictures of the card (with Chromium's screenshot of
+ the page when closing) and of the buttons in a panel over the window, the real card and buttons invisible at
+ their places until it lands. Animating the windows' frames (the first version) resized and laid out the card
+ and its page window on every frame and stuttered; Chromium also sets its page window's alpha back to 1 as it
+ shows it, so the page waits hidden (contentView.isHidden), not transparent.
- Cra: PeekLayout (CraCore) has the geometry; PeekBarView and PeekControlsPanel (PeekChrome.swift) the card's bar
and the buttons; MainWindowController.setPeekVeil fades the page; ShinyToast.Action.share the button.
+- [O, 4 Nov] Which links peek, with both Links settings on (`modalEnabled` and
+ `shiftClickModalEntryPointEnabled` set for the run, the sidebar reset before each run), HID clicks on a
+ lab page at 127.0.0.1 in a pinned tab: a link to localhost peeked, plain or target=_blank; a link to
+ 127.0.0.1 loaded in the tab, but with target=_blank it peeked, and so did window.open to localhost; a
+ ⌘-click opened a background Today tab. A Shift-click peeked, same host or not, also from a Today tab.
+ With `modalEnabled` unset (Victor's defaults) the pinned tab's link to localhost opened a new tab.
+ Cra: PeekTrigger (CraCore).
+- [O] Inside the Peek, links to either host loaded in the Peek. A click on another sidebar row closed the
+ Peek and opened that tab. ⌘W closed it, and ⇧⌘T right after brought the Peek back over the pinned tab.
+ ⌘O and Expand made it a tab at the top of Today. Add To Split from the pinned tab left the pinned tab
+ where it was and put a new split at the top of Today: a copy of the pinned page ("Lab") on the left,
+ the peeked page on the right. Cra: MainWindowController.closedPeek, LittleWindowController.promoteToSplit.
- [?] Not measured: the card at other window widths (Cra keeps 80 % of the area), and the Peek with Arc's
toolbar turned off.