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.

A test hook opens a menu without the pointer (cra://debug?menuAt=x,y) (#114)

Victor Kildahl1903f652c551
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swift
index 5c97f03..c415b4a 100644
--- a/Sources/Cra/App/AppDelegate.swift
+++ b/Sources/Cra/App/AppDelegate.swift
@@ -499,6 +499,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
TestGesture.scroll(by: g[0], steps: Int(g[1]), at: NSPoint(x: g[2], y: w.frame.height - g[3]), in: w)
return
}
+ // menuAt=x,y (&button=right): the menu a click there opens, e.g. the ⌄ or a row's (#89).
+ if let g = dict["menuAt"]?.split(separator: ",").compactMap({ Double($0) }), g.count == 2, let w = main.window {
+ TestGesture.openMenu(at: NSPoint(x: g[0], y: w.frame.height - g[1]), in: w, right: dict["button"] == "right")
+ return
+ }
if let st = dict["status"] { main.browserManager(statusMessage: st); return }
// Scenario hooks (scripts/scenario.sh): what a journey needs without a pointer.
if dict["checkStore"] != nil { logSidebarProblems(); return }
diff --git a/Sources/Cra/Services/TestGesture.swift b/Sources/Cra/Services/TestGesture.swift
index f29df87..61d6a1e 100644
--- a/Sources/Cra/Services/TestGesture.swift
+++ b/Sources/Cra/Services/TestGesture.swift
@@ -18,4 +18,32 @@ enum TestGesture {
}
}
}
+
+ /// Opens the menu a click (or a right-click) at a point of the window would open, without
+ /// the pointer: the hit view gets the mouse-down, or the nearest view with a menu(for:)
+ /// pops its menu. The menu tracks until Esc or a pick, so tests read it through AX.
+ static func openMenu(at point: NSPoint, in window: NSWindow, right: Bool) {
+ guard let root = window.contentView?.superview, let hit = root.hitTest(point) else { NSLog("Cra TestGesture: nothing at the point"); return }
+ guard let event = NSEvent.mouseEvent(with: right ? .rightMouseDown : .leftMouseDown, location: point, modifierFlags: [],
+ timestamp: ProcessInfo.processInfo.systemUptime, windowNumber: window.windowNumber,
+ context: nil, eventNumber: 0, clickCount: 1, pressure: 1) else { return }
+ // After this command returns: the menu's tracking loop would hold it.
+ DispatchQueue.main.async {
+ guard right else {
+ // Buttons act on the mouse-up; the ⌄'s menu has already closed by then.
+ hit.mouseDown(with: event)
+ if let up = NSEvent.mouseEvent(with: .leftMouseUp, location: point, modifierFlags: [], timestamp: ProcessInfo.processInfo.systemUptime,
+ windowNumber: window.windowNumber, context: nil, eventNumber: 0, clickCount: 1, pressure: 0) {
+ hit.mouseUp(with: up)
+ }
+ return
+ }
+ var view: NSView? = hit
+ while let v = view {
+ if let menu = v.menu(for: event) { NSMenu.popUpContextMenu(menu, with: event, for: v); return }
+ view = v.superview
+ }
+ NSLog("Cra TestGesture: no menu at the point")
+ }
+ }
}
diff --git a/docs/development.md b/docs/development.md
index 0310a45..12c59f4 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -138,6 +138,14 @@ swipe (22 trackpad samples of 14 pt) and `cra://debug?scroll=30,30,150,700` scro
scroll view at x 150, y 700 of the window (from its top left) 30 pt a frame for 30 frames.
Measure them with `sample <pid> 6 1` and compare the main thread's busy time between builds.
+`cra://debug?menuAt=315,24` opens the menu a click at that window point would open (the
+developer-mode ⌄ here), and `&button=right` the context menu, a tab row's for instance.
+Posted mouse events don't reach Cra's views and the rows have no AX menu action, so this is
+the way to check a menu without the pointer. The menu shows up on screen. While it's open,
+it is an AXMenu child of the app: each item's `AXMenuItemCmdChar`, `AXMenuItemCmdModifiers`
+and `AXMenuItemMarkChar` give its shortcut and checkmark, and AXCancel closes it (a posted
+Esc doesn't). The first menu after a launch can close before AX sees it, so open it again.
+
The sidebar's tab list and space pager are AppKit (`UI/Sidebar/List`): rows are plain
layer-backed views rebuilt from the store when it changes, a swipe moves the pager's layers
and the window tint (`PagedGradientView`) in Core Animation, and SwiftUI keeps the favorites,