Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eclipse should be able to 'follow system theme' (light/dark) #2440

Open
2 tasks done
rombert opened this issue Oct 23, 2024 · 17 comments
Open
2 tasks done

Eclipse should be able to 'follow system theme' (light/dark) #2440

rombert opened this issue Oct 23, 2024 · 17 comments
Labels
enhancement New feature or request

Comments

@rombert
Copy link

rombert commented Oct 23, 2024

Let's make sure issue is not already fixed in latest builds first.

Suggestion

From a fresh installation and clean workspace:

  • Open Preferences
  • Go to General → Appearance

I would like to be able to tell Eclipse to 'follow the system theme' and use a Light or Dark theme based on what the operating system preference is set to.

Community

  • I understand suggesting an enhancement doesn't mandate anyone to implement it. Other contributors may consider this suggestion, or not, at their own convenience. The most efficient way to get it fixed is that I implement it myself and contribute it back as a good quality patch to the project.
@rombert rombert added the enhancement New feature or request label Oct 23, 2024
@mickaelistria
Copy link
Contributor

The IDE is already supposed to switch to dark theme when system is dark. So please provide details about your setup to hopefully reproduce this issue.
But on a side note, if you want the strongest possible integration with the system theme, you should simply disable theming (untick checkbox in the preference page and restart Eclipse IDE) and you'll get the widgets following the system theme as Eclipse doesn't override it.

@Phillipus
Copy link
Contributor

Phillipus commented Oct 23, 2024

The IDE is already supposed to switch to dark theme when system is dark.

It does switch between light/dark with a fresh workspace. But once a theme has been set it won't.

If the themeid setting does not exist in .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.e4.ui.css.swt.theme.prefs then the system light or dark theme is used. However, once a user sets the theme in preferences themeid is set to the id of the theme and this auto setting no longer works.

In our RCP app we workaround this by deleting the org.eclipse.e4.ui.css.swt.theme.prefs file if the user chooses "Auto" which resets it.

@rombert
Copy link
Author

rombert commented Oct 24, 2024

Thanks for the info @mickaelistria ; been using Eclipse for around 20 years and always used theming. As @Phillipus says though, a theme was initially selected already in my installation so restarting after going to dark mode does not help. An explicit 'follow system theme' or similar would be very useful.

I am not sure if disabling theming is supposed to use OS colors in dark mode, but it does not.

image

I am using Gnome 47 in case that matters.

@Phillipus
Copy link
Contributor

As I said, all you have to do is delete the <workspace>/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.e4.ui.css.swt.theme.prefs file and it will follow the system theme.

@HeikoKlare
Copy link
Contributor

We could think about making this properly configurable through preferences, e.g.:

  • Add something like a "follow system theme" option (checkbox) that is enabled by default
  • Enable the drop-down for selecting an explicit theme only when the "follow system theme" is disabled

Or there could just be an additional "virtual" option in the themes drop-down menu for enabling to follow the system theme.

@Phillipus
Copy link
Contributor

Or there could just be an additional "virtual" option in the themes drop-down menu for enabling to follow the system theme.

That's what I do. Selecting this deletes the workspace>/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.e4.ui.css.swt.theme.prefs file.

@HeikoKlare
Copy link
Contributor

Or there could just be an additional "virtual" option in the themes drop-down menu for enabling to follow the system theme.

That's what I do. Selecting this deletes the workspace>/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.e4.ui.css.swt.theme.prefs file.

Sorry, I missed that comment. Sounds like a simple and sufficient approach to address this.

@Phillipus
Copy link
Contributor

Phillipus commented Oct 25, 2024

More accurately it deletes the themeid property in that file.

@mickaelistria
Copy link
Contributor

Or there could just be an additional "virtual" option in the themes drop-down menu for enabling to follow the system theme.

There used to be a "System" theme: https://eclipse.dev/eclipse/news/4.18/platform.html#system-theme
But I removed it some time ago with 9328b2d as I realized default SWT behavior is supposed to follow the system GTK theme (eg Adwaita-dark) so basically this System theme was not so relevant to address the problem of following system colors.
Note that to make it work, the light/dark setting in gnome settings is not sufficient: the relevant setting is the "Appearance/Legacy Applications" one you can find in gnome-tweaks. I guess the current gnome settings is GTK4 only and is ignored as long as GTK3 is used by SWT; but there might still be some possible way to pass the right GTK3 theme according to GTK4 settings; but I don't think it will make it into SWT as the priority should be to just use directly GTK4.

