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.

Why? opens the Site Control Center from its sliders button

Victord002f4c2c060
diff --git a/Sources/Cra/UI/PaneToolbarView.swift b/Sources/Cra/UI/PaneToolbarView.swift
index 844e185..ee3cf9d 100644
--- a/Sources/Cra/UI/PaneToolbarView.swift
+++ b/Sources/Cra/UI/PaneToolbarView.swift
@@ -222,8 +222,13 @@ final class PaneToolbarView: NSView {
}
/// A pinned extension's button (screen rect), for popups opened from the menu bar or a shortcut.
- func extensionButtonFrameOnScreen(_ id: String) -> NSRect? {
- guard let b = buttons["ext:" + id], !b.isHiddenOrHasHiddenAncestor, let window else { return nil }
+ func extensionButtonFrameOnScreen(_ id: String) -> NSRect? { buttonFrameOnScreen("ext:" + id) }
+
+ /// The sliders button (screen rect), for the Site Control Center opened from elsewhere (a toast's Why?).
+ func siteControlsButtonFrameOnScreen() -> NSRect? { buttonFrameOnScreen("extensions") }
+
+ private func buttonFrameOnScreen(_ key: String) -> NSRect? {
+ guard let b = buttons[key], !b.isHiddenOrHasHiddenAncestor, b.frame.width > 0, let window else { return nil }
return window.convertToScreen(b.convert(b.bounds, to: nil))
}
diff --git a/Sources/Cra/UI/Sidebar/List/SidebarView.swift b/Sources/Cra/UI/Sidebar/List/SidebarView.swift
index f90fa32..384d024 100644
--- a/Sources/Cra/UI/Sidebar/List/SidebarView.swift
+++ b/Sources/Cra/UI/Sidebar/List/SidebarView.swift
@@ -11,6 +11,9 @@ final class SidebarView: NSView {
private let favicons: FaviconCache
private let tabs = FlippedView()
private let topBar: SidebarTopBarView
+
+ /// The URL field's sliders button (screen rect), nil while the toolbar has it.
+ var siteControlsButtonFrameOnScreen: NSRect? { topBar.siteControlsButtonFrameOnScreen }
private let pager: SpacePagerView
private let trayHost: DownloadsTrayView
private let player: NowPlayingTrayView
@@ -302,6 +305,14 @@ final class SidebarTopBarView: NSView {
private var rowButtons: [SidebarGlyphButton] = []
private var chevron: NSView?
private let pill = SidebarURLPill()
+
+ /// Where the URL field's sliders button is or appears on hover (screen rect): its last
+ /// accessory, 28 pt ending 5 pt in. nil while the field isn't shown (the toolbar has it).
+ var siteControlsButtonFrameOnScreen: NSRect? {
+ guard !pill.isHiddenOrHasHiddenAncestor, let window else { return nil }
+ let f = window.convertToScreen(pill.convert(pill.bounds, to: nil))
+ return NSRect(x: f.maxX - 5 - 28, y: f.minY + (f.height - 28) / 2, width: 28, height: 28)
+ }
private var hoverHeader = false { didSet { if hoverHeader != oldValue { pill.showAccessories = hoverHeader } } }
private var syncQueued = false
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index cadbcf1..6ad1089 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -2295,13 +2295,24 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
/// Arc's sliders button (toolbar and URL pill): the Site Control Center, hung under the
/// button that was clicked (buttons are 32 × 28), not wherever the pointer is in it.
- private func showToolbarExtensionsMenu() {
+ /// The Site Control Center as if its sliders button was clicked, wherever the request came from
+ /// (the protected media toast's Why?): under the toolbar's button, else under the sidebar's URL
+ /// field at its right end, where that button sits. The arrow shows where to find it next time.
+ private func showSiteControlsFromTheirButton() {
+ if let button = (shell.focusedCard?.toolbarHost as? PaneToolbarView)?.siteControlsButtonFrameOnScreen() {
+ return showToolbarExtensionsMenu(from: button, inToolbar: true)
+ }
+ guard let button = (shell.sidebarHost as? SidebarView)?.siteControlsButtonFrameOnScreen else { return showToolbarExtensionsMenu() }
+ showToolbarExtensionsMenu(from: button, inToolbar: false)
+ }
+
+ private func showToolbarExtensionsMenu(from anchor: NSRect? = nil, inToolbar: Bool = false) {
// A split pane's bar has the sliders even with the toolbar hidden: hang under that bar then.
- let pressed = Self.buttonFrameUnderPointer { $0 is ToolbarGlyphButton }
+ let pressed = anchor.map { inToolbar ? $0 : nil } ?? Self.buttonFrameUnderPointer { $0 is ToolbarGlyphButton }
guard let window, let content = window.contentView,
let y = pressed != nil && shell.panesShowBars ? toolbarBottomOnScreen()?.y : urlBarBottomOnScreen() else { return }
ExtensionStore.shared.reload()
- let midX = (pressed ?? Self.buttonFrameUnderPointer { $0 is SidebarGlyphButton })?.midX ?? NSEvent.mouseLocation.x
+ let midX = (anchor ?? pressed ?? Self.buttonFrameUnderPointer { $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: midX - 16, y: y + 4, width: 32, height: 28)
let rect = content.convert(window.convertFromScreen(onScreen), from: nil)
@@ -2653,7 +2664,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
return
}
self.showToast("\(service) plays with Safari's engine",
- action: ShinyToast.Action(title: "Why?") { [weak self] in self?.showToolbarExtensionsMenu() })
+ action: ShinyToast.Action(title: "Why?") { [weak self] in self?.showSiteControlsFromTheirButton() })
}
}