changeset 2322:ebcaedfa7ff4

GTK4: Implement dw_pointer_set_pos() with Xlib. Also translate coordinate system in dw_window_get_pos_size().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 17 Feb 2021 05:32:02 +0000
parents 52ca7647f665
children 4b04943319c5
files gtk4/dw.c
diffstat 1 files changed, 35 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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