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,17 @@
import Foundation
// AppControl is the interface for the menu bar item and the settings window.
// AppDelegate implements AppControl. The protocol keeps the UI modules
// independent from the concrete controllers.
@MainActor
protocol AppControl: AnyObject {
var isPaused: Bool { get }
func togglePause()
var constrainWindows: Bool { get }
func setConstrainWindows(_ on: Bool)
func dumpWindowsToLog()
func copyWindowDump()
func openSettings()
}

View File

@@ -0,0 +1,254 @@
import AppKit
import ApplicationServices
import CoreGraphics
// AppDelegate wires every module of EPOD Window Bar together. The delegate
// starts the tracking, the strip, the activation, and the constraint services
// after Accessibility is granted. The delegate implements AppControl for the
// menu bar item and the settings window.
@MainActor
final class AppDelegate: NSObject, NSApplicationDelegate, AppControl {
private let permissions = PermissionManager()
private let settings = Settings.shared
private let store = WindowStore()
private let cache = AXElementCache()
private let spaceService = SpaceService()
private var menuBar: MenuBarController?
private var onboarding: OnboardingWindow?
private var settingsWindow: SettingsWindow?
private var tracking: TrackingController?
private var strip: StripController?
private var activator: WindowActivator?
private var constraint: WindowConstraintService?
private var servicesStarted = false
private var userContinuedReduced = false
private var isFullScreenNow = false
private var screenPollTimer: Timer?
private var lastVisibleFrame: CGRect = .zero
func applicationDidFinishLaunching(_ notification: Notification) {
Log.app.info("EPOD Window Bar starts.")
menuBar = MenuBarController(permissions: permissions, control: self, settings: settings)
permissions.onChange = { [weak self] state in
self?.handle(state)
}
permissions.start()
handle(permissions.current)
}
// handle reacts to a new permission state. The app starts the services if
// Accessibility is granted. The app shows the onboarding window if
// Accessibility is missing (spec section 6.1).
private func handle(_ state: PermissionState) {
menuBar?.updatePermissionState(state)
onboarding?.update(state: state)
if state.accessibility {
startServicesIfNeeded()
updateStripVisibility()
if state.allGranted {
onboarding?.close()
} else if userContinuedReduced == false {
showOnboarding()
}
} else {
userContinuedReduced = false
stopServices()
showOnboarding()
}
}
// MARK: - Services
private func startServicesIfNeeded() {
guard servicesStarted == false else { return }
servicesStarted = true
let tracking = TrackingController(store: store,
cache: cache,
spaceService: spaceService,
settings: settings)
let strip = StripController(store: store, settings: settings)
let activator = WindowActivator(store: store, cache: cache)
let constraint = WindowConstraintService(store: store, cache: cache, settings: settings)
// The strip forwards the tab actions to the activator.
strip.onActivate = { [weak self] id in self?.activator?.activate(windowID: id) }
strip.onMinimize = { [weak self] id in self?.activator?.minimize(windowID: id) }
strip.onClose = { [weak self] id in self?.activator?.close(windowID: id) }
// The tracking controller reports the focused window for the active tab.
tracking.onFocusedWindowChanged = { [weak self] id in
self?.strip?.activeWindowID = id
}
// The tracking controller reports the full-screen state. The strip
// hides in full screen (decision D7).
tracking.onFrontmostFocusedFullScreenChanged = { [weak self] full in
self?.isFullScreenNow = full
self?.updateStripVisibility()
}
// The tracking controller forwards the geometry events to the
// constraint service (spec section 7.10). The controller resolves the
// CGWindowID on the serial AX queue.
tracking.onWindowGeometryEvent = { [weak self] _, name, id in
guard let self = self, self.settings.paused == false else { return }
if name == kAXWindowCreatedNotification {
self.constraint?.constrainOnCreate(windowID: id)
} else {
self.constraint?.handleMovedOrResized(windowID: id)
}
}
self.tracking = tracking
self.strip = strip
self.activator = activator
self.constraint = constraint
strip.start()
tracking.start()
constraint.stripFrame = strip.stripFrame
startScreenObservers()
updateStripVisibility()
}
// stopServices stops all AX work. The app calls this function when
// Accessibility is revoked at runtime (spec section 6.1). The app does not
// crash.
private func stopServices() {
guard servicesStarted else { return }
servicesStarted = false
tracking?.onAccessibilityLost()
strip?.setVisible(false)
stopScreenObservers()
tracking = nil
strip = nil
activator = nil
constraint = nil
cache.removeAll()
}
// updateStripVisibility shows the strip only if the app is active, the app
// is not paused, and the frontmost window is not full screen.
private func updateStripVisibility() {
let visible = settings.paused == false
&& isFullScreenNow == false
&& permissions.current.accessibility
strip?.setVisible(visible)
}
// MARK: - Screen and Dock changes
private func startScreenObservers() {
NotificationCenter.default.addObserver(
self,
selector: #selector(screenParametersChanged),
name: NSApplication.didChangeScreenParametersNotification,
object: nil)
NSWorkspace.shared.notificationCenter.addObserver(
self,
selector: #selector(didWake),
name: NSWorkspace.didWakeNotification,
object: nil)
lastVisibleFrame = NSScreen.main?.visibleFrame ?? .zero
// The Dock preference change has no public notification. The app polls
// the visible frame every 2 s (spec section 7.8).
screenPollTimer = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: true) { [weak self] _ in
MainActor.assumeIsolated {
self?.pollVisibleFrame()
}
}
}
private func stopScreenObservers() {
NotificationCenter.default.removeObserver(
self, name: NSApplication.didChangeScreenParametersNotification, object: nil)
NSWorkspace.shared.notificationCenter.removeObserver(
self, name: NSWorkspace.didWakeNotification, object: nil)
screenPollTimer?.invalidate()
screenPollTimer = nil
}
@objc private func screenParametersChanged() {
repositionStrip()
}
@objc private func didWake() {
repositionStrip()
}
private func pollVisibleFrame() {
let current = NSScreen.main?.visibleFrame ?? .zero
if current != lastVisibleFrame {
lastVisibleFrame = current
repositionStrip()
}
}
private func repositionStrip() {
strip?.reposition()
if let strip = strip {
constraint?.stripFrame = strip.stripFrame
}
}
// MARK: - Onboarding
private func showOnboarding() {
if onboarding == nil {
let window = OnboardingWindow(permissions: permissions)
window.onContinue = { [weak self] in
self?.userContinuedReduced = true
self?.onboarding?.close()
}
onboarding = window
}
onboarding?.show()
}
// MARK: - AppControl
var isPaused: Bool {
return settings.paused
}
func togglePause() {
settings.paused.toggle()
updateStripVisibility()
Log.app.info("Pause is now \(self.settings.paused, privacy: .public).")
}
var constrainWindows: Bool {
return settings.constrainWindows
}
func setConstrainWindows(_ on: Bool) {
settings.constrainWindows = on
Log.app.info("Constrain windows is now \(on, privacy: .public).")
}
func dumpWindowsToLog() {
tracking?.dumpWindowsToLog()
}
func copyWindowDump() {
tracking?.dumpWindowsToPasteboard()
}
func openSettings() {
if settingsWindow == nil {
settingsWindow = SettingsWindow(settings: settings)
}
settingsWindow?.show()
}
}

