How To Use A Different GTK 3 Theme For Specific Applications

This article explains how to apply a different GTK 3 theme to specific applications (a theme other than the global/desktop GTK theme).

So why would you need to set some applications to use a GTK3 theme different than the theme set for your whole desktop? There are cases in which an application doesn't look as it's supposed to / looks broken with a particular theme, but you want to continue using that theme for the other applications on your Linux desktop. Or maybe you prefer to use a particular theme only for one or two applications, while using a different theme for the rest of applications, e.g. you could set text editors to use a dark theme, while using a light theme for all other applications on your desktop.

In this screenshot, Tweaks uses the Mint-Y theme, Nautilus uses Canta theme, Gedit uses Yaru-dark and Eolie web browser (installed from Flathub) uses Plata theme. They are all running in the same time.

Let me give you an example.

Ubuntu 19.10 uses a mixed light and dark theme by default, but different from the one used in earlier Ubuntu releases: the window title is dark, but the menubar is now light. Due to this, code editors like Visual Studio Code, Atom or Sublime Text, which use dark color themes by default, have a white menubar, with everything else being dark.

If you prefer to keep this setup (mixed Yaru theme as your global GTK 3 theme, and a dark color theme for VS Code / Atom / Sublime Text) but change the VS Code / Atom / Sublime Text menubar to a dark color so it doesn't look out of place, you could use the instructions in this article to set VS Code / Atom / Sublime Text to use the Yaru-dark theme, while having all other applications use the default mixed Yaru theme.

You might also like: How To Get Dark GNOME Shell Menus And Dialogs On Ubuntu 19.10 With Yaru Theme

To change the GTK theme on a per-application basis we'll use the GTK_THEME environment variable, which "is intended mainly for easy debugging of theme issues" according to this GNOME GTK page. Due to this, it's not guaranteed this option works everywhere (it actually doesn't work with DBus activated applications), and it may stop working at some point.

It's important to mention that this changes the application theme for any GTK 3 app, but the window decorations remain unchanged (continue to use the global GTK 3 theme) for applications that don't use client-side decorations.

This works for native applications, as well as Flatpak and Snap packages, as long as the theme you want to use for a particular application is supported by Flathub/Snapcraft (as a side note, Flatpak applications support support a lot more third-party themes than Snap).

Launching an individual application with a theme different than the global GTK3 theme

To overwrite the default GTK theme on a per-application basis, set the GTK_THEME environment variable, with the theme you want an application to use as its value, when launching the application. Like this:

GTK_THEME=<theme-name> <application>

You'll need to replace <theme-name> with the name of the theme (as it is shown in the Tweaks app for example), and <application> with the application executable.

It's important to note that you need to close all running instances of the application before running that app with a custom theme (in case it's running in the background you could kill it, e.g. to kill all running Nautilus instances: killall nautilus).

Let's look at an example. Say you want to launch Gedit with Yaru-dark as its theme:

GTK_THEME=Yaru-dark gedit

Or launch Nautilus (Files app) with Canta as its theme, keeping whatever other theme you have set for the other applications:

GTK_THEME=Canta nautilus

In case the theme you want to set has a dark variant but it's not separate, specify that you want to use a dark theme like this: GTK_THEME=theme-name:dark. For example, to make an application use the Adwaita dark theme (which doesn't have a separate Adwaita-dark folder, but it does have dark theme support), launch that application like this:

GTK_THEME=Adwaita:dark <application>

Always launch particular applications with a custom GTK 3 theme

In case you want to launch an application with a particular GTK 3 theme (different than your desktop's GTK theme) every time you click that application's icon in your applications menu or launcher, this is what you need to do.

Start by copying the application's desktop file from /usr/share/applications to ~/.local/share/applications. If you edit the desktop file directly in /usr/share/applications, the desktop file is overwritten on each application update, so you would have to redo this. But by copying the desktop file to ~/.local/share/applications, the modifications will persist through upgrades (and they only affect your user).

Next, open the application desktop file (the one located in ~/.local/share/applications) with a text editor such as Gedit, look for the line(s) that starts with Exec=, and immediately after = add env GTK_THEME=<theme-name> followed by a Space. Replace <theme-name> with the name of the theme (as it is shown in the Tweaks app for example), but don't modify anything else.

Example. Let's say you want to force VS Code to use Yaru-dark as its theme, while using a different theme for all other apps on your desktop. In this case, copy the code.desktop file from /usr/share/applications to ~/.local/share/applications/, open code.desktop from this new location with a text editor, and look for the Exec line.

The original VS Code desktop file (code.desktop) has the following Exec line:

Exec=/usr/share/code/code --unity-launch %F

After editing it to force VS Code to use the Yaru-dark theme, this line becomes:

Exec=env GTK_THEME=Yaru-dark /usr/share/code/code --unity-launch %F

If the application has multiple Exec lines (for example if the application desktop file has support for desktop actions which show up when you right click the app icon), do this for each of them.

Remember to close all running instances of the application before running it with a custom theme!

via r/Ubuntu (u/manyfacedgodd)