防止 GTK 中的窗口重叠

发布于 2024-09-26 05:43:19 字数 289 浏览 1 评论 0原文

我有一个 Python/Linux 应用程序,可以在 GTK 窗口中显示我需要的一些信息。出于本次讨论的目的,它的行为应该与扩展坞完全相同 - 存在于所有虚拟桌面上,并且最大化的窗口不会与其重叠。

第一点很简单,但我花了几天时间用头撞显示器,试图得到第二点——防止重叠。如果另一个窗口最大化,我的应用程序不应被覆盖。设置“始终在顶部”是不够的,因为其他窗口只是位于我的信息栏后面,而不是停在其边缘。

简而言之:对于停靠/面板样式的窗口,如何防止其他窗口在其上方/下方最大化?

更新:感谢 vsemenov 解决了问题

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月野兔 2024-10-03 05:43:19

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

使用 PyGtk,您可以像这样设置这些属性,假设 self.window 是 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]) 

对上面数据参数 [0, 0, 0, Bottom_width] 的说明:

该参数指定桌面屏幕每个边框保留空间的宽度,顺序为:[左、右、上、下]。因此 [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()

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文