Skip to content

Commit fb22c8e

Browse files
SyntevoAlexniraj-modi
authored andcommitted
Bug 563329 - [Dark theme] Ability to style the window title bar
While at it, also fix one instance that suffered from version lie when compatibility manifest is not present. Change-Id: I0cc01392655f30619f6a7c88ee28ae9589fe04e9 Signed-off-by: Alexandr Miloslavskiy <[email protected]> Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/186458 Tested-by: Platform Bot <[email protected]> Reviewed-by: Niraj Modi <[email protected]>
1 parent 465e26a commit fb22c8e

File tree

11 files changed

+248
-5
lines changed

11 files changed

+248
-5
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/make_win32.mak

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ SWT_VERSION = $(maj_ver)$(min_ver)r$(rev)
2626
SWT_LIB = $(SWT_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).dll
2727
SWT_LIBS = comctl32.lib shell32.lib imm32.lib oleacc.lib usp10.lib \
2828
wininet.lib Shlwapi.lib Uxtheme.lib Propsys.lib Urlmon.lib \
29-
Msimg32.lib
29+
Msimg32.lib Dwmapi.lib
3030
SWT_OBJS = swt.obj callback.obj c.obj c_stats.obj \
3131
os.obj os_structs.obj os_custom.obj os_stats.obj \
3232
com_structs.obj com.obj com_stats.obj com_custom.obj
@@ -53,7 +53,7 @@ WGL_OBJS = wgl.obj wgl_structs.obj wgl_stats.obj
5353
CFLAGS = -O1 -DNDEBUG -DUNICODE -D_UNICODE /c $(cflags) $(cvarsmt) $(CFLAGS) \
5454
-DSWT_VERSION=$(maj_ver)$(min_ver) -DSWT_REVISION=$(rev) $(NATIVE_STATS) -DUSE_ASSEMBLER \
5555
/I"$(SWT_JAVA_HOME)\include" /I"$(SWT_JAVA_HOME)\include\win32" /I.
56-
56+
5757
RCFLAGS = $(rcflags) $(rcvars) $(RCFLAGS) -DSWT_FILE_VERSION=\"$(maj_ver).$(min_ver).$(rev).0\" -DSWT_COMMA_VERSION=$(comma_ver)
5858
ldebug = /RELEASE /INCREMENTAL:NO /NOLOGO
5959
dlllflags = -dll

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,22 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(DuplicateHandle)
15081508
}
15091509
#endif
15101510

1511+
#ifndef NO_DwmSetWindowAttribute
1512+
JNIEXPORT jboolean JNICALL OS_NATIVE(DwmSetWindowAttribute)
1513+
(JNIEnv *env, jclass that, jlong arg0, jint arg1, jintArray arg2, jint arg3)
1514+
{
1515+
jint *lparg2=NULL;
1516+
jboolean rc = 0;
1517+
OS_NATIVE_ENTER(env, that, DwmSetWindowAttribute_FUNC);
1518+
if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail;
1519+
rc = (jboolean)DwmSetWindowAttribute((HDC)arg0, arg1, lparg2, arg3);
1520+
fail:
1521+
if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0);
1522+
OS_NATIVE_EXIT(env, that, DwmSetWindowAttribute_FUNC);
1523+
return rc;
1524+
}
1525+
#endif
1526+
15111527
#ifndef NO_EMREXTCREATEFONTINDIRECTW_1sizeof
15121528
JNIEXPORT jint JNICALL OS_NATIVE(EMREXTCREATEFONTINDIRECTW_1sizeof)
15131529
(JNIEnv *env, jclass that)
@@ -6399,6 +6415,18 @@ JNIEXPORT void JNICALL OS_NATIVE(NotifyWinEvent)
63996415
}
64006416
#endif
64016417

