1. Overview

In this article, we’ll configure screen sharing for web browsers running in a Wayland session. First, we’ll get an overview of the current state of screen sharing in the Linux ecosystem. Next, we’ll dive into the workings of screen sharing under Wayland and use various tools to make it work.

2. The State of Screen Sharing in Linux

X11 has complete support for screen sharing using the web browser. It’s quite stable, and there are a lot of applications, including web browsers, that support screen sharing over X. However, X has several drawbacks related to security. For that reason, Wayland is the secure and intended replacement for X.

Therefore, major desktop environments like GNOME and KDE have transitioned to Wayland. In addition, new window managers like Sway and Hyprland are also Wayland-based compositors. In Wayland, each window manager is responsible for providing its screen-sharing abilities. So, configuring screen sharing for different compositors may differ.

Luckily, GNOME and KDE support screen sharing via web browsers out of the box. Therefore, we don’t need to configure anything.

On the other hand, other window managers require a bit of work for this. So, we’ll need to use packages like PipeWire, Wireplumber, and xdg-desktop-portal, which we’ll go over in the next sections.

3. Screen Sharing in Wayland Session

In Wayland, screen sharing involves interaction between several components. Typically, we have an application such as a web browser that requests screen sharing through the XDG Desktop Portal. In turn, it forwards the request to the screen-sharing modules implemented by the compositor, which process the request and provide the requested ability.

The screen-sharing modules, in turn, interact with the PipeWire modules to offer media streaming capabilities:

Wayland Screen Sharing

3.1. PipeWire

PipeWire, a lightweight multimedia framework, is a layer that sits on top of ALSA. However, it may also interact with PulseAudio for audio management. PipeWire’s sole purpose is to provide a modern framework to handle video and audio streams securely and efficiently.

In the context of screen sharing, PipeWire captures video streams from the Wayland screen-sharing source under the supervision of a session manager such as Wireplumber.

By default, it’s shipped with the recent versions of GNOME and KDE. However, it may not be available for other window managers like Sway. In that case, we can install it from the package repositories using its canonical name, pipewire:

# Debian and derivatives
$ sudo apt install -y pipewire

# Fedora, CentOS Stream, and Red Hat
$ sudo dnf install -y pipewire

# openSUSE and derivatives
$ sudo zypper install --non-interactive pipewire

# Arch Linux and derivatives
$ sudo pacman -S --noconfirm pipewire

Once installed, we enable and start the PipeWire service:

$ systemctl enable --user pipewire
$ systemctl start --user pipewire

Now, let’s check whether it’s running:

$ systemctl status --user pipewire
● pipewire.service - PipeWire Multimedia Service
Active: active (running) since Wed 2024-02-06 17:59:33 PKT; 1min 34s ago
...

In the next sections, we’ll set up Wireplumber.

3.2. Wireplumber

Wireplumber manages the essential video streaming components involved in the multimedia session. For instance, it handles the permissions required for capturing the contents of the screen. In addition, it also directs the captured screen content to a specified destination, such as a web browser.

Like PipeWire, it comes with GNOME and KDE, but we’ll need to install it from the package repositories for other window managers:

# Debian and derivatives
$ sudo apt install -y wireplumber

# Fedora, CentOS Stream, and Red Hat
$ sudo dnf install -y wireplumber

# openSUSE and derivatives
$ sudo zypper install --non-interactive wireplumber

# Arch Linux and derivatives
$ sudo pacman -S --noconfirm wireplumber

As usual, let’s enable and start the Wireplumber service:

$ systemctl enable --user wireplumber
$ systemctl start --user wireplumber

In the next section, we’ll enable the communication channel between the Wayland compositor and the web browser for screen sharing.

3.3. XDG Desktop Portal

In Wayland, applications are run in a more secure and restricted environment. So, we’ll need an intermediate channel for the web browser to request screen-sharing resources. Usually, we use portals for this. Portals provide a standard API for the application to request resources.

xdg-desktop-portal-wlr is a generic package that exposes D-Bus interfaces known as portals, which act as an intermediary channel between the program and the display server.

We can install it from the package repositories:

# Debian and derivatives
$ sudo apt install -y xdg-desktop-portal-wlr

# Fedora, CentOS Stream, and Red Hat
$ sudo dnf install -y xdg-desktop-portal-wlr

# openSUSE and derivatives
$ sudo zypper install --non-interactive xdg-desktop-portal-wlr

# Arch Linux and derivatives
$ sudo pacman -S --noconfirm xdg-desktop-portal-wlr

We should keep in mind that we might need to install a package that is more specific to our window manager, such as xdg-desktop-portal-hyprland. Therefore, we need to read the docs for that specific window manager.

Next, we’ll need to enable and start the service:

$ systemctl enable --user xdg-desktop-portal
$ systemctl start --user xdg-desktop-portal

Once the service is running, we’re ready to share the screen using the web browser of our choice. Notably, we’ll need to restart the web browser for the changes to take effect.

4. Conclusion

In this tutorial, we learned how to configure screen sharing for applications such as web browsers that are running under the Wayland display manager. For that purpose, we made use of packages like PipeWire, Wireplumber, and xdg-desktop-portal.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.