使用 HeaderBar 时保存并恢复 window 大小和位置
Save and restore window size and position when using HeaderBar
在我的应用程序中,我想在重新启动后恢复我的应用程序 windows 的位置和大小。目前,我正在使用 Gtk.Window.get_size()
和 Gtk.Window.get_position()
来获取大小和位置,并使用 Gtk.Window.resize()
和 Gtk.Window.move()
来恢复它们。
这起初有效,但现在,我已将应用程序更改为使用 Gtk.HeaderBar
,但位置和大小都不正确了。
Gtk.Window.get_position()
states 的文档表明这是预期的行为。它说
The correct mechanism is to support the session management protocol (see the “GnomeClient” object in the GNOME libraries for example) and allow the window manager to save your window sizes and positions.
但我不知道它是如何工作的或如何实施的。
那么,在使用HeaderBar
时,如何保存和恢复window的位置和大小呢?便携式解决方案最好,但至少应该支持 X11 和 Wayland。
最近针对 GTK+ 3.20 修复了 gtk_window_get_size()
、gtk_window_set_size()
和客户端修饰的各种问题 — 参见 the release notes for the 3.20 version。
如果您想恢复 window 的大小,请确保您使用的是最新稳定版本的 GTK+,并且您从不使用分配的大小,而是 [=10= 返回的大小].同样重要的是要注意,您不应该在销毁期间查询 window 的状态,而是在状态本身发生变化时查询。例如,参见 Saving window state page on the GNOME wiki.
关于位置:你应该知道Wayland(和Mir)没有全局坐标系,因此你无法查询你的window在屏幕上的位置,也无法手动设置它在那个 windowing 系统上。
GnomeClient API 早已被弃用,作为会话管理的一部分的状态保存并没有真正起作用。文档需要修复。
在我的应用程序中,我想在重新启动后恢复我的应用程序 windows 的位置和大小。目前,我正在使用 Gtk.Window.get_size()
和 Gtk.Window.get_position()
来获取大小和位置,并使用 Gtk.Window.resize()
和 Gtk.Window.move()
来恢复它们。
这起初有效,但现在,我已将应用程序更改为使用 Gtk.HeaderBar
,但位置和大小都不正确了。
Gtk.Window.get_position()
states 的文档表明这是预期的行为。它说
The correct mechanism is to support the session management protocol (see the “GnomeClient” object in the GNOME libraries for example) and allow the window manager to save your window sizes and positions.
但我不知道它是如何工作的或如何实施的。
那么,在使用HeaderBar
时,如何保存和恢复window的位置和大小呢?便携式解决方案最好,但至少应该支持 X11 和 Wayland。
最近针对 GTK+ 3.20 修复了 gtk_window_get_size()
、gtk_window_set_size()
和客户端修饰的各种问题 — 参见 the release notes for the 3.20 version。
如果您想恢复 window 的大小,请确保您使用的是最新稳定版本的 GTK+,并且您从不使用分配的大小,而是 [=10= 返回的大小].同样重要的是要注意,您不应该在销毁期间查询 window 的状态,而是在状态本身发生变化时查询。例如,参见 Saving window state page on the GNOME wiki.
关于位置:你应该知道Wayland(和Mir)没有全局坐标系,因此你无法查询你的window在屏幕上的位置,也无法手动设置它在那个 windowing 系统上。
GnomeClient API 早已被弃用,作为会话管理的一部分的状态保存并没有真正起作用。文档需要修复。