Your submission was sent successfully! Close

Thank you for contacting us. A member of our team will be in touch shortly. Close

You have successfully unsubscribed! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates about Ubuntu and upcoming events where you can meet our team.Close

How to ensure your snap uses the correct theme

This article is more than 3 years old.


An app is an app is an app. But in the world of Linux, things are a little more nuanced. Take VLC as an example. The software may be packaged ever so slightly differently in various Linux distribution archives, even different releases of the same distribution – the av01 codec is an interesting use case in this regard. Then, software may also be packaged as a snap. Due to their security containment and bundling of necessary dependencies, snaps can behave or look differently to their classic RPM or Deb counterparts. As a publisher, you want to make sure that your users get a consistent look & feel, regardless of the target platform.

In this blog post, we’d like to highlight several ways you can ensure your users get the best visual experience with snaps. While there may still be outstanding issues with specific aspects of desktop usage, the tips and tricks today should help narrow that gap.

It’s a matter of style

We already talked about the snap theming roadmap toward the end of 2020. The project aims to simplify and automate the usage of visual elements in snaps. It also provides a template for how developers and publishers can include their own custom assets as parts during the snap build process. If you want to make sure your snap has a distinct style, you can add the necessary icons, themes, or other elements inside the snap.

...
parts:
  theme:
    plugin: dump
    # downloaded from https://www.gnome-look.org/p/1309630/
    source: ./TraditionalHumanized.tar.gz
    organize:
      gtk-*: share/themes/TraditionalHumanized/
    stage:
      - share/themes/*/gtk-*
...

But it is also possible you may not want to use any custom assets, and you just want the snap to integrate well into the desktop. Today, the easiest way to accomplish that is by using one of the supported desktop extensions in the snap build process.

Extend, Embrace, Snap

The concept of snapcraft extensions was introduced to help developers achieve faster, more consistent results with their snaps. Behind the scenes, the extensions abstractize a number of common declarations and reusable building blocks, making sure the developers can build their snaps quickly and successfully.

Notably, the desktop-focused extensions like GNOME, KDE and Flutter can significantly improve the overall experience. For instance, the GNOME 3.38 extension will automatically configure a number of interface connections, various environment variables necessary for the build step and runtime, layout sets, and commonly used library dependencies.

apps:
    tali:
        extensions: [gnome-3-38]
        command: usr/bin/tali
...

Quite importantly, the use of the extension will also make sure that snaps correctly use the necessary visual assets, like themes, and that snaps will respond correctly to look & feel changes in the system. The solution is not perfect at the moment, and there may be scenarios where the results differ from the Deb or RPM versions of the app on the system. However, the extensions go a long way toward mitigating the discrepancies in the visual experience.

End users can also choose their own themes

In some cases, some of your installed snaps may simply not be able to utilize the existing development features in the snap ecosystem. For example, snaps built years back predate the concept of extensions, and most likely do not have them declared in their snapcraft.yaml, and consequently, do not use some of the recent improvements introduced through the extensions. However, you can manually instruct any which snap to use any available theme on your host – even different themes for different snaps, if you like.

In the GNOME desktop, you can run something like:

GTK_THEME=Adwaita:dark snap run gnome-system-monitor

In the Plasma desktop, you can use the QT_STYLE_OVERRIDE environment variable. The value must be set to an existing, valid style available in the desktop. For instance:

QT_STYLE_OVERRIDE=igor snap run vlc
VLC media player 3.0.14 Vetinari (revision 3.0.14-0-g41878ff4f2)
QApplication: invalid style override 'igor' passed, ignoring it.
Available styles: Breeze, Windows, Fusion

You can then create your own shortcuts or application launchers, which will then launch the snaps styled how you need it, whether matching the system theme, or a different setup you desire.

You can also use other environment variables, like say QT_SCALE_FACTOR or GDK_SCALE to configure either fractional HD display scaling factor on smaller devices, in case your snaps are not rendered the same size as their classic counterparts.

Summary

Nailing the perfect look & feel for Linux applications is not an easy task, snaps notwithstanding. Things become even more complicated with self-contained, standalone application formats like snap, due to security confinement and isolation from the underlying system. However, there are ways the publishers – and users – can make things better. On the development side, desktop extensions can massively help standardize and improve the consistency of looks for snaps. Alternatively, the developers can also bundle their own visual assets with their applications, or provide them as separate snaps. The users can also manually override styles.

We’d like to hear from you – the more you tell us why something isn’t working as well as you believe it should, the more we can take that feedback into account, and improve the snap ecosystem. The best way to do that is to join our forum, and let us know your thoughts.

Photo by John Schaidler on Unsplash.

Talk to us today

Interested in running Ubuntu in your organisation?

Newsletter signup

Get the latest Ubuntu news and updates in your inbox.

By submitting this form, I confirm that I have read and agree to Canonical's Privacy Policy.

Related posts

We wish you RISC-V holidays!

There are three types of computer users: the end user, the system administrator, and the involuntary system administrator. As it happens, everyone has found...

Improving snap maintenance with automation

Co-written with Sergio Costas Rodríguez. As the number of snaps increases, the need for automation grows. Any automation to help us maintain a group of snaps...

Imagining the future of Cybersecurity

October 2024 marks the 20th anniversary of Ubuntu. The cybersecurity landscape has significantly shifted since 2004. If you have been following the Ubuntu...