swaying better
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 wireplumberAnd 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.confand add the following:XDG_CURRENT_DESKTOP=sway MOZ_ENABLE_WAYLAND=1Then update your sway config to look at the new file; edit
~/.config/sway/configand 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-portalNow 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 bemenuThen 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_outputwhich will create the beautifully named virtual output HEADLESS-1.Workflow
- Create virtual output
- Move a workspace to this output
- Switch back to original workspace
- Share Screen
To do this we can create two bash scripts
~/.config/sway/share-start.shand~/.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.shNow 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,
cliphiststores clipboard history (up to a set number of items) andfuzzelprovides a picker.Installation
At time of writing,
cliphistis not available through APT, but it can be built with cargo. We will also needwl-clipboardin order to read Waylands clipboard to add to the history:sudo apt install wl-clipboard cargo install cliphistThen, 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-copyHere the
-max-items 25defines the maximum items to be kept, this can be set arbitrarily high.