Go back to the main page.

lirons tildelog

html test

Toggling light/dark “mode” under Linux

January 12, 2025 — ~liron

I have been using so-called “dark mode” way back in 2005, before everyone starting to hop on that trend since 2017 or so. Nowadays, most Desktop Environments change the color theme automatically, and Emacs packages exist to adjust the editor colorscheme.

However, I have built my custom solution over the years and will likely stick with it, because I prefer to use plain window managers over DEs. It works as a switch-color.sh script, which is automatically called by redshift (or on demand via shortcut) and toggles light/dark in:

  • GTK Applications
  • Qt Applications
  • The XFCE Terminal
  • Emacs
  • Applications that respect dconf, like Firefox.

Basically, the script stores a variable “DARK=1” or “DARK=0” in a shell environment file and reads this back when executed. Then, it sets the colors as follows:

# Xfce terminal: Dark
xfconf-query -c xfce4-terminal -p /color-foreground -s "#dededd"
xfconf-query -c xfce4-terminal -p /color-background -s "#002b36"

# Emacs
ln -fs colors-dark.el ~/.emacs.d/colors.el

# GTK Theme / For applications that respect dconf/gsettings
gsettings set org.gnome.desktop.interface color-scheme prefer-dark
gsettings set org.gnome.desktop.interface gtk-theme Adwaita-dark

# Qt
sed -i '/^style=Adwaita/style=Adwaita-Dark/' ~/.config/qt6ct/qt6ct.conf

# cinnamon
dconf write /org/cinnamon/desktop/interface/gtk-theme "'Adapta-Nokto'"

As you can see, it is just a matter of using the config-tools to change the respective settings. Except for Emacs, all applications support switching the theme live without restarting.

In Firefox, websites even toggle the colors live. The only requirement is that a gsd-settings daemon is running.