Skip to content

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

Open

Description

@rombert

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.

Activity

  1. added
    enhancement
    on Oct 23, 2024
  2. mickaelistria commented on Oct 23, 2024

    @mickaelistria
    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.

  3. Phillipus commented on Oct 23, 2024

    @Phillipus
    Contributor

    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.

  4. rombert commented on Oct 24, 2024

    @rombert
    Author

    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.

  5. Phillipus commented on Oct 24, 2024

    @Phillipus
    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.

  6. HeikoKlare commented on Oct 25, 2024

    @HeikoKlare
    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.

  7. Phillipus commented on Oct 25, 2024

    @Phillipus
    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.

  8. HeikoKlare commented on Oct 25, 2024

    @HeikoKlare
    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.

  9. Phillipus commented on Oct 25, 2024

    @Phillipus
    Contributor

    More accurately it deletes the themeid property in that file.

  10. mickaelistria commented on Oct 25, 2024

    @mickaelistria
    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.

  11. sratz commented on Oct 25, 2024

    @sratz
    Member

    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
  12. rombert commented on Oct 28, 2024

    @rombert
    Author

    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.

  13. Phillipus commented on Oct 28, 2024

    @Phillipus
    Contributor

    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)

  14. rombert commented on Oct 28, 2024

    @rombert
    Author

    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.

  15. Phillipus commented on Oct 28, 2024

    @Phillipus
    Contributor

    Linux

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

  16. Mailaender commented on Nov 24, 2024

    @Mailaender
    Contributor

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

  17. mickaelistria commented on Nov 24, 2024

    @mickaelistria
    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.

  18. Mailaender commented on Nov 24, 2024

    @Mailaender
    Contributor

    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/chemclipse#1972.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions