From 97b79ad351e48e7d3c6f9c95bacdf4f9d5d158ef Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 31 Jan 2023 07:35:58 +0100 Subject: 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 --- .../jogamp/nativewindow/SurfaceScaleUtils.java | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/nativewindow/classes/jogamp') 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 env = SecurityUtil.doPrivileged(new PrivilegedAction>() { + @Override + public Map 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; + } + } } -- cgit v1.2.3