Open rfindler opened 4 years ago
I switched my Windows machine to Dark mode, and only some of the applications changed to Dark mode. In particular, most of the Windows tools, such as control panel property boxes remained to the default "light" mode.
I suspect the registry setting and the windows message about the mode change is more an "advisory" setting. Applications built on .Net technologies will use it because the .Net libraries use it, but the Win32 controls don't. As such, if DrRacket (and the Racket GUI library) would like to implement Dark mode, it would either have to change to use the .Net GUI libraries, or do their own drawing of controls such as buttons, and consult the registry to determine if dark mode is enabled or not.
Dark mode in the preferences of DrRacket may be the easy route to go ?
It looks like there has been some movement in the Windows API documentation related to dark mode. Here's an article from the end of 2022: Support Dark and Light themes in Win32 apps.
Currently the get-label-{background,foreground}-color
functions are implemented using GetSysColor
and the results do not seem to change when changing my Windows 10 VM into dark mode as described here.
The article above seems to suggest using UISettings.GetColorValue(UIColorType::Foreground)
but I don't know how to make that call from our FFI. This seems to be the docs for UISettings.GetColorValue
. Does anyone know how to call that function and get its value back into Racketdom?
Would that be helpful? Ref: https://learn.microsoft.com/en-us/answers/questions/715081/how-to-detect-windows-dark-mode
It depends on Windows versions On recent OS (>= Windows 10 1903) :
[DllImport("UXTheme.dll", SetLastError = true, EntryPoint = "#138")]
public static extern bool ShouldSystemUseDarkMode();
test :
bool bRet = ShouldSystemUseDarkMode();
Another uglier option: wrapping around PowerShell. I found this, but it doesn't work on my system. Maybe there's a way:
(New-Object Windows.UI.ViewManagement.UISettings).GetColorValue("background")
Ref: https://stackoverflow.com/questions/38734615/how-can-i-detect-windows-10-light-dark-mode
Also, according to this, Visual Styles have to be enabled for GetThemeSysColor to work.
Found the header file for the windows.ui.viewmanagement class for accessing UISettings, but for WinRT. Maybe these constants can help us with the FFI? Ref: https://github.com/tpn/winsdk-10/blob/master/Include/10.0.16299.0/winrt/windows.ui.viewmanagement.h
Here's a hack that uses an undocumented dark mode API introduced in Windows 10 1809: https://github.com/ysc3839/win32-darkmode I wouldn't use it, but it's a start?
Another example in low(er) level C, using uxtheme.dll: https://github.com/ysc3839/VCMPBrowser/blob/darkmode/DarkMode.h
Cheers
I was reminded of this by a Discourse thread. I haven't thought about this in the last year, but I'll consolidate thoughts I had then into this issue.
In https://github.com/racket/gui/pull/293#issuecomment-1482080488 I wrote:
On Windows, the de facto way seems to be using
RegNotifyChangeKeyValue
to detect changes to theAppsUseLightTheme
value ofHKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize
(which may not exist).
In https://github.com/racket/gui/pull/293#issuecomment-1482100580 I wrote:
I've looked into windows (and there is an issue discussing it somewhere, I think) and the OS doesn't seem to provide a way to detect the theme.
That's my understanding, too, as far as detecting the theme. There's a Microsoft article recommending basically the same strategy
white-on-black-panel-scheme?
uses, but using a Windows-specific API. The registry key I mentioned is undocumented, but seems to be used by a number of projects, like Chromium, to detect changes to the theme.
This issue has been mentioned on Racket Discourse. There might be relevant details there:
https://racket.discourse.group/t/scope-and-purpose-of-racket-gui/2965/2
The OS-drawn controls aren't working properly when DrRacket is in dark mode.
This issue was created by culling the specific comments from https://github.com/racket/drracket/issues/235.
@jcolivo wrote
@alex-hhh wrote
@mflatt wrote:
@jcolivo wrote