I am trying to understand how different components of a Linux system interact with the services offered by a display server. Before complicating the question with Wayland-based display servers, let me first focus on X11:

  1. I know that in order to implement a very basic GUI application for an X11-based system, it is theoretically possible to program against X11's C library binding and make use of low-level primitives such as XMapWindow or XDrawString to create a specific X client. Is this also the API that common GUI toolkits (such as GTK or Qt) make use of at the lowest level of their Linux implementation? Or do they draw their buttons and text fields in a different manner?
  2. According to this post, one the job of a window manager is to control the placement of a window. How exactly does this happen? Is the display server aware of every single window that the window manager wants to be shown and, for each of these windows, expects the window manager to provide it with a position and the desired dimensions? And when the window gets resized, for instance, it is the window manager's duty to update these dimensions?
  3. Considering the post from above again, another job of the window manager is to decorate the window, i.e., draw the borders and controls of the application. How does the window manager do this? Does it again use above-mentioned X11 primitives to draw objects around the actual X client? And if it does: How does it know which menus the developer of the X client programmed into its GUI?
  4. If we are not only running a window manager, but a complete desktop environment such as GNOME: How are environment-specific components such as panels and window switchers drawn? Do they run as individual X clients?

And finally, consider Wayland instead of X11. If I understand this article correctly, Wayland-based display servers are called “Wayland compositors” and integrate the functionality of a compositing window manager. Does this mean that a Wayland compositor such as Mutter is entirely incompatible with traditional window managers such as Compiz?

  1. Toolkits originally used the X11 low-level primitives to draw content on the screen. Nowadays, font handling and text rendering is done on the client side, and X protocol extensions like GLX (OpenGL over the X protocol) and Direct Rendering (DRI) are available.

  2. The X server is aware of all windows and their sizes and placements. A window is a server-side object in X11. Clients can send a window creation request to the X server, and the server responds with an id of the created window. A window typically get resized when the user interacts with the window manager, which in turn sends a request to the server to resize the window using an X11 API call.

  3. The window manager is a normal X11 client application, although a special one. The window manager does indeed use the same X calls and handle the same events as a normal X client application, like drawing primitives and pointer events. The application menus are not part of the decorations the window manager draws, but are handled by the application itself.

  4. The "panels" and "window switchers" of desktop environments can be either separate X clients, or they can be part of the window manager, especially if they do tasks like switching windows.

Wayland window managers are at the lowest level very different from their X11 counterparts, because the Wayland architecture differs quite a bit from X11. If you are running Wayland, you need a Wayland window manager/compositor. On the other hand, some Wayland window managers, like KWin, have been written with the original X11 version as a starting point, with the goal of providing an almost identical user experience, so from a user's point of view the two variants (KWin/X11 and KWin/Wayland) are compatible.

See How does Linux's display Work?

  • Thank you very much for your answer! Allow me to ask a short follow-up question: I was just experimenting with twm and used it to open a GTK app (Nautilus). To my surprise, the entire app (including the fancy GTK border and the integrated control buttons) was rendered into the twm window. Does this mean that when I open Nautilus on GNOME, Mutter will recognize it as a GTK app that brings its own decorations along and, therefore, do not add further decorations to this window? Which it would do if I opened a Qt app, for example? – user424386 Jul 25 '20 at 21:26
  • Sounds about right (your are saying that with twm it is decorated twice: self decoration + twm decoration). That is what I would expect. There is meta information that the client can set up, about its windows. The WM, is allowed to use this in its decisions. – ctrl-alt-delor Jul 25 '20 at 23:50

I have written an X11 app using Xlib ( a small game ). I have looked at how window managers work, but not written one.

Part 2&3 Window managers

When a client creates a window the server receives the request. When the client maps the window (asks the server to display it. It can also un-map: like when it is hidden in the task bar), the server will notify the window-manager (I think a client must register as the window-manager). The window manager intercepts the mapping ,and will get the window ID of the new window it then creates its own window containing sub-windows of title bar, frame parts (left, right, bottom), and a big bit in the middle. It the tells the server to re-parent the original window to this big bit in the middle. Then maps this now window.

Note, in X11 everything is a window. Windows contain other windows. The Display has one window, the root window. All other windows are withing this root window. Like directories in a file-system. re-parenting, is like moving a directory to another directory withing the same file-system.

Part 4 panels

These are just other clients. The task bar will co-operate with the window manager. The window manager will tell the task-bar, what the state of a window is.

Client menus etc.

These may be created using the same toolkit as the window manager. However they are part of the client.

Interesting experiments.

Try running X11 without the window-manager. Try the window manager without the rest of the desktop environment. Try pausing (stop in the process manager) the window manager, and the other clients (separately). Try switching window manager without logging out, or closing other clients.

These experiments will help you see what the window manager does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy