Skip to content

Commit 27d1b8d

Browse files
committed
Merge branch 'windows-dpi-awareness'
2 parents 5b690b9 + 1f1092f commit 27d1b8d

File tree

11 files changed

+78
-8
lines changed

11 files changed

+78
-8
lines changed

app/src/processing/app/Theme.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static public int getScale() {
122122
return scale;
123123
} catch (NumberFormatException ignore) {
124124
}
125-
return 100;
125+
return BaseNoGui.getPlatform().getSystemDPI() * 100 / 96;
126126
}
127127

128128
static public int scale(int size) {

arduino-core/src/processing/app/Platform.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,9 @@ public void chmod(File file, int mode) throws IOException, InterruptedException
333333
public void fixSettingsLocation() throws Exception {
334334
//noop
335335
}
336+
337+
public int getSystemDPI() {
338+
return 96;
339+
}
340+
336341
}

arduino-core/src/processing/app/windows/Platform.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
import java.util.LinkedList;
3636
import java.util.List;
3737

38+
import com.sun.jna.Native;
39+
import com.sun.jna.Pointer;
40+
import com.sun.jna.win32.StdCallLibrary;
41+
import com.sun.jna.win32.W32APIOptions;
3842

3943
public class Platform extends processing.app.Platform {
4044

@@ -240,4 +244,54 @@ public void fixSettingsLocation() throws Exception {
240244

241245
Files.move(oldSettingsFolder, settingsFolder.toPath());
242246
}
247+
248+
// Need to extend com.sun.jna.platform.win32.User32 to access
249+
// Win32 function GetDpiForSystem()
250+
interface ExtUser32 extends StdCallLibrary, com.sun.jna.platform.win32.User32 {
251+
ExtUser32 INSTANCE = (ExtUser32) Native.loadLibrary("user32", ExtUser32.class, W32APIOptions.DEFAULT_OPTIONS);
252+
253+
public int GetDpiForSystem();
254+
255+
public int SetProcessDpiAwareness(int value);
256+
257+
public final int DPI_AWARENESS_INVALID = -1;
258+
public final int DPI_AWARENESS_UNAWARE = 0;
259+
public final int DPI_AWARENESS_SYSTEM_AWARE = 1;
260+
public final int DPI_AWARENESS_PER_MONITOR_AWARE = 2;
261+
262+
public Pointer SetThreadDpiAwarenessContext(Pointer dpiContext);
263+
264+
public final Pointer DPI_AWARENESS_CONTEXT_UNAWARE = new Pointer(-1);
265+
public final Pointer DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = new Pointer(-2);
266+
public final Pointer DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = new Pointer(-3);
267+
}
268+
269+
private static int detected = detectSystemDPI();
270+
271+
@Override
272+
public int getSystemDPI() {
273+
if (detected == -1)
274+
return super.getSystemDPI();
275+
return detected;
276+
}
277+
278+
public static int detectSystemDPI() {
279+
try {
280+
ExtUser32.INSTANCE.SetProcessDpiAwareness(ExtUser32.DPI_AWARENESS_SYSTEM_AWARE);
281+
} catch (Throwable e) {
282+
// Ignore error
283+
}
284+
try {
285+
ExtUser32.INSTANCE.SetThreadDpiAwarenessContext(ExtUser32.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE);
286+
} catch (Throwable e) {
287+
// Ignore error (call valid only on Windows 10)
288+
}
289+
try {
290+
return ExtUser32.INSTANCE.GetDpiForSystem();
291+
} catch (Throwable e) {
292+
// DPI detection failed, fall back with default
293+
System.out.println("DPI detection failed, fallback to 96 dpi");
294+
return -1;
295+
}
296+
}
243297
}

build/build.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -926,17 +926,17 @@
926926

927927
<target name="download-launch4j-windows">
928928
<antcall target="unzip-with-ant-task">
929-
<param name="archive_file" value="windows/launch4j-3.8-win32.zip"/>
930-
<param name="archive_url" value="http://downloads.sourceforge.net/project/launch4j/launch4j-3/3.8/launch4j-3.8-win32.zip"/>
929+
<param name="archive_file" value="windows/launch4j-3.9-win32.zip"/>
930+
<param name="archive_url" value="http://downloads.sourceforge.net/project/launch4j/launch4j-3/3.9/launch4j-3.9-win32.zip"/>
931931
<param name="final_folder" value="windows/launcher/launch4j"/>
932932
<param name="dest_folder" value="windows/launcher/"/>
933933
</antcall>
934934
</target>
935935

936936
<target name="download-launch4j-linux">
937937
<antcall target="untar">
938-
<param name="archive_file" value="windows/launch4j-3.8-linux.tgz"/>
939-
<param name="archive_url" value="http://downloads.sourceforge.net/project/launch4j/launch4j-3/3.8/launch4j-3.8-linux.tgz"/>
938+
<param name="archive_file" value="windows/launch4j-3.9-linux.tgz"/>
939+
<param name="archive_url" value="http://downloads.sourceforge.net/project/launch4j/launch4j-3/3.9/launch4j-3.9-linux.tgz"/>
940940
<param name="final_folder" value="windows/launcher/launch4j"/>
941941
<param name="dest_folder" value="windows/launcher/"/>
942942
</antcall>
@@ -1026,7 +1026,7 @@
10261026

10271027
<copy todir="windows/work">
10281028
<fileset dir="windows/launcher"
1029-
includes="application.ico, config.xml, config_debug.xml, arduino.l4j.ini"/>
1029+
includes="application.ico, config.xml, config_debug.xml, arduino.l4j.ini, wrapper-manifest.xml"/>
10301030
</copy>
10311031
<launch4j configFile="windows/work/config.xml" fileVersion="${revision}.0" txtFileVersion="${revision}" productVersion="${revision}.0" txtProductVersion="${revision}"/>
10321032
<launch4j configFile="windows/work/config_debug.xml" fileVersion="${revision}.0" txtFileVersion="${revision}" productVersion="${revision}.0" txtProductVersion="${revision}"/>

build/windows/launch4j-3.8-linux.tgz.sha

Lines changed: 0 additions & 1 deletion
This file was deleted.

build/windows/launch4j-3.8-win32.zip.sha

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9d4c377af0149389da9ad3c3f1394fc5a655f540
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
da6645d030137672647f576c8358427bc663282e

build/windows/launcher/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@
7575
<launcherErr>The registry refers to a nonexistent Java Development Kit installation or the runtime is corrupted.</launcherErr>
7676
<instanceAlreadyExistsMsg>An application instance is already running.</instanceAlreadyExistsMsg>
7777
</messages>
78+
<manifest>wrapper-manifest.xml</manifest>
7879
</launch4jConfig>

build/windows/launcher/config_debug.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@
7575
<launcherErr>The registry refers to a nonexistent Java Development Kit installation or the runtime is corrupted.</launcherErr>
7676
<instanceAlreadyExistsMsg>An application instance is already running.</instanceAlreadyExistsMsg>
7777
</messages>
78+
<manifest>wrapper-manifest.xml</manifest>
7879
</launch4jConfig>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
2+
3+
<asmv3:application>
4+
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
5+
<dpiAware>true</dpiAware>
6+
</asmv3:windowsSettings>
7+
</asmv3:application>
8+
9+
</assembly>

0 commit comments

Comments
 (0)