diff --git a/samples/SkijaInjectSample/build.gradle.kts b/samples/SkijaInjectSample/build.gradle.kts index d7115b100..9fa52c6f5 100644 --- a/samples/SkijaInjectSample/build.gradle.kts +++ b/samples/SkijaInjectSample/build.gradle.kts @@ -52,6 +52,7 @@ val additionalArguments = mutableMapOf() val casualRun = tasks.named("run") { systemProperty("skiko.fps.enabled", "true") + systemProperty("skiko.linux.autodpi", "true") systemProperty("skiko.hardwareInfo.enabled", "true") jvmArgs?.add("-ea") // Use systemProperty("skiko.library.path", "/tmp") to test loader. diff --git a/skiko/src/jvmMain/cpp/linux/drawlayer.cc b/skiko/src/jvmMain/cpp/linux/drawlayer.cc index 272cc362b..622d91ef2 100755 --- a/skiko/src/jvmMain/cpp/linux/drawlayer.cc +++ b/skiko/src/jvmMain/cpp/linux/drawlayer.cc @@ -55,16 +55,33 @@ extern "C" return 1; } + double getDpiScale() { + Display *display = XOpenDisplay(nullptr); + if (display != nullptr) { + double result = getDpiScaleByDisplay(display); + XCloseDisplay(display); + return result; + } else { + return 1; + } + } + JNIEXPORT jfloat JNICALL Java_org_jetbrains_skiko_PlatformOperationsKt_linuxGetDpiScaleNative(JNIEnv *env, jobject properties, jlong platformInfoPtr) { JAWT_X11DrawingSurfaceInfo *dsi_x11 = fromJavaPointer(platformInfoPtr); return (float) getDpiScaleByDisplay(dsi_x11->display); } - JNIEXPORT jint JNICALL Java_org_jetbrains_skiko_SystemThemeKt_getCurrentSystemTheme(JNIEnv *env, jobject topLevel) - { - // Unknown. - return 2; - } + JNIEXPORT jint JNICALL Java_org_jetbrains_skiko_SystemThemeKt_getCurrentSystemTheme(JNIEnv *env, jobject topLevel) + { + // Unknown. + return 2; + } + + + JNIEXPORT jfloat JNICALL Java_org_jetbrains_skiko_SetupKt_linuxGetSystemDpiScale(JNIEnv *env, jobject layer) + { + return (float) getDpiScale(); + } } // extern "C" \ No newline at end of file diff --git a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Library.kt b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Library.kt index 1f0ab243b..5e1c071e5 100644 --- a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Library.kt +++ b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Library.kt @@ -79,11 +79,7 @@ object Library { } // TODO move properties to SkikoProperties - Setup.init( - System.getProperty("skiko.rendering.noerasebackground") != "false", - System.getProperty("skiko.rendering.laf.global") == "true", - System.getProperty("skiko.rendering.useScreenMenuBar") != "false" - ) + Setup.init() try { // Init code executed after library was loaded. diff --git a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/PlatformOperations.kt b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/PlatformOperations.kt index 8805e8b75..d3bf4aa7d 100644 --- a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/PlatformOperations.kt +++ b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/PlatformOperations.kt @@ -99,18 +99,6 @@ internal val platformOperations: PlatformOperations by lazy { override fun getDpiScale(component: Component): Float { return component.graphicsConfiguration.defaultTransform.scaleX.toFloat() - // TODO doesn't work well because java doesn't scale windows (content has offset with 200% scale) - // - // Two solutions: - // 1. dynamically change sun.java2d.uiScale (it is global property, - // so we have to be careful) and update all windows - // - // 2. apply contentScale manually to all windows - // (it is not good, because on different platform windows will have different size. - // Maybe we will apply contentScale manually on all platforms?) - - // see also comment for HardwareLayer.checkContentScale - // return component.useDrawingSurfacePlatformInfo(::linuxGetDpiScaleNative) } override fun createRedrawer( diff --git a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Setup.kt b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Setup.kt index 66a984359..6b0d8a207 100644 --- a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Setup.kt +++ b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Setup.kt @@ -4,10 +4,16 @@ import javax.swing.UIManager object Setup { fun init( - noEraseBackground: Boolean = true, - globalLAF: Boolean = false, - useScreenMenuBar: Boolean = true + noEraseBackground: Boolean = System.getProperty("skiko.rendering.noerasebackground") != "false", + globalLAF: Boolean = System.getProperty("skiko.rendering.laf.global") == "true", + useScreenMenuBar: Boolean = System.getProperty("skiko.rendering.useScreenMenuBar") != "false", + autoLinuxDpi: Boolean = System.getProperty("skiko.linux.autodpi") == "true" ) { + if (hostOs == OS.Linux && autoLinuxDpi) { + val scale = linuxGetSystemDpiScale() + System.setProperty("sun.java2d.uiScale.enabled", "true") + System.setProperty("sun.java2d.uiScale", "$scale") + } if (noEraseBackground) { // we have to set this property to avoid render flickering. System.setProperty("sun.awt.noerasebackground", "true") @@ -24,4 +30,6 @@ object Setup { // Not all platforms allow this. } } -} \ No newline at end of file +} + +private external fun linuxGetSystemDpiScale(): Float