如何为 GTK window 保留屏幕 space?

How to reserve screen space for GTK window?

can be done 使用 python 中的代码:

topw = window.get_toplevel().window
topw.property_change("_NET_WM_STRUT","CARDINAL",32,gtk.gdk.PROP_MODE_REPLACE, [0, 0, bar_size, 0])
topw.property_change("_NET_WM_STRUT_PARTIAL","CARDINAL",32,gtk.gdk.PROP_MODE_REPLACE, [0, 0, bar_size, 0, 0, 0, 0, 0, x, x+width, 0, 0])

但是 GJS 中有 property_change 绑定吗?

唉,gdk_property_change()marked non-introspectable所以在GJS、PyGObject等中没有绑定

如您所见,PyGTK 确实支持它,但它太旧了,您不能将它与 GTK 3 一起使用。

Here在Gtk3中是怎么做的:

display = Display()
topw = display.create_resource_object('window',
                                       window.get_toplevel().get_window().get_xid())
topw.change_property(display.intern_atom('_NET_WM_STRUT'),
                       display.intern_atom('CARDINAL'), 32,
                       [0, 0, bar_size, 0 ],
                       X.PropModeReplace)

topw.change_property(display.intern_atom('_NET_WM_STRUT_PARTIAL'),
                       display.intern_atom('CARDINAL'), 32,
                       [0, 0, bar_size, 0, 0, 0, 0, 0, x, x+width-1, 0, 0],
                       X.PropModeReplace)

您需要以下导入:

import gi
gi.require_version('Gtk','3.0')
from gi.repository import Gtk, Gdk
import Xlib
from Xlib.display import Display
from Xlib import X

confirmed via the mailing list 正如@ptomato 所述,该函数是 non-introspectable 这意味着它在 Python.

等自省绑定中不可用

附加信息

您可以在 Ruby(gtk2 或 gtk3 绑定)中执行此操作。您需要 require 'xlib-objects',然后从 Gtk::Window:

(的子类)的实例
topw = XlibObj::Window.new(XlibObj::Display.new(':0'),
            toplevel.window.xid)
XlibObj::Window::Property.new(topw, '_NET_WM_STRUT').set(
            [0, 0, self.height, 0 ],
            :CARDINAL)
XlibObj::Window::Property.new(topw, '_NET_WM_STRUT_PARTIAL').set(
            [0, 0, self.height, 0, 0, 0, 0, 0, x, x+width-1, 0, 0], 
            :CARDINAL)

或者你可以使用 xprop 通过 system 子 shell:

xid = toplevel.window.xid
system %Q{xprop -id #{xid} -format _NET_WM_STRUT 32c \
                           -set _NET_WM_STRUT \
                           "0, 0, #{self.height}, 0"}
system %Q{xprop -id #{xid} -format _NET_WM_STRUT_PARTIAL 32c \
                           -set _NET_WM_STRUT_PARTIAL \
          "0, 0, #{self.height}, 0, 0, 0, 0, 0, #{x}, #{x+width-1}, 0, 0"}

最后,从command-line开始做:

$ xprop -id 44040195 -format _NET_WM_STRUT_PARTIAL 32c -set _NET_WM_STRUT_PARTIAL "0, 0, 15, 0, 0, 0, 0, 0, 1600, 3519, 0, 0"

(其中 -id 44040195 指定 window 它;省略 select window 用鼠标)

要从 command-line 查看设置:

$ xprop _NET_WM_STRUT_PARTIAL _NET_WM_STRUT