I want to get a GTK4 Window’s X
, Y
, Height
and Width
coordinates.
Using GTK3, we could register a configure-event
callback to get window size changes.
g_signal_connect(G_OBJECT(window), "configure-event",
G_CALLBACK(frame_callback), NULL);
And in the callback we could get the x and y position of the window with:
void frame_callback(GtkWindow *window,
GdkEvent *event, gpointer data)
{
int x, y;
char buf[10];
x = event->configure.x;
y = event->configure.y;
sprintf(buf, "%d, %d", x, y);
gtk_window_set_title(window, buf);
}
Much less clear how to get this in GTK4, if at all…
The GTK 3 to GTK 4 migration guide notes that:
- If you were using
::configure-event
and::window-state-event
to save window state, you should use property notification for correspondingGtkWindow
properties, such asGtkWindow:default-width
,GtkWindow:default-height
,GtkWindow:maximized
orGtkWindow:fullscreened
.
So I presume that I need to use GObject > Object::notify however I do not see an X
or Y
coordinate on the window that I can watch.
From the signal notify page…
g_signal_connect (text_view->buffer, "notify::paste-target-list",
G_CALLBACK (gtk_text_view_target_list_notify),
text_view)
It is important to note that you must use
[canonical parameter names][canonical-parameter-names]
as detail strings for the notify signal.
I’ve read about Wayland having a different idea about X and Y window coordinates, so I hope that GTK4
window positions haven’t been removed in pursuit of being more like Wayland…
Wayland on desktops has no official way to position
windows from the client by global or per-output x,y coordinates. This
is by design for desktops. On the desktop, the window manager is the
only one that knows enough to be able to position windows correctly.