Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8248126: JavaFX ignores HiDPI scaling settings on some linux platforms
Reviewed-by: kcr, arapte
  • Loading branch information
Pankaj Bansal committed Feb 15, 2021
1 parent a23d4ae commit 782f22a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -132,7 +132,7 @@ JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkRobot__1mouseMove

Display *xdisplay = gdk_x11_get_default_xdisplay();
checkXTest(env);
jfloat uiScale = getUIScale();
jfloat uiScale = getUIScale(gdk_screen_get_default());
x = rint(x * uiScale);
y = rint(y * uiScale);
XWarpPointer(xdisplay,
Expand Down Expand Up @@ -228,7 +228,7 @@ JNIEXPORT jint JNICALL Java_com_sun_glass_ui_gtk_GtkRobot__1getMouseX

jint x;
glass_gdk_display_get_pointer(gdk_display_get_default(), &x, NULL);
x = rint(x / getUIScale());
x = rint(x / getUIScale(gdk_screen_get_default()));
return x;
}

Expand All @@ -245,7 +245,7 @@ JNIEXPORT jint JNICALL Java_com_sun_glass_ui_gtk_GtkRobot__1getMouseY

jint y;
glass_gdk_display_get_pointer(gdk_display_get_default(), NULL, &y);
y = rint(y / getUIScale());
y = rint(y / getUIScale(gdk_screen_get_default()));
return y;
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,7 +24,6 @@
*/

#include <stdlib.h>

#include "glass_screen.h"
#include "glass_general.h"

Expand All @@ -33,6 +32,7 @@
#include <gdk/gdkx.h>

jfloat OverrideUIScale = -1.0f;
int DEFAULT_DPI = 96;

static guint get_current_desktop(GdkScreen *screen) {
Display* display = gdk_x11_display_get_xdisplay(gdk_display_get_default());
Expand Down Expand Up @@ -103,7 +103,7 @@ static GdkRectangle get_screen_workarea(GdkScreen *screen) {

}

jfloat getUIScale() {
jfloat getUIScale(GdkScreen* screen) {
jfloat uiScale;
if (OverrideUIScale > 0.0f) {
uiScale = OverrideUIScale;
Expand All @@ -115,6 +115,9 @@ jfloat getUIScale() {
} else {
uiScale = (jfloat) glass_settings_get_guint_opt("org.gnome.desktop.interface",
"scaling-factor", 0);
if (uiScale < 1) {
uiScale = (jfloat) (gdk_screen_get_resolution(screen) / DEFAULT_DPI);
}
if (uiScale < 1) {
uiScale = 1;
}
Expand All @@ -140,7 +143,8 @@ static jobject createJavaScreen(JNIEnv* env, GdkScreen* screen, gint monitor_idx
GdkRectangle working_monitor_geometry;
gdk_rectangle_intersect(&workArea, &monitor_geometry, &working_monitor_geometry);

jfloat uiScale = getUIScale();
jfloat uiScale = getUIScale(screen);


jint mx = monitor_geometry.x / uiScale;
jint my = monitor_geometry.y / uiScale;
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -31,7 +31,7 @@
#include <gtk/gtk.h>

extern jfloat OverrideUIScale;
jfloat getUIScale();
jfloat getUIScale(GdkScreen* screen);
jobject createJavaScreen(JNIEnv* env, gint monitor_idx);
glong getScreenPtrForLocation(gint x, gint y);
jobjectArray rebuild_screens(JNIEnv* env);
Expand Down

1 comment on commit 782f22a

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.