At least the issue seems to be not related to the Nim bindings or my tiny CAD program.
I did a test with drawing.c GTK4 example program. The default drag gestures seems to have correct coordinates. But when I use instead
gboolean
legcb(GtkEventControllerLegacy *controller,
GdkEvent *event,
gpointer user_data)
{
double x, y;
gdk_event_get_position (event, &x, &y);
printf("%f %f\n", x, y);
return TRUE;
}
....
GtkEventController *leg;
leg =gtk_event_controller_legacy_new ();
gtk_widget_add_controller (drawing_area, GTK_EVENT_CONTROLLER (leg));
g_signal_connect (leg, "event", G_CALLBACK (legcb), drawing_area);
we have an y offset of approx 70 and an x offset of approx 30, so coordinates seems to be related to the parent window.
[EDIT]
Still unsolved. And I am not sure if I don’t get to manage the right coordinate transformation working or if it a GTK4 bug.
[EDIT2]
After reading GTK4 API docs for a few hours and using grep a lot on GTK4 sources I just came to
gboolean
legcb(GtkEventControllerLegacy *controller,
GdkEvent *event,
GtkWidget *widget)
{
double x, y;
double nx, ny;
gdk_event_get_position (event, &x, &y);
GtkNative *native;
native = gtk_widget_get_native (widget);
gtk_native_get_surface_transform (native, &nx, &ny);
GtkWidget *toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
gtk_widget_translate_coordinates (toplevel, widget, x - nx, y - ny, &x, &y);
printf("%f %f\n", x, y);
return TRUE;
}
That transformation gives me indeed values close to zero for top left edge of my drawing area.