Open jagot opened 3 weeks ago
On MacOS, you can detect this by running:
defaults read -g AppleInterfaceStyle
which will print "Dark" if dark mode is on, and an error message otherwise.
From there, you can check this at startup:
is_dark_mode = contains( read(`defaults read -g AppleInterfaceStyle`, String), "Dark")
and set the Makie theme appropriately:
is_dark_mode && Makie.set_theme!(Makie.theme_dark())
I don't think it makes sense to upstream this, since plotting would become quite unpredictable :D - but a small startup package could be nice.
You could also run some async task that queries the dark-mode status every minute or so, and performs the switch if necessary!
I created a small package that forks out to dark-notify to capture the theme switches on macOS:
I assume one could do similar things on e.g. Gnome.
This way, one could conceivably do something like
using GLMakie
using AutoDark
auto_dark() do theme
println("Setting theme: ", theme)
set_theme!(theme == :light ? theme_light() : theme_dark())
end
x = range(0, stop=1, length=1000)
fig = Figure()
ax = Axis(fig[1,1])
lines!(ax, x, sinpi.(2x))
fig
but the problem is that it does not change the theme of already displayed figure (which is what I am after).
Ah, that's not really possible with Makie at the moment I think - you would have to create a new Figure, and that would pick up the current theme. A lot of theme expansion/inheritance is done at the time of plot creation so it's pretty difficult to have that cascade downwards after the fact.
I completely understand that this is a hairy feature to implement and get right, but it would be so nice I still wished to make the feature request :)
Feature description
On some modern operating systems, there is support for automatically switching to a dark theme at sunset and a light theme at sunrise. I would like to be able to specify two themes, a light one and a dark one, and have GLMakie automatically switch between the two, when the desktop theme changes.
Example programs: