Dark mode for GTK in Windows
If you have a proper runtime for GTK, you only need to set a single environment variable in Windows, and you’ll have a good basic dark mode in every GTK app that supports it. GTK ships with Adwaita out of the box, which has a dark theme, and here are a couple ways of enabling it without having to figure out where to put themes and their assets, learning to create GTK stylesheets from scratch or populating your settings.ini with options that may or may not do anything at all for your particular situation… provided your app allows it. Let’s get to it.
Four ways to dark mode
Either one of these methods will get you to dark mode and three of them are persistent.
Note: everything in the code blocks are either labels, keyboard shortcuts or verbatim input text, including quotation marks. Note that quotes are " and ', not “, ”, ‘, or any other fancy symbols.
Non-permanent way
This solution requires launching your app from the command line, and only works for apps launched from there.
- Run cmd.exe (From the start menu, or
WIN+R→cmd), - Type
set GTK_THEME=Adwaita:dark, - Navigate to the folder where your GTK-based app is located with good old
cd, in my casecd "C:\Program Files\Geany\bin", - Run the app by typing in the name of the executable on the command line, in my case
geany(the .exe is optional).
You should now have your app display in dark mode.
Permanent way in Windows GUI
If you don’t like working on the command line, this is where you want to look.
- Find your way into the advanced system settings and press the “Environment variables” button (
Win+R→rundll32 sysdm.cpl,EditEnvironmentVariablesfor a shortcut), - Choose if you want to add the variable only to this user account, or the entire system, and press
New…,
- Note that you can only edit your user environment with the Run shortcut
- In the
Variable namefield, inputGTK_THEME, and in theVariable valuefield inputAdwaita:dark, - Press OK, reboot or log out and back in again and you’re good to go.
If you don’t want to do that last step, check the next method.
Permanent way on the command line
This time, you will need to launch the terminal as an administrator, regardless of whether you intend to add the variable to the entire system or only your user. That probably goes for the previous method, too.
- Search for
cmdorcommand promptin the start menu and select the actionRun as administrator, - Type either of the following, noting the
xinsetxand that there is now a space instead of=between the variable and its value: - For user account:
setx GTK_THEME Adwaita:dark - For the whole system:
setx GTK_THEME Adwaita:dark /m - That’s it! You’re good to go. You can close the command line and will hopefully not need to open it again for a while.
Permanent way in the registry
Worn and beaten disclaimer: Working in the registry can destroy your Windows installation fatally. You have been warned.
Environment variables are stored in the following places (on my system, anyway):
- User:
[Computer\HKEY_CURRENT_USER\Environment] - System:
[Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]
Simply add a string value with the name GTK_THEME and value Adwaita:dark there, and you’re done. You may need to log out and back in again if it doesn’t work after restarting the app.
Bonus - the GTK Inspector
If you want to play around with the GTK stylesheet for an app, you can start it in interactive debug mode. To do so, simply follow either of the four methods above, but replace the variable name with GTK_DEBUG and set its value to interactive, e.g. set GTK_DEBUG=interactive in the second step of the non-permanent method.
Tip: The target button (at the top left) is your greatest friend. You can get the selectors from the CSS Selector menu option if you switch to the details view (shown automatically when selecting a target, or from the next button at the top left).
Since GTK already has a basic theme, you will need to be specific with your selectors, preferably using the id (in parentheses) if you’re theming a specific app.
Have fun!
Conclusion and caveat
I hinted at it in the introduction, but this may or may not work for different reasons. One could be that your app explicitly prevents theming and only accepts the package’s included stylesheet. Another could be if you’re running an older or outdated version of GTK which does not function the way later releases of GTK3 does… although, honestly, that shouldn’t be a problem if you can run it on Windows in the first place.
Either way, I hope this helps someone out there, and if not, at least now you know how to set environment variables in Windows properly.