Commit c52e8155 authored by Roman Sedaikin's avatar Roman Sedaikin

Fixed getting dpi scale in Linux.

parent 07c14932
......@@ -5,3 +5,4 @@ local.properties
run.sh
.idea
deploy.sh
skiko/src/jvmMain/java/
......@@ -4,6 +4,8 @@
#include <GL/glx.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <cstdlib>
#include <unistd.h>
#include <stdio.h>
#include <set>
......@@ -230,4 +232,46 @@ extern "C"
return (jlong)window;
}
double getDpiScaleByDisplay(Display *display)
{
char *resourceManager = XResourceManagerString(display);
if (resourceManager != nullptr)
{
XrmDatabase db = XrmGetStringDatabase(resourceManager);
if (db != nullptr)
{
XrmValue value;
char *type;
XrmGetResource(db, "Xft.dpi", "Xft.dpi", &type, &value);
if (value.addr != nullptr)
{
return atof(value.addr) / 96.0;
}
}
}
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)
{
return (float)getDpiScale();
}
} // extern "C"
\ No newline at end of file
......@@ -34,7 +34,7 @@ abstract class HardwareLayer : Canvas(), Drawable {
external get
override val contentScale: Float
get() = graphicsConfiguration.defaultTransform.scaleX.toFloat()
get() = platformOperations.getDpiScale(this)
val absoluteX: Int
get() = convertPoint(this, x, y, getRootPane(this)).x
......
......@@ -7,6 +7,7 @@ import javax.swing.SwingUtilities
internal interface PlatformOperations {
fun isFullscreen(component: Component): Boolean
fun setFullscreen(component: Component, value: Boolean)
fun getDpiScale(component: Component): Float
}
internal val platformOperations: PlatformOperations by lazy {
......@@ -19,8 +20,12 @@ internal val platformOperations: PlatformOperations by lazy {
override fun setFullscreen(component: Component, value: Boolean) {
osxSetFullscreenNative(component, value)
}
override fun getDpiScale(component: Component): Float {
return component.graphicsConfiguration.defaultTransform.scaleX.toFloat()
}
}
else -> {
OS.Windows -> {
object: PlatformOperations {
override fun isFullscreen(component: Component): Boolean {
val window = SwingUtilities.getRoot(component) as Window
......@@ -33,10 +38,37 @@ internal val platformOperations: PlatformOperations by lazy {
val device = window.graphicsConfiguration.device
device.setFullScreenWindow(if (value) window else null)
}
override fun getDpiScale(component: Component): Float {
return component.graphicsConfiguration.defaultTransform.scaleX.toFloat()
}
}
}
OS.Linux -> {
object: PlatformOperations {
override fun isFullscreen(component: Component): Boolean {
val window = SwingUtilities.getRoot(component) as Window
val device = window.graphicsConfiguration.device
return device.getFullScreenWindow() == window
}
override fun setFullscreen(component: Component, value: Boolean) {
val window = SwingUtilities.getRoot(component) as Window
val device = window.graphicsConfiguration.device
device.setFullScreenWindow(if (value) window else null)
}
override fun getDpiScale(component: Component): Float {
return linuxGetDpiScaleNative()
}
}
}
}
}
// OSX
external private fun osxIsFullscreenNative(component: Component): Boolean
external private fun osxSetFullscreenNative(component: Component, value: Boolean)
// Linux
external private fun linuxGetDpiScaleNative(): Float
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment