Bug 540841: [GTK4] Rename GdkWindow to GdkSurface

Don't use gdk_get_default_root_window() on GTK4.

Change-Id: I45b7909c674df15cbb6d225264b0ee65b1893284
Signed-off-by: Eric Williams <ericwill@redhat.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DropTarget.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DropTarget.java
index 8ec97e0..ab9bef8 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DropTarget.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DropTarget.java
@@ -567,14 +567,14 @@
 
 int getOperationFromKeyState() {
 	int[] state = new int[1];
-	long /*int*/ root = GDK.gdk_get_default_root_window ();
-	long /*int*/ pointer = GDK.gdk_get_pointer (GDK.gdk_window_get_display (root));
+	long /*int*/ pointer = GDK.gdk_get_pointer (GDK.gdk_display_get_default());
 	if (GTK.GTK4) {
 		/*
 		 * TODO: calling gdk_window_get_device_position() here
 		 * uses gdk_get_default_root_window(), which doesn't exist on GTK4.
 		 */
 	} else {
+		long /*int*/ root = GDK.gdk_get_default_root_window ();
 		GDK.gdk_window_get_device_position(root, pointer, null, null, state);
 	}
 	boolean ctrl = (state[0] & GDK.GDK_CONTROL_MASK) != 0;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
index c15869c..740cf4c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
@@ -664,9 +664,7 @@
 		long /*int*/ gdkResource;
 		long /*int*/ surface;
 		if (GTK.GTK4) {
-			GTK.gtk_widget_realize(shellHandle);
-			gdkResource = GTK.gtk_widget_get_surface(shellHandle);
-			surface = GDK.gdk_surface_create_similar_surface(gdkResource, Cairo.CAIRO_CONTENT_COLOR, 10, 10);
+			surface = Cairo.cairo_image_surface_create(Cairo.CAIRO_CONTENT_COLOR, 10, 10);
 		} else {
 			gdkResource = GDK.gdk_get_default_root_window();
 			surface = GDK.gdk_window_create_similar_surface(gdkResource, Cairo.CAIRO_CONTENT_COLOR, 10, 10);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
index 76b9121..01532de 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
@@ -2618,7 +2618,7 @@
 	if (GTK.GTK_VERSION >= 	OS.VERSION(3, 22, 0)) {
 		long /*int*/ surface;
 		if (GTK.GTK4) {
-			surface = GDK.gdk_surface_create_similar_surface(data.drawable, Cairo.CAIRO_CONTENT_COLOR_ALPHA, data.width, data.height);
+			surface = Cairo.cairo_image_surface_create(Cairo.CAIRO_CONTENT_COLOR_ALPHA, data.width, data.height);
 		} else {
 			surface = GDK.gdk_window_create_similar_surface(data.drawable, Cairo.CAIRO_CONTENT_COLOR_ALPHA, data.width, data.height);
 		}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
index ccaef78..259d4a0 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
@@ -1249,7 +1249,11 @@
 	this.type = SWT.BITMAP;
 
 	/* Create the pixmap */
-	surface = GDK.gdk_window_create_similar_surface(GDK.gdk_get_default_root_window(), Cairo.CAIRO_CONTENT_COLOR, width, height);
+	if (GTK.GTK4) {
+		surface = Cairo.cairo_image_surface_create(Cairo.CAIRO_CONTENT_COLOR, width, height);
+	} else {
+		surface = GDK.gdk_window_create_similar_surface(GDK.gdk_get_default_root_window(), Cairo.CAIRO_CONTENT_COLOR, width, height);
+	}
 	if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
 	// When we create a blank image we need to set it to 100 in GTK3 as we draw using 100% scale.
 	// Cairo will take care of scaling for us when image needs to be scaled.
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
index 39211de..9c6e33d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
@@ -3959,13 +3959,19 @@
 @Override
 public long /*int*/ internal_new_GC (GCData data) {
 	if (isDisposed()) error(SWT.ERROR_DEVICE_DISPOSED);
-	long /*int*/ root = GDK.gdk_get_default_root_window();
 	long /*int*/ gc = 0;
-	if (GTK.GTK_VERSION >= OS.VERSION(3, 22, 0)) {
-		long /*int*/ surface = GDK.gdk_window_create_similar_surface(root, Cairo.CAIRO_CONTENT_COLOR_ALPHA, data.width, data.height);
+	long /*int*/ root = 0;
+	if (GTK.GTK4) {
+		long /*int*/ surface = Cairo.cairo_image_surface_create(Cairo.CAIRO_CONTENT_COLOR_ALPHA, data.width, data.height);
 		gc = Cairo.cairo_create(surface);
 	} else {
-		gc = GDK.gdk_cairo_create(root);
+		root = GDK.gdk_get_default_root_window();
+		if (GTK.GTK_VERSION >= OS.VERSION(3, 22, 0)) {
+			long /*int*/ surface = GDK.gdk_window_create_similar_surface(root, Cairo.CAIRO_CONTENT_COLOR_ALPHA, data.width, data.height);
+			gc = Cairo.cairo_create(surface);
+		} else {
+			gc = GDK.gdk_cairo_create(root);
+		}
 	}
 	if (gc == 0) error (SWT.ERROR_NO_HANDLES);
 	//TODO how gdk_gc_set_subwindow is done in cairo?
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java
index 7278e81..a2002de 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java
@@ -329,7 +329,12 @@
  * @param rects
  */
 void drawRectangles (Rectangle [] rects) {
-	long /*int*/ gdkResource = GDK.gdk_get_default_root_window();
+	long /*int*/ gdkResource = 0;
+	if (GTK.GTK4) {
+		if (parent != null) gdkResource = gtk_widget_get_surface(parent.handle);
+	} else {
+		gdkResource = GDK.gdk_get_default_root_window();
+	}
 	if (parent != null) {
 		long /*int*/ paintHandle = parent.paintHandle();
 		gdkResource = GTK.GTK4 ? gtk_widget_get_surface(paintHandle) : gtk_widget_get_window (paintHandle);
@@ -764,7 +769,7 @@
  */
 public boolean open () {
 	checkWidget();
-	window = GDK.gdk_get_default_root_window();
+	if (!GTK.GTK4) window = GDK.gdk_get_default_root_window();
 	if (parent != null) {
 		window = gtk_widget_get_window (parent.paintHandle());
 	}