EPOD Window Bar: a window strip above the macOS Dock

EPOD Window Bar is a macOS agent app. It shows a thin strip above the Dock
with one tab per window of the frontmost application. One click raises the
window.

Build from source with XcodeGen and Xcode. Signing uses Config.xcconfig
(ad-hoc by default; a local Local.xcconfig can set a team ID). The app needs
Accessibility and Screen Recording permissions, and runs in a reduced mode
without Screen Recording.

See README.md and docs/ for details.
This commit is contained in:
Erhan Keseli
2026-11-21 21:41:06 +01:00
commit 70d7ca5efe
43 changed files with 4332 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
import XCTest
import CoreGraphics
@testable import EPODWindowBar
// ConstraintMathTests checks the pure constraint math (spec 7.10).
// All rects use Cocoa coordinates. The origin is bottom-left. The Y axis
// points up. limitY is the strip top edge.
final class ConstraintMathTests: XCTestCase {
// A window fully above the limit needs no change.
func testWindowAboveLimitReturnsNil() {
let window = CGRect(x: 0, y: 200, width: 800, height: 400)
XCTAssertNil(ConstraintMath.newHeight(windowCocoa: window, limitY: 30))
}
// A window with the bottom below the limit gets a new height. The top stays
// fixed. The top is maxY = 20 + 600 = 620. The new height is 620 - 30 = 590.
func testWindowBottomBelowLimitReturnsNewHeight() {
let window = CGRect(x: 0, y: 20, width: 800, height: 600)
let height = ConstraintMath.newHeight(windowCocoa: window, limitY: 30)
XCTAssertEqual(height, 590, accuracy: 0.001)
}
// The boundary case: the window bottom is exactly at the limit. No change.
func testWindowBottomExactlyAtLimitReturnsNil() {
let window = CGRect(x: 0, y: 30, width: 800, height: 400)
XCTAssertNil(ConstraintMath.newHeight(windowCocoa: window, limitY: 30))
}
// The user moved the window down on purpose. The top is also below
// (limitY - 100). The service skips the window.
func testIntentionalMoveDownIsTrue() {
// limitY = 30. limitY - 100 = -70. A top at -80 is below -70.
XCTAssertTrue(ConstraintMath.isIntentionalMoveDown(windowTopCocoa: -80, limitY: 30))
}
// A normal window with a high top is not an intentional move-down.
func testIntentionalMoveDownIsFalse() {
XCTAssertFalse(ConstraintMath.isIntentionalMoveDown(windowTopCocoa: 500, limitY: 30))
}
// A window on a second screen below the primary screen. The second screen
// has negative Cocoa Y. The strip is on that screen. limitY = -770.
// The window bottom (-900) is below the limit. The top is -300.
// The top is not below (limitY - 100 = -870), so the service corrects the
// window. The new height is top - limitY = -300 - (-770) = 470.
func testWindowOnSecondScreenGetsNewHeight() {
let window = CGRect(x: 0, y: -900, width: 800, height: 600) // top = -300
XCTAssertFalse(ConstraintMath.isIntentionalMoveDown(windowTopCocoa: window.maxY, limitY: -770))
let height = ConstraintMath.newHeight(windowCocoa: window, limitY: -770)
XCTAssertEqual(height, 470, accuracy: 0.001)
}
}

55
Tests/GeometryTests.swift Normal file
View File

@@ -0,0 +1,55 @@
import XCTest
@testable import EPODWindowBar
// GeometryTests checks the coordinate conversion between the Cocoa system and
// the AX system. The tests use a primary screen height of 1000. The tests
// cover the primary screen and a second screen above, below, and left of the
// primary screen (spec section 7.10).
final class GeometryTests: XCTestCase {
private let primaryHeight: CGFloat = 1000
func testPrimaryScreenRect() {
// A window sits at the bottom-left of the primary screen.
let cocoa = CGRect(x: 0, y: 0, width: 100, height: 100)
let ax = Geometry.cocoaToAX(cocoa, primaryHeight: primaryHeight)
XCTAssertEqual(ax.origin.x, 0)
XCTAssertEqual(ax.origin.y, 900) // 1000 - 100
XCTAssertEqual(ax.width, 100)
XCTAssertEqual(ax.height, 100)
}
func testRoundTripPrimary() {
let cocoa = CGRect(x: 10, y: 20, width: 300, height: 200)
let ax = Geometry.cocoaToAX(cocoa, primaryHeight: primaryHeight)
let back = Geometry.axToCocoa(ax, primaryHeight: primaryHeight)
XCTAssertEqual(back, cocoa)
}
func testScreenAbovePrimary() {
// A window above the primary top has a negative AX Y value.
let cocoa = CGRect(x: 0, y: 1000, width: 100, height: 100)
let ax = Geometry.cocoaToAX(cocoa, primaryHeight: primaryHeight)
XCTAssertEqual(ax.origin.y, -100) // 1000 - 1100
}
func testScreenBelowPrimary() {
// A window below the primary bottom has an AX Y value past the height.
let cocoa = CGRect(x: 0, y: -200, width: 100, height: 100)
let ax = Geometry.cocoaToAX(cocoa, primaryHeight: primaryHeight)
XCTAssertEqual(ax.origin.y, 1100) // 1000 - (-100)
}
func testScreenLeftKeepsX() {
// A screen left of the primary has a negative X. The X value does not
// change in the conversion.
let cocoa = CGRect(x: -1440, y: 0, width: 100, height: 100)
let ax = Geometry.cocoaToAX(cocoa, primaryHeight: primaryHeight)
XCTAssertEqual(ax.origin.x, -1440)
}
func testCocoaYToAXTop() {
let top = Geometry.cocoaYToAXTop(100, primaryHeight: primaryHeight)
XCTAssertEqual(top, 900)
}
}

View File

@@ -0,0 +1,76 @@
import XCTest
@testable import EPODWindowBar
// TabLayoutTests check the pure layout function. See spec section 7.9.
final class TabLayoutTests: XCTestCase {
// All tabs fit. There is no overflow. The tabs have equal width.
func testAllTabsFitNoOverflow() {
let result = TabLayout.compute(availableWidth: 1000, windowCount: 4, activeIndex: 0)
XCTAssertEqual(result.visibleCount, 4)
XCTAssertFalse(result.showsOverflow)
XCTAssertEqual(result.overflowCount, 0)
XCTAssertEqual(result.visibleIndices, [0, 1, 2, 3])
XCTAssertTrue(result.overflowIndices.isEmpty)
}
// The tab width is equal for all tabs and inside the bounds.
func testTabWidthInsideBounds() {
let result = TabLayout.compute(availableWidth: 1000, windowCount: 4, activeIndex: 0)
XCTAssertGreaterThanOrEqual(result.tabWidth, 90)
XCTAssertLessThanOrEqual(result.tabWidth, 220)
}
// The tab width reaches the maximum when few tabs share a wide strip.
func testTabWidthReachesMaximum() {
let result = TabLayout.compute(availableWidth: 2000, windowCount: 2, activeIndex: 0)
XCTAssertEqual(result.tabWidth, 220, accuracy: 0.001)
}
// Too many tabs do not fit. The +N button appears.
func testOverflowAppears() {
let result = TabLayout.compute(availableWidth: 500, windowCount: 15, activeIndex: 0)
XCTAssertTrue(result.showsOverflow)
XCTAssertGreaterThan(result.overflowCount, 0)
XCTAssertEqual(result.visibleCount + result.overflowCount, 15)
}
// The visible tabs keep the minimum width in the overflow case.
func testOverflowTabsKeepMinimumWidth() {
let result = TabLayout.compute(availableWidth: 500, windowCount: 15, activeIndex: 0)
XCTAssertGreaterThanOrEqual(result.tabWidth, 90)
}
// The active window is always visible. The active window is in the overflow
// range before the swap. The swap puts the active window into the last
// visible slot.
func testActiveWindowAlwaysVisible() {
let result = TabLayout.compute(availableWidth: 500, windowCount: 15, activeIndex: 14)
XCTAssertTrue(result.visibleIndices.contains(14))
XCTAssertFalse(result.overflowIndices.contains(14))
XCTAssertEqual(result.visibleIndices.last, 14)
}
// The swap helper keeps the count correct.
func testSwapKeepsCounts() {
let split = TabLayout.visibleIndices(windowCount: 10, visibleCount: 3, activeIndex: 9)
XCTAssertEqual(split.visible.count, 3)
XCTAssertEqual(split.overflow.count, 7)
XCTAssertTrue(split.visible.contains(9))
XCTAssertFalse(Set(split.visible).intersection(Set(split.overflow)).isEmpty == false)
}
// Zero windows give an empty layout.
func testZeroWindows() {
let result = TabLayout.compute(availableWidth: 1000, windowCount: 0, activeIndex: nil)
XCTAssertEqual(result.visibleCount, 0)
XCTAssertFalse(result.showsOverflow)
XCTAssertTrue(result.visibleIndices.isEmpty)
}
// A nil active index does not swap. The first tabs stay visible.
func testNilActiveIndexNoSwap() {
let split = TabLayout.visibleIndices(windowCount: 10, visibleCount: 3, activeIndex: nil)
XCTAssertEqual(split.visible, [0, 1, 2])
}
}

