Multiscreen in Plasma: Improved tools and debugging

cube-small
Plasma 5.8 will be our first long-term supported release in the Plasma 5 series. We want to make this a release as polished and stable as possible. One area we weren’t quite happy with was our multi-screen user experience. While it works quite well for most of our users, there were a number of problems which made our multi-screen support sub-par.
Let’s take a step back to define what we’re talking about.

Multi-screen support means that connecting more than one screen to your computer. The following use cases give good examples of the scope:

  • Static workstation A desktop computer with more than one display connected, the desktop typically spans both screens to give more screen real estate.
  • Docking station A laptop computer that is hooked up to a docking station with additional displays connected. This is a more interesting case, since different configurations may be picked depending on whether the laptop’s lid is closed or not, and how the user switches between displays.
  • Projector The computer is connected to a projector or TV.

The idea is that the user plugs in or starts up with that configuration, if the user has already configured this hardware combination, this setup is restored. Otherwise, a reasonable guess is done to put the user to a good starting point to fine-tune the setup.

kcm-videowall
This is the job of KScreen. At a technical level, kscreen consists of three parts:

  • system settings module This can be reached through system settings
  • kscreen daemon Run in a background process, this component saves, restores and creates initial screen configurations.
  • libkscreen This is the library providing the screen setup reading and writing API. It has backends for X11, Wayland, and others that allow to talk to the exact same programming interface, independent of the display server in use.

At an architectural level, this is a sound design: the roles are clearly separated, the low-level bits are suitably abstracted to allow re-use of code, the API presents what matters to the user, implementation details are hidden. Most importantly, aside from a few bugs, it works as expected, and in principle, there’s no reason why it shouldn’t.

