I am building an app that at certain points needs to know the location of the user’s pointer. I am using GTK4 and C.
- I found this answer (How to use gdk_device_get_position()?) which pointed to the function
gdk_device_get_position
, but I can’t find it in the GTK4 docs, suggesting that its no longer supported. If there’s some equivalent that I’m missing I’d love to know. - Taking another tack, I’ve successfully implemented an event controller for the widget in question, thus:
GtkEventController *my_controller = gtk_event_controller_motion_new ();
gtk_widget_add_controller (my_widget, my_controller);
g_signal_connect(my_controller, "motion", my_function, NULL);
This successfully fires and runs my_function
when I move the mouse inside the widget. Reading the signature for the motion signal (https://docs.gtk.org/gtk4/signal.EventControllerMotion.motion.html) below, it appears that it should announce the x and y coordinates. How, so to speak, do I “get at” these?
void
motion (
GtkEventControllerMotion* self,
gdouble x,
gdouble y,
gpointer user_data
)
Sorry if I’m missing something obvious! Wouldn’t be asking if I hadn’t done my docs/SO due diligence.
Thank you!