Bug 541157: [GTK4] Clean up X11 functions

Handle certain X11 functions that have changed name on GTK4, or were
removed.

Change-Id: Ibff445ebf735d0251d7280404954911574cbe441
Signed-off-by: Eric Williams <ericwill@redhat.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
index 4fad2d0..23ec47a 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
@@ -2626,7 +2626,15 @@
 {
 	jintLong rc = 0;
 	GDK_NATIVE_ENTER(env, that, _1gdk_1x11_1screen_1get_1window_1manager_1name_FUNC);
-	rc = (jintLong)gdk_x11_screen_get_window_manager_name((GdkScreen *)arg0);
+/*
+	rc = (jintLong)gdk_x11_screen_get_window_manager_name(arg0);
+*/
+	{
+		GDK_LOAD_FUNCTION(fp, gdk_x11_screen_get_window_manager_name)
+		if (fp) {
+			rc = (jintLong)((jintLong (CALLING_CONVENTION*)(jintLong))fp)(arg0);
+		}
+	}
 	GDK_NATIVE_EXIT(env, that, _1gdk_1x11_1screen_1get_1window_1manager_1name_FUNC);
 	return rc;
 }
@@ -2638,19 +2646,59 @@
 {
 	jintLong rc = 0;
 	GDK_NATIVE_ENTER(env, that, _1gdk_1x11_1screen_1lookup_1visual_FUNC);
-	rc = (jintLong)gdk_x11_screen_lookup_visual((GdkScreen *)arg0, (VisualID)arg1);
+/*
+	rc = (jintLong)gdk_x11_screen_lookup_visual(arg0, (VisualID)arg1);
+*/
+	{
+		GDK_LOAD_FUNCTION(fp, gdk_x11_screen_lookup_visual)
+		if (fp) {
+			rc = (jintLong)((jintLong (CALLING_CONVENTION*)(jintLong, VisualID))fp)(arg0, (VisualID)arg1);
+		}
+	}
 	GDK_NATIVE_EXIT(env, that, _1gdk_1x11_1screen_1lookup_1visual_FUNC);
 	return rc;
 }
 #endif
 
