Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void createCOMInterfaces() {
public long method2(long[] args) {return Release();}
@Override
public long method3(long[] args) {
return Win32DPIUtils.runWithProperDPIAwareness(() -> {
return Win32DPIUtils.runWithProperDPIAwareness(getDisplay(), () -> {
if (args.length == 5) {
return DragEnter(args[0], (int)args[1], (int)args[2], (int)args[3], args[4]);
} else {
Expand All @@ -252,7 +252,7 @@ public long method3(long[] args) {
}
@Override
public long method4(long[] args) {
return Win32DPIUtils.runWithProperDPIAwareness(() -> {
return Win32DPIUtils.runWithProperDPIAwareness(getDisplay(), () -> {
if (args.length == 4) {
return DragOver((int)args[0], (int)args[1], (int)args[2], args[3]);
} else {
Expand All @@ -264,7 +264,7 @@ public long method4(long[] args) {
public long method5(long[] args) {return DragLeave();}
@Override
public long method6(long[] args) {
return Win32DPIUtils.runWithProperDPIAwareness(() -> {
return Win32DPIUtils.runWithProperDPIAwareness(getDisplay(), () -> {
if (args.length == 5) {
return Drop(args[0], (int)args[1], (int)args[2], (int)args[3], args[4]);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.win32.*;
import org.eclipse.swt.internal.win32.version.*;
import org.eclipse.swt.widgets.*;

/**
* This class is used in the win32 implementation only to provide
Expand Down Expand Up @@ -68,8 +69,11 @@ public static boolean setDPIAwareness(int desiredDpiAwareness) {
return true;
}

public static <T> T runWithProperDPIAwareness(Supplier<T> operation) {
// refreshing is only necessary, when monitor specific scaling is active
public static <T> T runWithProperDPIAwareness(Display display, Supplier<T> operation) {
// only with monitor-specific scaling enabled, the main thread's DPI awareness may be adapted
if (!display.isRescalingAtRuntime()) {
return operation.get();
}
long previousDPIAwareness = OS.GetThreadDpiAwarenessContext();
try {
if (!setDPIAwareness(OS.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ public Widget findWidget (Widget widget, long id) {

long foregroundIdleProc (long code, long wParam, long lParam) {
if (code >= 0) {
Runnable processMessages = () -> {
Supplier<Boolean> processMessages = () -> {
sendPostExternalEventDispatchEvent ();
if (runMessagesInIdle) {
if (runMessagesInMessageProc) {
Expand All @@ -1487,6 +1487,7 @@ long foregroundIdleProc (long code, long wParam, long lParam) {
int flags = OS.PM_NOREMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT;
if (!OS.PeekMessage (msg, 0, 0, 0, flags)) wakeThread ();
sendPreExternalEventDispatchEvent ();
return true;
};
if (!synchronizer.isMessagesEmpty()) {
// Windows hooks will inherit the thread DPI awareness from
Expand All @@ -1495,7 +1496,7 @@ long foregroundIdleProc (long code, long wParam, long lParam) {
// This requires to reset the thread DPi awareness to make
// sure, all UI updates caused by this will be executed
// with the correct DPI awareness
runWithProperDPIAwareness(processMessages);
Win32DPIUtils.runWithProperDPIAwareness(this, processMessages);
}
}
return OS.CallNextHookEx (idleHook, (int)code, wParam, lParam);
Expand Down Expand Up @@ -3478,10 +3479,11 @@ long msgFilterProc (long code, long wParam, long lParam) {
// This requires to reset the thread DPi awareness to make
// sure, all UI updates caused by this will be executed
// with the correct DPI awareness
runWithProperDPIAwareness(() -> {
Win32DPIUtils.runWithProperDPIAwareness(this, () -> {
if (!OS.PeekMessage (msg, 0, 0, 0, flags)) {
if (runAsyncMessages (false)) wakeThread ();
}
return true;
});
}
break;
Expand Down Expand Up @@ -5414,14 +5416,4 @@ private boolean setMonitorSpecificScaling(boolean activate) {
return false;
}

private void runWithProperDPIAwareness(Runnable operation) {
if (isRescalingAtRuntime()) {
Win32DPIUtils.runWithProperDPIAwareness(() -> {
operation.run();
return true;
});
} else {
operation.run();
}
}
}
Loading