Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLakshmi Shanmugam2018-04-04 11:04:38 +0000
committerAlexander Kurtakov2018-04-24 17:29:46 +0000
commitecb072664278dc6cfba0ce56ea06e669e0675959 (patch)
tree5fa26f9f1c3fa7cba9b47f2f86e426ed970eaf6f
parent2a181099876fa77b1c667c10abdcd03460f396d3 (diff)
downloadeclipse.platform.swt-ecb072664278dc6cfba0ce56ea06e669e0675959.tar.gz
eclipse.platform.swt-ecb072664278dc6cfba0ce56ea06e669e0675959.tar.xz
eclipse.platform.swt-ecb072664278dc6cfba0ce56ea06e669e0675959.zip
Bug 480639: [HiDPI][API] Provide monitor-specific DPI scaling / zoom
level GTK Monitor.getZoom() implementation Change-Id: If95004e85a2cfdc53223f03675a501556e0038f8
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c40
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java24
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java20
5 files changed, 87 insertions, 1 deletions
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 565ee2ac1c..85b5361401 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
@@ -992,6 +992,26 @@ JNIEXPORT jintLong JNICALL GDK_NATIVE(_1gdk_1display_1get_1device_1manager)
}
#endif
+#ifndef NO__1gdk_1display_1get_1monitor
+JNIEXPORT jintLong JNICALL GDK_NATIVE(_1gdk_1display_1get_1monitor)
+ (JNIEnv *env, jclass that, jintLong arg0, jint arg1)
+{
+ jintLong rc = 0;
+ GDK_NATIVE_ENTER(env, that, _1gdk_1display_1get_1monitor_FUNC);
+/*
+ rc = (jintLong)gdk_display_get_monitor(arg0, arg1);
+*/
+ {
+ GDK_LOAD_FUNCTION(fp, gdk_display_get_monitor)
+ if (fp) {
+ rc = (jintLong)((jintLong (CALLING_CONVENTION*)(jintLong, jint))fp)(arg0, arg1);
+ }
+ }
+ GDK_NATIVE_EXIT(env, that, _1gdk_1display_1get_1monitor_FUNC);
+ return rc;
+}
+#endif
+
#ifndef NO__1gdk_1display_1supports_1cursor_1color
JNIEXPORT jboolean JNICALL GDK_NATIVE(_1gdk_1display_1supports_1cursor_1color)
(JNIEnv *env, jclass that, jintLong arg0)
@@ -1690,6 +1710,26 @@ JNIEXPORT jlong JNICALL GDK_NATIVE(_1gdk_1keyval_1to_1unicode)
}
#endif
+#ifndef NO__1gdk_1monitor_1get_1scale_1factor
+JNIEXPORT jint JNICALL GDK_NATIVE(_1gdk_1monitor_1get_1scale_1factor)
+ (JNIEnv *env, jclass that, jintLong arg0)
+{
+ jint rc = 0;
+ GDK_NATIVE_ENTER(env, that, _1gdk_1monitor_1get_1scale_1factor_FUNC);
+/*
+ rc = (jint)gdk_monitor_get_scale_factor(arg0);
+*/
+ {
+ GDK_LOAD_FUNCTION(fp, gdk_monitor_get_scale_factor)
+ if (fp) {
+ rc = (jint)((jint (CALLING_CONVENTION*)(jintLong))fp)(arg0);
+ }
+ }
+ GDK_NATIVE_EXIT(env, that, _1gdk_1monitor_1get_1scale_1factor_FUNC);
+ return rc;
+}
+#endif
+
#ifndef NO__1gdk_1pango_1context_1get
JNIEXPORT jintLong JNICALL GDK_NATIVE(_1gdk_1pango_1context_1get)
(JNIEnv *env, jclass that)
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 01f966424d..cf583fd184 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
@@ -81,6 +81,7 @@ char * GDK_nativeFunctionNames[] = {
"_1gdk_1display_1get_1default_1group",
"_1gdk_1display_1get_1default_1seat",
"_1gdk_1display_1get_1device_1manager",
+ "_1gdk_1display_1get_1monitor",
"_1gdk_1display_1supports_1cursor_1color",
"_1gdk_1display_1warp_1pointer",
"_1gdk_1drag_1context_1get_1actions",
@@ -123,6 +124,7 @@ char * GDK_nativeFunctionNames[] = {
"_1gdk_1keymap_1get_1entries_1for_1keyval",
"_1gdk_1keyval_1to_1lower",
"_1gdk_1keyval_1to_1unicode",
+ "_1gdk_1monitor_1get_1scale_1factor",
"_1gdk_1pango_1context_1get",
"_1gdk_1pango_1layout_1get_1clip_1region",
"_1gdk_1pixbuf_1copy_1area",
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 64a3069337..d006679824 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
@@ -91,6 +91,7 @@ typedef enum {
_1gdk_1display_1get_1default_1group_FUNC,
_1gdk_1display_1get_1default_1seat_FUNC,
_1gdk_1display_1get_1device_1manager_FUNC,
+ _1gdk_1display_1get_1monitor_FUNC,
_1gdk_1display_1supports_1cursor_1color_FUNC,
_1gdk_1display_1warp_1pointer_FUNC,
_1gdk_1drag_1context_1get_1actions_FUNC,
@@ -133,6 +134,7 @@ typedef enum {
_1gdk_1keymap_1get_1entries_1for_1keyval_FUNC,
_1gdk_1keyval_1to_1lower_FUNC,
_1gdk_1keyval_1to_1unicode_FUNC,
+ _1gdk_1monitor_1get_1scale_1factor_FUNC,
_1gdk_1pango_1context_1get_FUNC,
_1gdk_1pango_1layout_1get_1clip_1region_FUNC,
_1gdk_1pixbuf_1copy_1area_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 6de79fb2c3..5595537b87 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
@@ -2013,6 +2013,18 @@ public class GDK extends OS {
}
/**
* @method flags=dynamic
+ */
+ public static final native int _gdk_monitor_get_scale_factor(long /*int*/ window);
+ public static final int gdk_monitor_get_scale_factor(long /*int*/ window) {
+ lock.lock();
+ try {
+ return _gdk_monitor_get_scale_factor(window);
+ } finally {
+ lock.unlock();
+ }
+ }
+ /**
+ * @method flags=dynamic
* @param screen cast=(GdkScreen *)
* @param x cast=(gint)
* @param y cast=(gint)
@@ -2042,6 +2054,18 @@ public class GDK extends OS {
}
/**
* @method flags=dynamic
+ */
+ public static final native long /*int*/ _gdk_display_get_monitor(long /*int*/ display, int monitor_num);
+ public static final long /*int*/ gdk_display_get_monitor(long /*int*/ display, int monitor_num) {
+ lock.lock();
+ try {
+ return _gdk_display_get_monitor(display, monitor_num);
+ } finally {
+ lock.unlock();
+ }
+ }
+ /**
+ * @method flags=dynamic
* @param screen cast=(GdkScreen *)
* @param dest flags=no_in
*/
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 e00c1e60cf..d983ed5557 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
@@ -2674,6 +2674,13 @@ public Monitor [] getMonitors () {
monitor.y = DPIUtil.autoScaleDown (dest.y);
monitor.width = DPIUtil.autoScaleDown (dest.width);
monitor.height = DPIUtil.autoScaleDown (dest.height);
+ if (GTK.GTK_VERSION >= OS.VERSION (3, 22, 0) && !OS.isX11()) {
+ int scale_factor = (int) GDK.gdk_monitor_get_scale_factor (
+ GDK.gdk_display_get_monitor (GDK.gdk_display_get_default (), (int) monitor.handle));
+ monitor.zoom = scale_factor * 100;
+ } else {
+ monitor.zoom = Display._getDeviceZoom(monitor.handle);
+ }
if (GTK.GTK_VERSION >= OS.VERSION (3, 4, 0)) {
// workarea was defined in GTK 3.4. If present, it will return the best results
@@ -5955,11 +5962,22 @@ protected long /*int*/ gsettingsProc (long /*int*/ gobject, long /*int*/ arg1, l
return 0;
}
-
+static int _getDeviceZoom (long /*int*/ monitor_num) {
+ long /*int*/ screen = GDK.gdk_screen_get_default ();
+ int dpi = (int) GDK.gdk_screen_get_resolution (screen);
+ if (dpi <= 0) dpi = 96; // gdk_screen_get_resolution returns -1 in case of error
+ if (GTK.GTK_VERSION > OS.VERSION (3, 9, 0)) {
+ int scale = GDK.gdk_screen_get_monitor_scale_factor (screen, (int) monitor_num);
+ dpi = dpi * scale;
+ }
+ return DPIUtil.mapDPIToZoom (dpi);
+}
}
+
class MonitorUtil {
static int getZoom (Monitor monitor) {
return monitor.zoom;
}
}
+

Back to the top