summaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-01-31 07:35:58 +0100
committerSven Gothel <[email protected]>2023-01-31 07:35:58 +0100
commit97b79ad351e48e7d3c6f9c95bacdf4f9d5d158ef (patch)
tree0945989bcd6ffbe87f295f422002b3055a1e082d /src/nativewindow/classes/jogamp
parent6eb13066996e94b2fe40bf64e74ea43d8f4e9171 (diff)
NEWT Soft-PixelScale (p6): Implement Soft-PixelScale for X11 and Windows ... (working state)
Both: - Using Soft-PixelScale mode, i.e. converting all given window-units to pixel-units for native GDI/X11 ops - Using scaled pixel-sized surface - Adjusting NEWT's Monitor's window-unit viewport value to pixel-scale For X11: - Using global scale factor from environment variable, either: "GDK_SCALE", "QT_SCALE_FACTOR" or "SOFT_SCALE". The latter is for testing only. See https://wiki.archlinux.org/title/HiDPI For Windows: - Using actual monitor's pixel-scale via native SHC API (Shellscaling API, shcore.dll) Misc: - SurfaceScaleUtils.getGlobalPixelScaleEnv() reads a float value from given env names, first come, first serve - MonitorModeProps.streamInMonitorDevice(..): Add `invscale_wuviewport` argument to scale wuvieport for soft-pixel-scale - TestGearsNEWT: Enhance GL2 demo to be suitable for manual tests, this since my Windows KVM machine doesn't support ES2 - TestGLContextDrawableSwitch10NEWT: Add a few more test constraints .. working Tested: - Manually on a Windows virtual machine (KVM) using - 2 virtualized 'Video QXL' cards and - and 'remote-viewer' to see the 2 monitors since `Virtual Machine Manager` build-in doesn't support - remote-viewer spice://localhost:5917 - Manually on a Linux machine w/ SOFT_SCALE - Both, X11 and Windows - Place window on each monitor - Move window across monitors w/ pixel-scale change (or not) - TODO: Test and fix utilization with AWT, i.e. NewtCanvasAWT
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;
+ }
+ }
}