Eclipse RCP 2022-06
After exporting the product, I found that if the current theme of win10 is dark, RCP also uses the dark theme
In other words, eclipse will now decide which theme to choose at startup based on the theme of the operating system
How do disable this feature?? I don't want to use it until the dark theme is complete
Updated as recommended by greg-449
Possibly set system property org.eclipse.swt.internal.win32.useDarkModeExplorerTheme to false. Look at the source of Display to see all the properties that can be set on Windows
This is my exported product profile
-startup
plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.2.500.v20220509-0833
-clearPersistedState
--launcher.appendVmargs
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=17
-Dorg.eclipse.swt.internal.win32.useDarkModeExplorerTheme=false
-Xms1024m
-Xmx2048m
-XX:+UseG1GC
--add-modules=ALL-SYSTEM
Still unsolvable
Reply to howlger
The exported product is the most basic product
This is a particularly simple test for the new version of RCP export products
Other settings are based on platform feature
plugin.xml
<plugin>
<extension
id="product"
point="org.eclipse.core.runtime.products">
<product
application="org.eclipse.ui.ide.workbench"
name="BitFan">
<property
name="appName"
value="BitFan">
</property>
<property
name="windowImages"
value="logo16.png,logo32.png,logo48.png,logo64.png,logo128.png,logo256.png">
</property>
<property
name="startupForegroundColor"
value="FFFFFF">
</property>
<property
name="startupMessageRect"
value="30,272,445,20">
</property>
<property
name="startupProgressRect"
value="28,295,445,15">
</property>
<property
name="applicationCSSResources"
value="platform:/plugin/org.eclipse.ui.themes/images/">
</property>
<property
name="applicationXMI"
value="org.eclipse.platform/LegacyIDE.e4xmi">
</property>
<property
name="cssTheme"
value="org.eclipse.e4.ui.css.theme.e4_default">
</property>
<property
name="buildIdLocation"
value="0,220">
</property>
<property
name="buildIdSize"
value="293,40">
</property>
<property
name="preferenceCustomization"
value="plugin_customization.ini">
</property>
</product>
</extension>
</plugin>
Reply to howlger again
boolean hasDarkTheme = getThemes().stream().anyMatch(t -> t.getId().startsWith(E4_DARK_THEME_ID));
String themeToRestore = Display.isSystemDarkTheme() && hasDarkTheme ? E4_DARK_THEME_ID : alternateTheme;
if (themeToRestore != null && flag) {
setTheme(themeToRestore, false);
}
I tracked that "Display.isSystemDarkTheme()" is true, so the dark theme is set
Then I set -Dorg.eclipse.swt.internal.win32.useDarkModeExplorerTheme=false in the Run Configurations VM Arguments
clear run, still the dark theme
This parameter has no effect
It judges by reading the registry
public static boolean isSystemDarkTheme () {
boolean isDarkTheme = false;
/*
* The registry settings, and Dark Theme itself, is present since Win10 1809
*/
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1809) {
int[] result = OS.readRegistryDwords(OS.HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "AppsUseLightTheme");
if (result!=null) {
isDarkTheme = (result[0] == 0);
}
}
return isDarkTheme;
}
I think this problem can only be solved by deleting the dark theme , But how to delete it? It seems that the "org.eclipse.ui.activities" extension point cannot disable themes
Maybe I can remove it through removeExtension, but this needs to be done before the workbench starts. At present, I only know that the splashHandlers extension point can be implemented. Should I do this?
Under normal circumstances, there is no way to solve this problem, because the restore method of ThemeEngine determines whether to use dark theme according to the Display
@Override
public void restore(String alternateTheme) {
String prefThemeId = getPreferenceThemeId();
// Bug 562794, 563601: Eclipse once contained two identical themes named
// "Classic" and "Windows Classic" and the second was removed with bug 562794.
// An old workspace using the removed "Windows Classic" theme would be reseted
// to the default theme on update. Since both themes are identical we silently
// change the theme to the remaining "Classic" theme and don't disturb the user.
if ("org.eclipse.e4.ui.css.theme.e4_classic6.0,6.1,6.2,6.3".equals(prefThemeId)) { //$NON-NLS-1$
prefThemeId = "org.eclipse.e4.ui.css.theme.e4_classic"; //$NON-NLS-1$
}
boolean flag = true;
if (prefThemeId != null) {
for (ITheme t : getThemes()) {
if (prefThemeId.equals(t.getId())) {
setTheme(t, false);
flag = false;
break;
}
}
}
/*
* Any Platform: if the system has Dark appearance set and Eclipse is using the
* default settings, then start Eclipse in Dark theme. Check that there is a
* dark theme present.
*/
boolean hasDarkTheme = getThemes().stream().anyMatch(t -> t.getId().startsWith(E4_DARK_THEME_ID));
String themeToRestore = Display.isSystemDarkTheme() && hasDarkTheme ? E4_DARK_THEME_ID : alternateTheme;
if (themeToRestore != null && flag) {
setTheme(themeToRestore, false);
}
}
But "Display.isSystemDarkTheme" is determined based on the operating system registry
public static boolean isSystemDarkTheme () {
boolean isDarkTheme = false;
/*
* The registry settings, and Dark Theme itself, is present since Win10 1809
*/
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1809) {
int[] result = OS.readRegistryDwords(OS.HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "AppsUseLightTheme");
if (result!=null) {
isDarkTheme = (result[0] == 0);
}
}
return isDarkTheme;
}
Solution
Remove all themes first
private void removeThemes()throws Exception {
ExtensionRegistry registry = (ExtensionRegistry)Platform.getExtensionRegistry() ;
Field field = ExtensionRegistry.class.getDeclaredField("masterToken") ; //$NON-NLS-1$
field.setAccessible( true ) ;
Object masterToken = field.get(registry) ;
IExtensionPoint extPoint = registry.getExtensionPoint(ThemeEngine.THEME_PLUGIN_ID);
IExtension extensions[] = extPoint.getExtensions() ;
for (IExtension e : extensions ) {
if( "org.eclipse.ui.themes".equals( e.getContributor().getName() ) ) { //$NON-NLS-1$
registry.removeExtension( e , masterToken ) ;
return ;
}
}
}
Then add extension points in the appropriate plug-ins (I defined in the product plug-ins)
<extension
point="org.eclipse.e4.ui.css.swt.theme">
<theme
basestylesheeturi="platform:/plugin/org.eclipse.ui.themes/css/e4_default_win.css"
id="org.eclipse.e4.ui.css.theme.e4_default"
label="Light"
os="win32">
</theme>
</extension>
Finally, modify the start method of the application
@Override
public Object start(IApplicationContext appContext) throws Exception {
removeThemes();
...
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With