From d63162b5a10abd8c3cc9b7c47cc4fb7c2bb2a4dd Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 3 Nov 2016 16:29:41 +0200 Subject: [PATCH 1/6] Added Platform.getSystemDPI() API --- app/src/processing/app/Theme.java | 2 +- arduino-core/src/processing/app/Platform.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/processing/app/Theme.java b/app/src/processing/app/Theme.java index cea6e6fe4d2..bfa39349888 100644 --- a/app/src/processing/app/Theme.java +++ b/app/src/processing/app/Theme.java @@ -122,7 +122,7 @@ static public int getScale() { return scale; } catch (NumberFormatException ignore) { } - return 100; + return BaseNoGui.getPlatform().getSystemDPI() * 100 / 96; } static public int scale(int size) { diff --git a/arduino-core/src/processing/app/Platform.java b/arduino-core/src/processing/app/Platform.java index f829699bd1c..0f3d5917522 100644 --- a/arduino-core/src/processing/app/Platform.java +++ b/arduino-core/src/processing/app/Platform.java @@ -333,4 +333,9 @@ public void chmod(File file, int mode) throws IOException, InterruptedException public void fixSettingsLocation() throws Exception { //noop } + + public int getSystemDPI() { + return 96; + } + } From 03225e787f66165e20aa8304c4f44b2cbc4f6bb4 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 3 Nov 2016 16:30:52 +0200 Subject: [PATCH 2/6] Windows: Autodetection of display resolution --- .../src/processing/app/windows/Platform.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arduino-core/src/processing/app/windows/Platform.java b/arduino-core/src/processing/app/windows/Platform.java index c9d6ea6155e..ec55246bdf6 100644 --- a/arduino-core/src/processing/app/windows/Platform.java +++ b/arduino-core/src/processing/app/windows/Platform.java @@ -35,6 +35,9 @@ import java.util.LinkedList; import java.util.List; +import com.sun.jna.Native; +import com.sun.jna.win32.StdCallLibrary; +import com.sun.jna.win32.W32APIOptions; public class Platform extends processing.app.Platform { @@ -240,4 +243,22 @@ public void fixSettingsLocation() throws Exception { Files.move(oldSettingsFolder, settingsFolder.toPath()); } + + // Need to extend com.sun.jna.platform.win32.User32 to access + // Win32 function GetDpiForSystem() + interface ExtUser32 extends StdCallLibrary, com.sun.jna.platform.win32.User32 { + ExtUser32 INSTANCE = (ExtUser32) Native.loadLibrary("user32", ExtUser32.class, W32APIOptions.DEFAULT_OPTIONS); + + public int GetDpiForSystem(); + } + + @Override + public int getSystemDPI() { + try { + return ExtUser32.INSTANCE.GetDpiForSystem(); + } catch (Throwable e) { + // DPI detection failed, fall back with default + return super.getSystemDPI(); + } + } } From 41291c290721ff7a40f61d06431c46b1a3ca331e Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 4 Nov 2016 11:43:38 +0200 Subject: [PATCH 3/6] Update launch4j to version 3.9 --- build/build.xml | 8 ++++---- build/windows/launch4j-3.8-linux.tgz.sha | 1 - build/windows/launch4j-3.8-win32.zip.sha | 1 - build/windows/launch4j-3.9-linux.tgz.sha | 1 + build/windows/launch4j-3.9-win32.zip.sha | 1 + 5 files changed, 6 insertions(+), 6 deletions(-) delete mode 100644 build/windows/launch4j-3.8-linux.tgz.sha delete mode 100644 build/windows/launch4j-3.8-win32.zip.sha create mode 100644 build/windows/launch4j-3.9-linux.tgz.sha create mode 100644 build/windows/launch4j-3.9-win32.zip.sha diff --git a/build/build.xml b/build/build.xml index d6159610f34..fe5de106c1e 100644 --- a/build/build.xml +++ b/build/build.xml @@ -926,8 +926,8 @@ - - + + @@ -935,8 +935,8 @@ - - + + diff --git a/build/windows/launch4j-3.8-linux.tgz.sha b/build/windows/launch4j-3.8-linux.tgz.sha deleted file mode 100644 index 3c6125ab7ab..00000000000 --- a/build/windows/launch4j-3.8-linux.tgz.sha +++ /dev/null @@ -1 +0,0 @@ -97a390c10c2c6fce7cc54bee2ef8bcdd790d6dc3 diff --git a/build/windows/launch4j-3.8-win32.zip.sha b/build/windows/launch4j-3.8-win32.zip.sha deleted file mode 100644 index 99cd59c5615..00000000000 --- a/build/windows/launch4j-3.8-win32.zip.sha +++ /dev/null @@ -1 +0,0 @@ -60bb9fd94177aff5e19d8cba8da84df157ae3200 diff --git a/build/windows/launch4j-3.9-linux.tgz.sha b/build/windows/launch4j-3.9-linux.tgz.sha new file mode 100644 index 00000000000..9374fd0f6f4 --- /dev/null +++ b/build/windows/launch4j-3.9-linux.tgz.sha @@ -0,0 +1 @@ +9d4c377af0149389da9ad3c3f1394fc5a655f540 diff --git a/build/windows/launch4j-3.9-win32.zip.sha b/build/windows/launch4j-3.9-win32.zip.sha new file mode 100644 index 00000000000..d6a20f2841b --- /dev/null +++ b/build/windows/launch4j-3.9-win32.zip.sha @@ -0,0 +1 @@ +da6645d030137672647f576c8358427bc663282e From fceb1d7edaab08c3c35036a2af572b836c6afad7 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 4 Nov 2016 16:03:17 +0200 Subject: [PATCH 4/6] Windows: added application manifest --- build/build.xml | 2 +- build/windows/launcher/config.xml | 1 + build/windows/launcher/config_debug.xml | 1 + build/windows/launcher/wrapper-manifest.xml | 9 +++++++++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 build/windows/launcher/wrapper-manifest.xml diff --git a/build/build.xml b/build/build.xml index fe5de106c1e..312f432f20a 100644 --- a/build/build.xml +++ b/build/build.xml @@ -1026,7 +1026,7 @@ + includes="application.ico, config.xml, config_debug.xml, arduino.l4j.ini, wrapper-manifest.xml"/> diff --git a/build/windows/launcher/config.xml b/build/windows/launcher/config.xml index 0ab5a8061f5..7168db2e01b 100644 --- a/build/windows/launcher/config.xml +++ b/build/windows/launcher/config.xml @@ -75,4 +75,5 @@ The registry refers to a nonexistent Java Development Kit installation or the runtime is corrupted. An application instance is already running. + wrapper-manifest.xml diff --git a/build/windows/launcher/config_debug.xml b/build/windows/launcher/config_debug.xml index 4fe7397ef6b..1710133024e 100644 --- a/build/windows/launcher/config_debug.xml +++ b/build/windows/launcher/config_debug.xml @@ -75,4 +75,5 @@ The registry refers to a nonexistent Java Development Kit installation or the runtime is corrupted. An application instance is already running. + wrapper-manifest.xml diff --git a/build/windows/launcher/wrapper-manifest.xml b/build/windows/launcher/wrapper-manifest.xml new file mode 100644 index 00000000000..61505254506 --- /dev/null +++ b/build/windows/launcher/wrapper-manifest.xml @@ -0,0 +1,9 @@ + + + + + true + + + + From 39577072186201d5019b63e82ccf08e379fd602f Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 10 Nov 2016 16:14:25 +0200 Subject: [PATCH 5/6] Use Win10 API SetThreadDpiAwarenessContext to force DPI Awareness This commit contains debug messages used for testing purposes. --- .../src/processing/app/windows/Platform.java | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/arduino-core/src/processing/app/windows/Platform.java b/arduino-core/src/processing/app/windows/Platform.java index ec55246bdf6..756113b09ce 100644 --- a/arduino-core/src/processing/app/windows/Platform.java +++ b/arduino-core/src/processing/app/windows/Platform.java @@ -36,6 +36,7 @@ import java.util.List; import com.sun.jna.Native; +import com.sun.jna.Pointer; import com.sun.jna.win32.StdCallLibrary; import com.sun.jna.win32.W32APIOptions; @@ -250,15 +251,54 @@ interface ExtUser32 extends StdCallLibrary, com.sun.jna.platform.win32.User32 { ExtUser32 INSTANCE = (ExtUser32) Native.loadLibrary("user32", ExtUser32.class, W32APIOptions.DEFAULT_OPTIONS); public int GetDpiForSystem(); + + public int SetProcessDpiAwareness(int value); + + public final int DPI_AWARENESS_INVALID = -1; + public final int DPI_AWARENESS_UNAWARE = 0; + public final int DPI_AWARENESS_SYSTEM_AWARE = 1; + public final int DPI_AWARENESS_PER_MONITOR_AWARE = 2; + + public Pointer SetThreadDpiAwarenessContext(Pointer dpiContext); + + public final Pointer DPI_AWARENESS_CONTEXT_UNAWARE = new Pointer(-1); + public final Pointer DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = new Pointer(-2); + public final Pointer DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = new Pointer(-3); } + private static int detected = detectSystemDPI(); + @Override public int getSystemDPI() { + if (detected == -1) + return super.getSystemDPI(); + return detected; + } + + public static int detectSystemDPI() { + try { + int res = ExtUser32.INSTANCE.SetProcessDpiAwareness(ExtUser32.DPI_AWARENESS_SYSTEM_AWARE); + System.out.println("SetProcessDpiAwareness returned " + res); + } catch (Throwable e) { + System.out.println("SetProcessDpiAwareness failed!"); + // Ignore error + } + try { + System.out.println("before any SetThreadDpiAwarenessContext(...) -> dpi " + ExtUser32.INSTANCE.GetDpiForSystem()); + ExtUser32.INSTANCE.SetThreadDpiAwarenessContext(ExtUser32.DPI_AWARENESS_CONTEXT_UNAWARE); + System.out.println("SetThreadDpiAwarenessContext(UNAWARE) -> dpi " + ExtUser32.INSTANCE.GetDpiForSystem()); + ExtUser32.INSTANCE.SetThreadDpiAwarenessContext(ExtUser32.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE); + System.out.println("SetThreadDpiAwarenessContext(SYSTEM) -> dpi " + ExtUser32.INSTANCE.GetDpiForSystem()); + } catch (Throwable e) { + System.out.println("SetThreadDpiAwarenessContext failed!"); + // Ignore error (call valid only on Windows 10) + } try { return ExtUser32.INSTANCE.GetDpiForSystem(); } catch (Throwable e) { // DPI detection failed, fall back with default - return super.getSystemDPI(); + System.out.println("DPI detection failed, fallback to 96 dpi"); + return -1; } } } From 1f1092fb3ad240ca50652e0141c7816bde3a77cf Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 21 Nov 2016 11:50:24 +0100 Subject: [PATCH 6/6] Removed debug messages in 39577072 --- arduino-core/src/processing/app/windows/Platform.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/arduino-core/src/processing/app/windows/Platform.java b/arduino-core/src/processing/app/windows/Platform.java index 756113b09ce..349415b2bb4 100644 --- a/arduino-core/src/processing/app/windows/Platform.java +++ b/arduino-core/src/processing/app/windows/Platform.java @@ -277,20 +277,13 @@ public int getSystemDPI() { public static int detectSystemDPI() { try { - int res = ExtUser32.INSTANCE.SetProcessDpiAwareness(ExtUser32.DPI_AWARENESS_SYSTEM_AWARE); - System.out.println("SetProcessDpiAwareness returned " + res); + ExtUser32.INSTANCE.SetProcessDpiAwareness(ExtUser32.DPI_AWARENESS_SYSTEM_AWARE); } catch (Throwable e) { - System.out.println("SetProcessDpiAwareness failed!"); // Ignore error } try { - System.out.println("before any SetThreadDpiAwarenessContext(...) -> dpi " + ExtUser32.INSTANCE.GetDpiForSystem()); - ExtUser32.INSTANCE.SetThreadDpiAwarenessContext(ExtUser32.DPI_AWARENESS_CONTEXT_UNAWARE); - System.out.println("SetThreadDpiAwarenessContext(UNAWARE) -> dpi " + ExtUser32.INSTANCE.GetDpiForSystem()); ExtUser32.INSTANCE.SetThreadDpiAwarenessContext(ExtUser32.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE); - System.out.println("SetThreadDpiAwarenessContext(SYSTEM) -> dpi " + ExtUser32.INSTANCE.GetDpiForSystem()); } catch (Throwable e) { - System.out.println("SetThreadDpiAwarenessContext failed!"); // Ignore error (call valid only on Windows 10) } try {