View File

@@ -0,0 +1,31 @@
import Foundation
import ServiceManagement
// LaunchAtLogin controls the login item of EPOD Window Bar. The helper uses
// SMAppService.mainApp. The helper logs an error and does not crash if the
// register call or the unregister call fails.
@MainActor
enum LaunchAtLogin {
// isEnabled is true if the app starts at login.
static var isEnabled: Bool {
return SMAppService.mainApp.status == .enabled
}
// setEnabled turns the login item on or off.
static func setEnabled(_ on: Bool) {
do {
if on {
if SMAppService.mainApp.status != .enabled {
try SMAppService.mainApp.register()
}
} else {
if SMAppService.mainApp.status == .enabled {
try SMAppService.mainApp.unregister()
}
}
} catch {
Log.app.error("Launch at login change failed: \(error.localizedDescription, privacy: .public)")
}
}
}

View File

@@ -0,0 +1,160 @@
import AppKit
// MenuBarController owns the NSStatusItem and the menu (spec section 7.12).
// The menu refreshes its checkmarks each time the user opens the menu. The
// button shows a warning symbol if a permission is missing.
@MainActor
final class MenuBarController: NSObject, NSMenuDelegate {
private let statusItem: NSStatusItem
private let permissions: PermissionManager
private weak var control: AppControl?
private let settings: Settings
private let menu = NSMenu()
private let pauseItem = NSMenuItem()
private let constrainItem = NSMenuItem()
private let launchItem = NSMenuItem()
private let permissionsItem = NSMenuItem()
private var lastState: PermissionState
init(permissions: PermissionManager, control: AppControl, settings: Settings) {
self.permissions = permissions
self.control = control
self.settings = settings
self.lastState = permissions.current
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
super.init()
configureButton()
buildMenu()
updatePermissionState(permissions.current)
}
private func configureButton() {
guard let button = statusItem.button else { return }
button.image = NSImage(systemSymbolName: "rectangle.split.3x1",
accessibilityDescription: "EPOD Window Bar")
button.image?.isTemplate = true
}
private func buildMenu() {
menu.delegate = self
pauseItem.title = "Pause EPOD Window Bar"
pauseItem.action = #selector(togglePause)
pauseItem.target = self
menu.addItem(pauseItem)
constrainItem.title = "Keep windows above strip"
constrainItem.action = #selector(toggleConstrain)
constrainItem.target = self
menu.addItem(constrainItem)
menu.addItem(.separator())
let excluded = NSMenuItem(title: "Excluded apps…",
action: #selector(openSettings),
keyEquivalent: "")
excluded.target = self
menu.addItem(excluded)
launchItem.title = "Launch at login"
launchItem.action = #selector(toggleLaunchAtLogin)
launchItem.target = self
menu.addItem(launchItem)
let dump = NSMenuItem(title: "Dump windows to log",
action: #selector(dumpWindows),
keyEquivalent: "")
dump.target = self
menu.addItem(dump)
let copyDump = NSMenuItem(title: "Copy window dump",
action: #selector(copyWindowDump),
keyEquivalent: "")
copyDump.target = self
menu.addItem(copyDump)
menu.addItem(.separator())
permissionsItem.title = "Permissions: unknown"
permissionsItem.isEnabled = false
menu.addItem(permissionsItem)
menu.addItem(.separator())
let quit = NSMenuItem(title: "Quit EPOD Window Bar",
action: #selector(quit),
keyEquivalent: "q")
quit.target = self
menu.addItem(quit)
statusItem.menu = menu
}
// updatePermissionState sets the status text and the button symbol.
// The button shows a warning symbol if a permission is missing.
func updatePermissionState(_ state: PermissionState) {
lastState = state
let text: String
if state.allGranted {
text = "Permissions: all granted"
} else if state.accessibility {
text = "Permissions: Screen Recording missing (reduced mode)"
} else {
text = "Permissions: Accessibility missing"
}
permissionsItem.title = text
guard let button = statusItem.button else { return }
let symbol = state.allGranted ? "rectangle.split.3x1" : "exclamationmark.triangle"
button.image = NSImage(systemSymbolName: symbol,
accessibilityDescription: "EPOD Window Bar")
button.image?.isTemplate = true
}
// refreshState sets the checkmarks from the current app state. The menu
// calls this function each time the user opens the menu.
private func refreshState() {
pauseItem.state = (control?.isPaused ?? false) ? .on : .off
constrainItem.state = (control?.constrainWindows ?? true) ? .on : .off
launchItem.state = LaunchAtLogin.isEnabled ? .on : .off
updatePermissionState(permissions.current)
}
// menuNeedsUpdate refreshes the menu state before macOS shows the menu.
func menuNeedsUpdate(_ menu: NSMenu) {
refreshState()
}
@objc private func togglePause() {
control?.togglePause()
}
@objc private func toggleConstrain() {
let now = control?.constrainWindows ?? true
control?.setConstrainWindows(!now)
}
@objc private func openSettings() {
control?.openSettings()
}
@objc private func toggleLaunchAtLogin() {
LaunchAtLogin.setEnabled(!LaunchAtLogin.isEnabled)
}
@objc private func dumpWindows() {
control?.dumpWindowsToLog()
}
@objc private func copyWindowDump() {
control?.copyWindowDump()
}
@objc private func quit() {
NSApp.terminate(nil)
}
}

14
Sources/App/main.swift Normal file
View File

@@ -0,0 +1,14 @@
import AppKit
// EPOD Window Bar entry point.
// The app is an agent (LSUIElement). It has no Dock icon and no main menu.
// The program starts on the main thread. The app and the delegate are
// main-actor isolated. MainActor.assumeIsolated makes the main-actor context
// available at the entry point.
MainActor.assumeIsolated {
let app = NSApplication.shared
let delegate = AppDelegate()
app.delegate = delegate
app.setActivationPolicy(.accessory)
app.run()
}