View File

@@ -0,0 +1,101 @@
import XCTest
import ApplicationServices
import CoreGraphics
@testable import EPODWindowBar
// WindowFilterTests checks the window filter of WindowEnumerator.buildWindows
// (spec section 7.3). The test uses the Teams case from the dump: a real window
// shows, and a ghost placeholder with the application name as the title hides.
// A window on another Space with a distinct title also shows.
final class WindowFilterTests: XCTestCase {
private let enumerator = WindowEnumerator()
private let pid: pid_t = 1234
private let appName = "Microsoft Teams"
private func axWindow(title: String) -> WindowEnumerator.AXRawWindow {
// The element is a placeholder. buildWindows does not read the element.
let element = AXUIElementCreateApplication(ProcessInfo.processInfo.processIdentifier)
return WindowEnumerator.AXRawWindow(element: element,
title: title,
isMinimized: false,
subrole: kAXStandardWindowSubrole as String,
isFullScreen: false)
}
private func cgWindow(id: CGWindowID, title: String?, bounds: CGRect) -> WindowEnumerator.CGRawWindow {
return WindowEnumerator.CGRawWindow(windowID: id, title: title, layer: 0, bounds: bounds)
}
private func shownIDs(ax: [WindowEnumerator.AXRawWindow],
axIDs: [CGWindowID?],
cg: [WindowEnumerator.CGRawWindow],
screenBoundsCG: CGRect = CGRect(x: 0, y: 0, width: 2560, height: 1440)) -> Set<CGWindowID> {
let result = enumerator.buildWindows(pid: pid,
bundleID: "com.microsoft.teams2",
appName: appName,
ax: ax,
axWindowIDs: axIDs,
cg: cg,
spaceIDsByWindow: [:],
currentSpaceIDs: [],
ownPID: 9999,
screenBoundsCG: screenBoundsCG,
now: Date())
return Set(result.windows.map { $0.id })
}
func testShowsRealAXWindow() {
let real = axWindow(title: "Chat | Team")
let cg = [cgWindow(id: 7476, title: "Chat | Team",
bounds: CGRect(x: 215, y: 249, width: 1307, height: 865))]
let shown = shownIDs(ax: [real], axIDs: [7476], cg: cg)
XCTAssertTrue(shown.contains(7476))
}
func testHidesGhostWithAppNameTitle() {
// Ghost: no AX element, title equals the application name.
let cg = [cgWindow(id: 8274, title: "Microsoft Teams",
bounds: CGRect(x: 0, y: 0, width: 800, height: 600))]
let shown = shownIDs(ax: [], axIDs: [], cg: cg)
XCTAssertFalse(shown.contains(8274))
}
func testHidesEmptyTitleGhost() {
// No AX element, empty CG title. The title falls back to the app name.
let cg = [cgWindow(id: 7475, title: nil,
bounds: CGRect(x: 0, y: 0, width: 2560, height: 300))]
let shown = shownIDs(ax: [], axIDs: [], cg: cg)
XCTAssertFalse(shown.contains(7475))
}
func testShowsOtherSpaceWindowWithDistinctTitle() {
// No AX element, distinct title: a real window on another Space.
let cg = [cgWindow(id: 999, title: "Terminal — ~/project",
bounds: CGRect(x: 0, y: 0, width: 1268, height: 1319))]
let shown = shownIDs(ax: [], axIDs: [], cg: cg)
XCTAssertTrue(shown.contains(999))
}
func testHidesOffScreenLimboWindow() {
// The Eclipse limbo shell sits at y=10000, off every screen.
let cg = [cgWindow(id: 9231, title: "PartRenderingEngine's limbo",
bounds: CGRect(x: 0, y: 10000, width: 1600, height: 900))]
let shown = shownIDs(ax: [], axIDs: [], cg: cg)
XCTAssertFalse(shown.contains(9231))
}
func testKeepsMinimizedOffScreenWindow() {
// A minimized window keeps its tab, even with off-screen bounds.
let element = AXUIElementCreateApplication(ProcessInfo.processInfo.processIdentifier)
let ax = [WindowEnumerator.AXRawWindow(element: element,
title: "Minimized Chat",
isMinimized: true,
subrole: kAXStandardWindowSubrole as String,
isFullScreen: false)]
let cg = [cgWindow(id: 555, title: "Minimized Chat",
bounds: CGRect(x: 0, y: 10000, width: 1200, height: 800))]
let shown = shownIDs(ax: ax, axIDs: [555], cg: cg)
XCTAssertTrue(shown.contains(555))
}
}

