Perfecting Pixels in Linux
So many ways to create the pixel perfect laptop, and it seems with these ever increasing hidpi monitors we create a lot of work for ourselves. It is nice though to have pixels so small we can no longer see the edges and even the blurriness begins to fade, but not entirely depending on how something is scaled.
It seems every Desktop Environment, of which there are many, wants to handle scaling and dpi density a little differently. Some apps are built for GDK, GTK, Gnome, QT, KDE or who knows what else, but the question is how do we reasonably reign them all in?
Initially, I handled the issue by looking towards the apps themselves and trying my hand at manually configuring various scaling options provided by the app, but really that is not an ideal method.
Double Scaling
If all you want to do is double your scaling then something like this command is all you need. Just make sure you scale 1 beforehand. This will cleanly scale your 2880x1800 to be more like 1440x900.
xrandr --output eDP-1 --mode 2880x1800 --scale 1
xrandr --output eDP-1 --mode 2880x1800 --scale 0.5
Alternatively, just do the following or change your resolution in the GUI of course.
xrandr --output eDP-1 --mode 1440x900 --scale 1
If you’re doing multiple monitors however (and keeping your laptop’s hidpi to a scale of 1) and the external monitor is not HiDPI but is something in between, like a 2560x1200 monitor, then this type of command can be very handy to create a consistent experience between your laptop and the external monitor.
The fb argument creates a framebuffer equivalent to a higher res screen and is surprisingly readable, even on a lower res screen. You essentially double your external monitors dimensions, but then need to add the appropriate pixels to cover your native monitor as well. You have to create a virtual rectangle of pixels that can hold both monitors inside of it, hence framebuffer. Manipulate the positioning argument pos as you see fit.
xrandr --output HDMI-3 --pos 0x0 --mode 2560x1440 --scale 2x2 --fb 5120x4680xrandr --output eDP-1 --pos 500x2880 --mode 2880x1800
Fractional Scaling
And now to the more complicated and specific scaling options to put things exactly at the scale you may want.
The best method I have found is the following. (e.g. 1.5 is just an example)
Fractional Scaling for GDK apps
env GDK_DPI_SCALE=1.5 firefox &
Fractional Scaling for QT apps
env QT_SCALE_FACTOR=1.5 krita &
Scaling for apps like Sublime Text 3 (that don’t accept GDK fractional scaling)
env GDK_SCALE=2 /opt/sublime_text/sublime_text
If doubling is too much, some apps like Sublime also allow you to configure the ui scaling in a user profile that I will not go into here. I am trying to demonstrate broad solutions, not narrow ones. You may also want to look into devPixelsPerPx for Firefox, if you want even finer control on the scale of websites.
Persistent App Scaling
Typically you can search for the apps desktop file location and then simply add what I mentioned above to any of the lines that start with Exec. This will allow the app to allows have the right scaling, updates to the app however may override it, needing you to re-apply it.
locate appname | grep desktop
Another important aspect of scaling well in KDE, specifically, is to mind the Xft.dpi setting. By default Xft.dpi is set to 96, at least on my hidpi macbook pro, and originally I bumped it up to 192 because it played well with my themes, but it was really too large.
To resolve this I played with dpi until I settled on what I found to be the most ideal size, despite the fact that my non-friendly hidpi themes did not appreciate it. The dpi setting that I found works best on hidpi 2880x1800 monitors is 116 and I placed the setting in my home directory to load on login. My cursor was also increased to 36, both in the same file and manually in GUI interface for cursors, otherwise you may see inconsistencies with cursor sizes varying.
vi ~/.Xresources
Xft.dpi: 116
Xcursor.size: 36
So how do you fix a theme, that is likely not operating at hidpi? (Typically by giving you unusable and unsightly large borders around the top, left, right and bottom of your applications.)
Find the rc file of the current theme and update a few parameters in it. I often use locate for finding a file location and then work from there, be mindful of case sensitivity — if you’re having difficulty finding your file.
/home/user/.local/share/aurorae/themes/McMojave/McMojaverc
Original Content
PaddingTop=35
PaddingBottom=85
PaddingRight=75
PaddingLeft=75
New Content
PaddingTop=30
PaddingBottom=70
PaddingRight=65
PaddingLeft=65
I didn’t come up with all of these solutions in a single day, but this is culmination of things I have learned over the course of weeks. Many things that did not work well have been left out entirely, but hopefully this article may be of some help to some people who are going through something similar.