Skip to content

Commit 5058d4d

Browse files
committed
Windows: Autodetection of display resolution
1 parent 89ef44e commit 5058d4d

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

@@ -228,4 +231,22 @@ public void fixSettingsLocation() throws Exception {
228231

229232
Files.move(oldSettingsFolder, settingsFolder.toPath());
230233
}
234+
235+
// Need to extend com.sun.jna.platform.win32.User32 to access
236+
// Win32 function GetDpiForSystem()
237+
interface ExtUser32 extends StdCallLibrary, com.sun.jna.platform.win32.User32 {
238+
ExtUser32 INSTANCE = (ExtUser32) Native.loadLibrary("user32", ExtUser32.class, W32APIOptions.DEFAULT_OPTIONS);
239+
240+
public int GetDpiForSystem();
241+
}
242+
243+
@Override
244+
public int getSystemDPI() {
245+
try {
246+
return ExtUser32.INSTANCE.GetDpiForSystem();
247+
} catch (Throwable e) {
248+
// DPI detection failed, fall back with default
249+
return super.getSystemDPI();
250+
}
251+
}
231252
}

0 commit comments

Comments
 (0)