mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-28 09:24:14 +01:00
Use Win10 API SetThreadDpiAwarenessContext to force DPI Awareness
This commit contains debug messages used for testing purposes.
This commit is contained in:
parent
fceb1d7eda
commit
3957707218
@ -36,6 +36,7 @@ import java.util.LinkedList;
|
||||
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 @@ public class Platform extends processing.app.Platform {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user