+#ifndef NO__1gdk_1x11_1surface_1get_1xid
+JNIEXPORT jintLong JNICALL GDK_NATIVE(_1gdk_1x11_1surface_1get_1xid)
+	(JNIEnv *env, jclass that, jintLong arg0)
+{
+	jintLong rc = 0;
+	GDK_NATIVE_ENTER(env, that, _1gdk_1x11_1surface_1get_1xid_FUNC);
+	rc = (jintLong)gdk_x11_surface_get_xid((GdkSurface *)arg0);
+	GDK_NATIVE_EXIT(env, that, _1gdk_1x11_1surface_1get_1xid_FUNC);
+	return rc;
+}
+#endif
+
+#ifndef NO__1gdk_1x11_1surface_1lookup_1for_1display
+JNIEXPORT jintLong JNICALL GDK_NATIVE(_1gdk_1x11_1surface_1lookup_1for_1display)
+	(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
+{
+	jintLong rc = 0;
+	GDK_NATIVE_ENTER(env, that, _1gdk_1x11_1surface_1lookup_1for_1display_FUNC);
+	rc = (jintLong)gdk_x11_surface_lookup_for_display((GdkDisplay *)arg0, (Window)arg1);
+	GDK_NATIVE_EXIT(env, that, _1gdk_1x11_1surface_1lookup_1for_1display_FUNC);
+	return rc;
+}
+#endif
+
 #ifndef NO__1gdk_1x11_1visual_1get_1xvisual
 JNIEXPORT jintLong JNICALL GDK_NATIVE(_1gdk_1x11_1visual_1get_1xvisual)
 	(JNIEnv *env, jclass that, jintLong arg0)
 {
 	jintLong rc = 0;
 	GDK_NATIVE_ENTER(env, that, _1gdk_1x11_1visual_1get_1xvisual_FUNC);
-	rc = (jintLong)gdk_x11_visual_get_xvisual((GdkVisual *)arg0);
+/*
+	rc = (jintLong)gdk_x11_visual_get_xvisual(arg0);
+*/
+	{
+		GDK_LOAD_FUNCTION(fp, gdk_x11_visual_get_xvisual)
+		if (fp) {
+			rc = (jintLong)((jintLong (CALLING_CONVENTION*)(jintLong))fp)(arg0);
+		}
+	}
 	GDK_NATIVE_EXIT(env, that, _1gdk_1x11_1visual_1get_1xvisual_FUNC);
 	return rc;
 }
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h
index d207c21..9e295d7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h
@@ -100,9 +100,21 @@
 #endif
 
 
-#if defined(GDK_WINDOWING_X11) && !GTK_CHECK_VERSION(3,94,0)
-#include <gdk/gdkx.h>
+#if defined(GDK_WINDOWING_X11)
+#if !GTK_CHECK_VERSION(3,94,0)
 #include <gtk/gtkx.h>
+#define NO__1gdk_1x11_1surface_1get_1xid
+#define NO__1gdk_1x11_1surface_1lookup_1for_1display
+#else
+#define NO__1gdk_1x11_1get_1default_1xdisplay
+#define NO__1gdk_1x11_1window_1get_1xid
+#define NO__1gdk_1x11_1window_1lookup_1for_1display
+#define NO__1GTK_1IS_1PLUG
+#define NO__1gtk_1plug_1new
+#define NO__1gtk_1socket_1get_1id
+#define NO__1gtk_1socket_1new
+#endif
+#include <gdk/gdkx.h>
 #else
 
 #define NO_GDK_1IS_1X11_1DISPLAY
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
index d99f20f..3b92256 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
@@ -220,6 +220,8 @@
 	"_1gdk_1x11_1get_1default_1xdisplay",
 	"_1gdk_1x11_1screen_1get_1window_1manager_1name",
 	"_1gdk_1x11_1screen_1lookup_1visual",
+	"_1gdk_1x11_1surface_1get_1xid",
+	"_1gdk_1x11_1surface_1lookup_1for_1display",
 	"_1gdk_1x11_1visual_1get_1xvisual",
 	"_1gdk_1x11_1window_1get_1xid",
 	"_1gdk_1x11_1window_1lookup_1for_1display",
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
index 903397c..2e824c0 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
@@ -230,6 +230,8 @@
 	_1gdk_1x11_1get_1default_1xdisplay_FUNC,
 	_1gdk_1x11_1screen_1get_1window_1manager_1name_FUNC,
 	_1gdk_1x11_1screen_1lookup_1visual_FUNC,
+	_1gdk_1x11_1surface_1get_1xid_FUNC,
+	_1gdk_1x11_1surface_1lookup_1for_1display_FUNC,
 	_1gdk_1x11_1visual_1get_1xvisual_FUNC,
 	_1gdk_1x11_1window_1get_1xid_FUNC,
 	_1gdk_1x11_1window_1lookup_1for_1display_FUNC,
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java
index da1e07b..67db51c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java
@@ -323,10 +323,11 @@
 		}
 	}
 	/**
-	 * @param screen cast=(GdkScreen *)
+	 * @method flags=dynamic
 	 * @param xvisualid cast=(VisualID)
 	 */
 	public static final native long /*int*/ _gdk_x11_screen_lookup_visual(long /*int*/ screen, int xvisualid);
+	/** [GTK3/GTK4, GTK3 uses GdkScreen but GTK4 uses GdkX11Screen -- method signature otherwise identical] */
 	public static final long /*int*/ gdk_x11_screen_lookup_visual(long /*int*/ screen, int xvisualid) {
 		lock.lock();
 		try {
@@ -336,9 +337,10 @@
 		}
 	}
 	/**
-	 * @param screen cast=(GdkScreen *)
+	 * @method flags=dynamic
 	 */
 	public static final native long /*int*/ _gdk_x11_screen_get_window_manager_name(long /*int*/ screen);
+	/** [GTK3/GTK4, GTK3 uses GdkScreen but GTK4 uses GdkX11Screen -- method signature otherwise identical] */
 	public static final long /*int*/ gdk_x11_screen_get_window_manager_name(long /*int*/ screen) {
 		lock.lock();
 		try {
@@ -347,8 +349,11 @@
 			lock.unlock();
 		}
 	}
-	/** @param visual cast=(GdkVisual *) */
+	/**
+	 * @method flags=dynamic
+	 */
 	public static final native long /*int*/ _gdk_x11_visual_get_xvisual(long /*int*/ visual);
