On Linux, we have tons of graphical applications in our arsenal. These applications are written in various GUI toolkits. Some of them are very popular such as GTK+, QT, and FLTK. However, currently, GTK is the dominant GUI toolkit of choice for many developers to write open-source and free software.
In this article, our main focus will be on how we can enable dark themes for all GTK applications on our Linux desktop. We’ll start with the current state of theming GTK applications under Linux. Then, we’ll discuss how we can specifically enable the dark theme for GTK 3 and GTK 4 applications.
Finally, we’ll also touch on the subject of installing third-party dark themes for the deprecated GTK 2 applications.
2. The Current State of GNOME and GTK Themes
GNOME is the most popular GTK-based desktop environment in the Linux world. It comes with a very modern and polished desktop and an application theme known as Adwaita. The GNOME Shell is rather limited in terms of visual customization, but we can install third-party plugins for the features it is missing.
The recent versions of GNOME provide a global dark theme for the desktop as well as the GTK 3 and GTK 4 applications. However, the traditional GTK 2 applications don’t obey this rule because of API incompatibilities. Therefore, we’ll need to set the GTK 2 application themes manually.
Additionally, if we’re using a different desktop environment, we’ll still be able to change the GTK theme to a dark one by customizing the GTK configuration files.
3. Enable Dark Theme for GTK 3 and GTK 4 Applications
The most straightforward way to enable the dark theme for GTK 3 and the entire GNOME desktop environment is to turn on the dark mode in the GNOME settings.
Simply head over to Settings → Appearance and select Dark to apply the theme:
Once we apply the theme, the entire desktop environment will be using the dark theme for all its core applications, such as Files, Calculator, GNOME Text Editor, GNOME Builder, and so on. However, we should know that this doesn’t apply to applications that are written in other GUI toolkits, such as QT and FLTK.
For applications that are written in other GUI toolkits, they should provide their own settings for enabling the dark themes or the option to upload the custom dark theme. Additionally, we can also use a tool like qt5ct and qt6ct to apply a dark theme to QT-based applications if they don’t implement their own dark themes.
On other desktop environments like Mate and XFCE, and window managers like i3 and SwayWM, there’s no straightforward way like the one we saw to enable the dark theme for the GTK application. For that reason, we will need to configure it manually, which we’ll cover next.
3.1. The GTK 3 Configuration File
A well-written GTK application should obey the rules defined in the global GTK configuration files. These configuration files are defined in the ~/$XDG_CONFIG_HOME/gtk-3.0 directory. Conventionally, the $XDG_CONFIG_DIR defines the directory to be ~/.config.
In the gtk-3.0 directory, we can define our own settings in the settings.ini file. So, let’s go ahead and specify the settings for a dark theme:
The above option only works if there is a dark theme available for the GTK 3 applications. Therefore, this option is viable if and only if the theme has a dark variant. Nevertheless, when we install a GTK 3-based application from our official distribution repository, it should also install the Adwaita theme, which has a dark variant, as a dependency.
3.2. Setting Up Themes Using GNOME Tweaks Tool
GNOME Tweaks Tool is a graphical utility that lets us set fonts, themes, and other tweaks for GTK 3 and GTK 4 applications. This tool is a user-friendly way to generate the ~/.config/gtk-3.0/settings.ini file.
We can install it from the official package repository using a package manager like apt:
$ sudo apt install gnome-tweaks -y
Once installed, we can launch it and set the default theme to Adwaita-dark or any user-installed dark theme:
The application should take effect instantly upon changing the theme.
3.3. The GTK_THEME Environment Variable
The GTK_THEME environment variable can be used to force-load a theme for all applications or for a specific application. For instance, we can load the Calculator application with the dark theme by specifying the “dark” variant:
$ GTK_THEME=Adwaita:dark gnome-calculator
This environment variable should apply to both GTK 3 and GTK 4 applications.
Additionally, we can also set this environment variable in our login shell profile. So, we wouldn’t have to set it all the time:
$ echo "export GTK_THEME=Adwaita:dark" >> ~/.profile
4. Dark Theme for GTK 2 Applications
The theming of GTK 2 applications is as good as the distribution that we use. For instance, Ubuntu uses the Yaru GTK theme. So, it implements the dark theme for all the GTK applications, including the GTK 2 applications. So, if we turn on the dark mode from Settings, we should have a good-looking dark theme for GTK 2 applications.
However, if we are using other Linux distributions that do not have a built-in GTK 2 theme, our best bet is to look for a dark theme on the Internet and install it manually. In addition to that, some distributions like Arch and Manjaro have added a lot of themes for GTK 2 applications to their official community and AUR repositories.
4.1. Using Third-Party Dark Themes
One of the major websites that contain a plethora of such themes is GNOME Look. We can browse for community-designed dark themes and download them for free. Some of the famous dark themes on the Linux desktop include Arc, Adapta, Materia, and Numix.
As an example, we can download the Arc theme from its official repository using curl:
$ curl -Ls https://github.com/horst3180/arc-theme/archive/refs/tags/20170302.tar.gz -O arc.tar.gz
Once we’ve downloaded a theme, we can simply extract the contents to the ~/.local/share/themes directory:
$ tar -xvf arc.tar.gz -C ~/.local/share/themes
Afterward, we can either use the GNOME Tweaks tool or the ~/.config/gtk-3.0/settings.ini file to set the theme.
In this article, we discussed how to apply dark themes to GTK applications. We covered how we can achieve this by changing the GTK config file, either directly or using the GNOME Tweaks Tool, and by changing the GTK_THEME environment variable.
Finally, we covered how we can download and install third-party themes for GTK 2 applications.