I'm a pretty out of the loop guy so most discoveries I make tend to be after they are common knowledge. But I stil regularly see people mentioning in forums that you can only share entire screens in SwayWM. As I just discovered, that's not quite true.


Desktop Portal

To share your screen in wayland, your window manager is going to need to use portals and the xdg-desktop-portal system. In SwayWM, we need to make sure we have xdg-desktop-portal-wlr configured and running also, which provides the interoperability between the desktop-portal and wlroots.


Selecting a window to share

The xdg-desktop-portal-wlr has multiple configuration options available around "screencast" which customize the behaviour. NixOS doesn't provide a default configuration for the wlr portal, so I recently looked into it to try and fix screensharing on my work laptop. This is where I learned that although I had previously had success using slurp and just selecting the screen I wanted to share, there were other pickers available. I'm quite fond of bemenu on SwayWM, so have been making an effort to use that more, and was happy to see that I could use that here too!

Once I switched that to bemenu, I was surprised to see not just entire monitors, but specific windows were offered as share targets. And they worked perfectly. When testing wayland screen sharing in Firefox, I found this test page very helpful.

Firefox screen sharing

  • Sharing screens in Firefox can be broken while other apps can work. In my case, Chromium could share perfectly fine while the wlr portal was misconfigured.
  • It's important to set all the environment variables and the dbus-activation-environment to ensure the values are propogated

Non NixOS

On non nixos installations, configure your xdg-desktop-portal-wlr to use a ini configuration file. The contents of the file will look something like this:

[screencast]
chooser_cmd=bemenu
chooser_type=dmenu

NixOS Configuration

My full NixOS configuration is available here. The relevant part is my xdg file which I just import on all my NixOS hosts. Note that chooser_type must be set to dmenu to ensure the right parameters are passed to bemenu. That file also includes some customization to the NixOS systemd service which runs xdg-desktop-portal-wlr, where I set the BEMENU_OPTS environment variable to include the dracula dark theme, which I apply to everything I can in the name of consistency.