+	/** [GTK3/GTK4, GTK3 uses GdkVisual but GTK4 uses GdkX11Visual -- method signature otherwise identical] */
 	public static final long /*int*/ gdk_x11_visual_get_xvisual(long /*int*/ visual) {
 		lock.lock();
 		try {
@@ -361,12 +366,27 @@
 	* @param gdkwindow cast=(GdkWindow *)
 	*/
 	public static final native long /*int*/ _gdk_x11_window_get_xid(long /*int*/ gdkwindow);
+	/** [GTK3 only, if-def'd in os.h] */
 	public static final long /*int*/ gdk_x11_window_get_xid(long /*int*/ gdkwindow) {
 		lock.lock();
 		try {
 			return _gdk_x11_window_get_xid(gdkwindow);
 		} finally {
 			lock.unlock();
+
+		}
+	}
+	/**
+	* @param surface cast=(GdkSurface *)
+	*/
+	public static final native long /*int*/ _gdk_x11_surface_get_xid(long /*int*/ surface);
+	/** [GTK4 only, if-def'd in os.h] */
+	public static final long /*int*/ gdk_x11_surface_get_xid(long /*int*/ surface) {
+		lock.lock();
+		try {
+			return _gdk_x11_surface_get_xid(surface);
+		} finally {
+			lock.unlock();
 		}
 	}
 	/**
@@ -374,6 +394,7 @@
 	 * @param xid cast=(Window)
 	 */
 	public static final native long /*int*/ _gdk_x11_window_lookup_for_display(long /*int*/ gdkdisplay, long /*int*/ xid);
+	/** [GTK3 only, if-def'd in os.h] */
 	public static final long /*int*/ gdk_x11_window_lookup_for_display(long /*int*/ gdkdisplay, long /*int*/ xid) {
 		lock.lock();
 		try {
@@ -383,6 +404,20 @@
 		}
 	}
 	/**
+	 * @param gdkdisplay cast=(GdkDisplay *)
+	 * @param xid cast=(Window)
+	 */
+	public static final native long /*int*/ _gdk_x11_surface_lookup_for_display(long /*int*/ gdkdisplay, long /*int*/ xid);
+	/** [GTK4 only, if-def'd in os.h] */
+	public static final long /*int*/ gdk_x11_surface_lookup_for_display(long /*int*/ gdkdisplay, long /*int*/ xid) {
+		lock.lock();
+		try {
+			return _gdk_x11_surface_lookup_for_display(gdkdisplay, xid);
+		} finally {
+			lock.unlock();
+		}
+	}
+	/**
 	 * @param window cast=(GdkWindow *)
 	 * @param function cast=(GdkFilterFunc)
 	 * @param data cast=(gpointer)
@@ -781,7 +816,7 @@
 	public static final long /*int*/ gdk_device_get_surface_at_position(long /*int*/ device, int[] win_x, int[] win_y) {
 		lock.lock();
 		try {
-			return _gdk_device_get_window_at_position(device, win_x, win_y);
+			return _gdk_device_get_surface_at_position(device, win_x, win_y);
 		} finally {
 			lock.unlock();
 		}
@@ -1946,7 +1981,7 @@
 	public static final long /*int*/ gdk_surface_create_similar_surface(long /*int*/ window, int content, int width, int height) {
 		lock.lock();
 		try {
-			return _gdk_window_create_similar_surface(window, content, width, height);
+			return _gdk_surface_create_similar_surface(window, content, width, height);
 		} finally {
 			lock.unlock();
 		}
@@ -1968,7 +2003,7 @@
 	public static final void gdk_surface_destroy(long /*int*/ window) {
 		lock.lock();
 		try {
-			_gdk_window_destroy(window);
+			_gdk_surface_destroy(window);
 		} finally {
 			lock.unlock();
 		}
@@ -2012,7 +2047,7 @@
 	public static final void gdk_surface_focus(long /*int*/ surface, int timestamp) {
 		lock.lock();
 		try {
-			_gdk_window_focus(surface, timestamp);
+			_gdk_surface_focus(surface, timestamp);
 		} finally {
 			lock.unlock();
 		}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java
index 9fda0c8..0531e92 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java
@@ -9242,7 +9242,7 @@
 	public static final void gtk_widget_set_parent_surface(long /*int*/ widget, long /*int*/ parent_surface) {
 		lock.lock();
 		try {
-			_gtk_widget_set_parent_window(widget, parent_surface);
+			_gtk_widget_set_parent_surface(widget, parent_surface);
 		} finally {
 			lock.unlock();
 		}