# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1613539922 0 # Node ID ebcaedfa7ff4223563a27a4471fcc8a859a95cfe # Parent 52ca7647f665f204c1c6478dd72b5c496139bcbf GTK4: Implement dw_pointer_set_pos() with Xlib. Also translate coordinate system in dw_window_get_pos_size(). diff -r 52ca7647f665 -r ebcaedfa7ff4 gtk4/dw.c --- a/gtk4/dw.c Wed Feb 17 03:52:41 2021 +0000 +++ b/gtk4/dw.c Wed Feb 17 05:32:02 2021 +0000 @@ -3107,10 +3107,29 @@ * x: X coordinate. * y: Y coordinate. */ +#ifndef GDK_WINDOWING_X11 void dw_pointer_set_pos(long x, long y) { - /* TODO: See if this is possible in GTK4 */ -} +} +#else +DW_FUNCTION_DEFINITION(dw_pointer_set_pos, void, long x, long y) +DW_FUNCTION_ADD_PARAM2(x, y) +DW_FUNCTION_NO_RETURN(dw_pointer_set_pos) +DW_FUNCTION_RESTORE_PARAM2(x, long, y, long) +{ + GdkDisplay *display = gdk_display_get_default(); + + if(display) + { + Display *xdisplay = gdk_x11_display_get_xdisplay(display); + Window xrootwin = gdk_x11_display_get_xrootwindow(display); + + if(xdisplay) + XWarpPointer(xdisplay, None, xrootwin, 0, 0, 0, 0, (int)x, (int)y); + } + DW_FUNCTION_RETURN_NOTHING; +} +#endif #define _DW_TREE_CONTAINER 1 #define _DW_TREE_TREE 2 @@ -8596,6 +8615,7 @@ DW_FUNCTION_RETURN_NOTHING; } #endif + /* * Sets the position and size of a given window (widget). * Parameters: @@ -8651,14 +8671,25 @@ if(surface) { + GdkDisplay *display = gdk_display_get_default(); XWindowAttributes xwa; + int ix = 0, iy = 0; + + if(display) + { + Window child, xrootwin = gdk_x11_display_get_xrootwindow(display); + + XTranslateCoordinates(GDK_SURFACE_XDISPLAY(surface), GDK_SURFACE_XID(surface), + xrootwin, 0, 0, &ix, &iy, &child); + + } XGetWindowAttributes(GDK_SURFACE_XDISPLAY(surface), GDK_SURFACE_XID(surface), &xwa); if(x) - *x = (long)xwa.x; + *x = (long)(ix - xwa.x); if(y) - *y = (long)xwa.y; + *y = (long)(ix - xwa.y); } } #else