I've created a new window and want to move it to the center of the screen, and how am I supposed to do it? I've tried below
gtk_widget_hide (GTK_WIDGET (window));
gtk_window_set_position (window, GTK_WIN_POS_CENTER);
gtk_widget_show_all (GTK_WIDGET (window));
but it seems that the
gtk_window_set_position (window, GTK_WIN_POS_CENTER)
is only triggered once. Is there something I did wrong?
you must use gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS)
:)
To tell your application to position in the center, the following should work. I am however not familiar with the function you mention, and perhaps it is as good as this way of doing it. You can use the gtk_window_move() to move your window, the coordinates is by default calculated by default from the upper left corner, it is however possible to change this with:
void gtk_window_set_gravity (GtkWindow *window,
GdkGravity gravity);
The available enums is as follows:
GDK_GRAVITY_NORTH_WEST, GDK_GRAVITY_NORTH, GDK_GRAVITY_NORTH_EAST,
GDK_GRAVITY_WEST,GDK_GRAVITY_CENTER, GDK_GRAVITY_EAST,
GDK_GRAVITY_SOUTH_WEST, GDK_GRAVITY_SOUTH, GDK_GRAVITY_SOUTH_EAST,
and GDK_GRAVITY_STATIC.
And then use
void gtk_window_move (GtkWindow *window,
gint x,
gint y);
It is not certain it will change the initial window position, it is up to the Windowmanager to comply or not, as the manual for gtk tells the reader, most window managers ignore initial window positions.
This link will give you a lot of information regarding the function above https://developer.gnome.org/gtk3/3.5/GtkWindow.html#gtk-window-move
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With