Set QT/GTK scaling per app in NixOS

Is it possible to bypass Global Scaling per app (in KDE Plasma in my case) using NixOS? My intention is to use certain apps without scaling for pixel perfect rendering, DaVinci resolve in particular, since it has its own UI scaling. With my monitor setup scaling is vital, so I really want to avoid having to manually turn it off when I use a certain app.

I expected I could set an environment variable using environment.sessionVariables but I can’t figure out how to do it there, let alone for multiple apps.

I also tried making duplicate .desktops (referencing this post Scaling individual applications in KDE Plasma - #2 by winnie - KDE Plasma - Manjaro Linux Forum), but that didn’t work.

You can create your own desktop files with scaling turned off and put them into environment.systemPackages:

{ pkgs, ... }:

let

  desktopFiles = pkgs.linkFarm "desktop-files" [
    { name = "share/applications";
      path = ./dir-containing-desktop-files;
    }
  ];

in

{
  environment.systemPackages = [ desktopFiles ];
}

They will be symlinked to /run/current-system/sw/share/applications/. To replace an existing one I guess lib.hiPrio desktopFiles may work, but I never tried.

1 Like

Yes, hiPrio works for this usecase, I use it to mask existing desktop files

2 Likes

Ah looks like it isn’t a Nix issue. Turns out if you put the scaling as “1” as I was doing, it doesn’t override the Global Scaling, instead it multiplies it by 1, doing nothing. Setting it to .83 or .75 causes glitches in Qt apps, so that’s a no go. And DaVinci Resolve doesn’t seem to respond to those arguments at all, nor the ones suggested in Arch Wiki: QT_DEVICE_PIXEL_RATIO=2 and QT_AUTO_SCREEN_SCALE_FACTOR=true

It turns out, at least on KDE Plasma, if you put your own .desktop file in ~/.local/share/Applications it will override the other .desktop when you launch an app.

I fixed a totally separate scaling issue this way. I changed the exec line in my .desktop for Krita to Exec=env QT_AUTO_SCREEN_SCALE_FACTOR=1 krita %F

QT_AUTO_SCREEN_SCALE_FACTOR does affect Davinci Resolve, but it does not (in any app) make 100% zoom display pixels 1:1.