Preventing window overlap in GTK

前端 未结 1 2038
情深已故
情深已故 2020-12-09 13:54

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 o

相关标签:
1条回答
  • 2020-12-09 14:14

    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()
    
    0 讨论(0)
提交回复
热议问题