Plasma desktop, HD scaling & snaps

Updated: June 23, 2021

I like the topic of HD scaling in Linux desktops. Like fonts, it's one of the most neglected areas of user experience in the Tux space. By and large, Plasma is the only environment that does scaling well. The other desktops sort of get along with full-integer scaling, font DPI tweaks, and, if you're lucky, some fractional scaling, with 25% increments and such.

Things get extra interesting when you use Plasma with non-native applications, i.e., stuff that goes beyond the default Plasma set. I talked about this in my first article on HD scaling in Plasma, where I showed you a whole bunch of tweaks for software like Firefox, Chrome, old GTK2 stuff, and such. Now, I want to elaborate and show you how to scale snaps, in those scenarios where the scaling does not work well out of the box. Follow me.

Teaser

A wee disclaimer

Before we move forth with gusto and enthusiasm, let's clarify a couple of things. One, I am involved with the snap project, therefore you should expect bias in this article, and thus carefully, with a pinch of salt, take or ignore my advice. However, do note I am writing this article without any specific explicit or implicit regard to my work. This tutorial is part of my series of articles on HD scaling in Linux, and there shall be others, touching on different desktops, tools and whatnot, including Gnome desktop, UHD screens, and then some. Henceforth endeth all and any relation to what I do professionally.

Two, ideally, regardless of which technology we're talking about, everything should work smoothly and perfectly. But that's not the case, for many reasons. Three, the reason why snaps are interesting is that they are self-contained applications, designed to run isolated from the underlying system. This brings about the important question of snap-to-system integration. How do snaps source and use global settings like themes, icons, DPI value, and so on?

The answer to that question is quite complicated. In some cases, they source and use these settings without any problems. The actual outcome also depends on how the specific snaps are packaged. TL;DR: there may be snaps that won't necessarily "see" or "pick" up your selected desktop configuration by default.

In essence, this is no different to what we saw with non-snap Chrome in the previous article, for that matter. The only difference is HOW the relevant settings are applied. As it happens, on my Slimbook, I'm using the same scaling tweak with Microsoft Edge, in the exactly same manner as the tweaks I introduced with Chrome two years back. We need to focus on the actual technical implementation of the change, and this is why we have this little tutorial.

Problem in more detail

All right. So now, the issue that you're facing: an application when installed using the traditional Linux packaging mechanism may scale differently on your desktop compared to the same application installed as a snap. Case in point: VLC. But not just. However, what's interesting is that VLC is a Qt-based application.

Two apps side by side

Solution

As an end user, you can tell the snap (VLC) to use a different scaling factor. This is just like we did with the browsers in the previous exercise. We need to find and edit the VLC desktop file. Standard Linux applications keep the desktop files under /usr/share/applications. Snaps store theirs under:

/var/lib/snapd/desktop/applications

Now, we need to open the vlc_vlc.desktop file and change the Exec line. However, the change is different from what we used with Google Chrome. The reason is, VLC is packaged using a different set of technologies, and the flag that is applicable to Chromium-based browsers isn't applicable here. If you try with the device-scale-factor and force-device-scale-factor flag, you will get an error:

vlc: unknown option or missing mandatory argument '--force-device-scale-factor=1.25'

Instead, you need the QT_SCALE_FACTOR. Hint, this is applicable for all reasonably modern Qt-based applications. Now, edit the Exec line in the desktop file from the one shown below:

Exec=env BAMF_DESKTOP_FILE_HINT=/var/lib/snapd/desktop/applications/vlc_vlc.desktop /snap/bin/vlc %U

To this line here:

Exec=env BAMF_DESKTOP_FILE_HINT=/var/lib/snapd/desktop/applications/vlc_vlc.desktop QT_SCALE_FACTOR=1.XX /snap/bin/vlc %U

For example, use any scale, like 1.16 or 1.25 or whatever you like.

Alternative implementations

If you're not comfortable editing these files (you also need sudo), then you can create your own wrapper launcher to the application. A one-liner something like:

QT_SCALE_FACTOR=1.25 snap run vlc

You can then put this into your own custom script or shortcut. Similarly, you can create your own Plasma menu launcher (entry). As I've outlined in my Plasma is awesome article, this desktop environment is insanely flexible and friendly, and you can tweak anything and everything you want. Among other things, you can manually add new application items in the system menu.

Right click on the menu icon > Edit applications. Then, click on New Item, and populate the fields on the right with the necessary information. You can copy the data from any existing VLC entries, and even set a custom icon if you like, so you can easily distinguish between different editions. Most importantly, set the command to the entry we have above. You can also use the QT_FONT_DPI or DPI environment variable as a different way of scaling the program.

Menu edit

Apps, side by side, fixed

Other application frameworks

VLC is but one of many application types that could be affected. For Chromium-based browsers and Electron applications, you can use the same trick we tried with Chrome (and Edge). Add the scale-factor flag(s) to the Exec line. You can try one, the other, or both:

--device-scale-factor=1.25

--force-device-scale-factor=1.25

For GTK3-based applications, you can use the following environment variable:

export GDK_SCALE="new value"

For the most part, that should cover the bulk of programs you will encounter in everyday use. It's also quite possible you won't have any issues whatsoever. But then, if you do, Qt, GTK and Electron really are the most common ways the software is built nowadays. Now, if you're interested in some other application types and the necessary changes, the Arch Linux wiki has a HUGE list of tweaks, and the various ways you can change the HD scaling - this is applicable with or without snaps.

Conclusion

While HD displays have been around for quite some time, the true problems of HD usage is still ahead of us. For example, if you have a sufficiently large monitor, you might never really feel that interface elements are too small to bother tweaking the scaling factor. But in those situations where you do need it, things sort of fall apart. It's not just Linux - I had plenty of trouble with HD scaling in Windows, too. In this regard, Plasma is really ahead in this game.

So far, when it comes to HD stuff, we covered a variety of browsers, we touched on several GTK2 and GTK3 apps. Hey, I even showed you how to change scaling and/or DPI for WINE applications, yup, yup. Now, we've covered snaps, too. At first glance, things may feel alien or complicated, but they aren't really. Next on the list? Gnome, and then 4K devices. And also, this is where you come in. If you have any requests or questions or suggestions, do tell. There are tons of other frameworks and tools in the Linux world, and we gotta explore them all. Anyway, hopefully, this was a useful and fun exercise. See you around.

Cheers.

You may also like: