I was reading a book called Low Level X Window Programming by Ross Maloney. He was talking about one of the key aspects of a stacked window system i.e restoration of "hidden" contents when you "remove" a window.

Normally you would expect the content "behind" to be immediately visible. However, apparently, this is not something that an x implementation has to provide though some does.

The save under and backing store services differ slightly. In save under, the contents of the screen onto which a window is mapped is save by the server at the instance before the window is mapped, using the memory of the server.

  1. If this is not something that x server provides, should it be implemented in the client side?
  2. How do some of the typical window manager implement stacking?
  3. If xorg does provide this feature, is there any specific algorithm that can be used especially for "save under"? I didn't understand how saving a copy of the overlapping area can be used later especially when you have multiple overlaps =) My mind is already blowing! Can such delta's be used to reconstruct the stack?

If not, does it repaint each of the stacked window one by one in case of a random window removal? Wikipedia says the following:

Stacking is a relatively slow process, requiring the redrawing of every window one-by-one, from the rear-most and outer-most to the front most and inner-most. Many stacking window managers don't always redraw background windows. Others can detect when a redraw of all windows is required, as some applications request stacking when their output has changed. Re-stacking is usually done through a function call to the window manager, which selectively redraws windows as needed. For example, if a background window is brought to the front, only that window should need to be redrawn.

PS: I know this is a big question, but it would be helpful to get some pointers.

2 Answers 2


Both backing store and save under are attributes/flags that can be set when creating a window with XCreateWindow(). However, they're only hints to the X11 server, are not on by default, and are not really worth the trouble with modern hardware.

Generally, when (part of) a background window becomes visible, the X11 server will send an Expose event to the X11 client, which should cause it to redraw it. Since those are only hints, the X11 server may still send an Expose even if the client had set both .backing_store = Always on the window and CWSaveUnder on the popup windows it opened on top of it.

There are also interfaces which allows a client to query if the server implements backing store and save under: XDoesBackingStore() and XDoesSaveUnders().

The window manager has nothing to do with all this; it does not redraw any windows (other than its own: the title bars, close buttons).

  • When you say "the X11 server will send an Expose event to the X11 client", does that mean client has to do something for that? Perhaps map? But wait that might map the whole window?
    – Nishant
    Dec 29, 2018 at 6:03
  • 1
    The client will have to either call XSelectInput() with ExposureMask or set it in the event_mask when creating the window. You should read the one page doc the links from my answer point to -- it contains just everything about X11 programming, except for the X11 extensions.
    – user313992
    Dec 29, 2018 at 12:41
  • 1
    And of course, the window will have to be mapped in order to generate Expose events; however, it could be mapped and fully hidden, in which case no expose events will be generated.
    – user313992
    Dec 29, 2018 at 12:46

If not, does it repaint each of the stacked window one by one in case of a random window removal?

Most popular desktops use the more recent XCOMPOSITE extension. The entire window contents is rendered to off-screen buffers, so they are all available to the compositing manager without needing to request applications to redraw them.

Here is an excerpt from the official site:

This extension causes a entire sub-tree of the window hierarchy to be rendered to an off-screen buffer. Applications can then take the contents of that buffer and do whatever they like. The off-screen buffer can be automatically merged into the parent window or merged by external programs, called compositing managers. Compositing managers enable lots of fun effects.

  • 2
    Nothing to do with it. And yes, Xorg does implement backing-store, though it's not enabled by default (with modern hardware, it's not really worth it; but the backing store implementation was the reason for some nasty legal stuff, Rob Pike heckling, etc) The XCOMPOSITE extension is basically about something different: implementing translucent, alpha-compositing windows.
    – user313992
    Dec 28, 2018 at 19:25
  • Thanks @sourcejedi. Do you know of any algorithms that can be used to implement "save under" kind of thing?!
    – Nishant
    Dec 28, 2018 at 19:28
  • @UncleBilly, interesting. I am just reading this commandcenter.blogspot.com/2006/06/… from Rob Pikes' blog.
    – Nishant
    Dec 28, 2018 at 19:50
  • @UncleBilly and Nishant: edited. XCOMPOSITE is related in the sense that using it removes the need for any other solution to this problem.
    – sourcejedi
    Dec 28, 2018 at 20:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .