Hide stale off-screen windows of limited-AX apps
Some checks failed
CI / Build and test (ad-hoc signing) (push) Has been cancelled
Some checks failed
CI / Build and test (ad-hoc signing) (push) Has been cancelled
Some apps (for example a Java GUI toolkit) leave windows in the window list that claim the current Space but are not on screen. These stale buffer windows appeared as extra tabs. Add kCGWindowIsOnscreen and kCGWindowAlpha to the CGWindowList read and to the window dump. New filter rule: hide a no-AX window that is on the current Space and not on screen, unless it is minimized. A real window on the current Space is on screen. A real window on another Space is not on the current Space, so the rule keeps it (decision D4). Add WindowFilterTests for the stale, on-screen, and other-Space cases. All 34 tests pass with xcodebuild test.
This commit is contained in:
@@ -24,7 +24,8 @@ final class WindowFilterTests: XCTestCase {
|
||||
}
|
||||
|
||||
private func cgWindow(id: CGWindowID, title: String?, bounds: CGRect) -> WindowEnumerator.CGRawWindow {
|
||||
return WindowEnumerator.CGRawWindow(windowID: id, title: title, layer: 0, bounds: bounds)
|
||||
return WindowEnumerator.CGRawWindow(windowID: id, title: title, layer: 0, bounds: bounds,
|
||||
isOnscreen: true, alpha: 1.0)
|
||||
}
|
||||
|
||||
private func shownIDs(ax: [WindowEnumerator.AXRawWindow],
|
||||
@@ -98,4 +99,72 @@ final class WindowFilterTests: XCTestCase {
|
||||
let shown = shownIDs(ax: ax, axIDs: [555], cg: cg)
|
||||
XCTAssertTrue(shown.contains(555))
|
||||
}
|
||||
|
||||
// The stale buffer window case: a no-AX window that claims the current
|
||||
// Space but is not on screen. Some Java GUI toolkits leave these windows.
|
||||
func testHidesStaleCurrentSpaceOffscreenWindow() {
|
||||
let cg = [WindowEnumerator.CGRawWindow(windowID: 500,
|
||||
title: "Report 1 - Overview",
|
||||
layer: 0,
|
||||
bounds: CGRect(x: 0, y: 0, width: 1624, height: 1247),
|
||||
isOnscreen: false,
|
||||
alpha: 1.0)]
|
||||
let result = enumerator.buildWindows(pid: pid,
|
||||
bundleID: "com.example.javaapp",
|
||||
appName: "JavaApp",
|
||||
ax: [],
|
||||
axWindowIDs: [],
|
||||
cg: cg,
|
||||
spaceIDsByWindow: [500: [4]],
|
||||
currentSpaceIDs: [4],
|
||||
ownPID: 9999,
|
||||
screenBoundsCG: CGRect(x: 0, y: 0, width: 2560, height: 1440),
|
||||
now: Date())
|
||||
XCTAssertFalse(result.windows.contains { $0.id == 500 })
|
||||
}
|
||||
|
||||
// A no-AX window on the current Space that IS on screen is a real window.
|
||||
func testKeepsOnscreenCurrentSpaceNoAXWindow() {
|
||||
let cg = [WindowEnumerator.CGRawWindow(windowID: 501,
|
||||
title: "Report 2 - Details",
|
||||
layer: 0,
|
||||
bounds: CGRect(x: 0, y: 0, width: 1624, height: 1247),
|
||||
isOnscreen: true,
|
||||
alpha: 1.0)]
|
||||
let result = enumerator.buildWindows(pid: pid,
|
||||
bundleID: "com.example.javaapp",
|
||||
appName: "JavaApp",
|
||||
ax: [],
|
||||
axWindowIDs: [],
|
||||
cg: cg,
|
||||
spaceIDsByWindow: [501: [4]],
|
||||
currentSpaceIDs: [4],
|
||||
ownPID: 9999,
|
||||
screenBoundsCG: CGRect(x: 0, y: 0, width: 2560, height: 1440),
|
||||
now: Date())
|
||||
XCTAssertTrue(result.windows.contains { $0.id == 501 })
|
||||
}
|
||||
|
||||
// A no-AX window with no Space id is on another Space. The rule keeps it,
|
||||
// even when it is not on screen (decision D4).
|
||||
func testKeepsOtherSpaceOffscreenNoAXWindow() {
|
||||
let cg = [WindowEnumerator.CGRawWindow(windowID: 502,
|
||||
title: "Document 3",
|
||||
layer: 0,
|
||||
bounds: CGRect(x: 0, y: 0, width: 1200, height: 800),
|
||||
isOnscreen: false,
|
||||
alpha: 1.0)]
|
||||
let result = enumerator.buildWindows(pid: pid,
|
||||
bundleID: "com.example.app",
|
||||
appName: "ExampleApp",
|
||||
ax: [],
|
||||
axWindowIDs: [],
|
||||
cg: cg,
|
||||
spaceIDsByWindow: [:],
|
||||
currentSpaceIDs: [4],
|
||||
ownPID: 9999,
|
||||
screenBoundsCG: CGRect(x: 0, y: 0, width: 2560, height: 1440),
|
||||
now: Date())
|
||||
XCTAssertTrue(result.windows.contains { $0.id == 502 })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user