From 6d2d93e72e27eb743c1b3103e06ece05476bd94f Mon Sep 17 00:00:00 2001 From: Jorgen Bruntveit Date: Wed, 18 Nov 2026 12:01:43 +0100 Subject: [PATCH 1/4] Show the real cursor over password prompts drawn above the hand macOS draws some system windows, like SecurityAgent's password prompts, in front of the overlay whatever its level, so the hand was hidden under them while the system cursor was hidden too. Windows in front of the overlay now count like open menus: over them the real cursor shows, even with Keep the hand on, and clicks reach them. Co-Authored-By: Claude Opus 5.5 --- Sources/TinyHand/OverlayController.swift | 44 +++++++++++++++++++----- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/Sources/TinyHand/OverlayController.swift b/Sources/TinyHand/OverlayController.swift index b0eae63e..6db50217 100644 --- a/Sources/TinyHand/OverlayController.swift +++ b/Sources/TinyHand/OverlayController.swift @@ -25,6 +25,7 @@ final class OverlayController { private var normalCursor = false private var ownMenuOpen = false private var menuRects: [CGRect] = [] + private var coverRects: [CGRect] = [] private var lastMenuScan = Date.distantPast private var menuOpeningUntil = Date.distantPast private var escHotKey: UInt32? @@ -500,7 +501,11 @@ final class OverlayController { let scanEvery = menuLikely ? OverlayController.menuScanFast : OverlayController.menuScanSlow if Date().timeIntervalSince(lastMenuScan) > scanEvery { lastMenuScan = Date() - menuRects = OverlayController.openMenus() + let hadCover = !coverRects.isEmpty + (menuRects, coverRects) = OverlayController.openMenus(overlay: window.windowNumber) + if hadCover != !coverRects.isEmpty { + Log.write(coverRects.isEmpty ? "no windows in front of the overlay" : "window in front of the overlay: \(coverRects.map { "\(Int($0.minX)),\(Int($0.minY)) \(Int($0.width))x\(Int($0.height))" })") + } } let menuBar = OverlayController.menuBarRect(screen) let cgMouse = OverlayController.cgPoint(mouse) @@ -511,12 +516,13 @@ final class OverlayController { interactHeld = interacting menuHover = overMenu let through = inputTap.clickThrough - let normal = !drawing && !Preferences.interactKeepsHand && ((interacting && !through) || overMenu || ownMenuOpen) + let overCover = coverRects.contains { $0.contains(cgMouse) } + let normal = overCover || (!drawing && !Preferences.interactKeepsHand && ((interacting && !through) || overMenu || ownMenuOpen)) setEscEnabled(menuRects.isEmpty && !ownMenuOpen && !through) if normal != normalCursor { let at = "at \(Int(mouse.x)),\(Int(mouse.y))" - let why = interacting ? "interact key" : menuBar.contains(mouse) ? "menu bar" : "menu" + let why = overCover ? "window in front" : interacting ? "interact key" : menuBar.contains(mouse) ? "menu bar" : "menu" Log.write(normal ? "real cursor (\(why)) \(at)" : "pointer back \(at)") normalCursor = normal armView.pointerHidden = normal @@ -553,20 +559,40 @@ final class OverlayController { return CGRect(x: screen.frame.minX, y: screen.frame.maxY - height, width: screen.frame.width, height: height) } - private static func openMenus() -> [CGRect] { + // Open menus, plus windows macOS draws in front of the overlay whatever its level, like the + // password prompts from SecurityAgent. Over these the real cursor shows and clicks go through. + // Returns all of them, and separately the ones in front of the overlay, which hide the hand. + private static func openMenus(overlay: Int) -> (all: [CGRect], covering: [CGRect]) { guard let list = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]] else { - return [] + return ([], []) } let menuLevel = Int(CGWindowLevelForKey(.popUpMenuWindow)) - return list.compactMap { info in - guard (info[kCGWindowLayer as String] as? Int) == menuLevel, + let cursorLevel = Int(CGWindowLevelForKey(.cursorWindow)) + let me = Int(getpid()) + var inFront = true + var rects: [CGRect] = [] + var coveringRects: [CGRect] = [] + // The list runs front to back, so everything before the overlay is drawn over it. + for info in list { + if (info[kCGWindowNumber as String] as? Int) == overlay { + inFront = false + continue + } + guard let layer = info[kCGWindowLayer as String] as? Int, let bounds = info[kCGWindowBounds as String] as? NSDictionary, let rect = CGRect(dictionaryRepresentation: bounds as CFDictionary) else { - return nil + continue + } + let covering = inFront && layer < cursorLevel && (info[kCGWindowOwnerPID as String] as? Int) != me + if layer == menuLevel || covering { + rects.append(rect) + } + if covering { + coveringRects.append(rect) } - return rect } + return (rects, coveringRects) } private static func cgPoint(_ p: CGPoint) -> CGPoint { From 2c126e27fdb9a9bd0a5a004ed5d864c3be6f3ff4 Mon Sep 17 00:00:00 2001 From: Jorgen Bruntveit Date: Tue, 24 Nov 2026 09:12:00 +0100 Subject: [PATCH 2/4] Ignore windows above the overlay's level when looking for covers The password-prompt fix counted every window listed in front of the overlay as covering it. CleanShot X keeps a full-screen window at a level above the overlay, so the whole screen counted as covered: the real cursor showed everywhere and clicks went through. Only windows macOS draws in front despite a level no higher than the overlay's, like SecurityAgent's prompts, now count. While the overlay is off the active Space during a switch it is not in the window list, so every window counted as in front of it, which made the hand flicker. Nothing counts as covering then. Co-Authored-By: Claude Opus 5.5 --- Sources/TinyHand/OverlayController.swift | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Sources/TinyHand/OverlayController.swift b/Sources/TinyHand/OverlayController.swift index 6db50217..2b846d89 100644 --- a/Sources/TinyHand/OverlayController.swift +++ b/Sources/TinyHand/OverlayController.swift @@ -502,7 +502,7 @@ final class OverlayController { if Date().timeIntervalSince(lastMenuScan) > scanEvery { lastMenuScan = Date() let hadCover = !coverRects.isEmpty - (menuRects, coverRects) = OverlayController.openMenus(overlay: window.windowNumber) + (menuRects, coverRects) = OverlayController.openMenus(overlay: window.windowNumber, overlayLevel: window.level.rawValue) if hadCover != !coverRects.isEmpty { Log.write(coverRects.isEmpty ? "no windows in front of the overlay" : "window in front of the overlay: \(coverRects.map { "\(Int($0.minX)),\(Int($0.minY)) \(Int($0.width))x\(Int($0.height))" })") } @@ -559,16 +559,17 @@ final class OverlayController { return CGRect(x: screen.frame.minX, y: screen.frame.maxY - height, width: screen.frame.width, height: height) } - // Open menus, plus windows macOS draws in front of the overlay whatever its level, like the - // password prompts from SecurityAgent. Over these the real cursor shows and clicks go through. - // Returns all of them, and separately the ones in front of the overlay, which hide the hand. - private static func openMenus(overlay: Int) -> (all: [CGRect], covering: [CGRect]) { + // Open menus, plus windows macOS draws in front of the overlay although their level is not + // higher, like the password prompts from SecurityAgent (layer 1000 against the overlay's 1002). + // Over these the real cursor shows and clicks go through. Windows above the overlay's level, + // like CleanShot X's full-screen layer, are there by their level and are usually click-through, + // so they don't count. Returns all of them, and separately the ones covering the overlay. + private static func openMenus(overlay: Int, overlayLevel: Int) -> (all: [CGRect], covering: [CGRect]) { guard let list = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]] else { return ([], []) } let menuLevel = Int(CGWindowLevelForKey(.popUpMenuWindow)) - let cursorLevel = Int(CGWindowLevelForKey(.cursorWindow)) let me = Int(getpid()) var inFront = true var rects: [CGRect] = [] @@ -584,14 +585,18 @@ final class OverlayController { let rect = CGRect(dictionaryRepresentation: bounds as CFDictionary) else { continue } - let covering = inFront && layer < cursorLevel && (info[kCGWindowOwnerPID as String] as? Int) != me - if layer == menuLevel || covering { + if layer == menuLevel { rects.append(rect) } - if covering { + if inFront && layer <= overlayLevel && (info[kCGWindowOwnerPID as String] as? Int) != me { coveringRects.append(rect) } } + // Not listed while it is off the active Space (during a Space switch): then nothing is in front of it. + if inFront { + coveringRects = [] + } + rects += coveringRects return (rects, coveringRects) } From b4da5a88040ff780f1006eb671bfc1bfd12de794 Mon Sep 17 00:00:00 2001 From: Jorgen Bruntveit Date: Tue, 24 Nov 2026 09:19:35 +0100 Subject: [PATCH 3/4] Rescan for covers once the overlay is listed, and count only lower levels Council review of the previous commit: activate() scans before the overlay is ordered front, and the Space-switch handler may skip its scan, so a password prompt could go uncounted for up to 250 ms. Both now force a scan on the next tick. A window at the overlay's own level is in front by ordinary ordering, so only lower levels count now. Co-Authored-By: Claude Opus 5.5 --- Sources/TinyHand/OverlayController.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Sources/TinyHand/OverlayController.swift b/Sources/TinyHand/OverlayController.swift index 2b846d89..9d392ea9 100644 --- a/Sources/TinyHand/OverlayController.swift +++ b/Sources/TinyHand/OverlayController.swift @@ -227,6 +227,7 @@ final class OverlayController { window.orderFrontRegardless() toolbar.show() currentFrame = nil + lastMenuScan = .distantPast tick() Log.write("re-showed overlay, now on active space=\(window.isOnActiveSpace)") } @@ -416,6 +417,8 @@ final class OverlayController { CursorHider.hide() tick() window.orderFrontRegardless() + // The scan in that tick ran before the overlay was listed, so scan again on the next one. + lastMenuScan = .distantPast stillSince = Date() runTimer(every: OverlayController.busyInterval) @@ -559,11 +562,11 @@ final class OverlayController { return CGRect(x: screen.frame.minX, y: screen.frame.maxY - height, width: screen.frame.width, height: height) } - // Open menus, plus windows macOS draws in front of the overlay although their level is not - // higher, like the password prompts from SecurityAgent (layer 1000 against the overlay's 1002). - // Over these the real cursor shows and clicks go through. Windows above the overlay's level, - // like CleanShot X's full-screen layer, are there by their level and are usually click-through, - // so they don't count. Returns all of them, and separately the ones covering the overlay. + // Open menus, plus windows macOS draws in front of the overlay although their level is lower, + // like the password prompts from SecurityAgent (layer 1000 against the overlay's 1002). + // Over these the real cursor shows and clicks go through. Windows at the same or a higher level, + // like CleanShot X's full-screen layer, are in front by their level alone; they don't count, as + // before this check existed. Returns all of them, and separately the ones covering the overlay. private static func openMenus(overlay: Int, overlayLevel: Int) -> (all: [CGRect], covering: [CGRect]) { guard let list = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]] else { @@ -588,7 +591,7 @@ final class OverlayController { if layer == menuLevel { rects.append(rect) } - if inFront && layer <= overlayLevel && (info[kCGWindowOwnerPID as String] as? Int) != me { + if inFront && layer < overlayLevel && (info[kCGWindowOwnerPID as String] as? Int) != me { coveringRects.append(rect) } } From 19d1c170804e5583e5e726c3095f99673ecc0b4b Mon Sep 17 00:00:00 2001 From: Jorgen Bruntveit Date: Tue, 24 Nov 2026 09:22:48 +0100 Subject: [PATCH 4/4] Rescan for covers after every Space change Council round 2: a normal Space switch, where the overlay is already on the new Space, did not force a scan, so a cover there could wait for the 250 ms poll. The reset now runs on both paths, after the re-show tick. Co-Authored-By: Claude Opus 5.5 --- Sources/TinyHand/OverlayController.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/TinyHand/OverlayController.swift b/Sources/TinyHand/OverlayController.swift index 9d392ea9..8229da14 100644 --- a/Sources/TinyHand/OverlayController.swift +++ b/Sources/TinyHand/OverlayController.swift @@ -219,6 +219,8 @@ final class OverlayController { guard isActive else { return } + // The window list changes with the Space, so scan for menus and covers again on the next tick. + defer { lastMenuScan = .distantPast } let onSpace = window.isOnActiveSpace Log.write("space changed, overlay on active space=\(onSpace)") if onSpace { @@ -227,7 +229,6 @@ final class OverlayController { window.orderFrontRegardless() toolbar.show() currentFrame = nil - lastMenuScan = .distantPast tick() Log.write("re-showed overlay, now on active space=\(window.isOnActiveSpace)") } @@ -565,8 +566,8 @@ final class OverlayController { // Open menus, plus windows macOS draws in front of the overlay although their level is lower, // like the password prompts from SecurityAgent (layer 1000 against the overlay's 1002). // Over these the real cursor shows and clicks go through. Windows at the same or a higher level, - // like CleanShot X's full-screen layer, are in front by their level alone; they don't count, as - // before this check existed. Returns all of them, and separately the ones covering the overlay. + // like CleanShot X's full-screen layer, are in front by ordinary window ordering; they don't + // count, as before this check existed. Returns all of them, and separately the ones covering the overlay. private static func openMenus(overlay: Int, overlayLevel: Int) -> (all: [CGRect], covering: [CGRect]) { guard let list = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]] else {