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.

 

16 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.

  5. Please help me! I’m completely new to Linux, but somehow I managed to build Pipewire.
    However, when I tried to build the xdg-desktop-portal, I had some warnings and errors after executing the “make” command:

    Makefile:3216: warning: overriding recipe for target ‘lcov-clean’
    Makefile:3129: warning: ignoring old recipe for target ‘lcov-clean’
    Makefile:3219: warning: overriding recipe for target ‘genlcov’
    Makefile:3124: warning: ignoring old recipe for target ‘genlcov’
    make all-recursive
    make[1]: Entering directory ‘/home/martyfrits/xdg-desktop-portal’
    Makefile:3216: warning: overriding recipe for target ‘lcov-clean’
    Makefile:3129: warning: ignoring old recipe for target ‘lcov-clean’
    Makefile:3219: warning: overriding recipe for target ‘genlcov’
    Makefile:3124: warning: ignoring old recipe for target ‘genlcov’
    Making all in doc
    make[2]: Entering directory ‘/home/martyfrits/xdg-desktop-portal/doc’
    GEN portal-org.freedesktop.portal.Flatpak.xml
    Traceback (most recent call last):
    File “/usr/bin/gdbus-codegen”, line 55, in
    sys.exit(codegen_main.codegen_main())
    File “/usr/share/glib-2.0/codegen/codegen_main.py”, line 218, in codegen_main
    parsed_ifaces = parser.parse_dbus_xml(xml_data)
    File “/usr/share/glib-2.0/codegen/parser.py”, line 292, in parse_dbus_xml
    parser = DBusXMLParser(xml_data)
    File “/usr/share/glib-2.0/codegen/parser.py”, line 56, in __init__
    self._parser.Parse(xml_data)
    xml.parsers.expat.ExpatError: not well-formed (invalid token): line 43, column 90
    Makefile:627: recipe for target ‘portal-org.freedesktop.portal.Flatpak.xml’ failed
    make[2]: *** [portal-org.freedesktop.portal.Flatpak.xml] Error 1
    make[2]: Leaving directory ‘/home/martyfrits/xdg-desktop-portal/doc’
    Makefile:2457: recipe for target ‘all-recursive’ failed
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory ‘/home/martyfrits/xdg-desktop-portal’
    Makefile:1064: recipe for target ‘all’ failed
    make: *** [all] Error 2

    In addition, I don’t really get what this “screencast portal” is, or where can I find it or how can I build it, or wheter I should build it before xdg or not…
    Also, while I was looking for a solution, I came across this thing called “Flatpak”. Do I need to install that too?
    I’m sorry, that I’m such a noob. I just wanted to be able to share my screen on Linux, and I’m just eager to find a solution for it. Could you possibly be so kind to explain what I should exactly do?
    (I’m on Ubuntu 18.04 LTS, and I have Gnome.)
    Thanks in advance!

  6. Just for other readers:
    As of Fedora 29 and/or gnome-shell >= 3.30 (see gnome-shell –version), this is all available right out of the box. HOWEVER, Google Chrome / Chromium does not yet support it (version 72). Firefox does.

    I installed Firefox just for this, which made me a little sad, but I’m sure it’ll get resolved by Chromium soonish? See this development branch for Chromium on Wayland: https://github.com/igalia/chromium/

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