< prev index next >

src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c

Print this page

        

@@ -2080,5 +2080,40 @@
 }
 
 /**
  * End DisplayMode/FullScreen support
  */
+
+int getScale(const char *name) {
+    char *uiScale = getenv(name);
+    if (uiScale != NULL) {
+        double scale = strtod(uiScale, NULL);
+        if (errno == ERANGE || scale < 1) {
+            return -1;
+        }
+        return (int) scale;
+    }
+    return -1;
+}
+
+/*
+ * Class:     sun_awt_X11GraphicsDevice
+ * Method:    getNativeScaleFactor
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL
+Java_sun_awt_X11GraphicsDevice_getNativeScaleFactor
+    (JNIEnv *env, jobject this, jint screen) {
+
+    // for debug purposes
+    static int scale = -2.0;
+
+    if (scale == -2) {
+        scale = getScale("J2D_UISCALE");
+    }
+
+    if (scale >= 1) {
+        return scale;
+    }
+
+    return getScale("GDK_SCALE");
+}
< prev index next >