TranslateProject/sources/tech/20211102 Flatpak Apps Look Out of Place- Here-s How to Apply GTK Themes on Flatpak Applications.md
DarkSun f5e7aba8f0 选题[tech]: 20211102 Flatpak Apps Look Out of Place? Here’s How to Apply GTK Themes on Flatpak Applications
sources/tech/20211102 Flatpak Apps Look Out of Place- Here-s How to Apply GTK Themes on Flatpak Applications.md
2021-11-02 05:04:11 +08:00

7.1 KiB
Raw Blame History

Flatpak Apps Look Out of Place? Heres How to Apply GTK Themes on Flatpak Applications

One of the reasons why some users avoid installing Flatpak apps is that most Flatpak apps dont change their appearance as per the current system theme. This makes the applications look out of the place in your otherwise beautiful set up.

Flatpak apps do not match system theme

The official way to apply GTK themes to Flatpak apps is by installing the desired theme as a flatpak. However, there are only a few GTK themes that can be installed as Flatpak.

This means that if you found a beautiful GTK theme, your Flatpak applications will still be using their default appearance. But wait! There is a workaround.

In this tutorial, I am going to introduce you a way to make flatpak apps aware of external GTK themes.

Applying GTK themes to Flatpak applications (intermediate level)

Before we proceed, lets understand why flatpak apps have this behavior.

Flatpak apps run inside a container, so they dont have access to the host filesystem, network, or physical devices without explicitly setting the appropriate permission, and that is what we are going to do.

As I said earlier, this is a workaround, not a flawless solution. Dont expect it to change the themes of Flatpak apps automatically when you change the system theme. You can, however, change it for all Flatpak apps in one single command.

Lets see how to achieve that. Please note that this tutorial requires that you are a bit familiar with the Linux command line and you can find your way around the terminal.

Step 1: Give Flatpak apps access to GTK themes location

GTK themes are located in /usr/share/themes for all users, and in ~/.themes for a specific user.

To give all flatpak packages permission to access ~/.themes run the following command:

sudo flatpak override --filesystem=$HOME/.themes

Notice that you cant give access to /usr/share/themes because according to flatpak documentaion they are black listed.

Alternatively, you can do this at per-application base as well. You need to specify the application ID for which you are going to change the theme.

sudo flatpak override org.gnome.Calculator --filesystem=$HOME/.themes

Step 2:Tell Flatpak apps which theme to use

Giving access to ~/.themes is not enough because this directory may contain multiple themes. To tell flatpak which GTK theme to use, first get the name of the desired theme and then apply the following command:

sudo flatpak override --env=GTK_THEME=my-theme

As you can see in the screenshot below, there is two themes available, Ant-Bloody and Orchis-dark. Copy and paste the exact theme name in the above command:

Set GTK themes for all Flatpak apps

Alternatively, for individual application, run:

sudo flatpak override org.gnome.Calculator --env=GTK_THEME=my-theme

and replace my-theme with the folder name of the theme you want to apply (and it must be located in ~/.themes).

Step 3: Test the theme change by running a Flatpak app

If the application was already running, youll have to close and start it again. Youll see that the newly started application uses the theme that you had specified earlier.

Here is a screenshot of GNOME calculator and GNOME builder (Flatpak version) before the above steps:

Flatpak applications with default Adwaita theme

And after the above steps (With Canta GTK theme):

Flatpak applications with Canta Dark theme

Thats better, right? Now, I could leave you here but it would be appropriate to mention the steps for reverting the changes.

Revert the changes

You can reset the changes by resetting all the overrides at once. Please note that this will reset any previous overrides you had explicitly set.

sudo flatpak override --reset

Alternatively, you can reset permissions at package level as well:

sudo flatpak override --reset org.example.app

If you have previously overridden the GTK_THEME or filesystem for a specific Flatpak package using “flatpak override” resetting will help you set it again.

Additional information

Normal GTK applications load GTK theme specified by gsettings, you can run the following command to get currently applied GTK themes:

gsettings get org.gnome.desktop.interface gtk-theme

And to set the GTK theme, run:

gsettings set org.gnome.desktop.interface gtk-theme my-theme

To do the above with Flatpak, you have to enter a shell session inside the container of the desired application by running:

flatpak run --command=bash org.gnome.Calculator

And inside this session, run the above command:

gsettings set org.gnome.desktop.interface gtk-theme my-theme

But that did not work with me, so I resorted to use GTK_THEME environment variable, which is supposed to be used for debugging purpose. If you managed to make gsettings work, then tell me in the comments.

I know its not an automated solution but at least it gives you the option to change the themes for the Flatpak applications with a couple of commands. This way, you can make the Flatpak application integrate with the rest of the system.

I hope this helped you. If you face any issues, please mention them in the comments.

Author Info: This article has been contributed by Its FOSS reader Hamza Algohary and edited by Abhishek Prakash. Hamza is a computer engineering student and a Linux and open source enthusiast. He also develops apps for Linux desktop. You can find his work on his GitHub profile.


via: https://itsfoss.com/flatpak-app-apply-theme/

作者:Community 选题:lujun9972 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出