Make screen sharing on wayland (sway) work!
Note: xdg-desktop-portal-wlr is on arch’s community repository.
From i3 to Sway
Reddit post on /r/unixporn
Few months ago I’ve updated my linux stack and decided to switch to a wayland-based infrastructure (see also: Wayland vs Xorg). I use i3 for some years now, the natural way further is Sway. I had to find alternatives to my previous tools, here’s a list:
|xsel, xclip||wl-clipboard-x11||Clipboard manager|
|scrot||grim slurp||Screenshot manager|
You can find all the packages I use daily in my dotfiles repository. Here are some of my favourite:
- bluez, bluez-utils, blueman - a classic to manage bluetooth connection
- udiskie (note to fix the waybar tray use libappindicator-gtk3 see this issue)
- wpa_gui - wpa supplicant gui
- zathura - pdf viewer
- syncthing - syncs my desktop / phone data
- keybase - most favorite private drive, git, chat
These are my only graphical interfaced applications, for the rest I’m living in tmux itself running on alacritty. Note that if you install
gvim instead of
vim, you’ll get that famous
vim! About everything else is handled by my dotfiles, the most recent change was to use bat as pager in man files.
In France, we’re now at the 36th day of the stay-at-home directive drived by the gouvernment. In that era, communication over the Internet is more important then ever. We need to use tools like Zoom, Google Meet or less corporate-owned alternatives like Jitsi. I’m looking for a more decentralized alternative if you know one! By the way, Framasoft may help working on live streaming with peertube (source).
The week before the confinment, I had to give an online course about reactive programming applied to Angular and redux. They chose to use a self-hosted jitsi instance and asked me to do a few tests. I noticed that I couldn’t share my screen, indeed I switched on wayland where our browsers use X-based windows to make screen sharing works. Thanks to chrome being able to share a chrome tab, I was able to make something work by sharing my tmux session in a web page. For the first session I used gotty, but damn that didn’t worked so well with my vim inside tmux. I had many complains that it was laggy / not readable (I type fast). I also had to make sure I focused the right tab. For the next session, I used tmate. This was better as it works seamlessly with tmux, and I can share a hosted URL so that people can open my tmux in their own browser.
Still, none of these solutions were as good as full screen sharing but I was in a hurry and didn’t got the time to investigate. About a month after, I’ve done my research and guess what it works:
Many thanks to emersion for the xdg-desktop-portal-wlr (he works on so many wayland-related tools, sponsored by sourcehut.org a set of web tools, worth the check if you don’t know what it is) and danshick he made the PR that makes things work!
How does this work?
Now because wayland is so different then X (see Wayland vs Xorg) many things change. GNOME is one of the most popular desktop environment to switch to Wayland. For desktop audio and video management, they decided to introduce a new multimedia framework called PipeWire (links to the archlinux documentation, the website is pipewire.org). This framework differs in using a PolKit-like security model asking Wayland for permission to record screen or audio instead of relying on user groups (audio and video).
Pipewire will become the new way to communicate with the desktop applications, at least on linux systems. In Chromium, you can enable it using the
enable-webrtc-pipewire-capturer flag (in
chrome://flags). On firefox today you need this patch, available as fedora-firefox-wayland-bin in the AUR.
Now this pipewire needs some additional packages to support pulseaudio (pipewire-pulse) or say wlroots-based window manager like sway. For this to work, you need “portals” using xdg-desktop-portal with a “backend”, which is one of:
- GTK backend xdg-desktop-portal-gtk
- KDE backend xdg-desktop-portal-kde
- Liri backend xdg-desktop-portal-liri
- wlroots xdg-desktop-portal-wlr
For sway, we’ll use the later. Let’s install everything from the AUR, note that for this process I use aurman which isn’t publicly maintained, if you don’t really know what you do in archlinux use yay.
Note: xdg-desktop-portal-wlr is on arch’s community repository which was not the case at the time of writing.
aurman -S pipewire-git xdg-desktop-portal-git xdg-desktop-portal-wlr-git
I forked all these and builded them manually, indeed
xdg-desktop-portal-wlr wasn’t aliased to
xdg-desktop-portal-impl and I had a conflict with the gtk backend. I think that this is fixed now.
From there, let’s run all these (following these debugging instructions):
env PIPEWIRE_DEBUG=3 pipewire
/usr/local/libexec/xdg-desktop-portal-wlr -p BGRx -l DEBUG
/usr/local/libexec/xdg-desktop-portal --verbose -r
Now you can test these via this webrtc test page. On Chromium it works very well. On Firefox it needs the patch discussed earlier.
I hope that this can help you setup screen sharing on your Wayland-based window manager.