6418+
#ifndef NO_OSVERSIONINFOEX_1sizeof
6419+
JNIEXPORT jint JNICALL OS_NATIVE(OSVERSIONINFOEX_1sizeof)
6420+
(JNIEnv *env, jclass that)
6421+
{
6422+
jint rc = 0;
6423+
OS_NATIVE_ENTER(env, that, OSVERSIONINFOEX_1sizeof_FUNC);
6424+
rc = (jint)OSVERSIONINFOEX_sizeof();
6425+
OS_NATIVE_EXIT(env, that, OSVERSIONINFOEX_1sizeof_FUNC);
6426+
return rc;
6427+
}
6428+
#endif
6429+
64026430
#ifndef NO_OUTLINETEXTMETRIC_1sizeof
64036431
JNIEXPORT jint JNICALL OS_NATIVE(OUTLINETEXTMETRIC_1sizeof)
64046432
(JNIEnv *env, jclass that)
@@ -7154,6 +7182,30 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(RoundRect)
71547182
}
71557183
#endif
71567184

7185+
#ifndef NO_RtlGetVersion
7186+
JNIEXPORT jint JNICALL OS_NATIVE(RtlGetVersion)
7187+
(JNIEnv *env, jclass that, jobject arg0)
7188+
{
7189+
OSVERSIONINFOEX _arg0, *lparg0=NULL;
7190+
jint rc = 0;
7191+
OS_NATIVE_ENTER(env, that, RtlGetVersion_FUNC);
7192+
if (arg0) if ((lparg0 = getOSVERSIONINFOEXFields(env, arg0, &_arg0)) == NULL) goto fail;
7193+
/*
7194+
rc = (jint)RtlGetVersion(lparg0);
7195+
*/
7196+
{
7197+
OS_LOAD_FUNCTION(fp, RtlGetVersion)
7198+
if (fp) {
7199+
rc = (jint)((jint (CALLING_CONVENTION*)(OSVERSIONINFOEX *))fp)(lparg0);
7200+
}
7201+
}
7202+
fail:
7203+
if (arg0 && lparg0) setOSVERSIONINFOEXFields(env, arg0, lparg0);
7204+
OS_NATIVE_EXIT(env, that, RtlGetVersion_FUNC);
7205+
return rc;
7206+
}
7207+
#endif
7208+
71577209
#ifndef NO_SAFEARRAYBOUND_1sizeof
71587210
JNIEXPORT jint JNICALL OS_NATIVE(SAFEARRAYBOUND_1sizeof)
71597211
(JNIEnv *env, jclass that)

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_custom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919

