Bug 481222 - Support proper output mirroring
Summary: Support proper output mirroring
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: platform-drm (other bugs)
Version First Reported In: 5.93.0
Platform: Other Linux
: VHI wishlist
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords: qt6
: 481584 486785 487796 488111 489849 491144 492827 493478 493811 493913 494447 494958 501624 504137 506050 509322 509559 511911 511913 512073 513042 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-02-11 13:18 UTC by Iyán M. V.
Modified: 2025-12-10 14:46 UTC (History)
36 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 6.6
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Iyán M. V. 2024-02-11 13:18:05 UTC
SUMMARY
First of all, a big THANK YOU for all the hard work and improvements around the multi-screen support. Plasma 5.x always felt a bit unreliable when connecting external screens. The RC 2 already feels much much better. Specially the "unify output" mode, which was quite broken in Plasma 5.x in my opinion.

After playing around with different setups, I only notice one small bug. My laptop has a 16:10 screen. When I connect at 16:9 external monitor and I change to "unify outputs" mode, the resolutions (correctly!) changes to a 16:9 one. There are some black bands in the built-in laptop screen (as it should!) and the external screen shows exactly the same as the laptop without any artifacts as it happens with Plasma 5.27.10.

However, when detaching the external monitor, the 16:9 resolution is kept instead of restoring the native 16:10 one.


STEPS TO REPRODUCE
1. Select native 16:10 resolution on a laptop (in my case 1920x1200)
2. Attach an external 16:9 monitor (in my case I tried with a 1920x1080 one)
3. Switch to "unify outputs" mode
4. Detach external screen

OBSERVED RESULT
Laptop keeps the 1920x1080 (16:9) resolution with black bands on the top and bottom edges

EXPECTED RESULT
Laptop should switch back to its native 16:10 resolution before the "unify outputs" mode was enabled


SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 5.93.0
KDE Frameworks Version: 5.249.0
Qt Version: 6.7.0
Kernel Version: 6.7.4-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 8 × 11th Gen Intel® Core™ i5-1135G7 @ 2.40GHz
Memory: 15.3 GiB of RAM
Graphics Processor: Mesa Intel® Xe Graphics
Manufacturer: LENOVO
Product Name: 20XYCTO1WW
System Version: ThinkPad X1 Yoga Gen 6
Comment 1 Zamundaaa 2024-02-19 15:58:24 UTC
Yeah, we'll need to properly plumb screen mirroring from KScreen to KWin, and handle this properly in KWin
Comment 2 Zamundaaa 2024-02-20 22:26:22 UTC
*** Bug 481584 has been marked as a duplicate of this bug. ***
Comment 3 Zamundaaa 2024-03-13 16:07:15 UTC
*** Bug 483437 has been marked as a duplicate of this bug. ***
Comment 4 Zamundaaa 2024-06-05 09:55:27 UTC
*** Bug 487796 has been marked as a duplicate of this bug. ***
Comment 5 Zamundaaa 2024-06-06 14:44:41 UTC
*** Bug 488111 has been marked as a duplicate of this bug. ***
Comment 6 Zamundaaa 2024-09-19 14:23:38 UTC
*** Bug 491144 has been marked as a duplicate of this bug. ***
Comment 7 Nate Graham 2024-09-19 16:01:39 UTC
*** Bug 492827 has been marked as a duplicate of this bug. ***
Comment 8 Miroslav Jarý 2024-09-22 09:07:10 UTC
Hey there!
Any news on when this can be expected?
Comment 9 Zamundaaa 2024-09-22 22:22:03 UTC
I plan to tackle this for the Plasma 6.3 release. No promises on completeness by then though, some parts of doing things properly require quite a lot of changes in KWin.
Comment 10 Nate Graham 2024-09-23 17:57:06 UTC
*** Bug 493478 has been marked as a duplicate of this bug. ***
Comment 11 Iyán M. V. 2024-09-23 18:23:19 UTC
Many bugs marked as duplicated of this one seem to be quite different to what I'm describing here.
Comment 12 Nate Graham 2024-09-23 18:36:16 UTC
I'll leave that for Xaver to explain, but as I understand it, they all have the same root cause.
Comment 13 Iyán M. V. 2024-09-23 18:39:59 UTC
No need to waste time explaining to me here. If it was not by mistake and the root cause is clear to Xaver, all good :) I was just confused by some of the other bugs. The bug I tried to describe here was a very minor issue, but others seem more severe and annoying.
Comment 14 Zamundaaa 2024-10-01 12:07:54 UTC
*** Bug 493913 has been marked as a duplicate of this bug. ***
Comment 15 Nate Graham 2024-10-11 19:13:13 UTC
*** Bug 494447 has been marked as a duplicate of this bug. ***
Comment 16 Nate Graham 2024-10-22 17:24:04 UTC
*** Bug 493811 has been marked as a duplicate of this bug. ***
Comment 17 Nate Graham 2024-12-12 19:52:41 UTC
*** Bug 494958 has been marked as a duplicate of this bug. ***
Comment 18 Rafael Lima 2025-02-04 23:52:51 UTC
Any hopes of having this bug fixed in time for Plasma 6.3?

