Date
May. 19th, 2024
 
2024年 4月 12日

Post: Flatpak Apps Look Out of Place? Here's How to Apply GTK Themes on Flatpak Applications

Flatpak Apps Look Out of Place? Here's How to Apply GTK Themes on Flatpak Applications

Published 15:12 Dec 17, 2023.

Created by @ezra. Categorized in #Technology, and tagged as #Flatpak.

Source format: Markdown

Table of Content

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

flatpak-app-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, only a few GTK themes can be installed for the job.

If you have found a beautiful GTK theme, your Flatpak applications will still use their default appearance. But wait! There is a workaround.

Before we proceed, let’s understand why Flatpak apps have this behavior.

Flatpak apps run inside a ‘container’, so they don’t 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. Don’t expect it to automatically change the themes of Flatpak apps when you change the system theme. You can, however, change it for all Flatpak apps in one single command.

Let’s see how to achieve that. Please note that this method requires that you are familiar with the Linux command line, and you can find your way around the terminal.

Step 1: Give Flatpak apps access to GTK themes and icons location

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

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

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

Notice that you can’t give access to /usr/share/themes because, according to Flatpak documentation they are blacklisted.

Alternatively, you can do this on a per-application basis as well. You need to specify the application ID for changing the theme.

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

Step 2: Tell Flatpak apps which theme/icon to use

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

sudo flatpack override --env=GTK_THEME=my-theme 
sudo flatpak override --env=ICON_THEME=my-icon-theme

Alternatively, for individual applications, run:

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

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

Don’t forget to restart the app to get the effect.

Test the theme change by running a Flatpak app

If the application is already running, you’ll have to close and start it again. Remember, if the app is reduced to tray, you need to quit and reopen it. You’ll see that the newly started application uses the theme you specified earlier.

Pinned Message
HOTODOGO
I'm looking for a SOFTWARE PROJECT DIRECTOR / SOFTWARE R&D DIRECTOR position in a fresh and dynamic company. I would like to gain the right experience and extend my skills while working in great teams and big projects.
Feel free to contact me.
For more information, please view online résumé or download PDF
本人正在寻求任职 软件项目经理 / 软件技术经理 岗位的机会, 希望加⼊某个新鲜⽽充满活⼒的公司。
如有意向请随时 与我联系
更多信息请 查阅在线简历下载 PDF