sfx2/source/appl/appserv.cxx | 62 +++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 34 deletions(-)
New commits: commit 9645c6d4e5cd0841d9d9e474ce5f27cec8fcda1c Author: Sahil Gautam <sahil.gautam.ext...@allotropia.de> AuthorDate: Sat Jun 7 08:28:48 2025 +0530 Commit: Sahil Gautam <sahil.gau...@collabora.com> CommitDate: Wed Jul 9 11:45:06 2025 +0200 tdf#164970 Update .uno:ChangeTheme as per current themes implementation Before the themes rework, the document appearance and the application appearance were separately managed which is not the case now. Now themes map to appearance modes as follows: Custom theme -> AppearanceMode::AUTO Automatic -> AppearanceMode::AUTO Light -> AppearanceMode::LIGHT Dark -> AppearanceMode::DARK The current implementation toggles between Light and Dark themes except for the case where the current theme is a custom theme. Change-Id: I6062924a36c7848794a7588cee157333fc3e5e9a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186233 Tested-by: Jenkins Reviewed-by: Sahil Gautam <sahil.gau...@collabora.com> diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx index 25d5ee8b4519..9c4a6765b885 100644 --- a/sfx2/source/appl/appserv.cxx +++ b/sfx2/source/appl/appserv.cxx @@ -698,45 +698,39 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq ) case FN_CHANGE_THEME: { const SfxStringItem* pNewThemeArg = rReq.GetArg<SfxStringItem>(FN_PARAM_NEW_THEME); - OUString sSchemeName - = pNewThemeArg ? pNewThemeArg->GetValue() : u"COLOR_SCHEME_LIBREOFFICE_AUTOMATIC"_ustr; + OUString sSchemeName = ThemeColors::GetThemeColors().GetThemeName(); + AppearanceMode eAppearnceMode = MiscSettings::GetAppColorMode(); + if (!pNewThemeArg) { - // toggle between light and dark mode - - // There are two separate things that can be dark mode themed: UI and document - // The modes can be 0 (automatic - what the OS/VCL asks for), 1 (light), or 2 (dark) - - // Since only gtk/osx/win support UI theme, toggle based on document colors - // Automatic in this case means "whatever GetUseDarkMode() says" - const bool bWasInDarkMode - = MiscSettings::GetAppColorMode() == AppearanceMode::DARK - || (MiscSettings::GetAppColorMode() == AppearanceMode::AUTO - && MiscSettings::GetUseDarkMode()); - - // Set the UI theme. It would be nicest to use automatic whenever possible - AppearanceMode eUseMode = AppearanceMode::AUTO; - if (MiscSettings::GetAppColorMode() != AppearanceMode::AUTO) - MiscSettings::SetAppColorMode(eUseMode); - - if (MiscSettings::GetUseDarkMode() == bWasInDarkMode) - { - // automatic didn't toggle, so force the desired theme - eUseMode = bWasInDarkMode ? AppearanceMode::LIGHT : AppearanceMode::DARK; - MiscSettings::SetAppColorMode(eUseMode); - } - - // Now set the document theme - // If the UI can be themed, then the document theme can always remain on automatic. - eUseMode = AppearanceMode::AUTO; - // NOTE: since SetDarkMode has run, GetUseDarkMode might return a different result. - if (MiscSettings::GetUseDarkMode() == bWasInDarkMode) + // we do not override custom themes if the unocommand was triggered from the UI + // by clicking on a toolbar/notebookbar button for example. + if (!ThemeColors::IsCustomTheme(sSchemeName)) { - eUseMode = bWasInDarkMode ? AppearanceMode::LIGHT : AppearanceMode::DARK; - sSchemeName = bWasInDarkMode ? u"Light" : u"Dark"; + bool bChangeToLightTheme = eAppearnceMode == AppearanceMode::DARK + || (eAppearnceMode == AppearanceMode::AUTO + && MiscSettings::GetUseDarkMode()); + + // note that a theme and an appearance mode are not orthogonal anymore, for + // "Custom Themes", appearance mode is AUTO, for the "Automatic", "Light" and + // "Dark" default themes, it's AUTO, LIGHT & DARK respectively. + if (bChangeToLightTheme) + { + sSchemeName = svtools::LIGHT_COLOR_SCHEME; + eAppearnceMode = AppearanceMode::LIGHT; + } + else + { + sSchemeName = svtools::DARK_COLOR_SCHEME; + eAppearnceMode = AppearanceMode::DARK; + } } - MiscSettings::SetAppColorMode(eUseMode); } + else + sSchemeName = pNewThemeArg->GetValue(); + + aEditableConfig.LoadScheme(sSchemeName); + MiscSettings::SetAppColorMode(eAppearnceMode); // kit explicitly ignores changes to the global color scheme, except for the current ViewShell, // so an attempted change to the same global color scheme when the now current ViewShell ignored