2020
/* Libraries for dynamic loaded functions */
2121
#define GetDpiForMonitor_LIB "shcore.dll"
22+
#define RtlGetVersion_LIB "ntdll.dll"

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ char * OS_nativeFunctionNames[] = {
131131
"DrawThemeBackground",
132132
"DrawThemeText",
133133
"DuplicateHandle",
134+
"DwmSetWindowAttribute",
134135
"EMREXTCREATEFONTINDIRECTW_1sizeof",
135136
"EMR_1sizeof",
136137
"EXTLOGFONTW_1sizeof",
@@ -490,6 +491,7 @@ char * OS_nativeFunctionNames[] = {
490491
"NONCLIENTMETRICS_1sizeof",
491492
"NOTIFYICONDATA_1V2_1SIZE",
492493
"NotifyWinEvent",
494+
"OSVERSIONINFOEX_1sizeof",
493495
"OUTLINETEXTMETRIC_1sizeof",
494496
"OffsetRect",
495497
"OffsetRgn",
@@ -542,6 +544,7 @@ char * OS_nativeFunctionNames[] = {
542544
"ReplyMessage",
543545
"RestoreDC",
544546
"RoundRect",
547+
"RtlGetVersion",
545548
"SAFEARRAYBOUND_1sizeof",
546549
"SAFEARRAY_1sizeof",
547550
"SCRIPT_1ANALYSIS_1sizeof",

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ typedef enum {
141141
DrawThemeBackground_FUNC,
142142
DrawThemeText_FUNC,
143143
DuplicateHandle_FUNC,
144+
DwmSetWindowAttribute_FUNC,
144145
EMREXTCREATEFONTINDIRECTW_1sizeof_FUNC,
145146
EMR_1sizeof_FUNC,
146147
EXTLOGFONTW_1sizeof_FUNC,
@@ -500,6 +501,7 @@ typedef enum {
500501
NONCLIENTMETRICS_1sizeof_FUNC,
501502
NOTIFYICONDATA_1V2_1SIZE_FUNC,
502503
NotifyWinEvent_FUNC,
504+
OSVERSIONINFOEX_1sizeof_FUNC,
503505
OUTLINETEXTMETRIC_1sizeof_FUNC,
504506
OffsetRect_FUNC,
505507
OffsetRgn_FUNC,
@@ -552,6 +554,7 @@ typedef enum {
552554
ReplyMessage_FUNC,
553555
RestoreDC_FUNC,
554556
RoundRect_FUNC,
557+
RtlGetVersion_FUNC,
555558
SAFEARRAYBOUND_1sizeof_FUNC,
556559
SAFEARRAY_1sizeof_FUNC,
557560
SCRIPT_1ANALYSIS_1sizeof_FUNC,

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_structs.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,6 +4213,73 @@ void setNOTIFYICONDATAFields(JNIEnv *env, jobject lpObject, NOTIFYICONDATA *lpSt
42134213
}
42144214
#endif
42154215

4216+
#ifndef NO_OSVERSIONINFOEX
4217+
typedef struct OSVERSIONINFOEX_FID_CACHE {
4218+
int cached;
4219+
jclass clazz;
4220+
jfieldID dwOSVersionInfoSize, dwMajorVersion, dwMinorVersion, dwBuildNumber, dwPlatformId, szCSDVersion, wServicePackMajor, wServicePackMinor, wSuiteMask, wProductType, wReserved;
4221+
} OSVERSIONINFOEX_FID_CACHE;
4222+
4223+
OSVERSIONINFOEX_FID_CACHE OSVERSIONINFOEXFc;
4224+
4225+
void cacheOSVERSIONINFOEXFields(JNIEnv *env, jobject lpObject)
4226+
{
4227+
if (OSVERSIONINFOEXFc.cached) return;
4228+
OSVERSIONINFOEXFc.clazz = (*env)->GetObjectClass(env, lpObject);
4229+
OSVERSIONINFOEXFc.dwOSVersionInfoSize = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "dwOSVersionInfoSize", "I");
4230+
OSVERSIONINFOEXFc.dwMajorVersion = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "dwMajorVersion", "I");
4231+
OSVERSIONINFOEXFc.dwMinorVersion = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "dwMinorVersion", "I");
4232+
OSVERSIONINFOEXFc.dwBuildNumber = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "dwBuildNumber", "I");
4233+
OSVERSIONINFOEXFc.dwPlatformId = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "dwPlatformId", "I");
4234+
OSVERSIONINFOEXFc.szCSDVersion = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "szCSDVersion", "[C");
4235+
OSVERSIONINFOEXFc.wServicePackMajor = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "wServicePackMajor", "I");
4236+
OSVERSIONINFOEXFc.wServicePackMinor = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "wServicePackMinor", "I");
4237+
OSVERSIONINFOEXFc.wSuiteMask = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "wSuiteMask", "I");
4238+
OSVERSIONINFOEXFc.wProductType = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "wProductType", "I");
4239+
OSVERSIONINFOEXFc.wReserved = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "wReserved", "I");
4240+
OSVERSIONINFOEXFc.cached = 1;
4241+
}
4242+
4243+
OSVERSIONINFOEX *getOSVERSIONINFOEXFields(JNIEnv *env, jobject lpObject, OSVERSIONINFOEX *lpStruct)
4244+
{
4245+
if (!OSVERSIONINFOEXFc.cached) cacheOSVERSIONINFOEXFields(env, lpObject);
4246+
lpStruct->dwOSVersionInfoSize = (*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.dwOSVersionInfoSize);
4247+
lpStruct->dwMajorVersion = (*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.dwMajorVersion);
4248+
lpStruct->dwMinorVersion = (*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.dwMinorVersion);
4249+
lpStruct->dwBuildNumber = (*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.dwBuildNumber);
4250+
lpStruct->dwPlatformId = (*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.dwPlatformId);
4251+
{
4252+
jcharArray lpObject1 = (jcharArray)(*env)->GetObjectField(env, lpObject, OSVERSIONINFOEXFc.szCSDVersion);
4253+
(*env)->GetCharArrayRegion(env, lpObject1, 0, sizeof(lpStruct->szCSDVersion) / sizeof(jchar), (jchar *)lpStruct->szCSDVersion);
4254+
}
4255+
lpStruct->wServicePackMajor = (*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.wServicePackMajor);
4256+
lpStruct->wServicePackMinor = (*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.wServicePackMinor);
4257+
lpStruct->wSuiteMask = (*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.wSuiteMask);
4258+
lpStruct->wProductType = (*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.wProductType);
4259+
lpStruct->wReserved = (*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.wReserved);
4260+
return lpStruct;
4261+
}
4262+
4263+
void setOSVERSIONINFOEXFields(JNIEnv *env, jobject lpObject, OSVERSIONINFOEX *lpStruct)
4264+
{
4265+
if (!OSVERSIONINFOEXFc.cached) cacheOSVERSIONINFOEXFields(env, lpObject);
4266+
(*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.dwOSVersionInfoSize, (jint)lpStruct->dwOSVersionInfoSize);
4267+
(*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.dwMajorVersion, (jint)lpStruct->dwMajorVersion);
4268+
(*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.dwMinorVersion, (jint)lpStruct->dwMinorVersion);
4269+
(*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.dwBuildNumber, (jint)lpStruct->dwBuildNumber);
4270+
(*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.dwPlatformId, (jint)lpStruct->dwPlatformId);
4271+
{
4272+
jcharArray lpObject1 = (jcharArray)(*env)->GetObjectField(env, lpObject, OSVERSIONINFOEXFc.szCSDVersion);
4273+
(*env)->SetCharArrayRegion(env, lpObject1, 0, sizeof(lpStruct->szCSDVersion) / sizeof(jchar), (jchar *)lpStruct->szCSDVersion);
4274+
}
4275+
(*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.wServicePackMajor, (jint)lpStruct->wServicePackMajor);
4276+
(*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.wServicePackMinor, (jint)lpStruct->wServicePackMinor);
4277+
(*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.wSuiteMask, (jint)lpStruct->wSuiteMask);
4278+
(*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.wProductType, (jint)lpStruct->wProductType);
4279+
(*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.wReserved, (jint)lpStruct->wReserved);
4280+
}
4281+
#endif
4282+
42164283
#ifndef NO_OUTLINETEXTMETRIC
42174284
typedef struct OUTLINETEXTMETRIC_FID_CACHE {
42184285
int cached;

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_structs.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2020 IBM Corporation and others.
2+
* Copyright (c) 2000, 2021 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -965,6 +965,18 @@ void setNOTIFYICONDATAFields(JNIEnv *env, jobject lpObject, NOTIFYICONDATA *lpSt
965965
#define NOTIFYICONDATA_sizeof() 0
966966
#endif
967967

968+
#ifndef NO_OSVERSIONINFOEX
969+
void cacheOSVERSIONINFOEXFields(JNIEnv *env, jobject lpObject);
970+
OSVERSIONINFOEX *getOSVERSIONINFOEXFields(JNIEnv *env, jobject lpObject, OSVERSIONINFOEX *lpStruct);
971+
void setOSVERSIONINFOEXFields(JNIEnv *env, jobject lpObject, OSVERSIONINFOEX *lpStruct);
972+
#define OSVERSIONINFOEX_sizeof() sizeof(OSVERSIONINFOEX)
973+
#else
974+
#define cacheOSVERSIONINFOEXFields(a,b)
975+
#define getOSVERSIONINFOEXFields(a,b,c) NULL
976+
#define setOSVERSIONINFOEXFields(a,b,c)
977+
#define OSVERSIONINFOEX_sizeof() 0
978+
#endif
979+
968980
#ifndef NO_OUTLINETEXTMETRIC
969981
void cacheOUTLINETEXTMETRICFields(JNIEnv *env, jobject lpObject);
970982
OUTLINETEXTMETRIC *getOUTLINETEXTMETRICFields(JNIEnv *env, jobject lpObject, OUTLINETEXTMETRIC *lpStruct);

bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,27 @@ public class OS extends C {
2828
* SWT Windows flags
2929
*/
3030
public static final boolean IsDBLocale;
31+
/**
32+
* WARNING: This value can't be trusted since Win10. If the launcher's exe
33+
* doesn't have compatibility GUID in its manifest:<br>
34+
* &lt;supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/&gt;<br>
35+
* then '6.2.9200' will be returned (version number for Win8).
36+
* JDK11 has the compatibility GUID, but Eclipse's launcher doesn't!
37+
* This may cause different behavior in debugger and in released SWT.
38+
*/
3139
public static final int WIN32_VERSION;
40+
/**
41+
* Always reports the correct build number, regardless of manifest and
42+
* compatibility GUIDs. Note that build number alone is sufficient to
43+
* identify Windows version.
44+
*/
45+
public static final int WIN32_BUILD;
46+
/**
47+
* Values taken from https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions
48+
*/
49+
public static final int WIN32_BUILD_WIN10_1809 = 17763; // "Windows 10 October 2018 Update"
50+
public static final int WIN32_BUILD_WIN10_2004 = 19041; // "Windows 10 May 2020 Update"
51+
public static final int WIN32_BUILD_WIN11_21H2 = 22000; // Initial Windows 11 release
3252

3353
public static final String NO_MANIFEST = "org.eclipse.swt.internal.win32.OS.NO_MANIFEST";
3454

@@ -44,6 +64,20 @@ public class OS extends C {
4464
int dwVersion = OS.GetVersion ();
4565
WIN32_VERSION = VERSION (dwVersion & 0xff, (dwVersion >> 8) & 0xff);
4666

67+
/*
68+
* Starting with Windows 10, GetVersionEx() lies about version unless
69+
* application manifest has a proper entry. RtlGetVersion() always
70+
* reports true version.
71+
*/
72+
OSVERSIONINFOEX osVersionInfoEx = new OSVERSIONINFOEX ();
73+
osVersionInfoEx.dwOSVersionInfoSize = OSVERSIONINFOEX.sizeof;
74+
if (0 == OS.RtlGetVersion (osVersionInfoEx)) {
75+
WIN32_BUILD = osVersionInfoEx.dwBuildNumber;
76+
} else {
77+
System.err.println ("SWT: OS: Failed to detect Windows build number");
78+
WIN32_BUILD = 0;
79+
}
80+
4781
/* Load the manifest to force the XP Theme */
4882
if (System.getProperty (NO_MANIFEST) == null) {
4983
ACTCTX pActCtx = new ACTCTX ();
@@ -1919,6 +1953,7 @@ public static int VERSION (int major, int minor) {
19191953
/** @method flags=const */
19201954
public static final native int NOTIFYICONDATA_V2_SIZE ();
19211955
public static final native int OUTLINETEXTMETRIC_sizeof ();
1956+
public static final native int OSVERSIONINFOEX_sizeof ();
19221957
public static final native int PAINTSTRUCT_sizeof ();
19231958
public static final native int POINT_sizeof ();
19241959
public static final native int PRINTDLG_sizeof ();
@@ -2211,6 +2246,7 @@ public static final void setTheme(boolean isDarkTheme) {
22112246
throw new NullPointerException("Display must be already created before you call OS.setTheme()");
22122247

22132248
display.setData("org.eclipse.swt.internal.win32.useDarkModeExplorerTheme", isDarkTheme);
2249+
display.setData("org.eclipse.swt.internal.win32.useShellTitleColoring", isDarkTheme);
22142250
display.setData("org.eclipse.swt.internal.win32.menuBarForegroundColor", isDarkTheme ? new Color(display, 0xD0, 0xD0, 0xD0) : null);
22152251
display.setData("org.eclipse.swt.internal.win32.menuBarBackgroundColor", isDarkTheme ? new Color(display, 0x30, 0x30, 0x30) : null);
22162252
display.setData("org.eclipse.swt.internal.win32.menuBarBorderColor", isDarkTheme ? new Color(display, 0x50, 0x50, 0x50) : null);
@@ -2562,6 +2598,8 @@ public static int HRESULT_FROM_WIN32(int x) {
25622598
* @param pRect flags=no_out
25632599
*/
25642600
public static final native int DrawThemeText (long hTheme, long hdc, int iPartId, int iStateId, char[] pszText, int iCharCount, int dwTextFlags, int dwTextFlags2, RECT pRect);
2601+
/** @param hwnd cast=(HDC) */
2602+
public static final native boolean DwmSetWindowAttribute (long hwnd, int dwAttribute, int[] pvAttribute, int cbAttribute);
25652603
/** @param hdc cast=(HDC) */
25662604
public static final native boolean Ellipse (long hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
25672605
/** @param hMenu cast=(HMENU) */
@@ -3857,6 +3895,8 @@ public static int HRESULT_FROM_WIN32(int x) {
38573895
public static final native boolean RestoreDC (long hdc, int nSavedDC);
38583896
/** @param hdc cast=(HDC) */
38593897
public static final native boolean RoundRect (long hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidth, int nHeight);
3898+
/** @method flags=dynamic */
3899+
public static final native int RtlGetVersion (OSVERSIONINFOEX lpVersionInformation);
38603900
/** @param hdc cast=(HDC) */
38613901
public static final native int SaveDC (long hdc);
38623902
/** @param hWnd cast=(HWND) */
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2021 Syntevo and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Syntevo - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.swt.internal.win32;
15+
16+
public class OSVERSIONINFOEX {
17+
public int dwOSVersionInfoSize;
18+
public int dwMajorVersion;
19+
public int dwMinorVersion;
20+
public int dwBuildNumber;
21+
public int dwPlatformId;
22+
public char[] szCSDVersion = new char[128];
23+
public int wServicePackMajor;
24+
public int wServicePackMinor;
25+
public int wSuiteMask;
26+
public int wProductType;
27+
public int wReserved;
28+
29+
public static final int sizeof = OS.OSVERSIONINFOEX_sizeof ();
30+
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,16 @@ public class Display extends Device {
183183
*/
184184
static final String USE_DARKMODE_EXPLORER_THEME_KEY = "org.eclipse.swt.internal.win32.useDarkModeExplorerTheme";
185185
boolean useDarkModeExplorerTheme;
186+
/**
187+
* Sets Shell titles to match theme selected in Windows. That is, dark is system is dark.
188+
* Limitations:<br>
189+
* <ul>
190+
* <li>Only available since Win10.</li>
191+
* <li>Does not affect already created Shells.</li>
192+
* </ul>
193+
*/
194+
static final String USE_SHELL_TITLE_COLORING = "org.eclipse.swt.internal.win32.useShellTitleColoring";
195+
boolean useShellTitleColoring;
186196
/**
187197
* Configures background/foreground colors of Menu(SWT.BAR).<br>
188198
* Side effects:
@@ -2093,9 +2103,9 @@ ImageList getImageListToolBarHot (int style, int width, int height) {
20932103
public static boolean isSystemDarkTheme () {
20942104
boolean isDarkTheme = false;
20952105
/*
2096-
* Win10 onwards we can read the Dark Theme from the OS registry.
2106+
* The registry settings, and Dark Theme itself, is present since Win10 1809
20972107
*/
2098-
if (OS.WIN32_VERSION >= OS.VERSION (10, 0)) {
2108+
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1809) {
20992109
try {
21002110
int result = OS.readRegistryDword(OS.HKEY_CURRENT_USER,
21012111
"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "AppsUseLightTheme");
@@ -4412,6 +4422,9 @@ public void setData (String key, Object value) {
44124422
OS.SetPreferredAppMode(PreferredAppMode_Default);
44134423
}
44144424
return;
4425+
case USE_SHELL_TITLE_COLORING:
4426+
useShellTitleColoring = !disableCustomThemeTweaks && _toBoolean(value);
4427+
return;
44154428
case MENUBAR_FOREGROUND_COLOR_KEY:
44164429
menuBarForegroundPixel = disableCustomThemeTweaks ? -1 : _toColorPixel(value);
44174430
return;

0 commit comments

Comments
 (0)