Changing desktop scaling on demand in Ubuntu

After a (I have to say) really nice experience with Windows 10, I decided to give a try again to Ubuntu in my Ultrabook. In particular, after a long time out of the Desktop Linux world, I chose to try Kubuntu as I heard amazing improvements since the last time I used the KDE desktop (KDE 3) and GNOME, despite being really nice, had some annoyances that I could not stand for long. But not as many as I could imagine I would find while trying to setting up scaling in KDE.My Ultrabook laptop is a Toshiba KIRA 107, and it has a HiDPI screen (2560x1440px in a 13′ screen). When I work at home, I use an additional 21:9 WQHD external monitor (2560x1080px). I usually have the external monitor on the left side, and the laptop on the right side of my desk.

Physical screen size

The physical size of the monitors

Screenshot_20170623_024058

The pixel resolution size does not resemble at all the physical size because of the laptop HiDPI screen

However, although KDE has a pretty decent support of scaling for HiDPI screens, I run over some problems that made my setup complicated:

  • KDE does not have scaling per screen, at least while using X.
  • When changing the number of monitors, it does not recalculate at all the scaling of the applications based on the screen information.
  • The scale can only be set manually, and changing it implies logging out and logging in back again every time.

All that combined made my everyday life harder

  • If I set up no scaling at all (most of the time I work on my desk, then when I unplugged the external monitor I had to change the scaling to 2x, log out and log in back again.
  • Furthermore, if I wanted to plug it back, I had to redo the whole process, but setting up the scaling to 1x. Additionally, everything in my laptop screen looked tiny.

Solving the problem

As I don’t change my monitor setup often, but occasionally, I decided that I could live without an automatic change: instead, I would create scripts that would allow me to enable or disable the scaling in the external screen on my will. For this, I will use the xrandr application, as recommended in the Arch Wiki.

For this, I created the following script for enabling the scaling:

#!/bin/bash
xrandr --output eDP-1 --auto --scale 0.55x0.55

Basically, this is telling to xrandr:

  • –output eDP-1 – Apply the next settings to the eDP-1 display (the laptop one)
  • –auto – Apply the default automatic settings for this screen
  • –scale 0.55×0.55 – Scale the desktop to be almost twice as big as the usual.

For disabling the scaling, the following script does the job:

 
#!/bin/bash
xrandr --output HDMI-1 --auto --scale 1x1 --output eDP-1 --auto --scale 1x1

If you read the explanation of the previous script, understanding the command should not be hard: we are setting the scaling in all screens back to normal (1×1).

Final notes

It should be noted that if  the scaling is enabled while using two monitors at the same time, it will also work correctly. However, in my case, due to a bug in X, the mouse pointer flickers.

Surprisingly, GNOME on Wayland did not have most of the described problems that KDE had: it does recalculate the scaling when changing monitor, offers by default a suggested scaling based on the screen information and the change of scaling is immediate. However, only GNOME native applications have been adapted for being rescaled when moving the application window to a monitor with a different scaling. The xrandr solution is able to scale all applications properly.


Sources:
HiDPI – Arch Wiki

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s