Engineering notes from building SnapState: what the window server knows, what Accessibility knows, and where simple restore logic breaks. Published November 27, 2026.
At first glance, restoring a Mac window layout looks easy: record each window's position and size, then write those values back later. In practice there is no single macOS object that represents "the same window" across app relaunches, display reconnects, full-screen transitions and Spaces. The reliable part is small; everything else is careful inference.
These are implementation lessons, not a promise that every app behaves perfectly. SnapState is a paid, closed-source product, but the problems below are useful to any Mac developer building window restoration.
1. The window server and Accessibility are two different views
Core Graphics can list windows across the system with bounds, layer, ownership and a CGWindowID. That global list is useful for observing what exists right now. It is not enough to move a window: frame writes go through the owning app's Accessibility objects.
Accessibility has the inverse tradeoff. It can set position and size, but it is app-centric. Windows on another Space, windows involved in a full-screen transition, and windows of an app that is still relaunching may be missing or incomplete. A restore engine that treats either list as complete will make bad decisions.
2. A window ID is not durable identity
CGWindowID is the best key while the same window object is still alive. It is not a durable identity across a relaunch. After an app quits and starts again, the restored document window gets a new ID even if it has the same title, frame and content.
That means restore logic needs several passes. Match still-open windows by ID first. For relaunched windows, fall back to weaker evidence: title, approximate frame, display, visible state and ordering. Each fallback can be wrong. Browser titles change as pages load, editors rewrite titles when the current file changes, and two windows can legitimately have the same title. A conservative miss is better than framing the user's unrelated window into a stale slot.
3. A Space is not encoded in the frame
A rectangle has x, y, width and height. It does not say which desktop the window belongs to. Each display also has its own active Space when "Displays have separate Spaces" is on, and a full-screen window gets its own Space rather than behaving like a large window on the original desktop.
Numeric Space identifiers are useful at runtime, but they are not enough as permanent state. They can be missing, and they are not a user-facing stable identity across every restart or display rearrangement. A serious restore model needs contextual facts: the display topology, whether the Space was a normal desktop or full screen, its ordering where possible, and whether several windows of one app belonged on different Spaces.
4. Some real-looking windows are not documents
macOS and apps expose helper surfaces that can look like ordinary layer-zero windows if geometry is the only test. Full-screen toolbars and title-bar strips can appear as separate windows on the same full-screen Space. Apps can also keep invisible helper windows, windows with empty titles, or ordered-out windows that belong to no active Space.
Filtering these by size alone is fragile: a short, wide window can be a real document window. The safer approach is to combine several signals — window layer, title, on-screen state, minimized state, whether it belongs to a Space, and whether it is an accessory of a full-screen window — before treating it as something worth saving or matching.
5. Writing a frame is asynchronous, even when the API is synchronous
An Accessibility write can succeed while the visible result is still wrong. Apps clamp sizes, enforce minimum widths, resize around toolbars, adjust origin after a resize, or move a window during a Space or full-screen animation. Moving between displays can also involve different scale factors, so the rectangle you wrote is not necessarily the rectangle the app settles into.
Reliable placement therefore becomes a write-and-verify loop rather than one write. Set size and position in a deliberate order, read the resulting frame, wait briefly when the app is still animating, and retry only while the window still appears to be the intended match. Just as important, stop when the user has clearly taken control of the window. Automation that keeps fighting a human feels broken even if it is technically correct.
6. Browser tabs are outside the window frame
Putting a browser window back in the right place does not restore the pages inside it. Safari and Chromium-family browsers need a separate Automation path for tab URLs and window ordering; Firefox uses a different session mechanism. Profiles complicate identity because the visible window title does not always tell you which browser profile owns the window.
This is why a workspace restore is really several coordinated restores: relaunch apps, wait for windows, identify them conservatively, place frames, move across Spaces where needed, then restore browser contents without confusing windows from different profiles.
7. The design rule: eventual consistency with a user veto
The biggest lesson is that window restoration is eventually consistent. Displays enumerate before WindowServer finishes rearranging. Apps launch before they create their documents. Accessibility answers before a full-screen transition settles. The correct model is a sequence of observations and reversible actions, not a single transaction.
For a user-facing app, the engine also needs an escape hatch. If a display never comes back, if a window cannot be identified, or if the user moves a window manually, the app should leave that window alone rather than guess. The best restore is not the most aggressive one; it is the one that does not move the wrong window.
How this shows up in SnapState
SnapState 2.15.1 applies these constraints in a native Mac menu bar app. It saves window frames, displays, Spaces, full-screen state, apps and browser tabs as named workspaces, then restores them manually or on wake, display connect, display disconnect, or a matching display layout. It needs Accessibility permission to move windows and Automation permission for supported browser tabs. Workspace data stays on the Mac.
SnapState is paid software, not free and not open source: $9.99 once for up to three Macs, with a 14-day refund. The short demo is at https://getsnapstate.com/demo.mp4, and the product page is at getsnapstate.com.
Frequently asked questions
Is there one public macOS API that saves and restores a whole window layout?
No. A developer has to combine the window server list, Accessibility window objects, display information, app relaunch behavior and browser-specific tab handling, then reconcile them over time.
Can Accessibility move a window directly to another Space?
Accessibility can move and resize a window, but a frame does not encode which Space the window belongs to. Space restore needs separate state and very careful sequencing.
Why not match windows only by title?
Titles duplicate and change. Two browser windows can have the same page title, a document title can change while it restores, and Terminal or editor titles often depend on the current folder or file.
Is SnapState open source?
No. SnapState is a paid, closed-source Mac app. This article shares engineering lessons, not the product source code.