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.

Picture in Picture: a click on play plays, edges resize toward the pointer, resize cursors show with another app in front (#134) (#144)

Victor Kildahlcee5df75658b
diff --git a/Packages/CraCore/Sources/CraCore/PictureInPictureGesture.swift b/Packages/CraCore/Sources/CraCore/PictureInPictureGesture.swift
new file mode 100644
index 0000000..32fb17b
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/PictureInPictureGesture.swift
@@ -0,0 +1,90 @@
+import CoreGraphics
+
+/// What a press on the Picture in Picture window does (issue #134): a drag from its middle moves
+/// the window, a drag from an edge or corner resizes it with the video's aspect ratio, and a
+/// press that travels less than `threshold` is a click and moves nothing. Points and frames are
+/// AppKit screen coordinates: origin at the bottom left, y going up.
+public struct PictureInPictureGesture: Sendable {
+ public enum Edge: Sendable, Equatable, CaseIterable {
+ case none, left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight
+
+ var isLeft: Bool { self == .left || self == .topLeft || self == .bottomLeft }
+ var isRight: Bool { self == .right || self == .topRight || self == .bottomRight }
+ var isTop: Bool { self == .top || self == .topLeft || self == .topRight }
+ var isBottom: Bool { self == .bottom || self == .bottomLeft || self == .bottomRight }
+ }
+
+ /// How far in from the window's edge a press resizes.
+ public static let grip: CGFloat = 8
+ /// How far along an edge from a corner a press takes the corner (Chromium's PiP: 16).
+ public static let corner: CGFloat = 16
+ /// How far the pointer travels before a press becomes a drag, the way a click on a normal
+ /// window never nudges it.
+ public static let threshold: CGFloat = 3
+
+ public let edge: Edge
+ public let startMouse: CGPoint
+ public let startFrame: CGRect
+ /// Set once the pointer has gone past `threshold`; the press is a drag from then on.
+ public private(set) var isDragging = false
+
+ /// A press at `mouse` (screen) on a window at `frame`.
+ public init(mouse: CGPoint, frame: CGRect) {
+ startMouse = mouse
+ startFrame = frame
+ edge = Self.edge(at: CGPoint(x: mouse.x - frame.minX, y: mouse.y - frame.minY), in: frame.size)
+ }
+
+ /// The edge or corner a point in the window (origin at its bottom left) is on.
+ public static func edge(at p: CGPoint, in size: CGSize) -> Edge {
+ let onLeft = p.x < grip, onRight = p.x > size.width - grip
+ let onBottom = p.y < grip, onTop = p.y > size.height - grip
+ guard onLeft || onRight || onTop || onBottom else { return .none }
+ let nearLeft = p.x < corner, nearRight = p.x > size.width - corner
+ let nearBottom = p.y < corner, nearTop = p.y > size.height - corner
+ let left = onLeft || ((onTop || onBottom) && nearLeft)
+ let right = onRight || ((onTop || onBottom) && nearRight)
+ let top = onTop || ((onLeft || onRight) && nearTop)
+ let bottom = onBottom || ((onLeft || onRight) && nearBottom)
+ switch (left, right, top, bottom) {
+ case (true, _, true, _): return .topLeft
+ case (_, true, true, _): return .topRight
+ case (true, _, _, true): return .bottomLeft
+ case (_, true, _, true): return .bottomRight
+ case (true, _, _, _): return .left
+ case (_, true, _, _): return .right
+ case (_, _, true, _): return .top
+ default: return .bottom
+ }
+ }
+
+ /// The window's frame with the pointer at `mouse`, or nil while the press is still a click.
+ /// A resize keeps the edge or corner opposite the grabbed one where it was (both sides keep
+ /// the top, the top and bottom keep the left) and stays between `minSize` and `maxSize`.
+ public mutating func frame(mouse: CGPoint, minSize: CGSize, maxSize: CGSize) -> CGRect? {
+ let dx = mouse.x - startMouse.x, dy = mouse.y - startMouse.y
+ if !isDragging {
+ guard hypot(dx, dy) >= Self.threshold else { return nil }
+ isDragging = true
+ }
+ let s = startFrame
+ if edge == .none { return s.offsetBy(dx: dx, dy: dy) }
+
+ let aspect = s.width / max(s.height, 1)
+ let byX = s.width + (edge.isRight ? dx : edge.isLeft ? -dx : 0)
+ let byY = (s.height + (edge.isTop ? dy : edge.isBottom ? -dy : 0)) * aspect
+ var w: CGFloat
+ switch edge {
+ case .left, .right: w = byX
+ case .top, .bottom: w = byY
+ default: w = max(byX, byY) // a corner follows whichever way the pointer went further
+ }
+ let lo = max(minSize.width, minSize.height * aspect)
+ let hi = min(maxSize.width, maxSize.height * aspect)
+ w = max(lo, min(w, max(lo, hi))).rounded()
+ let h = (w / aspect).rounded()
+ let x = edge.isLeft ? s.maxX - w : s.minX
+ let y = edge.isTop ? s.minY : s.maxY - h
+ return CGRect(x: x, y: y, width: w, height: h)
+ }
+}
diff --git a/Packages/CraCore/Tests/CraCoreTests/PictureInPictureGestureTests.swift b/Packages/CraCore/Tests/CraCoreTests/PictureInPictureGestureTests.swift
new file mode 100644
index 0000000..a1e3523
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/PictureInPictureGestureTests.swift
@@ -0,0 +1,90 @@
+import CoreGraphics
+import CraCore
+import Testing
+
+/// A press on the Picture in Picture window: click, move or aspect-locked resize (issue #134).
+struct PictureInPictureGestureTests {
+ /// Arc's 16:9 window, 782×440.
+ private let window = CGRect(x: 900, y: 600, width: 782, height: 440)
+ private let minSize = CGSize(width: 284, height: 160)
+ private let maxSize = CGSize(width: 1382, height: 867)
+
+ /// A press at `x, y` in the window (from its bottom left) dragged by `dx, dy`.
+ private func drag(at x: CGFloat, _ y: CGFloat, by dx: CGFloat, _ dy: CGFloat) -> (PictureInPictureGesture.Edge, CGRect?) {
+ let start = CGPoint(x: window.minX + x, y: window.minY + y)
+ var gesture = PictureInPictureGesture(mouse: start, frame: window)
+ return (gesture.edge, gesture.frame(mouse: CGPoint(x: start.x + dx, y: start.y + dy), minSize: minSize, maxSize: maxSize))
+ }
+
+ @Test func edgesAndCorners() {
+ let size = window.size
+ let expected: [(CGFloat, CGFloat, PictureInPictureGesture.Edge)] = [
+ (391, 220, .none), (100, 30, .none), (2, 220, .left), (780, 220, .right),
+ (391, 438, .top), (391, 2, .bottom), (2, 438, .topLeft), (780, 438, .topRight),
+ (2, 2, .bottomLeft), (780, 2, .bottomRight),
+ // A corner reaches 16 pt along each edge.
+ (12, 438, .topLeft), (2, 428, .topLeft), (770, 2, .bottomRight), (20, 438, .top),
+ ]
+ for (x, y, edge) in expected {
+ #expect(PictureInPictureGesture.edge(at: CGPoint(x: x, y: y), in: size) == edge, "\(x), \(y)")
+ }
+ }
+
+ /// A click carries a little drift; under 3 pt it moves and resizes nothing, from the middle
+ /// or from an edge.
+ @Test func aClickThatDriftsMovesNothing() {
+ #expect(drag(at: 391, 220, by: 2, -2).1 == nil)
+ #expect(drag(at: 780, 2, by: 2, -2).1 == nil)
+ #expect(drag(at: 391, 220, by: 3, 0).1 == window.offsetBy(dx: 3, dy: 0))
+ }
+
+ /// Past the threshold the press stays a drag, even back near where it started.
+ @Test func aDragStaysADrag() {
+ let start = CGPoint(x: window.midX, y: window.midY)
+ var gesture = PictureInPictureGesture(mouse: start, frame: window)
+ #expect(gesture.frame(mouse: CGPoint(x: start.x + 1, y: start.y), minSize: minSize, maxSize: maxSize) == nil)
+ #expect(gesture.frame(mouse: CGPoint(x: start.x + 10, y: start.y), minSize: minSize, maxSize: maxSize) != nil)
+ #expect(gesture.isDragging)
+ #expect(gesture.frame(mouse: CGPoint(x: start.x + 1, y: start.y), minSize: minSize, maxSize: maxSize) == window.offsetBy(dx: 1, dy: 0))
+ }
+
+ @Test func theMiddleMovesTheWindow() {
+ #expect(drag(at: 391, 220, by: -40, 25).1 == window.offsetBy(dx: -40, dy: 25))
+ }
+
+ /// Each edge and corner grows the window toward the pointer and keeps the opposite one put,
+ /// so the grabbed edge stays under the pointer.
+ @Test func resizeKeepsTheOppositeSideFixed() throws {
+ // 16:9, 782 → 960 wide is 540 high.
+ let cases: [(CGFloat, CGFloat, CGFloat, CGFloat, (CGRect) -> Bool)] = [
+ (780, 220, 178, 0, { $0.minX == window.minX && $0.maxY == window.maxY }), // right
+ (2, 220, -178, 0, { $0.maxX == window.maxX && $0.maxY == window.maxY }), // left
+ (391, 438, 0, 100, { $0.minY == window.minY && $0.minX == window.minX }), // top
+ (391, 2, 0, -100, { $0.maxY == window.maxY && $0.minX == window.minX }), // bottom
+ (780, 438, 178, 100, { $0.minX == window.minX && $0.minY == window.minY }), // top right
+ (2, 438, -178, 100, { $0.maxX == window.maxX && $0.minY == window.minY }), // top left
+ (780, 2, 178, -100, { $0.minX == window.minX && $0.maxY == window.maxY }), // bottom right
+ (2, 2, -178, -100, { $0.maxX == window.maxX && $0.maxY == window.maxY }), // bottom left
+ ]
+ for (x, y, dx, dy, anchored) in cases {
+ let (edge, frame) = drag(at: x, y, by: dx, dy)
+ let f = try #require(frame, "\(edge)")
+ #expect(f.width == 960 && f.height == 540, "\(edge): \(f)")
+ #expect(anchored(f), "\(edge): \(f)")
+ }
+ }
+
+ @Test func aCornerFollowsTheLongerWay() throws {
+ // Mostly down on the bottom-right corner: the height leads.
+ let f = try #require(drag(at: 780, 2, by: 10, -100).1)
+ #expect(f.height == 540 && f.width == 960)
+ }
+
+ @Test func resizeStaysWithinTheLimits() throws {
+ let small = try #require(drag(at: 780, 220, by: -700, 0).1)
+ #expect(small.width == 284 && small.height == 160)
+ let big = try #require(drag(at: 780, 220, by: 2000, 0).1)
+ #expect(big.width == 1382 && big.height == 778)
+ #expect(big.maxY == window.maxY)
+ }
+}
diff --git a/Sources/Cra/UI/PictureInPicture/PictureInPictureChrome.swift b/Sources/Cra/UI/PictureInPicture/PictureInPictureChrome.swift
index 9b9707d..113385b 100644
--- a/Sources/Cra/UI/PictureInPicture/PictureInPictureChrome.swift
+++ b/Sources/Cra/UI/PictureInPicture/PictureInPictureChrome.swift
@@ -173,90 +173,157 @@ final class PictureInPictureOverlay: NSWindow {
}
final class PictureInPictureOverlayView: NSView {
- private enum Edge { case none, left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight }
- private static let grip: CGFloat = 8
- private var edge: Edge = .none
- private var startMouse: NSPoint = .zero
- private var startFrame: NSRect = .zero
+ private typealias Edge = PictureInPictureGesture.Edge
+ private var gesture: PictureInPictureGesture?
+ private var requested: NSRect?
private var target: NSWindow? { window?.parent }
override var mouseDownCanMoveWindow: Bool { false }
override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
- override func resetCursorRects() {
- let g = Self.grip
- let b = bounds
- addCursorRect(NSRect(x: b.minX, y: b.minY + g, width: g, height: b.height - 2 * g), cursor: .resizeLeftRight)
- addCursorRect(NSRect(x: b.maxX - g, y: b.minY + g, width: g, height: b.height - 2 * g), cursor: .resizeLeftRight)
- addCursorRect(NSRect(x: b.minX + g, y: b.maxY - g, width: b.width - 2 * g, height: g), cursor: .resizeUpDown)
- addCursorRect(NSRect(x: b.minX + g, y: b.minY, width: b.width - 2 * g, height: g), cursor: .resizeUpDown)
+ // The cursor follows the same edge zones as a press. Cursor rects don't do: AppKit applies
+ // them to a key window, and this one never becomes key, so corners came and went (#134).
+ // While the pointer is over the window Cra may set it from the background as well, so the
+ // resize cursor shows with another app in front, as it does over any window's edge.
+ override func updateTrackingAreas() {
+ super.updateTrackingAreas()
+ for t in trackingAreas { removeTrackingArea(t) }
+ addTrackingArea(NSTrackingArea(rect: .zero, options: [.cursorUpdate, .mouseMoved, .mouseEnteredAndExited, .activeAlways, .inVisibleRect], owner: self))
}
- private func edge(at p: NSPoint) -> Edge {
- let g = Self.grip
- let l = p.x < g, r = p.x > bounds.maxX - g, t = p.y > bounds.maxY - g, bt = p.y < g
- switch (l, r, t, bt) {
- case (true, _, true, _): return .topLeft
- case (_, true, true, _): return .topRight
- case (true, _, _, true): return .bottomLeft
- case (_, true, _, true): return .bottomRight
- case (true, _, _, _): return .left
- case (_, true, _, _): return .right
- case (_, _, true, _): return .top
- case (_, _, _, true): return .bottom
- default: return .none
+ private func updateCursor(_ event: NSEvent) {
+ guard gesture == nil else { return }
+ let edge = PictureInPictureGesture.edge(at: convert(event.locationInWindow, from: nil), in: bounds.size)
+ (edge == .none ? NSCursor.arrow : Self.cursor(edge)).set()
+ }
+
+ override func cursorUpdate(with event: NSEvent) { updateCursor(event) }
+ override func mouseEntered(with event: NSEvent) {
+ BackgroundCursor.allow(true)
+ updateCursor(event)
+ }
+ override func mouseExited(with event: NSEvent) {
+ guard gesture == nil else { return }
+ NSCursor.arrow.set()
+ BackgroundCursor.allow(false)
+ }
+ override func viewWillMove(toWindow newWindow: NSWindow?) {
+ if newWindow == nil { BackgroundCursor.allow(false) }
+ }
+
+ /// The resize cursor for an edge or corner; AppKit has diagonal ones from macOS 15.
+ private static func cursor(_ edge: Edge) -> NSCursor {
+ if #available(macOS 15, *) {
+ let position: NSCursor.FrameResizePosition = switch edge {
+ case .left: .left
+ case .right: .right
+ case .top: .top
+ case .bottom: .bottom
+ case .topLeft: .topLeft
+ case .topRight: .topRight
+ case .bottomLeft: .bottomLeft
+ case .bottomRight, .none: .bottomRight
+ }
+ return .frameResize(position: position, directions: .all)
}
+ return edge == .top || edge == .bottom ? .resizeUpDown : .resizeLeftRight
}
override func mouseDown(with event: NSEvent) {
- guard let target else { return }
- edge = edge(at: convert(event.locationInWindow, from: nil))
- startMouse = NSEvent.mouseLocation
- startFrame = target.frame
+ guard let target else {
+ CraLog.note("pip: overlay has no parent window")
+ return
+ }
+ gesture = PictureInPictureGesture(mouse: Self.screenLocation(of: event), frame: target.frame)
}
override func mouseDragged(with event: NSEvent) {
- guard let target else { return }
- let m = NSEvent.mouseLocation
- let dx = m.x - startMouse.x, dy = m.y - startMouse.y
- if edge == .none {
- target.setFrameOrigin(NSPoint(x: startFrame.minX + dx, y: startFrame.minY + dy))
- return
+ guard let target, var g = gesture else { return }
+ // The button was let go without a mouse-up reaching this window.
+ if NSEvent.pressedMouseButtons & 1 == 0 { finish(event); return }
+ let constraints = target.contentMaxSize
+ let visible = target.screen?.visibleFrame.size ?? constraints
+ let maxSize = NSSize(width: min(constraints.width, visible.width - 2 * PictureInPictureChrome.edgeMargin),
+ height: min(constraints.height, visible.height - 2 * PictureInPictureChrome.edgeMargin))
+ let minSize = NSSize(width: max(target.contentMinSize.width, 160), height: max(target.contentMinSize.height, 90))
+ let wasDragging = g.isDragging
+ let frame = g.frame(mouse: Self.screenLocation(of: event), minSize: minSize, maxSize: maxSize)
+ gesture = g
+ guard let frame else { return }
+ if !wasDragging { CraLog.note(g.edge == .none ? "pip: move" : "pip: resize \(g.edge) from \(Self.size(g.startFrame))") }
+ if g.edge == .none {
+ target.setFrameOrigin(frame.origin)
+ } else {
+ // Cursor rects only describe the pointer before the press; keep the resize cursor
+ // for the whole drag, also when the pointer runs ahead of the edge.
+ Self.cursor(g.edge).set()
+ requested = frame
+ target.setFrame(frame, display: true)
}
- // Aspect-locked resize anchored on the opposite edge/corner.
- let aspect = startFrame.width / max(startFrame.height, 1)
- var w = startFrame.width
- switch edge {
- case .right, .topRight, .bottomRight: w = startFrame.width + dx
- case .left, .topLeft, .bottomLeft: w = startFrame.width - dx
- case .top: w = (startFrame.height + dy) * aspect
- case .bottom: w = (startFrame.height - dy) * aspect
- case .none: break
+ }
+
+ override func mouseUp(with event: NSEvent) { finish(event) }
+
+ private func finish(_ event: NSEvent) {
+ guard let target, let g = gesture else { return }
+ gesture = nil
+ if let window, !window.frame.contains(NSEvent.mouseLocation) {
+ // Let go outside the window: its exit came during the drag.
+ NSCursor.arrow.set()
+ BackgroundCursor.allow(false)
+ } else {
+ updateCursor(event)
}
- w = max(160, min(w, (target.screen?.visibleFrame.width ?? 2000) - 2 * PictureInPictureChrome.edgeMargin))
- let h = w / aspect
- var f = startFrame
- f.size = NSSize(width: w, height: h)
- switch edge {
- case .left, .bottomLeft: f.origin.x = startFrame.maxX - w
- case .topLeft: f.origin = NSPoint(x: startFrame.maxX - w, y: startFrame.maxY - h)
- case .topRight, .top: f.origin.y = startFrame.maxY - h
- default: break
+ guard g.isDragging else { return }
+ if g.edge != .none {
+ // Chromium owns the window's bounds; say so if it kept another size than the one asked.
+ let asked = requested.map { $0.size == target.frame.size ? "" : " (asked \(Self.size($0)))" } ?? ""
+ CraLog.note("pip: resized \(g.edge) \(Self.size(g.startFrame)) → \(Self.size(target.frame))\(asked)")
+ requested = nil
}
- target.setFrame(f, display: true)
+ PictureInPictureChrome.shared.remember(target.frame)
}
- override func mouseUp(with event: NSEvent) {
- guard let target else { return }
- PictureInPictureChrome.shared.remember(target.frame)
- edge = .none
+ /// Where on the screen the event happened. The window moves and resizes under the pointer, so
+ /// not its window location, and not `NSEvent.mouseLocation`, which is wherever the pointer is
+ /// by the time the event is handled.
+ private static func screenLocation(of event: NSEvent) -> NSPoint {
+ guard let p = event.cgEvent?.location, let primary = NSScreen.screens.first else { return NSEvent.mouseLocation }
+ return NSPoint(x: p.x, y: primary.frame.maxY - p.y)
}
+ private static func size(_ r: NSRect) -> String { "\(Int(r.width))×\(Int(r.height))" }
+
// The pointer never reaches Chromium (its own controls stay hidden); the
// controls subview shows Arc's on hover.
- override func mouseMoved(with event: NSEvent) {}
+ override func mouseMoved(with event: NSEvent) {
+ if gesture != nil { finish(event) } else { updateCursor(event) } // a move means no button is down: the mouse-up got lost
+ }
override func rightMouseDown(with event: NSEvent) {}
override func otherMouseDown(with event: NSEvent) {}
override func scrollWheel(with event: NSEvent) {}
}
+
+/// Lets Cra set the cursor while another app is in front. macOS only takes the frontmost app's
+/// cursor, so without this the Picture in Picture window, which floats over every app, shows no
+/// resize cursor unless Cra is active. On only while the pointer is over that window. Private
+/// WindowServer API (`CGSSetConnectionProperty`, "SetsCursorInBackground"); a no-op if it's gone.
+@MainActor
+enum BackgroundCursor {
+ private typealias MainConnection = @convention(c) () -> Int32
+ private typealias SetProperty = @convention(c) (Int32, Int32, CFString, CFTypeRef) -> Int32
+ private static let calls: (MainConnection, SetProperty)? = {
+ let any = UnsafeMutableRawPointer(bitPattern: -2) // RTLD_DEFAULT
+ guard let main = dlsym(any, "CGSMainConnectionID"), let set = dlsym(any, "CGSSetConnectionProperty") else { return nil }
+ return (unsafeBitCast(main, to: MainConnection.self), unsafeBitCast(set, to: SetProperty.self))
+ }()
+ private static var isAllowed = false
+
+ static func allow(_ on: Bool) {
+ guard on != isAllowed, let calls else { return }
+ isAllowed = on
+ let cid = calls.0()
+ _ = calls.1(cid, cid, "SetsCursorInBackground" as CFString, (on ? kCFBooleanTrue : kCFBooleanFalse) as CFTypeRef)
+ }
+}
diff --git a/Sources/Cra/UI/PictureInPicture/PictureInPictureControls.swift b/Sources/Cra/UI/PictureInPicture/PictureInPictureControls.swift
index e1a3dd0..95ca03b 100644
--- a/Sources/Cra/UI/PictureInPicture/PictureInPictureControls.swift
+++ b/Sources/Cra/UI/PictureInPicture/PictureInPictureControls.swift
@@ -31,7 +31,10 @@ final class PictureInPictureControlsView: NSView {
NSColor.black.withAlphaComponent(0.45).cgColor]
scrim.locations = [0, 0.3, 0.7, 1]
layer?.addSublayer(scrim)
- for b in buttons { addSubview(b) }
+ for b in buttons {
+ addSubview(b)
+ b.onPress = { [weak self] in self?.show() }
+ }
closeButton.onClick = { PictureInPictureChrome.shared.actions?.close() }
backButton.onClick = { PictureInPictureChrome.shared.actions?.backToTab() }
playButton.onClick = { [weak self] in
@@ -61,11 +64,13 @@ final class PictureInPictureControlsView: NSView {
skipAheadButton.setFrameOrigin(NSPoint(x: playButton.frame.maxX + gap, y: c.y - skipAheadButton.frame.height / 2))
}
- // Only the buttons are hit; drags anywhere else reach the overlay view below.
+ // Only the buttons are hit; drags anywhere else reach the overlay view below. A button takes
+ // its click while the controls are faded out too (the pointer was already in the window when
+ // it opened, or rested there): fading is drawing, and a click on a hidden play button still
+ // means play, not a drag (#134).
override func hitTest(_ point: NSPoint) -> NSView? {
let p = convert(point, from: superview)
- for b in buttons where b.frame.contains(p) { return shown ? b : nil }
- return nil
+ return buttons.first { $0.frame.contains(p) }
}
override func updateTrackingAreas() {
@@ -120,6 +125,7 @@ final class PictureInPictureControlsView: NSView {
@MainActor
final class PictureInPictureButton: NSView {
var onClick: () -> Void = {}
+ var onPress: () -> Void = {}
var symbol: String { didSet { image.image = Self.image(symbol, pointSize) } }
private(set) var isHovered = false { didSet { updateBackground() } }
private var isPressed = false { didSet { updateBackground() } }
@@ -171,7 +177,7 @@ final class PictureInPictureButton: NSView {
override func mouseEntered(with event: NSEvent) { isHovered = true }
override func mouseExited(with event: NSEvent) { isHovered = false }
- override func mouseDown(with event: NSEvent) { isPressed = true }
+ override func mouseDown(with event: NSEvent) { isPressed = true; onPress() }
override func mouseUp(with event: NSEvent) {
isPressed = false
if bounds.contains(convert(event.locationInWindow, from: nil)) { onClick() }
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index cd59036..d94046b 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -624,6 +624,19 @@ Chrome's own window ignores the pointer and has `preventKeyWindow` set (2 Nov):
resize band outside its frame that the overlay doesn't cover, and once key (a drag on that band, or
AppKit picking it when a click activates Cra) Chrome shows its ±10 s controls on focus and on every
mouse move, under Cra's ±15 s ones.
+Pressing the overlay (3 Nov, #134, `PictureInPictureGesture` in CraCore): the buttons take clicks
+whether or not the controls are faded in, a press moves or resizes only past 3 pt of travel (a click
+on play used to nudge the window by its drift), edges are 8 pt deep with 16 pt corners like
+Chromium's, and a resize keeps the opposite edge or corner where it was (the vertical anchors were
+inverted, so the top edge stayed put while the bottom was dragged). The cursor comes from a tracking
+area over the same zones (cursor rects only work in a key window, and the overlay never is one), and
+while the pointer is over the window Cra sets "SetsCursorInBackground" on its WindowServer
+connection, so the resize cursors show with another app in front too (verified with `screencapture
+-C` over each edge and corner, Finder in front and Cra in front). A press with Cra in the background
+already reached the overlay (it activates Cra and acceptsFirstMouse lets it through); without the
+cursor it only looked dead. Drags are measured from each
+event's own screen location; `cra.log` gets `pip: move`, `pip: resize <edge> from W×H`, `pip: resized
+<edge> W×H → W×H` (with "asked" when Chromium kept another size) and `pip: overlay has no parent window`.
One residual difference: Chrome paints its origin strip ("File on your device", top gradient)
inside the compositor layer for about two seconds when the window first appears (present at
1.5 s, gone at 2.5 s in quarter-second captures); it is drawn whether or not the window is