Bug 466312 - Using xrandr to enable and disable external screen results in it not having a Plasma containment
Summary: Using xrandr to enable and disable external screen results in it not having a...
Status: RESOLVED FIXED
Alias: None
Product: KScreen
Classification: Plasma
Component: common (show other bugs)
Version: 5.27.1
Platform: Neon Linux
: NOR normal
Target Milestone: 1.0
Assignee: kscreen-bugs-null@kde.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-23 17:33 UTC by S. Christian Collins
Modified: 2023-03-15 17:26 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.27.3


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description S. Christian Collins 2023-02-23 17:33:52 UTC
SUMMARY
***
I have keyboard shortcuts set up to disable and enable my secondary monitor:

• disable: xrandr --output HDMI-0 --off
• enable: xrandr --output HDMI-0 --mode 1280x1024 --rate 75 --pos 1920x120

The secondary monitor is enabled on boot and works fine, but if I disable and then re-enable the screen using the above shortcuts, the secondary monitor will be black with no desktop functionality. The cursor will show up and I can drag windows to it, but there are no wallpaper, icons, widgets, right-click menu, etc. This is a regression that I suspect is pretty recent.

I was also able to reproduce this bug in Virtualbox using virtual screens and adapting the xrandr commands accordingly. Restarting plasmashell restores the secondary screen to full functionality.
***

STEPS TO REPRODUCE
1. Ensure both screens are enabled and functioning correctly.
2. Run xrandr to get the screen name, resolution, position and active screen resolution & refresh rate. In my case, the line "HDMI-0 connected 1280x1024+1920+120" means screen name = "HDMI-0", resolution = "1280x1024", and position = "+1920+120". The active resolution and refresh rate is marked with an asterisk on the refresh rate. Use the values for your screen in the commands below.
3. Disable the screen: xrandr --output HDMI-0 --off
4. Re-enable the screen: xrandr --output HDMI-0 --mode 1280x1024 --rate 75 --pos 1920x120

OBSERVED RESULT
The secondary screen (HDMI-0) is black with no desktop functionality.

EXPECTED RESULT
The secondary screen should behave normally.

SOFTWARE/OS VERSIONS
Linux: KDE neon 5.27
KDE Plasma Version: 5.27.1
KDE Frameworks Version: 5.103.0
Qt Version: 5.15.8

ADDITIONAL INFORMATION
Video: EVGA NVIDIA GeForce GTX 980 Ti SC GAMING ACX 2.0+ w/ 6GB RAM
NVIDIA video driver: 515.86.01
Screen #1 (DVI-I-1, screen 0, marked as primary):
  • Monitor: ASUS VG248QE 24" LCD Monitor
  • Resolution: 1920 x 1280 @ 120 Hz
Screen #2 (HDMI-0, screen 1):
  • Monitor: Dell P170Sb 17" LCD Monitor
  • Resolution: 1280 x 1024 @ 75 Hz
  • Position relative to Screen #1: +1920+120
Comment 1 Nate Graham 2023-02-24 19:45:49 UTC
Ultimately the same as Bug 460341 since KScreen will notice the change, re-evaluate config data, and trigger the bug.

