Screen Sharing
Screensharing in Wayland is done with the help of Portals. Portals were initially designed to allow applications sandboxes via Flatpak to access resources of the desktop, but have since gained popularity outside of the realm of Flatpaks. In our case, we can use the screen sharing portal to allow applications to access the contents of the Wayland compositor.
Note
Please be aware that you will only be able to share a single screen with this method, not individual windows.
Setup
Installation
First, we need to install xdg-desktop-portal-wlr. Unfortunately, Mir only has support for v0.5.0 of this software, so we will need to checkout the source at a particualr commit:
git clone https://github.com/emersion/xdg-desktop-portal-wlr
cd xdg-desktop-portal-wlr
git checkout 7c0f352 # This is release 0.5.0
Next, we can build the project:
meson setup builddir
cd builddir
ninja -j4
sudo ninja install
Configuration
First, let's add a new environment variable to our Mir configuration:
# ~/.config/miracle-wm.yaml
environment_variables:
- key: XDG_CURRENT_DESKTOP
value: mir
Next, create a file at ~/.config/xdg-desktop-portal/mir-portals.conf
and write:
# ~/.config/xdg-desktop-portal/mir-portals.conf
[preferred]
default=gtk
org.freedesktop.impl.portal.Screenshot=wlr
org.freedesktop.impl.portal.ScreenCast=wlr
Next, create a file at ~/.config/xdg-desktop-portal-wlr/config
and write:
# ~/.config/xdg-desktop-portal-wlr/config
[screencast]
output_name=HDMI-A-1
max_fps=30
#exec_before=disable_notifications.sh
#exec_after=enable_notifications.sh
chooser_type=simple
chooser_cmd=slurp -f %o -or
Finally modify /usr/share/xdg-desktop-portal/portals/wlr.portal
to include "Mir" in the "UseIn"
value:
# /usr/share/xdg-desktop-portal/portals/wlr.portal
[portal]
DBusName=org.freedesktop.impl.portal.desktop.wlr
Interfaces=org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.ScreenCast;
UseIn=wlroots;sway;Wayfire;river;phosh;Hyprland;Mir;
Running
First, create a script somewhere called run_xdg_desktop_portal_wlr.sh
with the following contents:
# /usr/local/bin/run_xdg_desktop_portal_wlr.sh
# Export WAYLAND_DISPLAY and XDG_CURRENT_DESKTOP to dbus
dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=mir
# Stop xdg-desktop-portal
systemctl --user stop xdg-desktop-portal
# Also, you may want do stop any other portal service that you have enabled, e.g.:
systemctl --user stop xdg-desktop-portal-gtk
# Start xdg-desktop-portal-*
systemctl --user start xdg-desktop-portal
systemctl --user start xdg-desktop-portal-wlr
In your miracle-wm.yaml
configuration file, add:
# ~/.confg/miracle-wm.yaml
startup_apps:
- command: run_xdg_desktop_portal_wlr.sh
Restart your compositor and then open up obs-studio
or Google Meet
and see that you are able
to share your screen.