In macOS, apps including the Finder manage the contents of their own windows. To assemble all those into what you see on the display, it takes the master compositor, WindowServer. From the moment the login window appears during startup, WindowServer is hard at work, and remains so until you shut your Mac down. Without WindowServer there can be no GUI.
Open Activity Monitor, and you’ll see WindowServer close to the top of the lists of CPU, Memory and Energy users, and when it’s getting into trouble that’s always a good place to check what’s up with it. You may also notice that it’s one of a small group of processes including
distnoted and MTLCompilerService which have their own user, _windowserver. They’re part of a group of interconnected services which handle window management, the compositing of windows into the display image, and event-routing for apps.
distnoted is a system message notification service, and MTLCompilerService manages accelerated graphics commands in Metal.
You can get a good idea of what WindowServer does using screenshots. Using Command-Shift-4, then pressing the Space Bar and selecting a window, you’ll get a shot of an individual window, as shown in the examples below.
WindowServer then positions them according to their current locations on the whole display, and produces a layered composite, as you’ll see in a screenshot taken with Command-Shift-3.
That composite is then sent through the graphics driver to graphics output hardware.
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.
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. Although in the past macOS has sometimes been able to log the current user out and restart WindowServer, fatal WindowServer problems are now going to result in a kernel panic or a complete freeze. If your Mac freezes rather than restarts, a forced shutdown is likely to be your only way ahead.
Recurrent WindowServer crashes suggest a problem with the graphics driver or graphics hardware, and should be reported to Apple via Feedback.