Managing an External Display on Linux Shouldn’t Be This Hard

I first started using Linux and FreeBSD on laptops in the late 1990s. Back then, there were all sorts of hassles and problems, from hangs on suspend to pure failure to boot. I still worry a bit about suspend on unknown hardware, but by and large, the picture of Linux on laptops has dramatically improved over the last years. So much so that now I can complain about what would once have been a minor nit: dealing with external monitors.

I have a USB-C dock that provides both power and a Thunderbolt display output over the single cable to the laptop. I think I am similar to most people in wanting the following behavior from the laptop:

  • When the lid is closed, suspend if no external monitor is connected. If an external monitor is connected, shut off the built-in display and use the external one exclusively, but do not suspend.
  • Lock the screen automatically after a period of inactivity.
  • While locked, all connected displays should be powered down.
  • When an external display is connected, begin using it automatically.
  • When an external display is disconnected, stop using it. If the lid is closed when the external display is disconnected, go into suspend mode.

This sounds so simple. But somehow on Linux we’ve split up these things into a dozen tiny bits:

  • In /etc/systemd/logind.conf, there are settings about what to do when the lid is opened or closed.
  • Various desktop environments have overlapping settings covering the same things.
  • Then there are the display managers (gdm3, lightdm, etc) that also get in on the act, and frequently have DIFFERENT settings, set in different places, from the desktop environments. And, what’s more, they tend to be involved with locking these days.
  • Then there are screensavers (gnome-screensaver, xscreensaver, etc.) that also enter the picture, and also have settings in these areas.

Problems I’ve Seen

My problems don’t even begin with laptops, but with my desktop, running XFCE with xmonad and lightdm. My desktop is hooked to a display that has multiple inputs. This scenario (reproducible in both buster and bullseye) causes the display to be unusable until a reboot on the desktop:

  1. Be logged in and using the desktop
  2. Without locking the desktop screen, switch the display input to another device
  3. Keep the display input on another device long enough for the desktop screen to auto-lock
  4. At this point, it is impossible to re-awaken the desktop screen.

I should not here that the problems aren’t limited to Debian, but also extend to Ubuntu and various hardware.

Lightdm: which greeter?

At some point while troubleshooting things after upgrading my laptop to bullseye, I noticed that while both were running lightdm, I had different settings and a different appearance between the two. Upon further investigation, I realized that one hat slick-greeter and lightdm-settings installed, while the other had lightdm-gtk-greeter and lightdm-gtk-greeter-settings installed. Very strange.

XFCE: giving up

I eventually gave up on making lightdm work. No combination of settings or greeters would make things work reliably when changing screen configurations. I installed xscreensaver. It doesn’t hang, but it does sometimes take a few tries before it figures out what device to display on.

Worse, since updating from buster to bullseye, XFCE no longer automatically switches audio output when the docking station is plugged in, and there seems to be no easy way to convince Pulseaudio to do this.

X-Based Gnome and derivatives… sigh.

I also tried Gnome, Mate, and Cinnamon, and all of them had various inabilities to configure things to act the way I laid out above.

I’ve long not been a fan of Gnome’s way of hiding things from the user. It now has a Windows-like situation of three distinct settings programs (settings, tweaks, and dconf editor), which overlap in strange ways and interact with systemd in even stranger ways. Gnome 3 make it quite non-intuitive to make app icons from various programs work, and so forth.

Trying Wayland

I recently decided to set up an older laptop that I hadn’t used in awhile. After reading up on Wayland, I decided to try Gnome 3 under Wayland. Both the Debian and Arch wikis note that KDE is buggy on Wayland. Gnome is the only desktop environment that supports it then, unless I want to go with Sway. There’s some appeal to Sway to this xmonad user, but I’ve read of incompatibilities of Wayland software when Gnome’s not available, so I opted to try Gnome.

Well, it’s better. Not perfect, but better. After finding settings buried in a ton of different Settings and Tweaks boxes, I had it mostly working, except gdm3 would never shut off power to the external display. Eventually I found /etc/gdm3/greeter.dconf-defaults, and aadded:

sleep-inactive-ac-timeout=60
sleep-inactive-ac-type='blank'
sleep-inactive-battery-timeout=120
sleep-inactive-battery-type='suspend'

Of course, these overlap with but are distinct from the same kinds of things in Gnome settings.

Sway?

Running without Gnome seems like a challenge; Gnome is switching audio output appropriately, for instance. I am looking at some of the Gnome Shell tiling window manager extensions and hope that some of them may work for me.

