Skip to content

Commit 03225e7

Browse files
committed
Windows: Autodetection of display resolution
1 parent d63162b commit 03225e7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

+21
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
import java.util.LinkedList;
3636
import java.util.List;
3737

38+
import com.sun.jna.Native;
39+
import com.sun.jna.win32.StdCallLibrary;
40+
import com.sun.jna.win32.W32APIOptions;
3841

3942
public class Platform extends processing.app.Platform {
4043

@@ -240,4 +243,22 @@ public void fixSettingsLocation() throws Exception {
240243

241244
Files.move(oldSettingsFolder, settingsFolder.toPath());
242245
}
246+
247+
// Need to extend com.sun.jna.platform.win32.User32 to access
248+
// Win32 function GetDpiForSystem()
249+
interface ExtUser32 extends StdCallLibrary, com.sun.jna.platform.win32.User32 {
250+
ExtUser32 INSTANCE = (ExtUser32) Native.loadLibrary("user32", ExtUser32.class, W32APIOptions.DEFAULT_OPTIONS);
251+
252+
public int GetDpiForSystem();
253+
}
254+
255+
@Override
256+
public int getSystemDPI() {
257+
try {
258+
return ExtUser32.INSTANCE.GetDpiForSystem();
259+
} catch (Throwable e) {
260+
// DPI detection failed, fall back with default
261+
return super.getSystemDPI();
262+
}
263+
}
243264
}

0 commit comments

Comments
 (0)