Swaywm on Debian 11 - bullseye

02 Jan 2022


Getting a working sway/wayland desktop on my machine had always been a goal for sometime in the past year. I have been a huge dwm/X11 user and the reason I haven't jumped ship till now was that there were a few quality of life programs like redshift, unclutter, st etc that didn't have good substitutes in wayland.

However, a lot changed since I tried sway back in 2020. Now there are good alternatives for the tools that I use and I thought I could document what my setup is at the moment. The operating system is Debian 11 "bullseye".

Base install

I chose to install debian from a net-install iso. At the step where the installer asked me what all "collection" of software I wanted to install, I only chose standard system utilities. Reboot and login into your debian system.

Tip: If you skip setting a root password, the first user that you create during installation would get sudo privilleges.

Sway and foot

$ sudo apt install sway foot

foot is a lightweight terminal emulator for wayland. Copy over default config files to our home folder to mess with their settings.

$ mkdir -p ~/.config/foot
$ mkdir -p ~/.config/sway
$ cp /usr/share/foot/foot.ini ~/.config/foot/foot.ini
$ cp /etc/sway/config ~/.config/sway/config

If we type in just sway from our logged in tty, sway should launch. Take a look at sway's config file that we copied over to know the default keybinds. If you're an i3 user, you should feel right at home.

swaylock, the screen lock application for sway is not in the debian stable repos. So to install it grab its .deb from one of the sid repo mirrors.

$ cd ~/Downloads
$ wget http://ftp.us.debian.org/debian/pool/main/s/swaylock/swaylock_1.5-2+b1_amd64.deb
$ sudo apt install ./swaylock_1.5-2+b1_amd64.deb

If we run swaylock from a terminal, our screen should be locked now. Sweet!

Going through the default sway config that we copied over, both swayidle and swaylock are used together for locking the screen after a 300 second idle time.

Make sure swayidle is installed with

$ sudo apt install swayidle

Exit menu

Add the following to our sway config

# exit dialogue
set $mode_system System (e) xit, (s)leep, (r) eboot, (p) oweroff
mode "$mode_system" {
    bindsym e exec swaymsg exit, mode "default"
    bindsym r exec systemctl reboot, mode "default"
    bindsym p exec systemctl poweroff, mode "default"
    bindsym s exec systemctl suspend, mode "default"

    # back to normal: Enter or Escape
    bindsym Return mode "default"
    bindsym Escape mode "default"
}

bindsym $mod+Shift+x mode "$mode_system"

Reload sway with $mod+Shift+c. If we now press $mod+Shift+x, we'd see an exit menu in the bar.

Status line

i3status works fine for basic needs. We can roll our own shell script for this too.

$ sudo apt install i3status

By default the status line just has the date and time. To change this, find the line in the config file that configures the status line in the bar and change it to call i3status

bar {
  ... 
  ## example with a shell script
  # status_command while ~/bin/sway-status-line ; do sleep 10; done
  
  ## default status line
  # status_command while date +'%Y-%m-%d %l:%M:%S %p'; do sleep 1; done
  
  ## calling i3status
  status_command i3status
  ...
}

Input configuration

sway will handle our input devices directly if instructed to do so. The default config provides a few examples. Running swaymsg -t get_inputs will list all our input devices. For example, here's a snippet for my touchpad and keyboard

...
input "2:7:SynPS/2_Synaptics_TouchPad" {
    tap enabled
    middle_emulation enabled
}

input "type:keyboard" {
    xkb_options caps:escape
    repeat_delay 350
    repeat_rate 50
}
...

For X11, we'd have to use tools like setxkbmap, xset and synclient to do this.

Environment config

Append the following to ~/.profile to let GTK and QT apps know that we need them to run with wayland as their backend.

export MOZ_ENABLE_WAYLAND=1 # for firefox
export XDG_SESSION_TYPE=wayland 
export GDK_BACKEND=wayland
export QT_QPA_PLATFORM=wayland

We can ask the shell to run sway when we login into tty1 with the following in .profile

# automatically login into sway
if [ -z $DISPLAY ] && [ "$(tty)" = "/dev/tty1" ]; then
  exec sway
fi

If we are using zsh, make a symlink .zprofile to .profile. .bash_profile is the equivalent for bash.

$ ln -s $HOME/.profile $HOME/.zprofile
$ ln -s $HOME/.profile $HOME/.bash_profile

More configuration, tweaks and recommendations for sway can be found at the swaywm wiki and ofcourse man 5 sway.

Volume and brightness control

$ sudo apt install brightnessctl pavucontrol

Add the following to our sway config

#
# Volume control
#
bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5%
bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5%
bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle
bindsym XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle

#
# brightness
#
bindsym XF86MonBrightnessDown exec brightnessctl set 5%-
bindsym XF86MonBrightnessUp exec brightnessctl set +5%

Application launcher

$ sudo apt install wofi

Add/update the following in our config to launch wofi instead of dmenu

#set $menu dmenu_path | dmenu | xargs swaymsg exec --
set $menu wofi --show run | xargs swaymsg exec --

Internet/Wi-Fi

$ sudo apt install network-manager network-manager-gnome --no-install-recommends

From our terminal emulator running nmtui from the terminal should give us an ncurses UI to choose our network. nm-connections-editor will give a GTK gui to make changes to our network connections.

We could add

exec nm-applet --indicator

to our config to launch the network manager applet icon in the systray. But it doesn't give us a mouse click menu to do anything.

Browsers

Get firefox from mozilla. The one in the repos is a bit old and crashes if we hop on video calls from it.

Having MOZ_ENABLE_WAYLAND=1 set in our environment is crucial for firefox to run under sway.

For chromium/chrome, get the latest from their websites as well. I use ungoogled-chromium

$ sudo echo 'deb http://download.opensuse.org/repositories/home:/ungoogled_chromium/Debian_Bullseye/ /' | sudo tee /etc/apt/sources.list.d/home-ungoogled_chromium.list > /dev/null
$ sudo curl -s 'https://download.opensuse.org/repositories/home:/ungoogled_chromium/Debian_Bullseye/Release.key' | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home-ungoogled_chromium.gpg > /dev/null
# sudo apt update
# sudo apt install -y ungoogled-chromium

To run it, I use a wrapper script called chromium-wayland that looks like this.

#!/bin/sh

chromium --enable-features=UseOzonePlatform --ozone-platform=wayland

Screensharing

$ sudo apt install xdg-desktop-portal-wlr

We must reboot after installing this package.

This will also install a tool called pipewire. This is needed for sway to properly do screen sharing. To see if its running try

systemctl --user status pipewire.socket pipewire

More info can be found on its wiki.

Notifications

$ sudo apt install mako-notifier

Run mako when sway starts with adding this to sway's config file

exec mako

Clipboard management

sudo apt install wl-clipboard clipman

wl-clipboard gives us wl-copy and wl-paste which are tools in similar spirit to xsel. clipman is the actual clipboard manager. If we installed wofi, then running clipman pick from our terminal should bring up our clipboard history in wofi. I have the following in my sway config for this.

# start clipman on sway startup
exec wl-paste -t text --watch clipman store

...

# select stuff from clipboard
bindsym $mod+Insert exec clipman pick

Qt applications

sudo apt install qtwayland5

Without this package installed, qt apps will not run.

Libreoffice

sudo apt install libreoffice libreoffice-java-common default-jdk libreoffice-gtk3

Image and pdf viewer

sudo apt install imv zathura

imv-wayland is our image viewer and zathura is our pdf viewer.

Color temperature

sudo apt install gammastep

This is an alternative to redshift. Run it when sway starts by adding this to sway's config

exec gammastep

It's config file lives in ~/.config/gammastep/config.ini. man gammastep is our friend. The project has a sample config file as well.

Screenshot

sudo apt install slurp grim

Get the grimshot script from sway's contrib folder and put it in your $PATH.

Add the following to sway's config

bindsym $mod+Print exec grimshot save output ~/Pictures/screenshots/$(date -Ins).png 

Set our save path accordingly.

swaywm desktop on debian

More reading

Caution if also using X11!

If we are using other X11 desktop environments on our user account, having

export MOZ_ENABLE_WAYLAND=1 # for firefox
export XDG_SESSION_TYPE=wayland 
export GDK_BACKEND=wayland
export QT_QPA_PLATFORM=wayland

in our .profile will cause issues. If you are using KDE for example, having QT_QPA_PLATFORM=wayland in our env will not allow KDE plasma to start. The wiki says to install plasma-workspace-wayland to make it work.

A quick fix would be to comment out the above envs from .profile if we're running X. Another work around would be to create a wrapper script to invoke sway like so

$ cat /usr/local/bin/mysway

#!/bin/sh

export MOZ_ENABLE_WAYLAND=1 # for firefox
export XDG_SESSION_TYPE=wayland 
export GDK_BACKEND=wayland
export QT_QPA_PLATFORM=wayland

exec sway

And call mysway instead of sway to launch our swaywm session.

Thanks Ravi for testing this.

Fin

I'd love to hear your setup on wayland/sway. Please feel free to shoot me an email.

Shout outs to the swell people at the Window Manager Gang matrix group for hooking me up on sway!

Happy hacking & have a great day!