# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1641227031 0 # Node ID cd6a306800f5e1e1d7ef3f23505afad563895409 # Parent e1b5dbec07968096230ba19c1719d4645365458a GTK4: New way of querying the mouse pointer position. The old code was completely bogus and did not work at all. Since there doesn't seem to be a way to actually query the position... Plus with wayland there are no global coordinates... instead... Any event we handle that has pointer coordinates... we convert them to be window relative and save them. When querying the pointer location, we return the latest coordinates that we had handled. I removed the thread safety since there are no API calls, but we may want to put it back so that the data doesn't get changed during the call... although that may not be the most tragic thing. diff -r e1b5dbec0796 -r cd6a306800f5 gtk4/dw.c --- a/gtk4/dw.c Mon Jan 03 15:50:53 2022 +0000 +++ b/gtk4/dw.c Mon Jan 03 16:23:51 2022 +0000 @@ -474,6 +474,7 @@ static void _dw_html_changed_event(WebKitWebView *web_view, WebKitLoadEvent load_event, gpointer data); #endif static void _dw_signal_disconnect(gpointer data, GClosure *closure); +static void _dw_event_coordinates_to_window(GtkWidget *widget, double *x, double *y); GObject *_DWObject = NULL; GApplication *_DWApp = NULL; @@ -481,6 +482,8 @@ static char _dw_app_id[_DW_APP_ID_SIZE+1] = { 0 }; char *_DWDefaultFont = NULL; static char _dw_share_path[PATH_MAX+1] = { 0 }; +static long _dw_mouse_last_x = 0; +static long _dw_mouse_last_y = 0; typedef struct _dw_signal_list { @@ -778,6 +781,11 @@ mybutton = DW_BUTTON3_MASK; retval = buttonfunc(work.window, (int)x, (int)y, mybutton, work.data); + + _dw_event_coordinates_to_window(work.window, &x, &y); + + _dw_mouse_last_x = (long)x; + _dw_mouse_last_y = (long)y; } return retval; } @@ -798,6 +806,11 @@ mybutton = DW_BUTTON3_MASK; retval = buttonfunc(work.window, (int)x, (int)y, mybutton, work.data); + + _dw_event_coordinates_to_window(work.window, &x, &y); + + _dw_mouse_last_x = (long)x; + _dw_mouse_last_y = (long)y; } return retval; } @@ -822,6 +835,11 @@ keys |= DW_BUTTON3_MASK; retval = motionfunc(work.window, (int)x, (int)y, keys, work.data); + + _dw_event_coordinates_to_window(work.window, &x, &y); + + _dw_mouse_last_x = (long)x; + _dw_mouse_last_y = (long)y; } return retval; } @@ -991,7 +1009,7 @@ } /* Convert coordinate system from the widget to the window */ -void _dw_event_coordinates_to_window(GtkWidget *widget, double *x, double *y) +static void _dw_event_coordinates_to_window(GtkWidget *widget, double *x, double *y) { GtkRoot *root = (widget && GTK_IS_WIDGET(widget)) ? gtk_widget_get_root(widget) : NULL; @@ -1042,6 +1060,9 @@ GtkWidget *widget = work.window; _dw_event_coordinates_to_window(widget, &x, &y); + + _dw_mouse_last_x = (long)x; + _dw_mouse_last_y = (long)y; /* Containers and trees are inside scrolled window widgets */ if(GTK_IS_SCROLLED_WINDOW(widget)) @@ -3298,22 +3319,12 @@ * x: Pointer to variable to store X coordinate. * y: Pointer to variable to store Y coordinate. */ -DW_FUNCTION_DEFINITION(dw_pointer_query_pos, void, long *x, long *y) -DW_FUNCTION_ADD_PARAM2(x, y) -DW_FUNCTION_NO_RETURN(dw_pointer_query_pos) -DW_FUNCTION_RESTORE_PARAM2(x, long *, y, long *) -{ - GdkSeat *seat = gdk_display_get_default_seat(gdk_display_get_default()); - GdkDevice *mouse = gdk_seat_get_pointer(seat); - double dx, dy; - - gdk_device_get_surface_at_position(mouse, &dx, &dy); - +void API dw_pointer_query_pos(long *x, long *y) +{ if(x) - *x = (long)dx; + *x = (long)_dw_mouse_last_x; if(y) - *y = (long)dy; - DW_FUNCTION_RETURN_NOTHING; + *y = (long)_dw_mouse_last_y; } /*