Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

python - Preventing window overlap in GTK

I've got a Python/Linux application that displays bits of info I need in a GTK window. For the purposes of this discussion, it should behave exactly like a dock - exists on all virtual desktops, and maximized windows do not overlap it.

The first point is pretty easy, but I have spent days bashing my head against my monitor trying to get the second point - preventing overlap. My app should not be covered if another window is maximized. Setting "always on top" is not enough, as the other windows just sit behind my info bar instead of stopping at its edge.

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

Update: Problem solved thanks to vsemenov

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use _NET_WM_STRUT and _NET_WM_STRUT_PARTIAL (for backwards compatibility) properties to reserve space at the edge of X Window System desktop.

With PyGtk you can set these properties like so, assuming 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]) 

Clarification on the data parameter [0, 0, 0, bottom_width] in above:

This parameter specifies the width of reserved space at each border of the desktop screen in order: [left, right, top, bottom]. So [0, 0, 0, 50] would reserve 50 pixels at the bottom of the desktop screen for 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()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...