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: 153841 160925
Blocks: Notebookbar Dark-Mode
  Show dependency treegraph
 
Reported: 2024-03-25 10:43 UTC by Timur
Modified: 2024-06-26 08:52 UTC (History)
10 users (show)

See Also:
Crash report or crash signature:


Attachments
preferences > view > mode change from system to light with system set to dark (120.76 KB, image/png)
2024-05-11 19:35 UTC, steve
Details

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
Comment 15 Justin L 2024-05-10 13:21:50 UTC
Can someone verify that this works for Windows and for MacOS? I expect that both the document itself (Options-Application Colors) and the Legacy UI (Options-View-Appearance Mode) should alternate between light and dark mode.

Steps to test:
1.) take note of the document area - I assume for the purposes of these steps that it is in light mode, and that the OS itself is also in light mode.
2.) toggle on Dark mode: both UI and document should turn dark.
3.) toggle off Dark mode: both should turn light
4.) toggle to match your OS's mode. The Options settings for both should be set to "System/System Theme". Close LibreOffice.

Then toggle the OS's dark mode.
5.) start LO. I would HOPE that LibreOffice obeys the "System" setting and that both the document and UI follow the system theme.
6.) repeat steps 3,2,4.
Comment 16 steve 2024-05-11 19:35:36 UTC
Created attachment 194089 [details]
preferences > view > mode change from system to light with system set to dark

Not quite sure what to test and what to expect. Headline sounds as if there should be a toolbar icon? If so, could you please share a screenshot indicating where that would be found and what it looks like? The release note addition talks about UNO command which seems to be a start parameter and not a toolbar icon. I could not find a toolbar icon to change dark / light mode.

What I can say is that when changing system OS from Light to Dark and having LO preferences set to follow system, that changes document, UI and icon set (Automatic Sukapura) from light to dark and vice versa. That is a huge improvement over the previous situation where adjustments had to be made in several locations and toolbar icons would not follow the change.

Does the fact that document color is now following system mean https://bugs.documentfoundation.org/show_bug.cgi?id=160445 is resolved or is that change still pending?

There are still several problems when switching Mode in LibreOffice > Preferences > View > Appearance. e.g. when system is dark and mode is changed from System to light and change applied, document color remains dark, UI becomes light but dropdown boxes remain dark, icons are not updated and preferences window is not updated. But those are old issues which are probably not in the scope of the issue here.
Comment 17 Justin L 2024-05-11 20:22:26 UTC
(In reply to steve from comment #16)
> Headline sounds as if there should be a toolbar icon?

Sorry. All the information is in the commit message, but never placed in this bug report.

The toggle can be customize-assigned to keyboard, menu, and toolbar,
and can be found by searching for "Dark Mode" (in Tools - Customize).

Dark mode has been added to the view tab of the main notebookbar.ui.
I added it as NOT VISIBLE, so a notebookbar tester needs to customize the toolbar and made it visible. (See https://gerrit.libreoffice.org/c/core/+/166781 for the reasons).

The primary benefit of making it available in the notebookbar
is for QA testers who want to easily switch back and forth.
WARNING: by customizing the notebookbar, you prevent seeing
any future NBB changes made to the program
(until you reset to defaults or blow away the user profile).

> Does the fact that document color is now following system mean
> bug 160445 is resolved?
I haven't looked at that bug report. Document color following system is only related to the dark mode toggle that I implemented.
Comment 18 Heiko Tietze 2024-05-14 08:41:05 UTC
On macOS started in safe-mode it changes from light to dark (View > Appearance = System, and View > Application Colors still showing System Theme). Clicking again changes View > Appearance to Light, which requires a restart (white font on white background). The setting under View > Application Colors remains System Theme. Coming from there the command goes back to Appearance = System.

Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 3eb427b31e624af9b2fe2bd68fee859d3d76a661
CPU threads: 8; OS: macOS 14.4.1; UI render: Skia/Metal; VCL: osx
Locale: en-US (en_DE.UTF-8); UI: en-US
Calc: threaded
Comment 19 Rafael Lima 2024-05-14 12:18:06 UTC
(In reply to Justin L from comment #17) 
> The primary benefit of making it available in the notebookbar
> is for QA testers who want to easily switch back and forth.
> WARNING: by customizing the notebookbar, you prevent seeing
> any future NBB changes made to the program
> (until you reset to defaults or blow away the user profile).

Thanks Justin for implementing this nice feature.

I would argue that this should be enabled by default in the Tabbed UI. This is a very useful feature for all users (not only QA testers).

If a user is editing a document that will later be printed (or exported to a PDF), they'll want to see it with a light background. But later on, if the user opens a file simply for reading or reviewing, they might want to quickly switch to dark mode. And then on a future document, the user might need to quickly go back to light... and so on.

In summary, this feature is too nice to be hidden from the user.
Comment 20 Justin L 2024-05-14 15:27:01 UTC
(In reply to Heiko Tietze from comment #18)
> Clicking again changes View > Appearance to Light, which requires a
> restart (white font on white background).
Wow, the background changed from dark to light, but the fonts didn't? It sounds like the underlying code I am calling is rather glitchy then.

> On macOS started in safe-mode it changes from light to dark.
> (View > Appearance = System, and View > Application Colors
> still showing System Theme).
So your macOS must be in dark mode?  In that case I would expect the UI to initially be in dark mode, and the document in light mode. The first toggle would also make the document dark.

But your setting results don't make much sense to me. A brand new profile (which I assume you would have in safe mode) starts with View > Appearance == System, and Application Colors == Light, so saying "still showing System Theme" can't be right. The toggle is based on Application Colors, so it should turn from "Light" to either "Dark" or System - it can't "still be system". 


Perhaps I am too optimistic with sfx2/source/appl/appserv.cxx's
// Set the UI theme. It would be nicest to use automatic whenever possible.
It works to leave "Options > Application Colors == System theme" without restart for GTK, but obviously not for macOS.

But obviously Dark Mode is nowhere near ready for prime time, so for now I will leave everything as it is, and .uno:ChangeTheme can be used by the dark mode developers to fix issues relating switching back and forth from system theme.
Comment 21 Stéphane Guillou (stragu) 2024-05-15 01:31:56 UTC
A 7.6 regression that might muddy the waters too: bug 157365.

(In reply to Justin L from comment #20)
> (In reply to Heiko Tietze from comment #18)
> > Clicking again changes View > Appearance to Light, which requires a
> > restart (white font on white background).
> Wow, the background changed from dark to light, but the fonts didn't? It
> sounds like the underlying code I am calling is rather glitchy then.
Likely bug 156855, else one of the other macOS dark mode issues that require a restart to refresh: https://bugs.documentfoundation.org/showdependencytree.cgi?id=118017&hide_resolved=1
Comment 22 Rizal Muttaqin 2024-05-23 11:10:46 UTC
Hi, using 

Version: 24.8.0.0.alpha1+ (X86_64) / LibreOffice Community
Build ID: 101b08fe1ec77ffe8c1a9b2b8f9f20884269a1ed
CPU threads: 12; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded

under KDE Neon 22.04 the button just switch the document color between dark and light color while the UI always follow system. Is this expected behaviour? I just see the bug title including as well. But if the button is mimicking what Office 365 does, it is not an issue.
Comment 23 Rizal Muttaqin 2024-05-23 11:13:58 UTC
(In reply to Rizal Muttaqin from comment #22)
> Hi, using 
> 
> Version: 24.8.0.0.alpha1+ (X86_64) / LibreOffice Community
> Build ID: 101b08fe1ec77ffe8c1a9b2b8f9f20884269a1ed
> CPU threads: 12; OS: Linux 6.5; UI render: default; VCL: gtk3
> Locale: en-US (en_US.UTF-8); UI: en-US
> Calc: threaded
> 
> under KDE Neon 22.04 the button just switch the document color between dark
> and light color while the UI always follow system. Is this expected
> behaviour? I just see the bug title including as well. But if the button is
> mimicking what Office 365 does, it is not an issue.

Update:

Going through Tools > Options > PRODUCTNAME > View, I can confirm Appearance Mode is "Dark" when the button active, and change back to "System" when the button inactive. So may be it KDE related issue.
Comment 24 Stéphane Guillou (stragu) 2024-05-23 12:54:59 UTC
(In reply to Rizal Muttaqin from comment #22)
> under KDE Neon 22.04 the button just switch the document color between dark
> and light color while the UI always follow system.
Sounds like bug 153841.
Comment 25 Heiko Tietze 2024-05-28 04:19:17 UTC Comment hidden (obsolete)
Comment 26 Timur 2024-06-26 08:52:52 UTC
(In reply to Justin L from comment #15)
> Can someone verify that this works for Windows and for MacOS? I expect that
> both the document itself (Options-Application Colors) and the Legacy UI
> (Options-View-Appearance Mode) should alternate between light and dark mode.
> 
> Steps to test:
> 1.) take note of the document area - I assume for the purposes of these
> steps that it is in light mode, and that the OS itself is also in light mode.
> 2.) toggle on Dark mode: both UI and document should turn dark.
> 3.) toggle off Dark mode: both should turn light
> 4.) toggle to match your OS's mode. The Options settings for both should be
> set to "System/System Theme". Close LibreOffice.
> 
> Then toggle the OS's dark mode.
> 5.) start LO. I would HOPE that LibreOffice obeys the "System" setting and
> that both the document and UI follow the system theme.
> 6.) repeat steps 3,2,4.

I tried 25.2+ in Windows 10. 
With new profile Appearance mode is System. Scheme is Automatic, Automatic is Light. As a result, OS toggle to dark app makes LO UI dark but document stays light. 
With OS and App set to Light, Dark mode icon changes the document, and UI needs a LO restart to function. Most important is that is changes Scheme Automatic to System Theme (correcting LO behavior) so all seems correct. 

The only issue is with LO that does not apply UI mode change immediatelly, but needs LO restart. Probably should be checked in older LO and in Win 11, but anyway not of interest for me to pursue.