summaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes/jogamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/nativewindow/classes/jogamp')
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java b/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java
index f5804cd12..c732151e5 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java
@@ -28,6 +28,10 @@
*/
package jogamp.nativewindow;
+import java.security.PrivilegedAction;
+import java.util.Map;
+
+import com.jogamp.common.util.SecurityUtil;
import com.jogamp.nativewindow.ScalableSurface;
/**
@@ -222,4 +226,46 @@ public class SurfaceScaleUtils {
result[1] = resultY;
return changed;
}
+
+ /**
+ * Get global pixel-scale values from environment variables, e.g.:
+ * - QT_SCALE_FACTOR
+ * - GDK_SCALE
+ * See https://wiki.archlinux.org/title/HiDPI
+ * @param env_var_names array of potential environment variable names, treated as float.
+ * @param pixel_scale_xy store for resulting scale factors
+ * @return index of first found variable name within env_var_names, otherwise -1
+ */
+ public static int getGlobalPixelScaleEnv(final String[] env_var_names, final float[] pixel_scale_xy) {
+ final Map<String, String> env = SecurityUtil.doPrivileged(new PrivilegedAction<Map<String, String>>() {
+ @Override
+ public Map<String, String> run() {
+ return System.getenv();
+ }
+ });
+ float value = -1.0f;
+ boolean done = false;
+ int var_idx = 0;
+ while( var_idx < env_var_names.length && !done ) {
+ final String env_var_name = env_var_names[var_idx];
+ final String s_value = env.get(env_var_name);
+ if( null != s_value ) {
+ try {
+ value = Float.valueOf(s_value);
+ done = true;
+ } catch(final NumberFormatException nfe) {
+ ++var_idx;
+ }
+ } else {
+ ++var_idx;
+ }
+ }
+ if( done ) {
+ pixel_scale_xy[0] = value;
+ pixel_scale_xy[1] = value;
+ return var_idx;
+ } else {
+ return -1;
+ }
+ }
}