11 thoughts on “Managing an External Display on Linux Shouldn’t Be This Hard

  1. For what it’s worth: I spent some time earlier this year improving my desktop setup, and I ended up with a Sway-on-Wayland configuration. I have a similar situation: laptop with an external monitor, ex-XMonad / i3 /ion3 / … user. An additional factor in my case was that the external factor was 4K, and support for that is a bit spotty (in particular, X doesn’t have good support for using two monitors with vastly different DPI).

    I’ve been pretty happy with my new setup. It was fiddly to get it working, but in the way that old-school Linux was fiddly — it didn’t magically do what I wanted, but once I tracked down the right software to use, the configuration options I needed were documented, and I was able to set it up the way I wanted (including screen blanking/locking and handling hotplugging). And it shows every sign of remaining set-up. Now I just need Emacs to support dpi scaling so it’s not all fuzzy…

    Reviewing the notes I kept and summarizing:

    – I set up kanshi to handle multiple output configuration. This auto-adjusts DPI factors so that my laptop screen is magnified when connected to my monitor, to account for it being on a stand a couple feet farther from my eyes than usual.
    – Since you mentioned audio: I route audio through the monitor when it’s plugged in. This mostly works for me, but I have had occasional cases of audio not switching over properly. I’ve also had some issues with the external camera (routed via the monitor) getting “lost” sometimes. It usually seems to work, so I have been assuming that it’s a driver problem rather than missing desktop infrastructure. It hasn’t been annoying enough for me to track down yet.
    – I set up sawyidle and swaylock to set up locking on demand and when idle.
    – Getting Firefox to scale required custom configuration: https://wiki.archlinux.org/title/Firefox#Wayland
    – The default terminal in sway is “foot”, but that had a bunch of issues for me, so I went back to gnome-terminal, which I’ve been fairly happy with over the years.
    – I’m using the Cinnamon config GUIs (cinnamon-settings) for things that don’t have a clear path via lower level tools. Don’t know if this is recommended, but it works OK for printers, audio, etc.
    – I haven’t bothered to set up a working polkit daemon. Just the other day I figured out that I can run “lxpolkit” in a terminal. Probably I’ll eventually configure it to run on startup, like swayidle.
    – Typing this comment inspired me to figure out how to get battery status into my status bar. There doesn’t seem to be anything out of the box for it, but it was pretty easy to get basic info up there. Getting colors and handling my laptop’s multiple batteries required cobbling together a simple bash script, probably about half an hour.

  2. As Daniel, I have switched from i3 to sway, in three out of four computers (the fourth one is the one I use to give my classes, and I’m wary of breaking a setup that has finally worked fine for me after trying many different combinations). I am very satisfied with Sway. Granted, I don’t do much desktop-environmenty stuff, but I have not had software break for me because of not having a Gnome sesion.

    Yes, I like controlling the bits by myself, so I find it perfectly acceptable to write «for_window [title=”Firefox – Sharing Indicator”] floating enable» to avoid the sharing indicator of Firefox to occupy a full window tile.

    I originally hesitated, and made the switch because my ARM laptop (Lenovo Yoga C630) was too slow under X and i3. But the ease of converting the i3 setup to Sway was a strong reason for me to be willing to do the leap, and I am absolutely happy with it!

  3. Last year I’ve got to use an ASUS FX505D TUF, one of those gamer notebooks with dual video card. With a little gotcha: it featured both an AMD/ATi and an NVidia card.

    The AMD one was the default and the less power-hungry of both, hooked to the notebook’s display. The NVidia was of course the “gaming” one… and the one hooked to the external HDMI port.

    When a user wants to use both displays one video card does the rendering and writes the final image into a buffer accessible by the other card, which will only put that buffer in the necessary port. The problem is that NVidia and AMD uses some “kernel big pages” feature differently, and so they weren’t able to cooperate between them: you can only use one display at a time.

    I had to return the notebook, so I don’t know if the situation improved or not.

    It really felt like being back in the old days of configuring a CRT by hand :-)

  4. I have to use a Dell laptop in my job. Working from home, I’d rather use my larger but lower-resolution monitor and my cheap USB keyboard than the laptop’s own screen and horrid laptop keyboard. However, running Fedora on the laptop, which I guess is semi-supported, has produced all sorts of weird display-related issues.

    Perhaps the worst thing has been the interaction between the laptop and the monitor. I have to open up the laptop, which is like an unergonomic metal brick, and press the rubberised power button on the rubberised surface that will presumably be sticky in twenty years (although with “technological progress” on overdrive, it will be e-waste long before then). The idea is then to close the laptop and let everything happen on the monitor, like using the laptop as a small form factor machine.

    Using the monitor alone did work once upon a time, but then I started to have problems with the login screen. The absolute worst was the way that somehow both the laptop and monitor outputs (in a virtual sense) became superimposed on each other. Clicking on the navigation menus on the login screen caused a kind of pulsating blur effect as if one’s eyeballs were being subjected to vibration, and it became difficult to select the now-important reboot option.

    I now log in with the laptop screen open and then close it when GNOME shows up. At various points, I would get windows opening with the wrong dimensions but with the buttons in their correct places. So I have to point at the place where I think the maximise icon is and hope I am not clicking on something else. This was a problem with a previous Fedora version, then not, then it is once again.

    It is all really rather unpleasant.

  5. This is a really odd post for me to see, because I run Ubuntu and Kubuntu full time on both my Thinkpad laptops and the behavior you describe is precisely what I get without any manual configuration.

  6. Pingback: Javi López G.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.