Skip to content

Commit f6590d2

Browse files
committed
[GTK4] Shell.get[Minimum|Maximum]Size
Implement minimum size for Gtk 4. Maximum size as a concept is missing in Gtk 4 thus it's been made a no-op to prevent crashes attempting to use it on Gtk 4. It might be possible to override size-allocate and not allow getting bigger than size set in maximum store but that would be a later exercise (preventing crashes is more important right now).
1 parent cb61a92 commit f6590d2

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,6 +2581,23 @@ JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1widget_1get_1root)
25812581
}
25822582
#endif
25832583

2584+
#ifndef NO_gtk_1widget_1get_1size_1request
2585+
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1widget_1get_1size_1request)
2586+
(JNIEnv *env, jclass that, jlong arg0, jintArray arg1, jintArray arg2)
2587+
{
2588+
jint *lparg1=NULL;
2589+
jint *lparg2=NULL;
2590+
GTK4_NATIVE_ENTER(env, that, gtk_1widget_1get_1size_1request_FUNC);
2591+
if (arg1) if ((lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL)) == NULL) goto fail;
2592+
if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail;
2593+
gtk_widget_get_size_request((GtkWidget*)arg0, (int *)lparg1, (int *)lparg2);
2594+
fail:
2595+
if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0);
2596+
if (arg1 && lparg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0);
2597+
GTK4_NATIVE_EXIT(env, that, gtk_1widget_1get_1size_1request_FUNC);
2598+
}
2599+
#endif
2600+
25842601
#ifndef NO_gtk_1widget_1insert_1after
25852602
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1widget_1insert_1after)
25862603
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jlong arg2)
@@ -2656,6 +2673,16 @@ JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1widget_1set_1focusable)
26562673
}
26572674
#endif
26582675

2676+
#ifndef NO_gtk_1widget_1set_1size_1request
2677+
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1widget_1set_1size_1request)
2678+
(JNIEnv *env, jclass that, jlong arg0, jint arg1, jint arg2)
2679+
{
2680+
GTK4_NATIVE_ENTER(env, that, gtk_1widget_1set_1size_1request_FUNC);
2681+
gtk_widget_set_size_request((GtkWidget*)arg0, (int)arg1, (int)arg2);
2682+
GTK4_NATIVE_EXIT(env, that, gtk_1widget_1set_1size_1request_FUNC);
2683+
}
2684+
#endif
2685+
26592686
#ifndef NO_gtk_1widget_1size_1allocate
26602687
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1widget_1size_1allocate)
26612688
(JNIEnv *env, jclass that, jlong arg0, jobject arg1, jint arg2)

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4_stats.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,14 @@ typedef enum {
210210
gtk_1widget_1get_1prev_1sibling_FUNC,
211211
gtk_1widget_1get_1receives_1default_FUNC,
212212
gtk_1widget_1get_1root_FUNC,
213+
gtk_1widget_1get_1size_1request_FUNC,
213214
gtk_1widget_1insert_1after_FUNC,
214215
gtk_1widget_1insert_1before_FUNC,
215216
gtk_1widget_1measure_FUNC,
216217
gtk_1widget_1pick_FUNC,
217218
gtk_1widget_1set_1cursor_FUNC,
218219
gtk_1widget_1set_1focusable_FUNC,
220+
gtk_1widget_1set_1size_1request_FUNC,
219221
gtk_1widget_1size_1allocate_FUNC,
220222
gtk_1widget_1snapshot_1child_FUNC,
221223
gtk_1widget_1translate_1coordinates_FUNC,

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,18 @@ public class GTK4 {
684684
public static final native void gtk_widget_set_focusable(long widget, boolean focusable);
685685
/** @param widget cast=(GtkWidget *) */
686686
public static final native long gtk_widget_get_clipboard(long widget);
687+
/**
688+
* @param widget cast=(GtkWidget*)
689+
* @param width cast=(int *)
690+
* @param height cast=(int *)
691+
*/
692+
public static final native void gtk_widget_get_size_request(long widget, int[] width, int[] height);
693+
/**
694+
* @param widget cast=(GtkWidget*)
695+
* @param width cast=(int)
696+
* @param height cast=(int)
697+
*/
698+
public static final native void gtk_widget_set_size_request(long widget, int width, int height);
687699
/**
688700
* @param widget cast=(GtkWidget *)
689701
* @param allocation cast=(GtkAllocation *),flags=no_out

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,14 @@ public boolean getMaximized () {
13021302
*/
13031303
public Point getMinimumSize () {
13041304
checkWidget ();
1305+
if (GTK.GTK4) {
1306+
int[] widthP = new int[1];
1307+
int[] heightP = new int[1];
1308+
GTK4.gtk_widget_get_size_request(shellHandle, widthP, heightP);
1309+
int width = Math.max (1, widthP[0] + trimWidth ());
1310+
int height = Math.max (1, heightP[0] + trimHeight ());
1311+
return new Point (width, height);
1312+
}
13051313
int width = Math.max (1, geometry.getMinWidth() + trimWidth ());
13061314
int height = Math.max (1, geometry.getMinHeight() + trimHeight ());
13071315
return new Point (width, height);
@@ -1324,6 +1332,11 @@ public Point getMinimumSize () {
13241332
*/
13251333
public Point getMaximumSize () {
13261334
checkWidget ();
1335+
if (GTK.GTK4) {
1336+
// GTK 4 doesn't have the concept of Window maximum size
1337+
// A possibility might be size_allocate
1338+
return new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
1339+
}
13271340
int width = Math.min (Integer.MAX_VALUE, geometry.getMaxWidth() + trimWidth ());
13281341
int height = Math.min (Integer.MAX_VALUE, geometry.getMaxHeight() + trimHeight ());
13291342
return new Point (width, height);
@@ -2668,6 +2681,7 @@ public void setMinimumSize (int width, int height) {
26682681

26692682
if(GTK.GTK4) {
26702683
geometry.setMinSizeRequested(true);
2684+
GTK4.gtk_widget_set_size_request(shellHandle, width, height);
26712685
return;
26722686
}
26732687

@@ -2723,6 +2737,11 @@ public void setMinimumSize (Point size) {
27232737
*/
27242738
public void setMaximumSize (int width, int height) {
27252739
checkWidget ();
2740+
if (GTK.GTK4) {
2741+
// Gtk 4 doesn't have the concept of maximum window size
2742+
// A possibility might be size_allocate
2743+
return;
2744+
}
27262745
geometry.setMaxWidth(Math.max (width, trimWidth ()) - trimWidth ());
27272746
geometry.setMaxHeight(Math.max (height, trimHeight ()) - trimHeight ());
27282747
int hint = GDK.GDK_HINT_MAX_SIZE;

0 commit comments

Comments
 (0)