So much for the theory. In reality, we’re dealing with a huge amount of complexity. There are hardware events such as suspending, waking up with different configurations, the laptop’s lid may be closed or opened (and when that’s done, we don’t even get an event that it closed, displays come and go, depending on their connection, the same piece of hardware might support completely different resolutions, hardware comes with broken EDID information, display connectors come and go, so do display controllers (crtcs); and on top of all that: the only way we get to know what actually works in reality for the user is the “throw stuff against the wall and observe what sticks” tactic.

This is the fabric of nightmares. Since I prefer to not sleep, but hack at night, I seemed to be the right person to send into this battle. (Coincidentally, I was also “crowned” kscreen maintainer a few months ago, but let’s stick to drama here.)

So, anyway, as I already mentioned in an earlier blog entry, we had some problems restoring configurations. In certain situations, displays weren’t enabled or positioned unreliably, or kscreen failed to restore configurations altogether, making it “forget” settings.
kscreen-doctor

Better tools

Debugging these issues is not entirely trivial. We need to figure out at which level they happen (for example in our xrandr implementation, in other parts of the library, or in the daemon. We also need to figure out what happens exactly, and when it does. A complex architecture like this brings a number of synchronization problems with it, and these are hard to debug when you have to figure out what exactly goes on across log files. In Plasma 5.8, kscreen will log its activity into one consolidated, categorized and time-stamped log. This rather simple change has already been a huge help in getting to know what’s really going on, and it has helped us identify a number of problems.

A tool which I’ve been working on is kscreen-doctor. On the one hand, I needed a debugging helper tool that can give system information useful for debugging. Perhaps more importantly I know I’d be missing a command-line tool to futz around with screen configurations from the command-line or from scripts as Wayland arrives. kscreen-doctor allows to change the screen configuration at runtime, like this:

Disable the hdmi output, enable the laptop panel and set it to a specific mode
$ kscreen-doctor output.HDMI-2.disable output.eDP-1.mode.1 output.eDP-1.enable

Position the hdmi monitor on the right of the laptop panel
$ kscreen-doctor output.HDMI-2.position.0,1280 output.eDP-1.position.0,0

Please note that kscreen-doctor is quite experimental. It’s a tool that allows to shoot yourself in the foot, so user discretion is advised. If you break things, you get to keep the pieces. I’d like to develop this into a more stable tool in kscreen, but for now: don’t complain if it doesn’t work or eat your hamster.

Another neat testing tool is Wayland. The video wall configuration you see in the screenshot is unfortunately not real hardware I have around here. What I’ve done instead is run a Wayland server with these “virtual displays” connected, which in turn allowed me to reproduce a configuration issue. I’ll spare you the details of what exactly went wrong, but this kind of tricks allows us to reproduce problems with much more hardware than I ever want or need in my office. It doesn’t stop there, I’ve added this hardware configuration to our unit-testing suite, so we can make sure that this case is covered and working in the future.

14 thoughts on “Multiscreen in Plasma: Improved tools and debugging

  1. Thanks so much for this work. This kind of bugfixing will be great when I move to Plasma 5. I like the idea of an LTS release, too.

  2. Thank you for your work! Certainly Plasma has improved in multiscreen management but there are still many areas where the user experience is far from ideal.

    Another problem I see is that the Display Configuration dialog doesn’t fit on my 1366×768 screen so I’ve to use Alt+click to drag the window in order to click the OK button. AFAIK 1366×768 is a fairly standard resolution for laptops so a redesign for the dialog should be considered. I think something like Spectacle vs Ksnapshot is a good starting point.

    1. We work on a new kcm layout. There are some issues the devs are aware of, but they want first fix the code stuff and than/now the kcm design

    2. I agree with this. I’ve got a 1920×1080 screen attached, but sometimes I mess up my configuration resulting in some low resolution. That’s of course exactly the time when you actually need KScreen to fix it… then having to drag around the window is not ideal ;)

      Anyway, thanks for improving multi-screen setups in Plasma

    3. This was corrected for most configuration modules in frameworks 5.25

      A patch for the last ones is currently in review.

  3. Thank you too for your work. Kscreen works quite stable for me in the last releases.

    I want to make a point about the usecases. I have a multimonitor desktop (static workstation) and I don’t want to use the same configuration all the time. Instead I have three configurations that I switch between (this is quite similar to the docking case, where you also have several configurations to switch betwwen).

    What do you think of a dialog in kscreen, to save this configurations (“Save actual display configuration under the name: …”) and a hotkey etc. to switch between them?

    Another unrelated question. I have my TV connected to my PC. Is it possible to switch only one monitor off (in software without changing the display setup)?

    1. Interesting. Could you describe the three setups you want to switch between in a bit more detail? There is a couple of ways to do that already, depending on your exact setup and configuration.

      How do you mean “switch a monitor off without changing display setup”, if you’re switching a monitor off, you’re doing that on purpose to change display setup, why would you otherwise switch it off? (Aside, if you just hit the power button, kscreen doesn’t change the layout or disables a screen.) I’m not saying that what you ask doesn’t make sense, I’m just not understanding it well. I think. :)

      1. My display configuration is a “main monitor” 2560×1440 connected with Display Port, a 1080p monitor on the right side connected via DVI and a 1080p TV on the left side connected via HDMI.

        The wanted configurations are mainly:
        – Only main monitor
        – Main Monitor + right monitor
        – TV + Main Monitor
        (and sometimes only TV)

        (I have to align the 1080p displays at the center of the main monitor, otherwise the plasma control panel switches to the TV).

        To my second question, switching off one monitor: The problem is, when looking a movie on the TV, I don’t always need the mainmonitor. My display setup nevertheless is: Main monitor activated and TV left to it (aligned at the center), the panel is on the main monitor.
        (The meaning of this setup is, that you can play a movie on the left monitor, the TV, and use the main monitor as normal PC monitor with the plasma panel.)

        My ideal solution would be, the main monitor would detect, that there is no activity on it (only on the TV) and go into standby mode (so wobbling with the mouse would turn it on again). This does not happen, I think, because the movie deactivates the standby.
        So the simplest solution would be, to switch it off manually. If I use the hardware button of the main monitor itself, the monitor turns off, kscreen(?) detects this, the right monitor turns on and displays the same picture as the TV, the plasma panel (previously on the now deactivated main monitor) went to the middle of the now visible picture and the whole system does not react anymore. Turning the main monitor on again, restores the previous behaviour (except that the panel is on the TV). So I assume the main monitor sends some signal, and plasma react in a way, that I don’t want.

        So my question is. Is there something like “xset dpms force off” but only for one display? (I make videos of the bugs anytime soon and report it :).)

        1. The behavior you’re describing when you turn off your main monitor with the hardware button does seem like a bug, or perhaps something that’s very specific to your monitor. My setup is a main monitor and a tv (both 1080p) running as extended desktop. I frequently turn off (and on) either the main monitor or the tv, which has absolutely no impact on my screen configuration. It works as sebas described, “if you just hit the power button, kscreen doesn’t change the layout or disables a screen.”

          The behavior you’re describing sounds more like what happens when I unplug the DVI or HDMI from my main monitor or tv. Perhaps this is a setting on your monitor which causes the power button to “unplug” the monitor. If so, this might just be something you can change in your monitor settings, instead of being a problem with kscreen.

          1. I have no doubt that this is a relatively specific behaviour of the interaction between my monitor and the software (anyway, not reacting anymore and placing the panel in the wild is a bug).
            For me it looks also, that kscreen reacts, as if the monitor was removed completely. This is the reason why I asked for some kind of software switch to turn this one specific monitor off/in standby.

            Thanks for the tip with the monitor settings, I will take a look.

  4. I recently ran into this problem with KDE Plasma 5.7.x on my machine. My solution was to set my monitors up with NVIDIA’s settings and once they were positioned how I wanted them I turned off KScreen’s autostarting in System Settings. This successfully stopped KScreen from messing up my setup.

    I look forward to 5.8 addressing this issue and if there is anything I can do for testing this bug I’d be happy to do so.

    My Setup:
    i5 (Haswell)
    NVIDIA GTX 760
    Gigabyte Z97 board
    16 GB Gskill RAM

    I wasn’t having this issue with Plasma 5.5, I only encountered it via 5.7.x.

  5. I also hope there’s a fix for the bug where a second monitor keeps stealing your plasma panel, even after being disconnected. There’s a lot of fighting getting the panel on your preferred monitor after every boot. Thanks for your work tho’. :)

Comments are closed.