senya
senya

Reputation: 1159

How to make window centered in GTK4?

In GTK3 there was a property on the Gtk.Window class called 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.

In GTK4 this property has been removed. How to achieve the same behavior in GTK4, i.e. how to make the main window of my application to be rendered in the center of the screen?

I checked the migration guide but I couldn't find the solution.

Upvotes: 10

Views: 1492

Answers (1)

nielsdg
nielsdg

Reputation: 2733

There is no replacement API, since it can't possibly work cross-platform, so it is broken API by definition. 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. 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.

Upvotes: 9

Related Questions