Prevent Window Overlap in GTK

I have a Python / Linux application that displays a bit of the information I need in a GTK window. For the purposes of this discussion, it should behave exactly like a docking station - exists on all virtual desktops, and the maximum windows do not overlap it.

The first moment is quite simple, but I spent days smashing my head against my monitor, trying to get the second point - preventing overlap. My application should not be closed if another window is maximized. Installing "always on top" is not enough, as other windows just sit behind my dashboard, and do not stop at its edge.

In short: with a dock / panel style window, how can you prevent other windows from expanding beneath it?

Update: the problem is solved thanks to vsemenov

+4
source share
1 answer

Use _NET_WM_STRUT and _NET_WM_STRUT_PARTIAL (for backward compatibility) to reserve space on the edge of the X Window System desktop.

With PyGtk, you can set these properties as follows: it is assumed that self.window is an instance of gtk.Window:

 self.window.get_toplevel().show() # must call show() before property_change() self.window.get_toplevel().window.property_change("_NET_WM_STRUT", "CARDINAL", 32, gtk.gdk.PROP_MODE_REPLACE, [0, 0, 0, bottom_width]) 

Explanation of the data parameter [0, 0, 0, bottom_width] above:

This parameter determines the width of the reserved space on each border of the desktop screen to: [left, right, top, bottom] . Thus, [0, 0, 0, 50] would reserve 50 pixels at the bottom of the desktop screen of your widget.

Here is a simple working example:

 import gtk class PyGtkWidgetDockExample: def __init__(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_default_size(100, gtk.gdk.screen_height()) self.window.move(gtk.gdk.screen_width()-100, 0) self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DOCK) self.window.show() self.window.window.property_change("_NET_WM_STRUT", "CARDINAL", 32, gtk.gdk.PROP_MODE_REPLACE, [0, 100, 0, 0]) app = PyGtkWidgetDockExample() gtk.main() 
+12
source

All Articles