Skip to content

Commit

Permalink
Add win32 methods for changing and retrieving DPI awareness
Browse files Browse the repository at this point in the history
This adds the win32 API methods GetThreadDpiAwarenessContext and
SetThreadDpiAwarenessContext to be able to manually set and retrieve the
DPI awareness mode for a thread, including the PerMonitorV2 mode.

Contributes to
eclipse-platform#62
Contributes to
eclipse-platform#131
  • Loading branch information
HeikoKlare authored and lathapatil committed Nov 7, 2024
1 parent f02adc4 commit 12ff1bd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
24 changes: 24 additions & 0 deletions bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -3368,6 +3368,18 @@ JNIEXPORT jint JNICALL OS_NATIVE(GetThemeTextExtent)
}
#endif

#ifndef NO_GetThreadDpiAwarenessContext
JNIEXPORT jlong JNICALL OS_NATIVE(GetThreadDpiAwarenessContext)
(JNIEnv *env, jclass that)
{
jlong rc = 0;
OS_NATIVE_ENTER(env, that, GetThreadDpiAwarenessContext_FUNC);
rc = (jlong)GetThreadDpiAwarenessContext();
OS_NATIVE_EXIT(env, that, GetThreadDpiAwarenessContext_FUNC);
return rc;
}
#endif

#ifndef NO_GetTouchInputInfo
JNIEXPORT jboolean JNICALL OS_NATIVE(GetTouchInputInfo)
(JNIEnv *env, jclass that, jlong arg0, jint arg1, jlong arg2, jint arg3)
Expand Down Expand Up @@ -8847,6 +8859,18 @@ JNIEXPORT jint JNICALL OS_NATIVE(SetTextColor)
}
#endif

#ifndef NO_SetThreadDpiAwarenessContext
JNIEXPORT jlong JNICALL OS_NATIVE(SetThreadDpiAwarenessContext)
(JNIEnv *env, jclass that, jlong arg0)
{
jlong rc = 0;
OS_NATIVE_ENTER(env, that, SetThreadDpiAwarenessContext_FUNC);
rc = (jlong)SetThreadDpiAwarenessContext((DPI_AWARENESS_CONTEXT)arg0);
OS_NATIVE_EXIT(env, that, SetThreadDpiAwarenessContext_FUNC);
return rc;
}
#endif

#ifndef NO_SetTimer
JNIEXPORT jlong JNICALL OS_NATIVE(SetTimer)
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jint arg2, jlong arg3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ typedef enum {
GetTextMetrics_FUNC,
GetThemePartSize_FUNC,
GetThemeTextExtent_FUNC,
GetThreadDpiAwarenessContext_FUNC,
GetTouchInputInfo_FUNC,
GetUpdateRect_FUNC,
GetUpdateRgn_FUNC,
Expand Down Expand Up @@ -660,6 +661,7 @@ typedef enum {
SetScrollInfo_FUNC,
SetStretchBltMode_FUNC,
SetTextColor_FUNC,
SetThreadDpiAwarenessContext_FUNC,
SetTimer_FUNC,
SetWindowLong_FUNC,
SetWindowLongPtr_FUNC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ public class OS extends C {
public static final short DMDUP_SIMPLEX = 1;
public static final short DMDUP_VERTICAL = 2;
public static final short DMDUP_HORIZONTAL = 3;
public static final int DPI_AWARENESS_CONTEXT_UNAWARE = 16;
public static final int DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = 17;
public static final int DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = 18;
public static final int DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = 34;
public static final int DSTINVERT = 0x550009;
public static final int DT_BOTTOM = 0x8;
public static final int DT_CALCRECT = 0x400;
Expand Down Expand Up @@ -4345,6 +4349,9 @@ public static int HRESULT_FROM_WIN32(int x) {
/** @param hdc cast=(HDC) */
public static final native int SetPolyFillMode (long hdc, int iPolyFillMode);
public static final native boolean SetProcessDPIAware ();
/** @param dpiContext cast=(DPI_AWARENESS_CONTEXT) */
public static final native long SetThreadDpiAwarenessContext (long dpiContext);
public static final native long GetThreadDpiAwarenessContext ();
/** @method flags=no_gen */
public static final native int SetPreferredAppMode(int mode);
/** @param lprc flags=no_in */
Expand Down

0 comments on commit 12ff1bd

Please sign in to comment.