Files
sttlab-tech 561a547b70 Initial FocusFixer implementation
Menu-bar utility that fixes cross-display keyboard focus loss: a
listen-only CGEvent tap locates the window under the cursor and
reasserts app activation + AX focus on it, with debounce, tap
auto-recovery, and an Accessibility permission gate.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-10 12:02:29 +02:00

48 lines
1.9 KiB
Swift

import XCTest
@testable import FocusFixer
final class WindowLocatorTests: XCTestCase {
func testReturnsOwnerPIDWhenPointInsideWindow() {
let windows = [
WindowInfo(ownerPID: 111, layer: 0, bounds: CGRect(x: 0, y: 0, width: 100, height: 100))
]
XCTAssertEqual(WindowLocator.ownerPID(at: CGPoint(x: 50, y: 50), in: windows), 111)
}
func testIgnoresNonZeroLayerWindows() {
let windows = [
WindowInfo(ownerPID: 999, layer: 25, bounds: CGRect(x: 0, y: 0, width: 100, height: 100))
]
XCTAssertNil(WindowLocator.ownerPID(at: CGPoint(x: 50, y: 50), in: windows))
}
func testFallsThroughToNextWindowWhenTopWindowIsWrongLayer() {
let windows = [
WindowInfo(ownerPID: 1, layer: 25, bounds: CGRect(x: 0, y: 0, width: 100, height: 100)),
WindowInfo(ownerPID: 2, layer: 0, bounds: CGRect(x: 0, y: 0, width: 100, height: 100))
]
XCTAssertEqual(WindowLocator.ownerPID(at: CGPoint(x: 50, y: 50), in: windows), 2)
}
func testReturnsFrontmostWindowInZOrder() {
// Overlapping layer-0 windows: front-to-back order (as returned by
// CGWindowListCopyWindowInfo) determines which owner wins.
let windows = [
WindowInfo(ownerPID: 1, layer: 0, bounds: CGRect(x: 0, y: 0, width: 200, height: 200)),
WindowInfo(ownerPID: 2, layer: 0, bounds: CGRect(x: 0, y: 0, width: 200, height: 200))
]
XCTAssertEqual(WindowLocator.ownerPID(at: CGPoint(x: 50, y: 50), in: windows), 1)
}
func testEmptyWindowListReturnsNil() {
XCTAssertNil(WindowLocator.ownerPID(at: CGPoint(x: 50, y: 50), in: []))
}
func testPointOutsideAllWindowsReturnsNil() {
let windows = [
WindowInfo(ownerPID: 1, layer: 0, bounds: CGRect(x: 0, y: 0, width: 100, height: 100))
]
XCTAssertNil(WindowLocator.ownerPID(at: CGPoint(x: 500, y: 500), in: windows))
}
}