*** This bug has been marked as a duplicate of bug 460341 ***
Comment 2 S. Christian Collins 2023-02-24 21:33:12 UTC
(In reply to Nate Graham from comment #1)
> Ultimately the same as Bug 460341 since KScreen will notice the change,
> re-evaluate config data, and trigger the bug.
> 
> *** This bug has been marked as a duplicate of bug 460341 ***

Are you sure? That bug is about a display being disabled, whereas with my bug, the display is enabled and functions, but just doesn't have a wallpaper or desktop functionality. I can still drag windows to it, etc. Also, that bug appears to involve NVIDIA, but I can repro this bug in Virtualbox.
Comment 3 Nate Graham 2023-02-27 15:44:23 UTC
Ok, definitely a different issue then. Looks like Plasma has misplaced your desktop containment. Sorry about that.
Comment 4 Nate Graham 2023-02-27 15:45:29 UTC
I would strongly recommend using `kscreen-doctor` to turn on and off your secondary screen from the command line, rather than xrandr. This way KScreen gets notified of the change automatically and informs Plasma immediately, rather than all of this happening in a roundabout way because KScreen has to watch for external config changes.

Instead of xrandr, If you instead run 
> kscreen-doctor output.HDMI-0.disable
and 
> kscreen-doctor output.HDMI-0.disable
to disable and re-enable your external screen, does Plasma react properly?
Comment 5 S. Christian Collins 2023-02-27 16:33:20 UTC
(In reply to Nate Graham from comment #4)
> Instead of xrandr, If you instead run 
> > kscreen-doctor output.HDMI-0.disable
> and 
> > kscreen-doctor output.HDMI-0.disable
> to disable and re-enable your external screen, does Plasma react properly?

Hi Nate. I assume you meant to write `kscreen-doctor output.HDMI-0.enable` for the second command. Unfortunately, this results in the screen being in "duplicate" mode rather than extending my desktop.

All I could find for documentation was in "kscreen-doctor --help", which doesn't show all available options. By looking at the source code and experimenting, I finally figured out how to make this work with kscreen-doctor. At first, I had the display enabling and parameter setting in a single command, which resulted in the screen not becoming enabled, but by splitting it into two commands, it works. I have it running in a single line as follows:

> kscreen-doctor output.HDMI-0.enable && kscreen-doctor output.HDMI-0.mode.1280x1024@75 output.HDMI-0.position.1920,120

I will update my screen commands to use kscreen-doctor, since this is the officially supported way.
Comment 6 Nate Graham 2023-02-27 18:10:22 UTC
Cool, so that works? You get a desktop on the secondary screen when you do that?
Comment 7 S. Christian Collins 2023-02-27 18:51:34 UTC
Yes. The kscreen-doctor command chain gives me a proper, usable desktop on the secondary monitor.
Comment 8 Nate Graham 2023-02-27 18:59:37 UTC
Awesome!

So now we need to figure out why the config that KScreen generates automatically when it detects those external xrandr changes don't result in the external screen getting a proper Plasma containment.
Comment 9 Gerardo Exequiel Pozzi 2023-02-27 22:37:42 UTC
Same issue here

My video setup is just iGPU of 11700K CPU. Using HDMI and DP at one time. Now I switched from using xrandr to kscreen-doctor and works perfect.

Old commmands for hotkeys:
> xrandr --output DP-1 --auto --output HDMI-1 --off  --output HDMI-2 --off
> xrandr --output DP-1 --off  --output HDMI-1 --auto --output HDMI-2 --off
> xrandr --output DP-1 --off --output HDMI-1 --off  --output HDMI-2 --auto

New commmands for hotkeys:
> kscreen-doctor output.DP-1.enable output.HDMI-1.disable output.HDMI-2.disable
> kscreen-doctor output.DP-1.disable output.HDMI-1.enable output.HDMI-2.disable
> kscreen-doctor output.DP-1.disable output.HDMI-1.disable output.HDMI-2.enable
Comment 10 Gerardo Exequiel Pozzi 2023-02-28 12:28:16 UTC
(In reply to Gerardo Exequiel Pozzi from comment #9)
> Same issue here
> 
> My video setup is just iGPU of 11700K CPU. Using HDMI and DP at one time.
> Now I switched from using xrandr to kscreen-doctor and works perfect.
> 
> Old commmands for hotkeys:
> > xrandr --output DP-1 --auto --output HDMI-1 --off  --output HDMI-2 --off
> > xrandr --output DP-1 --off  --output HDMI-1 --auto --output HDMI-2 --off
> > xrandr --output DP-1 --off --output HDMI-1 --off  --output HDMI-2 --auto
> 
> New commmands for hotkeys:
> > kscreen-doctor output.DP-1.enable output.HDMI-1.disable output.HDMI-2.disable
> > kscreen-doctor output.DP-1.disable output.HDMI-1.enable output.HDMI-2.disable
> > kscreen-doctor output.DP-1.disable output.HDMI-1.disable output.HDMI-2.enable

Well, not fixed at all. For example switching from TV (1366x768) to Monitor (1920x1200). "KDE" only uses a rectangle al top-left of the screen of 1366x768 and without anything (no panels). Also switching from TV to Monitor, there are screen tearing on videos for example.

All of these issues are fixed if I touch <Meta> + <P> and select current config: no tearing, normal desktop with panel.
Comment 11 Nate Graham 2023-02-28 18:21:55 UTC
That seems like a different issue. Can you submit a new bug report for it? Thanks!
Comment 12 Bug Janitor Service 2023-03-10 22:14:39 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/2735
Comment 13 David Edmundson 2023-03-13 16:57:16 UTC
Git commit 253034f3da5b89d70b5946665c5f8f5011013896 by David Edmundson.
Committed on 13/03/2023 at 16:57.
Pushed by davidedmundson into branch 'master'.

Screenpool: avoid uniqueConnection with lambda

Handling QScreen geometryChanged was connected to a lambda with a unique
connection. Qt cannot determine this and doesn't connect.

The unique connection was used as handleScreenAdded is also called when
the output order changed to handle things being async.
(I don't think that's actually needed, but that's a refactor for another thread)

This patch shuffles the code so we only connect once which is cleaner
anyway.
Related: bug 466020

M  +21   -11   shell/screenpool.cpp
M  +1    -0    shell/screenpool.h

https://invent.kde.org/plasma/plasma-workspace/commit/253034f3da5b89d70b5946665c5f8f5011013896
Comment 14 Bug Janitor Service 2023-03-13 17:03:58 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/2739
Comment 15 David Edmundson 2023-03-13 17:39:12 UTC
Git commit 3164e1367122245dda4a3a4d95cbcb623e8168a2 by David Edmundson.
Committed on 13/03/2023 at 17:03.
Pushed by davidedmundson into branch 'Plasma/5.27'.

Screenpool: avoid uniqueConnection with lambda

Handling QScreen geometryChanged was connected to a lambda with a unique
connection. Qt cannot determine this and doesn't connect.

The unique connection was used as handleScreenAdded is also called when
the output order changed to handle things being async.
(I don't think that's actually needed, but that's a refactor for another thread)

This patch shuffles the code so we only connect once which is cleaner
anyway.
Related: bug 466020


(cherry picked from commit 253034f3da5b89d70b5946665c5f8f5011013896)

M  +21   -11   shell/screenpool.cpp
M  +1    -0    shell/screenpool.h

https://invent.kde.org/plasma/plasma-workspace/commit/3164e1367122245dda4a3a4d95cbcb623e8168a2
Comment 16 Nate Graham 2023-03-15 17:26:19 UTC
We think the above changes may have fixed the issue for 5.27.3. Can you please upgrade to that version and verify? Thanks a lot!