cloudberries

navigation

swaying better

[tags]
linux
[date]
2026.03.29

It’s been a few months since I started using Sway, as I wrote about previously. I very much love Sway; I use it at home and work, on both desktop and laptop. It’s great. And as with many great things it can be a little frustrating at times. Here are a few tweaks and additions that I found very useful.

Swaying Better

Screen Sharing

Screen sharing can be a little difficult on Sway, this is in part due to Wayland, in part due to Sway itself and in part due to various environmental factors. First things first, it requires a solid portal stack: Pipewire and xdg-desktop-portal as well as a backend for the specific compositor. For Sway, this is xdg-desktop-portal-wlr.

Some of these are likely already installed, but if not they can all be installed with:

sudo apt install xdg-desktop-portal \
     xdg-desktop-portal-wlr pipewire-pulse wireplumber

And now that we have a portal available, we need to tell it where it is (Wayland/Sway and the choice of browser):

To do this you can create a new file, for example ~/.config/environment.d/envvars.conf and add the following:

XDG_CURRENT_DESKTOP=sway 
MOZ_ENABLE_WAYLAND=1

Then update your sway config to look at the new file; edit ~/.config/sway/config and add the following lines:

exec systemctl --user import-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP
exec dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
exec /usr/libexec/xdg-desktop-portal

Now if you attempt to share a screen during a video call, you will get the option to allow, and then can click on a display to select which screen (notably not which workspace) to share.

If you, like me, would prefer a menu rather than click to select, this can be added with bemenu. First you need to install the menu:

sudo apt install bemenu 

Then create a config at ~/.config/xdg-desktop-portal-wlr/config:

[screencast]
max_fps=30
chooser_type=dmenu 
chooser_cmd=bemenu --prompt "Share output:"

This will generate a menu in waybar where you can select which screen you wish to share with tab and enter, or cancel with escape.

Sharing a Specific Workspace

As briefly mentioned above, so far we can share a screen but not a workspace. And, to be completely honest, that is going to remain the case below. What we can add though is a fake screen to share. This is especially useful if you want to share a screen in a meeting where you only have your laptop, but still take notes, look things up or procrastinate without what you are doing also being shared to the meeting.

Luckily Sway supports virtual outputs. This is done with swaymsg create_output which will create the beautifully named virtual output HEADLESS-1.

Workflow

  1. Create virtual output
  2. Move a workspace to this output
  3. Switch back to original workspace
  4. Share Screen

To do this we can create two bash scripts ~/.config/sway/share-start.sh and ~/.config/sway/share-stop.sh. These contain the following:

Start

#!/bin/bash
CURRENT=$(swaymsg -t get_workspaces | jq -r '.[] | select(.focused==true) | .name')
swaymsg create_output
swaymsg output HEADLESS-1 resolution 1920x1080
swaymsg workspace 9
swaymsg move workspace to output HEADLESS-1
swaymsg workspace $CURRENT
notify-send "Sharing ready" "Switch to workspace 9 and then share HEADLESS-1"

Stop

#!/bin/bash
swaymsg workspace 9
swaymsg move workspace to output eDP-1
swaymsg output HEADLESS-1 unplug
notify-send "Sharing stopped"

Then update the sway config once again to add:

bindsym $mod+F9 exec ~/.config/sway/share-start.sh
bindsym $mod+F10 exec ~/.config/sway/share-stop.sh

Now before a call $mod+F9 will set everything up, you can move any windows that need to be shared to workspace 9, share HEADLESS-1 and then afterwards $mod+F10 will shut it all down again.

Clipboard Manager

A persistent clipboard can be really nice, and hard to go back from once you get used to it. For this, cliphist stores clipboard history (up to a set number of items) and fuzzel provides a picker.

Installation

At time of writing, cliphist is not available through APT, but it can be built with cargo. We will also need wl-clipboard in order to read Waylands clipboard to add to the history:

sudo apt install wl-clipboard
cargo install cliphist

Then, as always, we must update our Sway config:

exec_always --no-startup-id wl-paste --type text --watch cliphist -max-items 25 store
exec_always --no-startup-id wl-paste --type image --watch cliphist -max-items 25 store
bindsym $mod+Shift+v exec cliphist list | fuzzel --dmenu | cliphist decode | wl-copy

Here the -max-items 25 defines the maximum items to be kept, this can be set arbitrarily high.