Judging from window management on Linux (at least on Ubuntu using Gnome with Compiz), windows are organised in a stack. Switching to a window other than the one in focus will bring the former on top of the stack, right above the latter.

So is it theoretically possible to tell the WM to raise or lower windows in that stack and to raise them to topmost or lower them to bottommost?

If so, would Python XLib be able to do that? Is there any WM that already has this feature?


Yes, windows are arranged in a stack and can be raised and lowered or brought to the top or bottom. In some window managers they can even stay at the top or 'stick' to all panes (aka workspaces).

Look into the send_event() method and the relevant X Window System documentation for more information, but yes, you should be able to do it. You may want to look at the output of xev(1) for more help on what needs to be changed (from the running X server POV).

If this is your own window (for example in Tkinter), then look into the WM operations. There are already lower() and raise() methods as part of Tkinter's TopLevel class. Check your library's documentation for specifics.

  • Cool thanks. I am planning a project for a new DE in which there would be no desktop but a dashboard-launcher instead and windows would not minimize but rather be sent behind/below the dashboard window. So now I know it is feasible---cheers :) – Benjamin Aug 27 '11 at 16:55
  • How would send_event help to raise a window? The event notifies a window that it's been raised. If you fake the event, the window will be told that it's been raised, but it won't actually be raised. – Gilles Aug 27 '11 at 17:59
  • Everything in Xwindows is handled by events. An XRaiseWindow() call is managed by sending Expose and ConfigureRequest events with the proper window/event masks. I didn't see raise or lower window mechanisms in the Python X11 documentation (granted I didn't look at every page), but event management is there, including send_event. There is also wm_state, which when toggled to a normal state might bring the window to the top (depending on WM settings). I haven't done any of this level programming since the late '80s, but with the original C XLib, you could do this. – Arcege Aug 27 '11 at 18:29

Yes, a window manager can raise and lower windows. In fact the window manager is normally in charge of lowering, raising, moving, resizing, focusing, and generally managing windows.

The X library functions to lower and raise a window are XRaiseWindow and XLowerWindow. There are more functions to act on the stacking order. They don't seem to be available in Python Xlib, but you can reach them easily with the help of ctypes.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.