I use Plasma for teaching and I mirror my screen with a projector, and the overview effect simply doesn't work in the projector.
Comment 19 Vlad Zahorodnii 2025-02-05 00:07:52 UTC
For 6.3, no
Comment 20 Nate Graham 2025-02-19 19:08:33 UTC
*** Bug 500371 has been marked as a duplicate of this bug. ***
Comment 21 Nate Graham 2025-03-17 17:03:35 UTC
*** Bug 501624 has been marked as a duplicate of this bug. ***
Comment 22 Bug Janitor Service 2025-04-09 20:32:08 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/7476
Comment 23 Zamundaaa 2025-04-16 15:55:10 UTC
Git commit 3e0ecbaad2981874608118005d4dc28daf6e3ec4 by Xaver Hugl.
Committed on 16/04/2025 at 15:20.
Pushed by zamundaaa into branch 'master'.

outputconfigurationstore: implement better screen mirroring

Instead of KScreen trying to move and scale outputs in a way that kind of looks
like mirroring, this makes KWin aware of which outputs replicate which, and makes
it responsible for implementing mirroring in whatever way is best.

This commit implements simliar workarounds like KScreen had, with the only real
difference being that it avoids modifying the source display mode and position,
and takes screen rotation into account.
A better implementation can replace that bit later on, while making use of the
same information stored in the configuration.
Related: bug 502630

M  +11   -6    autotests/integration/outputchanges_test.cpp
M  +1    -0    src/backends/drm/drm_output.cpp
M  +1    -0    src/backends/virtual/virtual_output.cpp
M  +1    -0    src/backends/wayland/wayland_output.cpp
M  +9    -0    src/core/output.cpp
M  +3    -0    src/core/output.h
M  +1    -0    src/core/outputconfiguration.h
M  +88   -0    src/outputconfigurationstore.cpp
M  +2    -0    src/outputconfigurationstore.h
M  +26   -1    src/wayland/outputdevice_v2.cpp
M  +1    -0    src/wayland/outputdevice_v2.h
M  +12   -1    src/wayland/outputmanagement_v2.cpp
M  +4    -3    src/workspace.cpp
M  +1    -1    src/workspace.h

