Bug 160349 - Add toolbar icons to change UI and scheme to switch Light/Dark
Summary: Add toolbar icons to change UI and scheme to switch Light/Dark
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium enhancement
Assignee: Justin L
URL:
Whiteboard: target:24.8.0 inReleaseNotes:24.8
Keywords:
Depends on: 160925
Blocks: Notebookbar Dark-Mode
  Show dependency treegraph
 
Reported: 2024-03-25 10:43 UTC by Timur
Modified: 2024-05-08 01:24 UTC (History)
7 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Timur 2024-03-25 10:43:09 UTC
LO can change UI and document background colors scheme in Tools-Options but it takes time.
Especially for testers, it would be useful to have drop-down icons in toolbar to be able to change:

1. Tools > Options > LibreOffice > View
2. Tools > Options > LibreOffice > Appearance
Comment 1 Rafael Lima 2024-03-25 11:54:17 UTC
This might be useful not only for testers, but for users as well. I'm not sure this command should be visible by default though.

FTR this is not something that can be done via macro, because simply changing the value of the ApplicationAppearance entry won't automatically apply it.

The actual code to apply the changes are in ColorConfig_Impl::Load, which is not accessible to macros.
Comment 2 Heiko Tietze 2024-03-26 10:30:17 UTC
Strong -1 from my side to expose these configuration switches in the primary UI. Nothing to say against making the life easier for QA but it's quite some work and could be done per macro.
Comment 3 Rafael Lima 2024-04-04 13:26:35 UTC
FTR this is the macro that I created to change the Appearance option. It does change the appearance option in the registry, but it does not get applied until LO is restarted. Hence, AFAIK this cannot be achieved solely via macros.

Sub ToggleDarkLight
  Dim oConfigProvider As Object
  Dim oConfigAccess As Object
  Dim pNode(0) As New com.sun.star.beans.PropertyValue
  oConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider")
  pNode(0).Name = "nodepath"
  pNode(0).Value = "org.openoffice.Office.Common/Misc"
  oConfigAccess = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", pNode)
  Dim nCurValue As Integer
  nCurValue = oConfigAccess.ApplicationAppearance
  ' Values can be 0: Automatic; 1: Light; 2: Dark
  If nCurValue >= 2 Then
    oConfigAccess.ApplicationAppearance = 0
  Else
    oConfigAccess.ApplicationAppearance = nCurValue + 1
  End If
  oConfigAccess.CommitChanges()
End Sub
Comment 4 Heiko Tietze 2024-04-05 12:29:52 UTC
We discussed the topic in the design meeting.

The idea seems to be supported by the fact that MSO provides a mode switch, see
https://support.microsoft.com/en-gb/office/dark-mode-in-word-e17b79a3-762f-4280-a81c-a15a859a693a

The argument to not add rarely used functions to the primary UI, in particular not when the option is part of a user-defined list (color schemes can be added; dark/light change the value of Automatic) was rejected.

So let's add the command.
Comment 5 Justin L 2024-04-27 13:03:14 UTC
There appears to be an existing uno command to do this.
    .uno:ChangeTheme  (FN_CHANGE_THEME)
and is often used in unit tests.

sfx/sdi/sfx.sdi would need
AccelConfig = TRUE,  // keyboard shortcuts IIUC
MenuConfig = TRUE,   // Menu entry
ToolBoxConfig = TRUE // can be added to toolbar

and probably Toggle = TRUE as well as ReadOnlyDoc = TRUE

FN_CHANGE_THEME already knows the GetCurrentSchemeName (maybe), and if it is auto (system), then MiscSettings::GetUseDarkMode() might indicate if the OS is asking for dark mode.

MiscSettings::GetDarkMode() returns 0(system) 1(light) or 2(dark)
from officecfg::Office::Common::Misc::Appearance
and MiscSettings::SetDarkMode(0/1/2) triggers a redraw to the new mode.

The options page managing the AppearanceStyle is cui/source/options/optdlg.cxx.
Comment 6 Justin L 2024-04-27 17:14:05 UTC
proposed at https://gerrit.libreoffice.org/c/core/+/166781
Comment 7 Justin L 2024-05-01 12:27:23 UTC
(In reply to Justin L from comment #5)
> options page managing the AppearanceStyle is cui/source/options/optgdlg.cxx
The UI theme is hidden on the config page except for certain VCLs
    const bool bHasDarkMode = sToolKitName.startsWith("gtk")
        || sToolKitName == "osx" || sToolKitName == "win";
    if (!bHasDarkMode)
        m_xDarkModeFrame->hide();
Comment 8 Commit Notification 2024-05-03 15:58:25 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/da86bfd89e529e787da0bbb3e3150c1f5d4e0dfd

tdf#160349: add .uno:ChangeTheme to notebookbar to toggle dark mode

It will be available in 24.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 9 Timur 2024-05-04 22:26:14 UTC
Thanks Justin, works nice for me. 
In Options > LibreOffice > View > Appearance change would not be accepted with Apply, only OK, so it used to take more time.

Can you please explain something:
in the same menu, there is also System mode, which in my GTK sets Light appearance although I have Dark system.
I assume that this toggle switches Light-Dark? But when I set Light and open Options, it says System.
Comment 10 Justin L 2024-05-05 01:53:00 UTC
(In reply to Timur from comment #9)
> I assume that this toggle switches Light-Dark? But when I set Light and open
> Options, it says System.
I found that "Application colors - scheme - automatic = system settings" takes its cue from "View - appearance - mode", and so (at least for gtk and I assume win/osx) it can always stay on "System Theme". For gen/kf* it will toggle between dark and system theme.
Comment 11 Justin L 2024-05-05 01:56:43 UTC
Hmm, I don't think I answered your question though. You are saying that your GTK OS system is dark mode, but LibreOffice equates "System" with Light. I wouldn't know about that.
Comment 12 Justin L 2024-05-05 02:02:15 UTC
The toggle switches between "system" and non-system actually.
Comment 13 Timur 2024-05-05 06:33:13 UTC
I'm not clear how, but in my Linux Mint Cinnamon GTK3 this icon works reliably, while Options does not, I assume that would be bug 153841.
Comment 14 Stéphane Guillou (stragu) 2024-05-08 01:24:03 UTC
Added the UNO command to the release notes: https://wiki.documentfoundation.org/index.php?title=ReleaseNotes%2F24.8&type=revision&diff=750277&oldid=750142