moin icon indicating copy to clipboard operation
moin copied to clipboard

Automatic light/dark theme switching with `prefers-color-scheme` CSS media query

Open nekohayo opened this issue 2 years ago • 5 comments

It would be nice if MoinMoin's default stylesheet / theming system would automatically offer a dark stylesheet at nighttime. GitHub itself does this, for example.

My operating system does the switch for me everyday at the correct times, and my web browser follows suit, telling webpages' CSS mediaqueries that dark is now "preferred" or not.

MoinMoin could either automatically offer a dark stylesheet at nighttime using this trick, i.e. "automatic" light and dark themes "based on browser/OS setting", as the default behavior (rather than needing users to turn this on as a setting), though maybe some users will want the ability to override the automatic behavior.

You can detect the system's state using this simple piece of CSS, such as:

@media (prefers-color-scheme: dark) { blah blah }

This might be interesting not only for desktop computers, but also for people using the web interface on mobile devices; that way if they're reading messages/directions at night on the street or in a dimly lit location, they won't get blinded by the white screen. It also tends to consume less power on AMOLED displays.

nekohayo avatar Sep 07 '23 03:09 nekohayo

@UlrichB22 i would like to work on this

omjamnekar avatar Oct 19 '25 14:10 omjamnekar

@omjamnekar, thanks for your support. I like the new dark theme.

Can you check the other themes? In the “Focus” theme e.g., the input fields are now black, but everything else seems unaffected by the changes. This is a problem with the use of variable names in the different designs. Some variables are used globally. Do you have any ideas for a naming concept that includes global variables and theme-dependent variables?


Image

UlrichB22 avatar Oct 21 '25 16:10 UlrichB22

@omjamnekar are you still working on this issue?

The PR still needs some optimization, such as

  • using the newly introduced variable names in the common.css file and
  • fixing side effects on themes other than the default “topside” theme.

UlrichB22 avatar Nov 01 '25 17:11 UlrichB22

I might not be able to work on it

omjamnekar avatar Nov 01 '25 17:11 omjamnekar

I might not be able to work on it

Thanks for supporting moin. I'll try to finish the feature.

UlrichB22 avatar Nov 01 '25 18:11 UlrichB22