https://invent.kde.org/plasma/kwin/-/commit/3e0ecbaad2981874608118005d4dc28daf6e3ec4
Comment 24 Nate Graham 2025-05-13 19:27:16 UTC
*** Bug 504137 has been marked as a duplicate of this bug. ***
Comment 25 Rafael Lima 2025-06-24 17:37:48 UTC
This problem persists in Plasma 6.4, despite the commit from comment #23.
Comment 26 Nate Graham 2025-06-24 22:44:13 UTC
*** Bug 506050 has been marked as a duplicate of this bug. ***
Comment 27 Zamundaaa 2025-07-22 20:05:39 UTC
*** Bug 488111 has been marked as a duplicate of this bug. ***
Comment 28 Zamundaaa 2025-09-10 21:18:41 UTC
*** Bug 509322 has been marked as a duplicate of this bug. ***
Comment 29 Zamundaaa 2025-09-17 17:34:31 UTC
*** Bug 509559 has been marked as a duplicate of this bug. ***
Comment 30 Zamundaaa 2025-09-17 18:53:06 UTC
*** Bug 489849 has been marked as a duplicate of this bug. ***
Comment 31 Zamundaaa 2025-10-17 11:58:49 UTC
*** Bug 486785 has been marked as a duplicate of this bug. ***
Comment 32 Mike Vaughn 2025-10-24 15:44:14 UTC
Just curious if this might get fixed any time soon. I updated to KDE 6.5 (all-around great release, btw 👏 ), and windows are still only showing on one of two replicated screens in the Grid/Overview and Present Windows effects.
Comment 33 Zamundaaa 2025-10-28 17:26:58 UTC
Yes, I have a working prototype that gets rid of the remaining issues with mirroring, and that should land before Plasma 6.6.
Comment 34 Iyán M. V. 2025-10-29 06:56:39 UTC
(In reply to Zamundaaa from comment #33)
> Yes, I have a working prototype that gets rid of the remaining issues with
> mirroring, and that should land before Plasma 6.6.

Thanks for working on this! I'll be happy to test the changes in the Plasma 6.6 Beta ;)
Comment 35 Bug Janitor Service 2025-11-04 22:47:34 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/8365
Comment 36 Kevin Kofler 2025-11-04 23:23:15 UTC
> To render a logical output on a display with potentially mismatching aspect ratio, this also adds infrastructure to have an offset (black bar) when compositing on a mirroring display.

So this hardcodes letterboxing, whereas several of the duplicates (including mine) have actually asked for stretching instead.
Comment 37 Zamundaaa 2025-11-05 12:55:16 UTC
Stretching is not something I intend to support atm. You can however select which screen gets letterboxed to match the other.
Comment 38 Kevin Kofler 2025-11-05 14:54:53 UTC
That is not what we asked for, and what is easily achievable on X11 with the xrandr CLI. So Wayland remains unusable.
Comment 39 Zamundaaa 2025-11-11 13:35:22 UTC
*** Bug 511911 has been marked as a duplicate of this bug. ***
Comment 40 Zamundaaa 2025-11-11 14:38:59 UTC
*** Bug 511913 has been marked as a duplicate of this bug. ***
Comment 41 Zamundaaa 2025-12-01 13:06:39 UTC
*** Bug 512073 has been marked as a duplicate of this bug. ***
Comment 42 Zk Wang 2025-12-02 22:00:25 UTC
The --scale-from option of xrandr handles screen mirroring issues very well and meets the basic needs when using mirror mode:

1. It maintains the native resolution of the built-in internal display (such as 2K or 4K resolution), ensuring that the speaker does not experience discomfort when viewing the built-in screen.
2. It automatically downsamples the high-resolution content from the built-in display to the highest resolution supported by the projector (typically 1080p), while ensuring that the content displayed on the projector remains **complete** and preserves the aspect ratio as much as possible.
From my experience, the following configuration of xrandr makes mirror mode exceptionally comfortable to use, particularly well-suited for delivering presentations: Suppose the internal display is ePD-1 and the external display (projector) is DP-1, the xrandr command to handle the mirror display is:

```bash
$ xrandr --output eDP-1 --auto --pos 0x0 --output DP-1 --auto --pos 0x0 --scale-from 3120x2080[the native resolution of the internal display]
```

FYI, gnome-shell is also not ideal for handling the mirror mode. gnome-shell will reduce the built-in display’s resolution to match the lower resolution of the external display, making the built-in screen look and feel very uncomfortable—windows become overly oversized and the available content area becomes noticeably cramped.
Comment 43 Zk Wang 2025-12-06 12:04:22 UTC
For those who still face difficulties with effective screen mirroring in KDE under Wayland when giving public presentations, I have written a simple Python script to temporarily address the screen mirroring needs. 

This script utilizes the screen capture API provided by xdg-desktop-portal to capture the video stream of the built-in display and then displays the captured screen content in a separate window. This allows us to move the window to the screen of the projector, then maximize the window to full the whole screen. As a result, the window precisely shows the content from the built-in display, maintains its aspect ratio, and ensures all content from the built-in screen is fully displayed on the external projector screen!

Link to the script: https://gist.github.com/wangzk/2c19b945507d80840adba7070e8d1362  

(The script relies on gstreamer, GTK4 and libadwaita. This script was developed with the assistance of AI. Due to the lack of comprehensive documentation for gstreamer-related APIs in Qt, the AI was unable to generate a fully correct program directly. If anyone could help migrate this script to a KDE environment, any assistance would be greatly appreciated!)
Comment 44 Nate Graham 2025-12-08 18:06:04 UTC
*** Bug 513042 has been marked as a duplicate of this bug. ***
Comment 45 Zamundaaa 2025-12-10 12:36:13 UTC
Git commit 8548b5fdc2540b4c093756176e97fcbb2ee92080 by Xaver Hugl.
Committed on 10/12/2025 at 12:09.
Pushed by zamundaaa into branch 'master'.

implement mirroring in a better way

Instead of awkwardly changing the scale and position of outputs to make their
viewports overlap, this makes use of the split between logical and backend
outputs and only creates one logical output for the two backend outputs.
This has the benefit that window management code, effects and applications only
see the one output, which removes a whole bunch of user visible problems.

To render a logical output on a display with potentially mismatching aspect
ratio, this also adds infrastructure to have an offset (black bar) when
compositing on a mirroring display. With the projection matrix and item
renderer adjusted to handle that offset, effects only need very few changes.

M  +9    -9    autotests/integration/drm_test.cpp
M  +1    -0    autotests/integration/kwin_wayland_test.cpp
M  +10   -9    autotests/integration/layershellv1window_test.cpp
M  +85   -17   autotests/integration/outputchanges_test.cpp
M  +1    -1    src/backends/drm/drm_egl_layer_surface.cpp
M  +2    -0    src/backends/drm/drm_output.cpp
M  +3    -0    src/backends/virtual/virtual_output.cpp
M  +1    -1    src/backends/virtual/virtual_qpainter_backend.cpp
M  +4    -4    src/backends/wayland/wayland_backend.cpp
M  +1    -1    src/backends/wayland/wayland_output.cpp
M  +1    -1    src/backends/x11/x11_windowed_egl_backend.cpp
M  +1    -1    src/backends/x11/x11_windowed_output.cpp
M  +1    -1    src/backends/x11/x11_windowed_qpainter_backend.cpp
M  +82   -67   src/compositor.cpp
M  +3    -3    src/compositor.h
M  +25   -51   src/core/backendoutput.cpp
M  +23   -42   src/core/backendoutput.h
M  +7    -3    src/core/output.cpp
M  +4    -0    src/core/output.h
M  +2    -0    src/core/outputconfiguration.h
M  +5    -1    src/core/renderloop.cpp
M  +38   -19   src/core/renderviewport.cpp
M  +11   -3    src/core/renderviewport.h
M  +1    -1    src/effect/offscreeneffect.cpp
M  +5    -0    src/effect/offscreenquickview.cpp
M  +7    -1    src/kscreenintegration.cpp
M  +2    -2    src/main.cpp
M  +64   -84   src/outputconfigurationstore.cpp
M  +1    -1    src/outputconfigurationstore.h
M  +11   -11   src/plugins/blur/blur.cpp
M  +1    -1    src/plugins/colorpicker/colorpicker.cpp
M  +1    -1    src/plugins/screencast/outputscreencastsource.cpp
M  +1    -1    src/plugins/screencast/regionscreencastsource.cpp
M  +1    -1    src/plugins/screencast/windowscreencastsource.cpp
M  +3    -3    src/plugins/screenshot/screenshot.cpp
M  +2    -2    src/plugins/screentransform/screentransform.cpp
M  +1    -1    src/plugins/showpaint/showpaint.cpp
M  +3    -2    src/plugins/zoom/zoom.cpp
M  +10   -6    src/scene/itemrenderer_opengl.cpp
M  +1    -0    src/scene/itemrenderer_opengl.h
M  +39   -19   src/scene/scene.cpp
M  +12   -7    src/scene/scene.h
M  +8    -8    src/scene/workspacescene.cpp
M  +1    -1    src/scene/workspacescene.h
M  +1    -1    src/scripting/windowthumbnailitem.cpp
M  +3    -3    src/wayland/output.cpp
M  +2    -2    src/wayland/output_order_v1.cpp
M  +4    -4    src/wayland/outputdevice_v2.cpp
M  +1    -1    src/wayland/outputmanagement_v2.cpp
M  +18   -9    src/workspace.cpp
M  +1    -1    src/xwayland/xwayland.cpp

https://invent.kde.org/plasma/kwin/-/commit/8548b5fdc2540b4c093756176e97fcbb2ee92080
Comment 46 Rafael Lima 2025-12-10 14:22:30 UTC
Thanks for the fix!

What's the best way for a non-developer to test this? Should I try KDE Neon Unstable Edition?
Comment 47 Zamundaaa 2025-12-10 14:46:46 UTC
Yeah, you can use a live boot of Neon Unstable or KDE Linux. You'll want to wait for a few days though, until the distro image actually has the commit in it