Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make window centered in GTK4?

Tags:

gtk

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.

like image 798
senya Avatar asked Jun 27 '20 19:06

senya


1 Answers

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.

like image 138
nielsdg Avatar answered Oct 04 '22 02:10

nielsdg