@sratz
Copy link
Member

sratz commented Oct 25, 2024

A System theme is a different concept (at least on Windows).

I think what we would want / need to have is the following:

  • An 'Auto' / 'Inherit from system' setting which inherits the system theme, like it is done on the first them and/or if no theme preference is set:

/*
* 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. Can be disabled using a system property.
*/
boolean hasDarkTheme = getThemes().stream().anyMatch(t -> t.getId().startsWith(E4_DARK_THEME_ID));
boolean disableOSDarkThemeInherit = "true".equalsIgnoreCase(System.getProperty(DISABLE_OS_DARK_THEME_INHERIT));
boolean overrideWithDarkTheme = Display.isSystemDarkTheme() && hasDarkTheme && !disableOSDarkThemeInherit;
String themeToRestore = overrideWithDarkTheme ? E4_DARK_THEME_ID : alternateTheme;
if (themeToRestore != null && flag) {
setTheme(themeToRestore, false);
}

However, simply doing that is not enough, because

  • This is really just supposed to be a 'first time initialization' thing, i.e. it choses some sane default theme.
  • But there are multiple light themes and there can be multiple dark themes
  • The user would need to be able to select a preferred dark theme and a preferred light theme.

To consider:

  • Having such an 'Auto' mode would suggest that we can handle theme changes on-the-fly without restart - which we can't.
  • I am not sure whether we should add this in the current state.

Technically, we would therefore need to:

  • Optional, but probably way overdue: Make it possible to explicitly flag a theme as isLight or isDark and not derive it from the theme ID via some string comparison heuristics.
  • Improve the UI
    • Add an 'Inherit from system' / 'Auto' option
    • While still allowing the user to chose which light and dark themes to use
  • React on changed Windows light<->dark theme
    • If inheritance is enabled:
      • Apply the theme change
      • Inform the user that Windows theme changed, but an Eclipse restart is needed

@rombert
Copy link
Author

rombert commented Oct 28, 2024

As I said, all you have to do is delete the <workspace>/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.e4.ui.css.swt.theme.prefs file and it will follow the system theme.

@Phillipus - that does not work for me, for whatever reason. I removeds the existing file, closed Eclipse, and started it again but I was still in light mode while the OS was in dark mode.

Regarding the wider discussion: I think ideally there would be a way to say 'follow System dark/light setting'. And yes, there may be multiple light and dark theme modes but for starters it would be great to be able to toggle between the build in dark and light modes through a virtual theme or checkbox in the preferences page.

@Phillipus
Copy link
Contributor

Phillipus commented Oct 28, 2024

that does not work for me, for whatever reason. I removeds the existing file, closed Eclipse, and started it again but I was still in light mode while the OS was in dark mode.

Which OS? Works for me on Windows and Mac (Linux might not work)

@rombert
Copy link
Author

rombert commented Oct 28, 2024

that does not work for me, for whatever reason. I removeds the existing file, closed Eclipse, and started it again but I was still in light mode while the OS was in dark mode.

Which OS? Works for me on Windows and Mac (Linux might not work)

Linux :-) Using Gnome 47.1 , to be more precise.

@Phillipus
Copy link
Contributor

Linux

In that case I'd say that the expected outcome will be...unpredictable.

@Mailaender
Copy link

I can confirm that this follows the system theme on macOS, but it doesn't on Fedora KDE.

@mickaelistria
Copy link
Contributor

I can confirm that this follows the system theme on macOS, but it doesn't on Fedora KDE.

Does it work for plain SWT application in Fedora KDE ?
If plain SWT apps do follow the system colors, then it means that the Display.getSystemColor() do provide the right information; and we can then rely on those colors more reliably than on other settings in order to determine what is the closer theme to system.

@Mailaender
Copy link

Mailaender commented Nov 24, 2024

What I found out so far is

  • on Windows 10 you can use the Eclipse RCP theme name to detect dark mode, system colors stay bright
  • on macOS you can only use the darkness of the background, querying for the theme name gives wrong results
  • on Linux KDE both methods work fine

See also https://bugs.eclipse.org/bugs/show_bug.cgi?id=564022 and my current workaround eclipse/chemclipse#1972.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants