This page is intended to help you set up a more functional sway desktop environment. Features that will be covered:
- Manual and automatic screen locking using
swayidle
andswaylock
- Working notifications with
mako
. - Nice application launcher and exit menu using
fzf
andkitty
- Taking of screenshots, optionally selecting a region, using
grim
andslurp
- Volume control with multimedia keys
- Laptop screen brightness adjustment using
brightnessctl
and bound to keyboard keys
These instruction were tested under Debian 10 (Buster), but should also work under Ubuntu with minimal modifications.
To do a basic install of sway under Debian 10, follow the instructions on the page Debian-10-(Buster)-Installation. They should also work with minimal modifications under Ubuntu.
Then make a local copy of the default configuration, in order to customize it:
mkdir ~/.config/sway
cp /usr/local/etc/sway/config ~/.config/sway/config
To configure manual and automatic screen locking, we'll be using Sway's own swaylock and swayidle. Install then both from source:
sudo apt install libpam0g-dev
# swaylock
cd ~/sway-src
git clone https://github.com/swaywm/swaylock.git
cd swaylock
git checkout 1.4
meson build
sudo ninja -C build install
# swayidle
cd ~/sway-src
git clone https://github.com/swaywm/swayidle.git
cd swayidle
git checkout 1.5
meson build
sudo ninja -C build install
Now edit ~/.config/sway/config
and add the following example settings to start swayidle with Sway, and so enable auto locking and monitor poweroff:
exec swayidle -w \
timeout 600 'swaylock -f -c 000000' \
timeout 300 'swaymsg "output * dpms off"' \
resume 'swaymsg "output * dpms on"' \
before-sleep 'swaylock -f -c 000000'
I find it easier to put it right after the Variables
section. The arguments are quite self-explanatory.
You can also set a key combination to trigger a screen lock, like for example by adding this line to sway's config:
bindsym $mod+Shift+Alt+l exec swaylock -c 000000
Mako is a lightweight Wayland notification daemon. Let's install it from source:
cd ~/sway-src
git clone https://github.com/emersion/mako.git
cd mako
git checkout v1.4
meson build
sudo ninja -C build install
If you want to customize mako:
mkdir ~/.config/mako
editor ~/.config/mako/config # or open with your gui editor
Here is an example configuration:
anchor=bottom-right
border-radius=5
default-timeout=10000
height=500
width=400
Now edit ~/.config/sway/config
and add the line exec mako
somewhere, to start mako with sway.
We'll improvise an application launcher using fzf
and the terminal emulator kitty
, it'll look like this:
We need the newest version of kitty for proper wayland support, so we'll install the binary release from their GitHub repository. Install them:
sudo apt install fzf curl xz-utils suckless-tools
sudo mkdir /opt/kitty
curl -L https://github.com/kovidgoyal/kitty/releases/download/v0.14.4/kitty-0.14.4-x86_64.txz | sudo tar xvJ -C /opt/kitty
sudo ln -s /opt/kitty/bin/kitty /usr/local/bin
Now configure a profile for the kitty+fzf launcher:
mkdir -p ~/.config/kitty
cat <<EOF >~/.config/kitty/fzf-launcher.config
font_family DejaVu Sans Mono
font_size 20
enable_audio_bell no
remember_window_size no
initial_window_width 50c
initial_window_height 10c
background_opacity 0.85
EOF
Then edit ~/.config/sway/config
and replace the line set $menu dmenu_path | dmenu | xargs swaymsg exec --
with the following:
set $fzf_launcher kitty --config \"$HOME/.config/kitty/fzf-launcher.config\" --class fzf-launcher --detach
set $menu $fzf_launcher sh -c \"dmenu_path | fzf | xargs -r swaymsg exec\"
for_window [app_id="fzf-launcher"] focus, floating enabled, border pixel 1
This will setup a basic menu launcher that can be summoned with the default $meta+d
key combination.
This is how the exit menu will look:
We'll use this simple script: https://gist.github.com/davidrios/41d72ef3f97104400c353bab3b1b89ab, like so:
cd /tmp
curl -L https://gist.githubusercontent.com/davidrios/41d72ef3f97104400c353bab3b1b89ab/raw/a305a9ef3e44bac370de5165eaabaf3ce53e207b/sway-exit | tee sway-exit
sudo cp sway-exit /usr/local/bin/
sudo chmod +x /usr/local/bin/sway-exit
Then edit ~/.config/sway/config
and replace the line:
bindsym $mod+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -b 'Yes, exit sway' 'swaymsg exit'
with:
bindsym $mod+Shift+e exec $fzf_launcher /usr/local/bin/sway-exit
Now the default $mod+Shift+e
key combination will show a nice exit menu with Logout, Sleep, Reboot and Shutdown options.
For this we'll use grim and slurp. Let's install them first:
sudo apt install libjpeg-dev
cd ~/sway-src
git clone https://github.com/emersion/grim.git
cd grim
git checkout v1.2.0
meson build
sudo ninja -C build install
cd ~/sway-src
git clone https://github.com/emersion/slurp.git
cd slurp
git checkout v1.2.0
meson build
sudo ninja -C build install
Now to set sway key bindings. In the example below, the PrtScn
key save a screenshot of the whole desktop and Alt+PrtScn
lets you select a region to capture. Add them to the sway config:
set $screenshot_file \"$HOME/Pictures/screenshot-$(date '+%Y-%m-%d_%H-%M-%S').png\"
bindsym Print exec grim -s1 $screenshot_file
bindsym Alt+Print exec (slurp | grim -g- -s1 $screenshot_file)
Put these keybindings on your Sway config file:
bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ $(printf "%s\n" 100 $(($(pacmd dump-volumes | grep -m1 Sink | grep -Po '\d+(?=%)' | head -n1) + 3)) | sort -g | head -n1)%
bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -3%
bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle
bindsym XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle
Install brightnessctl:
sudo apt install brightnessctl
And put these keybindings on your Sway config file:
bindsym XF86MonBrightnessDown exec brightnessctl set 5%-
bindsym XF86MonBrightnessUp exec brightnessctl set +5%