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.
A click that takes focus from an extension popup only closes it (#87) (#104)
Victor Kildahl7704decee3ea
diff --git a/Packages/CraCore/Sources/CraCore/FirstClick.swift b/Packages/CraCore/Sources/CraCore/FirstClick.swiftnew file mode 100644index 0000000..9a8bad0--- /dev/null+++ b/Packages/CraCore/Sources/CraCore/FirstClick.swift@@ -0,0 +1,18 @@+import Foundation++/// Whether a button in Cra's window acts on the click that makes the window key (AppKit's+/// acceptsFirstMouse; a click it does not hand over only gives the window focus).+///+/// DevTools and the page are Chromium child windows of the main window. Chrome draws all of it+/// in one window, so after a click in them the next click on a toolbar button counts (GitHub+/// #42). An extension's popup is a child window too, but like Arc's it takes focus (the window+/// greys out), and Arc 1.170's toolbar then only takes focus back, which closes the popup: its+/// own button does not open it again, and another extension's button or Split View needs a+/// second click (GitHub #87). A click into an inactive Cra only activates it.+public enum FirstClick {+ /// `focusInWindow`: the key window is this window or one of its child windows.+ /// `closedPopup`: this mouse-down took focus from an extension's popup.+ public static func takes(appActive: Bool, focusInWindow: Bool, closedPopup: Bool) -> Bool {+ appActive && focusInWindow && !closedPopup+ }+}diff --git a/Packages/CraCore/Tests/CraCoreTests/FirstClickTests.swift b/Packages/CraCore/Tests/CraCoreTests/FirstClickTests.swiftnew file mode 100644index 0000000..75d81ee--- /dev/null+++ b/Packages/CraCore/Tests/CraCoreTests/FirstClickTests.swift@@ -0,0 +1,21 @@+import CraCore+import Testing++/// Which clicks the browser window's buttons take while focus is somewhere else.+struct FirstClickTests {+ /// After a click in DevTools or the page, one click on a toolbar button counts (GitHub #42).+ @Test func focusInTheWindowOrItsChildren() {+ #expect(FirstClick.takes(appActive: true, focusInWindow: true, closedPopup: false))+ }++ /// The click that takes focus from an extension's popup only closes it, as in Arc: the+ /// popup's own button does not open it again (GitHub #87).+ @Test func closingAPopupIsAllTheClickDoes() {+ #expect(!FirstClick.takes(appActive: true, focusInWindow: true, closedPopup: true))+ }++ @Test func otherwiseTheClickOnlyFocuses() {+ #expect(!FirstClick.takes(appActive: false, focusInWindow: true, closedPopup: false))+ #expect(!FirstClick.takes(appActive: true, focusInWindow: false, closedPopup: false))+ }+}diff --git a/Sources/Cra/UI/AppKitControls.swift b/Sources/Cra/UI/AppKitControls.swiftindex e270384..f8c4e75 100644--- a/Sources/Cra/UI/AppKitControls.swift+++ b/Sources/Cra/UI/AppKitControls.swift@@ -67,9 +67,11 @@ extension NSView {/// 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.+ /// window or its children; a click into an inactive Cra still only activates it, and one that+ /// takes focus from an extension's popup only closes the popup (GitHub #87). See FirstClick.var takesClickFromChildWindow: Bool {- guard NSApp.isActive, let window, let key = NSApp.keyWindow else { return false }- return key === window || key.parent === window+ guard let window, let key = NSApp.keyWindow else { return false }+ return FirstClick.takes(appActive: NSApp.isActive, focusInWindow: key === window || key.parent === window,+ closedPopup: ExtensionPopupWindow.closed(by: NSApp.currentEvent))}}diff --git a/Sources/Cra/UI/Windows/ExtensionPopupWindow.swift b/Sources/Cra/UI/Windows/ExtensionPopupWindow.swiftindex 2f311ce..a9f883d 100644--- a/Sources/Cra/UI/Windows/ExtensionPopupWindow.swift+++ b/Sources/Cra/UI/Windows/ExtensionPopupWindow.swift@@ -19,6 +19,8 @@ final class ExtensionPopupWindow: NSWindow {private static let savedOffsetKey = "extensionPopupWindowOffset"private static var current: ExtensionPopupWindow?+ /// When the mouse-down that closed the last popup happened (event time), if one did.+ private static var closingClick: TimeInterval?private weak var bubble: NSWindow?/// The top-right point (screen) the popup hangs from: right edge of its button, under the bar.@@ -176,7 +178,15 @@ final class ExtensionPopupWindow: NSWindow {override func performClose(_ sender: Any?) { dismiss(closingBubble: true) }override func close() { dismiss(closingBubble: true) }+ /// `event` is the mouse-down that took focus from a popup, closing it. AppKit makes the+ /// clicked window key before it asks the view whether it takes that click.+ static func closed(by event: NSEvent?) -> Bool {+ guard let event, event.type == .leftMouseDown, let closingClick else { return false }+ return event.timestamp == closingClick+ }+private func dismiss(closingBubble: Bool) {+ if let e = NSApp.currentEvent, e.type == .leftMouseDown { Self.closingClick = e.timestamp }for o in observers { NotificationCenter.default.removeObserver(o) }observers = []if let bubble {diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.mdindex b514263..791b997 100644--- a/docs/arc-reverse-engineering.md+++ b/docs/arc-reverse-engineering.md@@ -1546,6 +1546,13 @@ Arc's popup this time, so geometry is not measured.(plus Boost items).- [O] Extension popup window (user screenshot): ≈472×380 pt titled window, ≈25 pt title bar with a red close button anddisabled minimize/zoom, the popup page filling the rest.+- [O] Clicks while a popup is up (2 Nov 2026, live: HID clicks, CGWindowList sampled every 15 ms, AX focused window;+ Detailed SEO and 1Password pinned): the popup window is key, so the browser window is inactive. A click in the+ normal toolbar only takes focus back, which closes the popup: its own button leaves it closed (nothing reopens+ within 3.5 s), 1Password's button closes Detailed SEO's popup and opens nothing (one plain click opens it), and+ Split View Menu opens no menu (it does on a plain click). The developer bar's Extensions Menu did act on that+ click (popup closed and the Site Control Center opened); its Detailed SEO tile then did nothing on the first+ click. Cra: `FirstClick` (CraCore), GitHub #87. [U] Back/reload/URL: Arc's popup covered them.- Cra: `UI/SiteControlCenter.swift` (same geometry; Cra's popover lands at Arc's exact screen coordinates), thesecond action is Copy URL (no Boosts), Capture = visible page, Capture full page = DevTools`Page.captureScreenshot` with `captureBeyondViewport`; Clear Cookies = `Storage.clearDataForOrigin`, Clear Cache =