防止GTK中的窗口重叠 [英] Preventing window overlap in GTK

查看:171
本文介绍了防止GTK中的窗口重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Python / Linux应用程序,它在GTK窗口中显示我需要的信息。为了讨论的目的,它的行为应该像码头一样 - 存在于所有虚拟桌面上,并且最大化的窗口不会与其重叠。

第一点很简单,但我花了几天的时间把我的头撞向我的显示器,试图获得第二点 - 防止重叠。如果另一个窗口最大化,我的应用程序不应被覆盖。将始终在最上面设置是不够的,因为其他窗口只是坐在我的信息栏后面,而不是停在它的边缘。简而言之:使用dock / panel样式的窗口,你怎样才能防止其他窗口最大化/超出/不足?



更新:由于vsemenov解决了问题

解决方案

href =http://standards.freedesktop.org/wm-spec/wm-spec-1.3.html#id2507592 =noreferrer> _NET_WM_STRUT _NET_WM_STRUT_PARTIAL (为了向后兼容性)属性以在X Window系统桌面的边缘保留空间。



使用PyGtk,您可以像这样设置这些属性,假设自己.window是gtk.Window的一个实例:

  self.window.get_toplevel()。show()#must call show( )property_change()之前
self.window.get_toplevel()。window.property_change(_ NET_WM_STRUT,
CARDINAL,32,gtk.gdk.PROP_MODE_REPLACE,[0,0,0,bottom_width] )

澄清数据参数 [0,0,0,bottom_width] 在上面:



这个参数ter按照以下顺序指定桌面屏幕各边界处的保留空间宽度: [left,right,top,bottom] 。因此, [0,0,0,50] 会在桌面屏幕底部为您的小部件保留50个像素。



下面是一个简单的工作示例:

  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()


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

解决方案

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()

这篇关于防止GTK中的窗口重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