Monday, October 2, 2017

LightDM and 4K / HiDPI displays

I have recently acquired a 4K display and the fonts were tiny on it. I did a quick Internet search and found several questions from people having the same problem.

Most suggestions were involving around changing the font DPI. But this has undesirable effects, such as fonts being so much larger than other elements. I opted in to change scaling/resolution. To be honest from few meters away, I can't tell the difference between FullHD and 4K anyway.

The solution was setting the scaling with xrandr. To be able to apply the settings at startup, one should use the greeter-setup-script and session-setup-script options in lightdm. Below is how my /etc/lightdm/lightdm.conf file looks like

[SeatDefaults]
user-session=xfce
greeter-show-manual-login=true
greeter-setup-script=/etc/profile.d/lightdm.sh
session-setup-script=/etc/profile.d/lightdm.sh
 
Inside the /etc/profile.d/lightdm.sh file (this file needs to have executable permissions for lightdm to be able to execute it). You have to change HDMI-0 with the name of your display output. Unfortunately making too large scaling causes jagged edges. I had good quality with 0.5. The alternative line works much better.

#!/bin/sh
if [ ! -z "$DISPLAY" ]; then
  # Scale the display
  #/usr/bin/xrandr --output HDMI-0 --scale 0.5x0.5
  # Alternative method, this may give better results
  /usr/bin/xrandr --output HDMI-0 --scale-from 1920x1080
fi

There was one problem with this. I use KODI and it does not seem to care about the scaling. Therefore it didnt fit to screen. In my system KODI has it's own user. I created a .profile file under this user with the following information to rescale the display when KODI starts.

#!/usr/bin/env bash
/usr/bin/xrandr --output HDMI-0 --scale 1x1

If anything goes wrong. You should check your file permissions.

1 comment: