Jan Grulich

How to enable and use screen sharing on Wayland

Two days ago I wrote about our work on screen sharing in web browsers. While there was a lot of work done recently on this area, it’s not still in the state where everything would just work out of the box. There are few steps necessary to make this work for you and here is a brief summary what you need. This is not a distro specific how to, but given I use Fedora 28 and I know that everything you need is there, it’s most likely you will need to figure out the differences for your distribution or build it yourself.

PipeWire

PipeWire is the core technology used behind all of this. In Fedora you just need to install it, it’s available for Fedora 27 and newer. Once PipeWire is installed, you can just start it using “pipewire” command. If you want to see what’s going on, you can use “PIPEWIRE_DEBUG=4 pipewire”  to start PipeWire with debug information. For Fedora 29, there is a feature planned for PipeWire which should make it to start automatically.

Xdg-desktop-portal and xdg-desktop-portal-[kde,gtk]

We use xdg-desktop-portal (+ backend implementation) for communication between the app requesting to share a screen and between desktop (Plasma or Gnome). You need xdg-desktop-portal, which is the middle man between the app and backend implementation, compiled with screencast portal. This portal will be build automatically when PipeWire is present during the build. In Fedora you should be already covered when you install it. For backend implementation, if you are using Plasma, you need xdg-desktop-portal-kde from Plasma 5.13.x, again compiled with screencast portal, which is build when PipeWire is present. For Fedora 28+, you can use this COPR repository and you are ready to go. I highly recommend using Plasma 5.13.2, where I have some minor fixes and if you have a chance, try to compile upcoming 5.13.3 version from git (Plasma/5.13 branch), as I rewrote how we connect to PipeWire. Previously our portal implementation worked only when PipeWire was started first, now it shouldn’t matter. If you use Gnome, you can just install xdg-desktop-portal-gtk from Fedora repository or build it yourself. You again need to build screencast portal.

Enabling screen sharing in your desktop

Both Plasma and Gnome need some adjustments to enable screen sharing, as in both cases it’s an experimental feature. For Gnome you can follow this guide, just enable screen-cast feature using gsettings. For Plasma, you need to get KWin from Plasma 5.13.x, which is available for Fedora in the COPR repository mentioned above. Then you need to set and export KWIN_REMOTE=1 env variable before KWin starts. There is also one more thing needed for Gnome at this moment, you need to backport this patch to Mutter, otherwise it won’t be able to match PipeWire stream configuration with the app using different framerate, e.g. when using Firefox.

Edit: It seems that exporting KWIN_REMOTE=1 is not necessary, it probably was only during the time when this feature was not merged yet. Now it should work without it. You still need KWin from Plasma 5.13.

Start with screen sharing

Now you should be all set and ready to share a screen on Gnome/Plasma Wayland session. You can now try Firefox for Fedora 28 or Rawhide from this COPR repository. For Firefox there is a WebRTC test page, where you can test this screen share functionality. Another option is to use my  test application for Flatpak portals or use gnome-remote-desktop app.

Edit: I didn’t realize that not everyone knows about xdg-desktop-portal or PipeWire, below are some links where you can get an idea what is everything about. I should also mention that while xdg-desktop-portals is primarily designed for flatpak, its usage has been expanded over time as it perfectly makes sense to use it for e.g. Wayland, where like in sandbox, where apps don’t have access to your system, on Wayland apps don’t know about other apps or windows and communication can by done only through compositor.

 

12 thoughts on “How to enable and use screen sharing on Wayland

  1. Hi,

    Is there any technical overview of how all of this works together?
    For instance I have no idea what xdg-*-portal are supposed to be. Pipewire I’ve heard of, but am unsure about the usecases…
    How does it work if I don’t use flatpack/snap?

  2. I understand this is screen sharing, e.g a desktop, as opposed to display of remote applications. Is that correct, and if so, is there anything on the horizon in that regard?

    1. This is unfortunately only for screens at this moment. There is API already for this in xdg-desktop-portal, actually it’s just an enum for one of methods we call, but it’s not yet implemented in any of existing xdg-desktop-portal backends. There is also missing implementation in both Mutter and KWin. We will definitely implement this in future, but now I cannot promise when you can expect it.

      1. Thanks for the clarification. As you can probably infer, for many of my workflows, I find the “all my remote windows in one local window” as in no way a replacement for the “seamless remote and local windows” experience. I don’t know how fashionable remote displaying like this is, but I certainly hope for a solution before I “have” to move to Wayland.

        (I’m aware of nx and while the technology is attractive in principle, the implementations are…limited).

  3. I’m using Fedora 28 with Gnome. I followed these instructions except for: “There is also one more thing needed for Gnome at this moment, you need to backport this patch to Mutter”. WebRTC screen sharing still shows a black screen with no debug activity in my pipeline logs. I just don’t don’t know how to backport the patch. I never patched Gnome module before. Would you be so kind as to briefly explain how to do this? Thanks!

    1. In Fedora 28 you should be ready to go as the fix for Mutter has been included in mutter-3.28.3-1.fc28, which should be in updates-testing already. Do you have xdg-desktop-portal and xdg-desktop-portal-gtk installed?

  4. Thanks for the great work!
    I was never more happy to see screenception in Firefox…

    Unfortunately when using the experimental fractional scaling option (‘scale-monitor-framebuffer’) with a scaling factor other than 1, the screen stays blank.

    But now at least I don’t have to switch to Xorg anymore, to get screen sharing.

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.

Scroll To Top