View File

@@ -0,0 +1,81 @@
import XCTest
@testable import EPODWindowBar
// WindowOrderTests checks the stable order of the WindowStore (decision D5).
// The store sorts windows by firstSeen. A known window keeps its firstSeen
// value on a refresh. A new window gets the firstSeen value "now". A window
// that closes and opens again gets a new firstSeen value.
@MainActor
final class WindowOrderTests: XCTestCase {
private let pid: pid_t = 42
private func makeWindow(id: CGWindowID, title: String) -> WindowInfo {
return WindowInfo(
id: id,
pid: pid,
bundleID: "com.test.app",
title: title,
spaceIDs: [],
isOnCurrentSpace: true,
isMinimized: false,
isFullScreen: false,
firstSeen: Date(timeIntervalSince1970: 0))
}
func testEqualFirstSeenSortsByID() {
let store = WindowStore()
let t0 = Date(timeIntervalSince1970: 100)
store.replaceWindows([makeWindow(id: 2, title: "B"),
makeWindow(id: 1, title: "A")],
for: pid, now: t0)
let order = store.windows(for: pid).map { $0.id }
XCTAssertEqual(order, [1, 2])
}
func testNewWindowKeepsStableOrder() {
let store = WindowStore()
let t0 = Date(timeIntervalSince1970: 100)
store.replaceWindows([makeWindow(id: 1, title: "A"),
makeWindow(id: 2, title: "B")],
for: pid, now: t0)
// A later refresh adds window 3. The order of 1 and 2 does not change.
let t1 = Date(timeIntervalSince1970: 200)
store.replaceWindows([makeWindow(id: 2, title: "B"),
makeWindow(id: 1, title: "A"),
makeWindow(id: 3, title: "C")],
for: pid, now: t1)
let order = store.windows(for: pid).map { $0.id }
XCTAssertEqual(order, [1, 2, 3])
}
func testReopenGetsNewFirstSeen() {
let store = WindowStore()
let t0 = Date(timeIntervalSince1970: 100)
store.replaceWindows([makeWindow(id: 1, title: "A"),
makeWindow(id: 2, title: "B")],
for: pid, now: t0)
// Window 1 closes.
let t1 = Date(timeIntervalSince1970: 200)
store.replaceWindows([makeWindow(id: 2, title: "B")], for: pid, now: t1)
// Window 1 opens again. Window 1 gets a new firstSeen value. Window 1
// moves after window 2.
let t2 = Date(timeIntervalSince1970: 300)
store.replaceWindows([makeWindow(id: 2, title: "B"),
makeWindow(id: 1, title: "A")],
for: pid, now: t2)
let order = store.windows(for: pid).map { $0.id }
XCTAssertEqual(order, [2, 1])
}
func testFrontmostWindows() {
let store = WindowStore()
store.replaceWindows([makeWindow(id: 1, title: "A")], for: pid,
now: Date(timeIntervalSince1970: 100))
store.setFrontmost(pid)
XCTAssertEqual(store.frontmostWindows.map { $0.id }, [1])
}
}