Jan Bodnar
Jan Bodnar

Reputation: 11637

GTK4 - how to get coordinates of a moving window

In previous versions of GTK, we added a necessary event mask, attached to a configure-event.

gtk_widget_add_events(GTK_WIDGET(window), GDK_CONFIGURE);

g_signal_connect(G_OBJECT(window), "configure-event",
      G_CALLBACK(configure_callback), NULL);

We got the corresponding x,y coordinates from the handler.

void configure_callback(GtkWindow *window, 
      GdkEvent *event, gpointer data) {
          
   int x, y;
   x = event->configure.x;
   y = event->configure.y;
   ...
}

The closest thing that resembles this is GtkEventControllerMotion, but it is for mouse pointer, not for window move events.

How to do it in GTK4?

Upvotes: 0

Views: 358

Answers (1)

AlexApps99
AlexApps99

Reputation: 3584

You can't. This is because not all window managers/compositors provide this information, for privacy and/or technical reasons.

Wayland, for example, does not provide window coordinates, because not every Wayland compositor is even a 2D rectangle - for example, kiosk compositors like cage or gamescope, or VR compositors like wxrd.

Because of this, the functionality was removed from GTK4. You will need to use an X11-specific API to get this information, but note that you would need to force your application to use X11 (over XWayland on Wayland compositors)

https://docs.gtk.org/gtk4/migrating-3to4.html#adapt-to-gtkwindow-api-changes

Upvotes: 2

Related Questions