Skip to content

Commit 22c3714

Browse files
committed
[GTK] Add native methods for retrieving icons based on size and scale factor
This change adds the native method gtk_icon_theme_lookup_by_gicon_for_scale() and gdk_window_get_scale_factor(), to prepare for retrieving theme application icons based on DPI. See: #3003
1 parent c20fea4 commit 22c3714

7 files changed

Lines changed: 45 additions & 4 deletions

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2025 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -1097,6 +1097,18 @@ JNIEXPORT jlong JNICALL GTK3_NATIVE(gtk_1icon_1theme_1lookup_1by_1gicon)
10971097
}
10981098
#endif
10991099

1100+
#ifndef NO_gtk_1icon_1theme_1lookup_1by_1gicon_1for_1scale
1101+
JNIEXPORT jlong JNICALL GTK3_NATIVE(gtk_1icon_1theme_1lookup_1by_1gicon_1for_1scale)
1102+
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jint arg2, jint arg3, jint arg4)
1103+
{
1104+
jlong rc = 0;
1105+
GTK3_NATIVE_ENTER(env, that, gtk_1icon_1theme_1lookup_1by_1gicon_1for_1scale_FUNC);
1106+
rc = (jlong)gtk_icon_theme_lookup_by_gicon_for_scale((GtkIconTheme *)arg0, (GIcon *)arg1, (gint)arg2, (gint)arg3, (GtkIconLookupFlags)arg4);
1107+
GTK3_NATIVE_EXIT(env, that, gtk_1icon_1theme_1lookup_1by_1gicon_1for_1scale_FUNC);
1108+
return rc;
1109+
}
1110+
#endif
1111+
11001112
#ifndef NO_gtk_1im_1context_1filter_1keypress
11011113
JNIEXPORT jboolean JNICALL GTK3_NATIVE(gtk_1im_1context_1filter_1keypress)
11021114
(JNIEnv *env, jclass that, jlong arg0, jlong arg1)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2025 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -111,6 +111,7 @@ typedef enum {
111111
gtk_1icon_1theme_1get_1default_FUNC,
112112
gtk_1icon_1theme_1load_1icon_FUNC,
113113
gtk_1icon_1theme_1lookup_1by_1gicon_FUNC,
114+
gtk_1icon_1theme_1lookup_1by_1gicon_1for_1scale_FUNC,
114115
gtk_1im_1context_1filter_1keypress_FUNC,
115116
gtk_1image_1new_1from_1icon_1name_FUNC,
116117
gtk_1image_1new_1from_1surface_FUNC,

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2025 IBM Corporation and others. All rights reserved.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others. All rights reserved.
33
* The contents of this file are made available under the terms
44
* of the GNU Lesser General Public License (LGPL) Version 2.1 that
55
* accompanies this distribution (lgpl-v21.txt). The LGPL is also
@@ -2755,6 +2755,18 @@ JNIEXPORT void JNICALL GDK_NATIVE(gdk_1window_1get_1root_1origin)
27552755
}
27562756
#endif
27572757

2758+
#ifndef NO_gdk_1window_1get_1scale_1factor
2759+
JNIEXPORT jint JNICALL GDK_NATIVE(gdk_1window_1get_1scale_1factor)
2760+
(JNIEnv *env, jclass that, jlong arg0)
2761+
{
2762+
jint rc = 0;
2763+
GDK_NATIVE_ENTER(env, that, gdk_1window_1get_1scale_1factor_FUNC);
2764+
rc = (jint)gdk_window_get_scale_factor((GdkWindow *)arg0);
2765+
GDK_NATIVE_EXIT(env, that, gdk_1window_1get_1scale_1factor_FUNC);
2766+
return rc;
2767+
}
2768+
#endif
2769+
27582770
#ifndef NO_gdk_1window_1get_1state
27592771
JNIEXPORT jint JNICALL GDK_NATIVE(gdk_1window_1get_1state)
27602772
(JNIEnv *env, jclass that, jlong arg0)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194
#define NO_gdk_1window_1get_1root_1origin
195195
#define NO_gdk_1window_1get_1state
196196
#define NO_gdk_1window_1get_1user_1data
197+
#define NO_gdk_1window_1get_1scale_1factor
197198
#define NO_gdk_1window_1get_1visible_1region
198199
#define NO_gdk_1window_1show
199200
#define NO_gdk_1window_1hide

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2025 IBM Corporation and others. All rights reserved.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others. All rights reserved.
33
* The contents of this file are made available under the terms
44
* of the GNU Lesser General Public License (LGPL) Version 2.1 that
55
* accompanies this distribution (lgpl-v21.txt). The LGPL is also
@@ -204,6 +204,7 @@ typedef enum {
204204
gdk_1window_1get_1origin_FUNC,
205205
gdk_1window_1get_1parent_FUNC,
206206
gdk_1window_1get_1root_1origin_FUNC,
207+
gdk_1window_1get_1scale_1factor_FUNC,
207208
gdk_1window_1get_1state_FUNC,
208209
gdk_1window_1get_1user_1data_FUNC,
209210
gdk_1window_1get_1visible_1region_FUNC,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,11 @@ public class GDK extends OS {
11071107
*/
11081108
/* [GTK3 only, if-def'd in os.h] */
11091109
public static final native void gdk_window_get_user_data(long window, long [] data);
1110+
/**
1111+
* @param window cast=(GdkWindow *)
1112+
*/
1113+
/* [GTK3 only, if-def'd in os.h] */
1114+
public static final native int gdk_window_get_scale_factor(long window);
11101115
/** @param window cast=(GdkWindow *) */
11111116
/* [GTK3 only, if-def'd in os.h] */
11121117
public static final native void gdk_window_hide(long window);

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,15 @@ public class GTK3 {
795795
* @param flags cast=(GtkIconLookupFlags)
796796
*/
797797
public static final native long gtk_icon_theme_lookup_by_gicon(long icon_theme, long icon, int size, int flags);
798+
/* GtkIconTheme */
799+
/**
800+
* @param icon_theme cast=(GtkIconTheme *)
801+
* @param icon cast=(GIcon *)
802+
* @param size cast=(gint)
803+
* @param scale cast=(gint)
804+
* @param flags cast=(GtkIconLookupFlags)
805+
*/
806+
public static final native long gtk_icon_theme_lookup_by_gicon_for_scale(long icon_theme, long icon, int size, int scale, int flags);
798807
/**
799808
* @param icon_theme cast=(GtkIconTheme *)
800809
* @param icon_name cast=(const gchar *)

0 commit comments

Comments
 (0)