changeset 2320:829228de003f

GTK4: Use package gtk4-x11 instead of gtk4 so we can call Xlib directly to fill in the gaps of removed functionality. Apparently Wayland has no globaly coordinate system? So this will only work on X11 not Wayland. This enables basic functionality for window positioning. Might need to port some of the workarounds back from GTK3 that got removed in the rewrite.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 16 Feb 2021 14:14:54 +0000
parents 36522ed00ef8
children 52ca7647f665
files configure configure.in gtk4/dw.c
diffstat 3 files changed, 90 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/configure	Tue Feb 16 09:01:07 2021 +0000
+++ b/configure	Tue Feb 16 14:14:54 2021 +0000
@@ -5486,7 +5486,7 @@
       fi
       if test $with_gtk4 = "yes"; then
          DW_DIR=gtk4
-         GTK_PACKAGES="gtk4"
+         GTK_PACKAGES="gtk4-x11"
          GTK_LIBS=`$PKG_CFG --silence-errors --libs $GTK_PACKAGES`
       fi
       WEBKIT_PKG="webkit2gtk-4.0"
--- a/configure.in	Tue Feb 16 09:01:07 2021 +0000
+++ b/configure.in	Tue Feb 16 14:14:54 2021 +0000
@@ -221,7 +221,7 @@
       fi
       if test $with_gtk4 = "yes"; then
          DW_DIR=gtk4
-         GTK_PACKAGES="gtk4"
+         GTK_PACKAGES="gtk4-x11"
          GTK_LIBS=`$PKG_CFG --silence-errors --libs $GTK_PACKAGES`
       fi
       WEBKIT_PKG="webkit2gtk-4.0"
--- a/gtk4/dw.c	Tue Feb 16 09:01:07 2021 +0000
+++ b/gtk4/dw.c	Tue Feb 16 14:14:54 2021 +0000
@@ -29,6 +29,9 @@
 #include <math.h>
 #include <gdk/gdkkeysyms.h>
 
+#ifdef GDK_WINDOWING_X11
+#include <gdk/x11/gdkx.h>
+#endif
 
 #ifdef USE_WEBKIT
 #include <webkit2/webkit2.h>
@@ -1686,22 +1689,64 @@
  * Parameters:
  *           handle: The window handle to make topmost.
  */
+#ifndef GDK_WINDOWING_X11
 int dw_window_raise(HWND handle)
 {
-   /* TODO: See if this is possible in GTK4 */
    return DW_ERROR_UNKNOWN;
 }
+#else
+DW_FUNCTION_DEFINITION(dw_window_raise, int, HWND handle)
+DW_FUNCTION_ADD_PARAM1(handle)
+DW_FUNCTION_RETURN(dw_window_raise, int)
+DW_FUNCTION_RESTORE_PARAM1(handle, HWND)
+{
+   int retval = DW_ERROR_UNKNOWN;
+   
+   if(handle && GTK_IS_WINDOW(handle))
+   {
+      GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle));
+      
+      if(surface)
+      {
+         XRaiseWindow(GDK_SURFACE_XDISPLAY(surface), GDK_SURFACE_XID(surface));
+         retval = DW_ERROR_NONE;
+      }
+   }
+   DW_FUNCTION_RETURN_THIS(retval);
+}
+#endif
 
 /*
  * Makes the window bottommost.
  * Parameters:
  *           handle: The window handle to make bottommost.
  */
+#ifndef GDK_WINDOWING_X11
 int dw_window_lower(HWND handle)
 {
-   /* TODO: See if this is possible in GTK4 */
    return DW_ERROR_UNKNOWN;
 }
+#else
+DW_FUNCTION_DEFINITION(dw_window_lower, int, HWND handle)
+DW_FUNCTION_ADD_PARAM1(handle)
+DW_FUNCTION_RETURN(dw_window_lower, int)
+DW_FUNCTION_RESTORE_PARAM1(handle, HWND)
+{
+   int retval = DW_ERROR_UNKNOWN;
+   
+   if(handle && GTK_IS_WINDOW(handle))
+   {
+      GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle));
+      
+      if(surface)
+      {
+         XLowerWindow(GDK_SURFACE_XDISPLAY(surface), GDK_SURFACE_XID(surface));
+         retval = DW_ERROR_NONE;
+      }
+   }
+   DW_FUNCTION_RETURN_THIS(retval);
+}
+#endif
 
 /*
  * Makes the window visible.
@@ -8483,11 +8528,30 @@
  *          x: X location from the bottom left.
  *          y: Y location from the bottom left.
  */
+#ifndef GDK_WINDOWING_X11
 void dw_window_set_pos(HWND handle, long x, long y)
 {
-   /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
-}
-
+}
+#else
+DW_FUNCTION_DEFINITION(dw_window_set_pos, void, HWND handle, long x, long y)
+DW_FUNCTION_ADD_PARAM3(handle, x, y)
+DW_FUNCTION_NO_RETURN(dw_window_set_pos)
+DW_FUNCTION_RESTORE_PARAM3(handle, HWND, x, long, y, long)
+{
+   if(handle && GTK_IS_WINDOW(handle))
+   {
+      GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle));
+      
+      if(surface)
+      {
+         XMoveWindow(GDK_SURFACE_XDISPLAY(surface),
+                     GDK_SURFACE_XID(surface),
+                     x, y);
+      }
+   }
+   DW_FUNCTION_RETURN_NOTHING;
+}
+#endif
 /*
  * Sets the position and size of a given window (widget).
  * Parameters:
@@ -8517,17 +8581,35 @@
 DW_FUNCTION_NO_RETURN(dw_window_get_pos_size)
 DW_FUNCTION_RESTORE_PARAM5(handle, HWND, x, long *, y, long *, width, ULONG *, height, ULONG *)
 {
-   /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
    if(handle && GTK_IS_WIDGET(handle))
    {
       if(width)
          *width = (ULONG)gtk_widget_get_width(GTK_WIDGET(handle));
       if(height)
          *height = (ULONG)gtk_widget_get_height(GTK_WIDGET(handle));
+
+#ifdef GDK_WINDOWING_X11
+      {
+         GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle));
+         
+         if(surface)
+         {
+            XWindowAttributes xwa;
+
+            XGetWindowAttributes(GDK_SURFACE_XDISPLAY(surface), 
+                                 GDK_SURFACE_XID(surface), &xwa);
+            if(x)
+               *x = (long)xwa.x;
+            if(y)
+               *y = (long)xwa.y;
+          }
+      }
+#else                                 
       if(x)
          *x = 0;
       if(y)
          *y = 0;
+#endif
    }
    DW_FUNCTION_RETURN_NOTHING;
 }