WindowServer: display compositor and input event router

WindowServer, sometimes referred to with a space as Window Server, is a group of interconnected services which handle window management, compositing of windows into the display image, and event-routing for apps. As a key part of the GUI, it’s launched to support the login window and runs until the user logs out. It has moved around between different systems over the years: originally it was Quartz Compositor, then part of Core Graphics, and currently is part of SkyLight. In Catalina, it’s to be found in /System/Library/PrivateFrameworks/SkyLight.framework/Resources, alongside pointer/cursor support.

Apps manage the contents of their own windows, and can generate OpenGL (now deprecated) and Metal code to take advantage of GPUs, for example. WindowServer takes each window from each running app and builds them into a layered display image. It passes that on to the graphics drivers to render in the graphics card(s), thus into the display(s). Accelerated graphics commands, such as Metal code, are managed in conjuction with MTLCompilerService, the other process owned by the user _windowserver, also listed in Activity Monitor.

For example, here are two windows which are drawn by different apps.

winserv01

winserv02

WindowServer positions them according to their current locations on the whole display, and produces a layered composite.

winserv03

That is then sent out through the graphics driver to the graphics card.

With its central position in managing windows and compositing them, WindowServer is also responsible for handling multiple displays, and behaviours which stream or extract parts or all of a display image, such as taking screenshots.

Because WindowServer knows which app’s windows are where, and which are at the front, it also routes events to each app. For example, when you click on a window it’s WindowServer which determines which app owns it, and passes the event to that app to handle.

One of the best ways to see WindowServer at work is to take a screenshot of one window using the Command-Shift-4 shortcut. The cursor then changes to a crosshair, through the related pointer/cursor management system. Press the spacebar to turn that into a single-window screenshot, and WindowServer highlights each window as the pointer passes over it. When you click on a window, WindowServer determines which window you have selected, and takes that window from those it is compositing to form the whole display. It then sets that image against a transparent background and generates the screenshot.

WindowServer has no options or controls for the user, and apps themselves have limited calls which they can make to it. Among those are Quartz Display Services, which configure and control display hardware, and Quartz Event Services, which manage event taps, filters for observing and altering the stream of user input events.

WindowServer and SkyLight as a whole are well-represented in the unified log, under the subsystems com.apple.windowserver and com.apple.SkyLight respectively. The latter is one of the most active components seen in Signposts, together with com.apple.coreanimation, to monitor performance of rendering. WindowServer is most loquacious around the time of user login, and when there are problems in its compositing-rendering pathway.

If WindowServer stops working, for instance when it crashes, not only does everything on the display(s) freeze, but routing of input events such as clicks or taps also stops. macOS normally attempts to restart WindowServer to restore function. If it can’t be restarted, probably because of a downstream failure such as an unresponsive GPU, then there are only two ways forward: log the current user out, address the graphics output problem then restart WindowServer, or panic the kernel to force a restart. These are discussed in more detail in this article.

Recurrent WindowServer crashes suggest a problem with the graphics driver or graphics hardware.

As WindowServer and its related services are on the System volume, they are protected in Catalina.

Further reading

Daemons and Agents, Technical Note TN2083 (old)
Quartz Display Services documentation (old)
Quartz Window Services programming reference
Quartz Display Services programming reference
Quartz Event Services programming reference