Bug 573701 - [GTK4] Shell children rendering/resizing off window -
GtkRange warnings

- Remove GTK3 specific initial widget allocation code that caused
GtkRange allocation warning
- Added notify signals on default-height & default-width as a
replacement to size-allocate signal
(https://docs.gtk.org/gtk4/migrating-3to4.html#adapt-to-gtkwidgets-size-allocation-changes)

Change-Id: I3fe3feb31a77cfe0917d9d0438a4f1f90e7d052f
Signed-off-by: Paul D'Pong <sdamrong@redhat.com>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/180885
Tested-by: Platform Bot <platform-bot@eclipse.org>
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
index 1474291..511f6ed 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
@@ -375,6 +375,8 @@
 	public static final byte[] value_changed = ascii("value-changed");
 	public static final byte[] window_state_event = ascii("window-state-event");
 	public static final byte[] notify_state = ascii("notify::state");
+	public static final byte[] notify_default_height = ascii("notify::default-height");
+	public static final byte[] notify_default_width = ascii("notify::default-width");
 	public static final byte[] notify_theme_change = ascii("notify::gtk-application-prefer-dark-theme");
 	public static final byte[] response = ascii("response");
 
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
index 7b5e6c4..e911530 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
@@ -5519,26 +5519,26 @@
 
 void setInitialBounds () {
 	if ((state & ZERO_WIDTH) != 0 && (state & ZERO_HEIGHT) != 0) {
-		/*
-		* Feature in GTK.  On creation, each widget's allocation is
-		* initialized to a position of (-1, -1) until the widget is
-		* first sized.  The fix is to set the value to (0, 0) as
-		* expected by SWT.
-		*/
-		long topHandle = topHandle ();
-		GtkAllocation allocation = new GtkAllocation();
-		if ((parent.style & SWT.MIRRORED) != 0) {
-			allocation.x = parent.getClientWidth ();
-		} else {
-			allocation.x = 0;
-		}
-		allocation.y = 0;
-		if (mustBeVisibleOnInitBounds ()) {
-			GTK.gtk_widget_set_visible(topHandle, true);
-		}
-		if (GTK.GTK4) {
-			GTK.gtk_widget_size_allocate (topHandle, allocation, -1);
-		} else {
+		if (!GTK.GTK4) {
+			/*
+			* Feature in GTK.  On creation, each widget's allocation is
+			* initialized to a position of (-1, -1) until the widget is
+			* first sized.  The fix is to set the value to (0, 0) as
+			* expected by SWT.
+			*/
+			long topHandle = topHandle();
+
+			GtkAllocation allocation = new GtkAllocation();
+			if ((parent.style & SWT.MIRRORED) != 0) {
+				allocation.x = parent.getClientWidth();
+			} else {
+				allocation.x = 0;
+			}
+			allocation.y = 0;
+
+			if (mustBeVisibleOnInitBounds ()) {
+				GTK.gtk_widget_set_visible(topHandle, true);
+			}
 			// Prevent GTK+ allocation warnings, preferred size should be retrieved before setting allocation size.
 			GTK.gtk_widget_get_preferred_size(topHandle, null, null);
 			GTK.gtk_widget_size_allocate (topHandle, allocation);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
index 66828df..3abd86d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
@@ -933,7 +933,8 @@
 		GTK.gtk_widget_realize(shellHandle);
 		long gdkSurface = gtk_widget_get_surface (shellHandle);
 		OS.g_signal_connect (gdkSurface, OS.notify_state, display.notifyProc, shellHandle);
-		OS.g_signal_connect(handle, OS.resize, display.resizeProc, 0);
+		OS.g_signal_connect(shellHandle, OS.notify_default_height, display.notifyProc, Widget.NOTIFY_DEFAULT_HEIGHT);
+		OS.g_signal_connect(shellHandle, OS.notify_default_width, display.notifyProc, Widget.NOTIFY_DEFAULT_WIDTH);
 	} else {
 		OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [WINDOW_STATE_EVENT], 0, display.getClosure (WINDOW_STATE_EVENT), false);
 		OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [CONFIGURE_EVENT], 0, display.getClosure (CONFIGURE_EVENT), false);
@@ -1129,11 +1130,12 @@
 	if (!OS.isX11()) {
 		if (GTK.GTK4) {
 			double[] window_offset_x = new double[1], window_offset_y = new double[1];
-
 			boolean validTranslation = GTK4.gtk_widget_translate_coordinates(vboxHandle, shellHandle, 0, 0, window_offset_x, window_offset_y);
+
 			if (validTranslation && !isMappedToPopup()) {
 				allocation.x += window_offset_x[0];
 				allocation.y += window_offset_y[0];
+				allocation.height -= window_offset_y[0];
 			}
 		} else {
 			int [] dest_x = new int[1];
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
index 35c4afa..dbd0b74 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
@@ -239,7 +239,9 @@
 	static final int NOTIFY_STATE = 102;
 	static final int SIZE_ALLOCATE_GTK4 = 103;
 	static final int DPI_CHANGED = 104;
-	static final int LAST_SIGNAL = 105;
+	static final int NOTIFY_DEFAULT_HEIGHT = 105;
+	static final int NOTIFY_DEFAULT_WIDTH = 106;
+	static final int LAST_SIGNAL = 107;
 
 	static final String IS_ACTIVE = "org.eclipse.swt.internal.control.isactive"; //$NON-NLS-1$
 	static final String KEY_CHECK_SUBWINDOW = "org.eclipse.swt.internal.control.checksubwindow"; //$NON-NLS-1$
@@ -2246,6 +2248,9 @@
 	switch ((int)user_data) {
 		case DPI_CHANGED: return dpiChanged(object, arg0);
 		case NOTIFY_STATE: return notifyState(object, arg0);
+		case NOTIFY_DEFAULT_HEIGHT:
+		case NOTIFY_DEFAULT_WIDTH:
+			return gtk_size_allocate(object, 0);
 	}
 	return 0;
 }