Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSravan Kumar Lakkimsetti2018-06-14 08:22:07 -0400
committerSravan Kumar Lakkimsetti2018-06-15 01:59:10 -0400
commitdca6f677b85c2d83c4b6378dfcc811694796cc53 (patch)
treedc40f59d9b9afa1136675950f7e485f1e32a8739
parent7f9335300c85ac44fc805263899dbf1db2f7d1e2 (diff)
downloadeclipse.platform.swt-dca6f677b85c2d83c4b6378dfcc811694796cc53.tar.gz
eclipse.platform.swt-dca6f677b85c2d83c4b6378dfcc811694796cc53.tar.xz
eclipse.platform.swt-dca6f677b85c2d83c4b6378dfcc811694796cc53.zip
Bug 535064 - [HiDPI][GTK3] Device#getDPI method returns an incorrect
value on x2 scaled screen Signed-off-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c62
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c3
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h3
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java37
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java33
5 files changed, 130 insertions, 8 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 5145a2d507..404666fc84 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
@@ -1012,6 +1012,26 @@ JNIEXPORT jintLong JNICALL GDK_NATIVE(_1gdk_1display_1get_1monitor)
}
#endif
+#ifndef NO__1gdk_1display_1get_1primary_1monitor
+JNIEXPORT jintLong JNICALL GDK_NATIVE(_1gdk_1display_1get_1primary_1monitor)
+ (JNIEnv *env, jclass that, jintLong arg0)
+{
+ jintLong rc = 0;
+ GDK_NATIVE_ENTER(env, that, _1gdk_1display_1get_1primary_1monitor_FUNC);
+/*
+ rc = (jintLong)gdk_display_get_primary_monitor(arg0);
+*/
+ {
+ GDK_LOAD_FUNCTION(fp, gdk_display_get_primary_monitor)
+ if (fp) {
+ rc = (jintLong)((jintLong (CALLING_CONVENTION*)(jintLong))fp)(arg0);
+ }
+ }
+ GDK_NATIVE_EXIT(env, that, _1gdk_1display_1get_1primary_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)
@@ -1710,6 +1730,28 @@ JNIEXPORT jlong JNICALL GDK_NATIVE(_1gdk_1keyval_1to_1unicode)
}
#endif
+#ifndef NO__1gdk_1monitor_1get_1geometry
+JNIEXPORT void JNICALL GDK_NATIVE(_1gdk_1monitor_1get_1geometry)
+ (JNIEnv *env, jclass that, jintLong arg0, jobject arg1)
+{
+ GdkRectangle _arg1, *lparg1=NULL;
+ GDK_NATIVE_ENTER(env, that, _1gdk_1monitor_1get_1geometry_FUNC);
+ if (arg1) if ((lparg1 = &_arg1) == NULL) goto fail;
+/*
+ gdk_monitor_get_geometry(arg0, lparg1);
+*/
+ {
+ GDK_LOAD_FUNCTION(fp, gdk_monitor_get_geometry)
+ if (fp) {
+ ((void (CALLING_CONVENTION*)(jintLong, GdkRectangle *))fp)(arg0, lparg1);
+ }
+ }
+fail:
+ if (arg1 && lparg1) setGdkRectangleFields(env, arg1, lparg1);
+ GDK_NATIVE_EXIT(env, that, _1gdk_1monitor_1get_1geometry_FUNC);
+}
+#endif
+
#ifndef NO__1gdk_1monitor_1get_1scale_1factor
JNIEXPORT jint JNICALL GDK_NATIVE(_1gdk_1monitor_1get_1scale_1factor)
(JNIEnv *env, jclass that, jintLong arg0)
@@ -1730,6 +1772,26 @@ JNIEXPORT jint JNICALL GDK_NATIVE(_1gdk_1monitor_1get_1scale_1factor)
}
#endif
+#ifndef NO__1gdk_1monitor_1get_1width_1mm
+JNIEXPORT jint JNICALL GDK_NATIVE(_1gdk_1monitor_1get_1width_1mm)
+ (JNIEnv *env, jclass that, jintLong arg0)
+{
+ jint rc = 0;
+ GDK_NATIVE_ENTER(env, that, _1gdk_1monitor_1get_1width_1mm_FUNC);
+/*
+ rc = (jint)gdk_monitor_get_width_mm(arg0);
+*/
+ {
+ GDK_LOAD_FUNCTION(fp, gdk_monitor_get_width_mm)
+ if (fp) {
+ rc = (jint)((jint (CALLING_CONVENTION*)(jintLong))fp)(arg0);
+ }
+ }
+ GDK_NATIVE_EXIT(env, that, _1gdk_1monitor_1get_1width_1mm_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 967e5ef5fe..db9ba58217 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
@@ -82,6 +82,7 @@ char * GDK_nativeFunctionNames[] = {
"_1gdk_1display_1get_1default_1seat",
"_1gdk_1display_1get_1device_1manager",
"_1gdk_1display_1get_1monitor",
+ "_1gdk_1display_1get_1primary_1monitor",
"_1gdk_1display_1supports_1cursor_1color",
"_1gdk_1display_1warp_1pointer",
"_1gdk_1drag_1context_1get_1actions",
@@ -124,7 +125,9 @@ char * GDK_nativeFunctionNames[] = {
"_1gdk_1keymap_1get_1entries_1for_1keyval",
"_1gdk_1keyval_1to_1lower",
"_1gdk_1keyval_1to_1unicode",
+ "_1gdk_1monitor_1get_1geometry",
"_1gdk_1monitor_1get_1scale_1factor",
+ "_1gdk_1monitor_1get_1width_1mm",
"_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 a9dfc1f899..85f589547b 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
@@ -92,6 +92,7 @@ typedef enum {
_1gdk_1display_1get_1default_1seat_FUNC,
_1gdk_1display_1get_1device_1manager_FUNC,
_1gdk_1display_1get_1monitor_FUNC,
+ _1gdk_1display_1get_1primary_1monitor_FUNC,
_1gdk_1display_1supports_1cursor_1color_FUNC,
_1gdk_1display_1warp_1pointer_FUNC,
_1gdk_1drag_1context_1get_1actions_FUNC,
@@ -134,7 +135,9 @@ typedef enum {
_1gdk_1keymap_1get_1entries_1for_1keyval_FUNC,
_1gdk_1keyval_1to_1lower_FUNC,
_1gdk_1keyval_1to_1unicode_FUNC,
+ _1gdk_1monitor_1get_1geometry_FUNC,
_1gdk_1monitor_1get_1scale_1factor_FUNC,
+ _1gdk_1monitor_1get_1width_1mm_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 5595537b87..3388cf54f2 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
@@ -2066,6 +2066,30 @@ public class GDK extends OS {
}
/**
* @method flags=dynamic
+ */
+ public static final native int _gdk_monitor_get_width_mm(long /*int*/ monitor);
+ public static final int gdk_monitor_get_width_mm(long /*int*/ monitor) {
+ lock.lock();
+ try {
+ return _gdk_monitor_get_width_mm(monitor);
+ } finally {
+ lock.unlock();
+ }
+ }
+ /**
+ * @method flags=dynamic
+ */
+ public static final native long /*int*/ _gdk_display_get_primary_monitor(long /*int*/ display);
+ public static final long /*int*/ gdk_display_get_primary_monitor(long /*int*/ display) {
+ lock.lock();
+ try {
+ return _gdk_display_get_primary_monitor(display);
+ } finally {
+ lock.unlock();
+ }
+ }
+ /**
+ * @method flags=dynamic
* @param screen cast=(GdkScreen *)
* @param dest flags=no_in
*/
@@ -2080,6 +2104,19 @@ public class GDK extends OS {
}
/**
* @method flags=dynamic
+ * @param dest flags=no_in
+ */
+ public static final native void _gdk_monitor_get_geometry (long /*int*/ monitor, GdkRectangle dest);
+ public static final void gdk_monitor_get_geometry (long /*int*/ monitor, GdkRectangle dest) {
+ lock.lock();
+ try {
+ _gdk_monitor_get_geometry(monitor, dest);
+ } 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/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
index 0bff506f95..c8da6a7399 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
@@ -467,13 +467,22 @@ public FontData[] getFontList (String faceName, boolean scalable) {
}
Point getScreenDPI () {
- 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 monitor_num = GDK.gdk_screen_get_monitor_at_point (screen, 0, 0);
- int scale = GDK.gdk_screen_get_monitor_scale_factor (screen, monitor_num);
- dpi = dpi * scale;
+ int dpi = 96; //default value
+ if (GTK.GTK3) {
+ long /*int*/ display = GDK.gdk_display_get_default();
+ long /*int*/ pMonitor = GDK.gdk_display_get_primary_monitor(display);
+ if (pMonitor == 0) {
+ pMonitor = GDK.gdk_display_get_monitor(display, 0);
+ }
+ int widthMM = GDK.gdk_monitor_get_width_mm(pMonitor);
+ int scaleFactor = GDK.gdk_monitor_get_scale_factor(pMonitor);
+ GdkRectangle monitorGeometry = new GdkRectangle ();
+ GDK.gdk_monitor_get_geometry(pMonitor, monitorGeometry);
+ dpi = Compatibility.round (254 * monitorGeometry.width * scaleFactor, widthMM * 10);
+ } else {
+ int widthMM = GDK.gdk_screen_width_mm ();
+ int width = GDK.gdk_screen_width ();
+ dpi = Compatibility.round (254 * width, widthMM * 10);
}
return new Point (dpi, dpi);
}
@@ -1067,7 +1076,15 @@ int _getDPIx () {
* @since 3.105
*/
protected int getDeviceZoom() {
- return DPIUtil.mapDPIToZoom (getScreenDPI().x);
+ 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 monitor_num = GDK.gdk_screen_get_monitor_at_point (screen, 0, 0);
+ int scale = GDK.gdk_screen_get_monitor_scale_factor (screen, monitor_num);
+ dpi = dpi * scale;
+ }
+ return DPIUtil.mapDPIToZoom (dpi);
}
/**
* @noreference This method is not intended to be referenced by clients.

Back to the top