Sway install - nutthawit/alpine-dotfile GitHub Wiki

Sway is a tiling Wayland compositor and a drop-in replacement for the i3 window manager. It works with your existing i3 configuration and supports most of i3's features, plus a few extras. Read more

Installation

Install Sway

sudo apk add font-dejavu foot grim i3status sway swaybg swayidle swaylock swaylockd wl-clipboard wmenu

Configuration

eudev

Before using the compositor we need to setup udev, which allows the discovery of usable graphics and input devices on the system, using the udev system daemon. Reference

eudev is a fork of udev from systemd, The goal of eudev is to obtain better compatibility with the OpenRC init system.

Setup eudev as device manager

sudo setup-devd udev

Warning

If you forget this step, you can also start Sway by using WLR_LIBINPUT_NO_DEVICES=1 sway -d 2> sway.log. However, after Sway starts, you will not be able to use your keyboard and mouse.

seat

What is a seat?

A seat is a collection of physical input/output devices (keyboard, mouse, monitor/GPU) associated with where a physical user sits, hence "seat".

If a computer serves two independent users with each their own keyboard, mouse and monitor, then it is said to be a multi-seat system. This is not particularly common.

If a computer serves multiple users from a single set of keyboard, mouse and monitor, with other user sessions suspended in the meanwhile, then it is set to be a single-seat but multi-session system.

What is seat management?

Seat management daemons like seatd, (e)logind and ConsoleKit(2) all provide a way for display servers to access input/output devices without having to be root. They also coordinate things like session switching and access revocation.

Note that ConsoleKit and (e)logind also perform other functions entirely unrelated to seat management.

Read more about seat

Install seatd

YOUR_USER="tie"

sudo apk add seatd dbus
sudo rc-update add seatd
sudo rc-service seatd start
sudo adduser $YOUR_USER seat

Usage

Create a wrapper script to run Sway. Reference

cat << 'EOF' | sudo tee /usr/local/bin/run-sway > /dev/null
#!/bin/sh
# Session
export XDG_SESSION_TYPE=wayland
export XDG_SESSION_DESKTOP=sway
export XDG_CURRENT_DESKTOP=sway
export XDG_RUNTIME_DIR=/run/user/"$(id -u $USER)"
export XDG_RUNTIME_CONFIG="${HOME}/.config"

# Wayland stuff
export MOZ_ENABLE_WAYLAND=1
export QT_QPA_PLATFORM=wayland
export SDL_VIDEODRIVER=wayland
export _JAVA_AWT_WM_NONREPARENTING=1

# Launch Sway with a D-Bus server
dbus-run-session -- sway "$@"
EOF
sudo chmod +x /usr/local/bin/run-sway

Create a .start file to create the XDG_RUNTIME_DIR directory at system startup.

YOUR_GROUP="tie"
XDG_RUNTIME_DIR=/run/user/`id -u $YOUR_USER`

cat << EOF | sudo tee /etc/local.d/create-xdg-runtime-dir.start > /dev/null

#!/bin/sh -eu

# Delete existing directory, create a new one and set permissions
rm -rf $XDG_RUNTIME_DIR
mkdir -p $XDG_RUNTIME_DIR
chown $YOUR_USER:$YOUR_GROUP $XDG_RUNTIME_DIR
chmod 700 $XDG_RUNTIME_DIR
EOF
sudo chmod +x /etc/local.d/create-xdg-runtime-dir.start
sudo rc-update add local default

You can read more about /etc/local.d at https://wiki.gentoo.org/wiki//etc/local.d

Configure Sway to start automatically when logging into TTY 1.

cat << 'EOF' >> ~/.profile

# Autostart sway when login tty 1
if [ "$(tty)" = "/dev/tty1" ]; then
    run-sway -d 2> ~/sway.log
fi
EOF

Tip

If you encounter a problem use sway -d 2> ~/sway.log to view the log

Reboot a linux machine

When your machine is back online, login with your normal user. Sway should run immediately

Apply user-level configurations

Important

For those who won't to use my configuration, you can create by your self:

  1. Copy sway default configuration: doas cp /etc/sway/config ~/.config/sway/config
  2. Copy foot default configuration: doas cp /etc/xdg/foot/foot.ini ~/.config/foot/foot.ini
  3. The following shell configuration files must be copied from me:

You can now skip this topic.

Install the necessary software packages

doas apk add btop curl git lazygit stow

Clone dotfile repository

DF="${HOME}/.dotfile"
git clone https://github.com/nutthawit/alpine-dotfile.git $DF

Before continuing, you need to install IBMPlexMono font, as the foot terminal uses it.

Apply configure for shell, sway, foot and git

mv ~/.ashrc ~/.ashrc-old
mv ~/.profile ~/.profile-old
stow -v sh

mkdir ~/.config/sway
stow -v sway

mkdir ~/.config/foot
stow -v foot

stow -v git

Apply shell configure for root

doas cp "${DF}/etc/ashrc" /etc/ashrc
doas cp "${DF}/root/.ashrc" /root/.ashrc
doas cp "${DF}/root/.profile" /root/.profile

# Verify
echo $EDITOR
# Output should be
vi
⚠️ **GitHub.com Fallback** ⚠️