简体   繁体   English

如何使 window 以 GTK4 为中心?

[英]How to make window centered in GTK4?

In GTK3 there was a property on the Gtk.Window class called window-position .在 GTK3 中有一个属性Gtk.Window class 称为window-position By setting this property to Gtk.WindowPosition.CENTER it was possible to tell the window to render in the center of the screen.通过将此属性设置为Gtk.WindowPosition.CENTER可以告诉 window 在屏幕中心进行渲染。

In GTK4 this property has been removed.在 GTK4 中,此属性已被删除。 How to achieve the same behavior in GTK4, ie how to make the main window of my application to be rendered in the center of the screen?如何在 GTK4 中实现相同的行为,即如何使我的应用程序的主要 window 呈现在屏幕中央?

I checked the migration guide but I couldn't find the solution.我检查了迁移指南,但找不到解决方案。

There is no replacement API, since it can't possibly work cross-platform, so it is broken API by definition.没有替代API,因为它不可能跨平台工作,所以它被定义为损坏的API。 As such, it was removed.因此,它被删除了。

For example: this is impossible to implement when running on top of a Wayland session, since the protocol doesn't allow getting/setting global coordinates.例如:在 Wayland session 上运行时,这是不可能实现的,因为该协议不允许获取/设置全局坐标。 If you still want to have something similar working, you'll have to call the specific platform API (for example, X11) for those platforms that you want to support.如果您仍然希望有类似的工作,您必须为您想要支持的平台调用特定平台 API(例如 X11)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM