← all posts

Linux dark mode: how the hell (2023 edition)

Dark mode on Linux is a mess.

Maybe one day I'll add more explanation, but for now, this is the script you want:

#!/bin/sh

case $1 in
	enable)
		dconf write /org/gnome/desktop/interface/color-scheme "'prefer-dark'"
		echo 'Net/ThemeName "Adwaita-dark"' > ~/.xsettingsd
		systemctl --user kill -s HUP xsettingsd.service
		;;
	disable)
		dconf write /org/gnome/desktop/interface/color-scheme "'default'"
		echo 'Net/ThemeName "Adwaita"' > ~/.xsettingsd
		systemctl --user kill -s HUP xsettingsd.service
		;;
	*) echo "Usage: dark-mode <enable|disable>";;
esac

You'll need xsettingsd set up and running (with home-manager: services.xsettingsd.enable = true, and leave services.xsettingsd.settings alone), plus xdg-desktop-portal and xdg-desktop-portal-gtk (other backends probably also work, but you'll need to adjust the dconf invocation – I found the relevant key here, for example).

If Thunar doesn't pick up the change immediately, check that your xsettingsd is working.

If Chrome doesn't pick up the change immediately, check that you have a org.freedesktop.impl.portal.Settings available somewhere (you can run ReadAll() with an empty array; if it's working, you should see something along the lines of org.freedesktop.appearance.color-scheme: 0).

If Electron apps don't pick up the change immediately, that's unfortunately normal; wait for them to update to a more recent Electron version (Chrome 117 is probably new enough, which corresponds to Electron 27).

relevant links: