Skip to content

🏠 Sway desktop environment dotfile installation for Arch Linux

License

Notifications You must be signed in to change notification settings

alex-morgun/Sway-Ansible

Β 
Β 

Repository files navigation

Sway Maintenance License: MIT

My Sway configuration.
DE stands for desktop environment because I strive to create an easy to use feeling similar to a DE.

Screenshot

More Screenshots can be found in the screenshots folder.

Table of content

Current setup

Features

  • Services are started / stopped via systemd when sway starts / stops
  • Dynamic monitor output configuration via kanshi, even when reloading sway via $mod+Shift+C
  • Device specific sway configuration
  • Multi-monitor lock screen support via swaylock-effects
  • Notifications support via mako
  • Window activity follows mouse
  • Inactive windows are semi-transparent
  • Suppress lockscreen when a window is in fullscreen, usefull when e.g. watching videos
  • Multiple floating window rules for a more familiar desktop feeling
  • Tag XWayland windows with an [X] in title bar to know which application is wayland native
  • Alacritty as "scratchpad terminal"
  • Waybar tooltips actually do feel like tooltips and not like a sway application container
  • Setting custom environment variables to tailor the desktop environment to your needs
  • Wayland Screensharing via script or natively in browsers via xdg-desktop-portal-wlr
  • Autotiling depending on the currently focused window dimensions
  • Hotkey Dialog. View every available Hotkey in your sway session
  • Emoji selector via bemenu. Select an emoji from a drop down menu and put it into your clipboard or configure ydotool to automatically input it into any application
  • Color adaptive waybar
  • Automount removable drives via udiskie
  • Full QHD Support (I also assume WHD). I haven't noticed scaling problems with XWayland applications
  • Clipboard Manager (clipman) which hides KeePassXC data
  • pywal support!
  • Flatpak Support

Prerequisites

  • git
  • xdg-user-dirs
  • ansible >= 2.7
  • When using arch: ansible-aur module, though it will be installed when using the playbook setup01-arch-prerequirements.yml
  • Disable your display manager. It can work, but I can not guarantee it because I do not use one

Installation

I prefer using ansible for managing my desktop environment so you need it to install everything.

Reasons why I use ansible:

  • integrated idempotence tests
  • templating
  • been using it on a daily base
  • can use system facts, e.g. ansible_distribution

The playbooks are completely idempotent and can be re-run without problems. The playbook setup-01 is required for the other playbooks as it will install the ansible aur module. setup-02 installs the desktop environment and setup-03 does adjustments mainly to suit my preferences, which can also be useful for others. Every task in the playbooks has a describing name. So it should be easy even without ansible knowledge to know, what each task does.

ansible-galaxy collection install community.general kewlfft.aur
ansible-playbook setup-01-arch-prerequirements.yml -K -e 'ansible_python_interpreter=/usr/bin/python3' --diff
ansible-playbook setup-02-de.yml -K -e 'ansible_python_interpreter=/usr/bin/python3' --diff
ansible-playbook setup-03-additions-arch.yml -K -e 'ansible_python_interpreter=/usr/bin/python3' --diff

If you would like to use my zsh config in alacritty, run step 2 with the following option:

ansible-playbook setup-02-de.yml -K -e 'ansible_python_interpreter=/usr/bin/python3' -e 'SWAY_ZSH=true' --diff

At the moment my main focus is on arch. It was previously on Fedora. But Fedora has become obsolete and got removed.

The ansible playbook will do the following changes to the system:

  • Install required software (see the playbook *.yml files for details)

  • Files from the config folder will be symlinked to the appropriate location

  • Enables ssh-agent via systemd --user

  • Downloads Windows-10 themes and icons to $HOME/.local/share/.themes and $HOME/.local/share/.icons

  • Sets Windows-10 themes and icons in ~/.config/gtk-3.0/settings.ini and ~/.gtkrc-2.0

    • ~/.config/gtk-3.0/settings.ini
    [Settings]
    gtk-theme-name = Windows-10
    gtk-icon-theme-name = Windows-10
    • ~/.gtkrc-2.0
    gtk-theme-name = Windows-10
    gtk-icon-theme-name = Windows-10
  • Add entries to /root/.bashrc and ~/.bashrc

  • setup03 installs / removes some GTK applications. I try to avoid QT applications if I'm not forced to use them...

Applications beeing installed

This role installs multiple applications from arch repository and aur.

Arch Repository

Name Description
Alacritty A cross-platform, GPU-accelerated terminal emulator
antiword
bemenu Dmenu replacement
bemenu-wlroots Wayland renderer for bemenu
blueman Blueman is a GTK+ Bluetooth Manager
cdrtools
docx2txt
ffmpeg
gammastep Adjust color temperature in the evening
gnome-power-manager
grim Grab images from a Wayland compositor
highlight
imagemagick
jq
kanshi
libpipewire02
lsd
mako A lightweight Wayland notification daemon
ncmpcpp
network-manager-applet
noto-fonts-emoji
odt2txt
otf-font-awesome
pavucontrol
pcmanfm-gtk3
perl-image-exiftool
playerctl
polkit-gnome
qt5-wayland
rsync
slurp
sway
swayidle
ttf-dejavu
udiskie Manage removeable media from userspace
waybar

Aur

Name Description
archivemount FUSE based filesystem for mounting compressed archives
autotiling Switches the layout splith / splitv depending on the currently focused window dimensions
avizo Avizo is a simple notification daemon, intended to be used for multimedia keys
bemenu-dmenu
clipman A simple clipboard manager for Wayland
edir Rename, Delete, and Copy Files and Directories Using Your Editor
fedora-firefox-wayland-bin
glow-bin
j4-dmenu-desktop
lf Terminal file manager written in Go. For full functionality open with lfcd.
otf-font-awesome-4
remontoire-git
swappy A Wayland native snapshot editing tool, inspired by Snappy on macOS
starship-bin The minimal, blazing-fast, and infinitely customizable prompt for any shell
swaylock-effects-git Swaylock, with fancy effects
ttf-font-awesome-4
wf-recorder-git Screen recording of wlroots-based compositors
wl-clipboard-git Command-line copy/paste utilities for Wayland
wshowkeys Shows keypresses on first output
xdg-desktop-portal-wlr

Theming with pywal

It's possible to change the theme from various applications via pywal.

Theme Switching

The following applications are currently supported:

  • alacritty
  • bemenu-run.sh (and all scripts depending on this)
  • mako
  • sway
  • waybar

To list all supported themes:

wal --theme

Choose one of the available themes and apply it with

wal -o wal.sh --theme solarized

The wal.sh script takes care to update the theme from applications pywal can't directly update.

pywal supported applications

More applications are supported but need to be configured separately.

Firefox

Firefox requires the addon pywalfox.

VS Code

VS Code requires the Wal Theme extension.

Hotkeys

This is not a list of all hotkeys but more for some none defaults. You can view all hotkeys in config/sway.d/07_hotkeys.conf or within sway by opening a hotkey overview with $mod+Shift+k.

By default $mod is the super key (or windows key) and $alt is the Alt key.

Action Binding
Reload Sway $mod+Shift+r
Open bemenu $mod+d
Toggle Gammastep $mod+Shift+t
Make current focus fullscreen $mod+f
Make current container fullscreen $mod+Shift+f
Open KeePassXC from scratchpad $mod+k
Screenshot whole screen Print
Screenshot focused window $mod+Print
Screenshot selected region $mod+Shift+Print
Desktop color picker $mod+c
Open floating terminal Menu
Screensharing $mod+x
Toggle Hotkey GUI $mod+Shift+k
Emoji Selector $alt+Shift+e
Show notification actions $alt+Shift+m
Show keypresses like in YouTube videos $mod+Shift+s
Open clipboard manager $mod+y
Pause / resume audio / video player (playerctl) $mod+Shift+c
Previous track from playlist (playerctl) $mod+Shift+Previous
Next track from playlist (playerctl) $mod+Shift+Next

Screenshots are saved via swappy to $XDG_PICTURES_DIR/screenshots/ and the path is copied to the clipboard.

Custom Sway configuration

You can add your own sway configuration by creating a folder with the hostname of your device and putting your specific configuration in there (recommended).

mkdir -p $HOME/.config/sway/$(hostname)

Alternatively all config/sway.d/99_*.conf files are ignored in git.

Device specific configuration

At the moment the following settings are considered device specific:

  • Background (02_output.conf)

  • Workspace to monitor assignment (03_workspace.conf)

The files do provide some commented examples. You can copy them to $HOME/.config/sway/$(hostname) and adjust them to your needs.

Output configuration

In the past I used sway to handle monitor configuration (e.g. resolution and position). But it wasn't reliable for me so I switched to kanshi. Kanshi dynamically changes output configuration depending on the connected devices, which sway can't. Very convenient when using a notebook on different places. You can find an example configuration in config/kanshi/config.example.

Example host specific configuration

nano $HOME/.config/sway/$(hostname)/example.conf
# https://wallpaperscraft.com/download/mushrooms_toadstools_glow_135444/3840x2160
output "*" background ~/Pictures/mushrooms_toadstools_glow_135444_3840x2160.jpg stretch

input * {
    xkb_layout de
    xkb_numlock enable
    natural_scroll enabled
}

exec nextcloud
exec evolution
exec firefox

set $my_cursor volantes_light_cursors
set $my_cursor_size 48
set $my_gtk_theme Qogir-win-light
set $my_icon_theme Qogir

seat seat0 xcursor_theme $my_cursor $my_cursor_size
exec_always {
    gsettings set $gnome-schema cursor-theme $my_cursor
    gsettings set $gnome-schema cursor-size $my_cursor_size
    gsettings set $gnome-schema gtk-theme $my_gtk_theme
    gsettings set $gnome-schema icon-theme $my_icon_theme
}

Clipboard Manager

Clipman is used as a clipboard manager and can be viewed in bemenu with $mod+y. Because many people handle sensitive data in their clipboard it's not activated by default. To activate the clipboard manager you need to add the following line to your host specific sway configuration.

exec wl-paste -t text --watch myclipman.sh

myclipman.sh is a script from reddit user u/StrangeAstronomer which avoids, that content copied from KeePassXC is saved with clipman.

Custom bash configuration

The playbooks do add the following lines to your ~/.bashrc and /root/.bashrc:

 # BEGIN Sway desktop environment config
for f in $HOME/.local/bin/bash/*.sh; do source $f; done
 # END Sway desktop environment config

This will source all *.sh files from your $HOME/.local/bin/bash folder.

Environment variables

There are two files where environment variables can be set / modified: ~/.config/sway/env and ~/.config/environmentd/*.conf

~/.config/sway/env is for sway / wayland specific variables and ~/.config/environmentd/*.conf for the more generic ones. This allows to load the more generic ones in other desktop environments or ttys without problems. You can e.g. add the following snippet at the top of your .bashrc and your tty will use the same XDG settings variables like in sway.

set -a
[ -f "$HOME/.profile" ] && . "$HOME/.profile"
set +a

.profile gets a "magic" snippet to source all variables from ~/.config/environment.d/*.conf. Or you can let your display manager source $HOME/.profile before loading the desktop environment. The custom provided startup script /usr/local/sbin/sway will source both files before executing sway. This way the command sway can be executed via command line or from a display manager and every required environment variable will be set properly.

Weather information in waybar

Weather information is provided from wttr.in and downloaded with a scrip from Robinhuet.

Variable Description
WEATHER_LOC Postal code of your location

Weather Example

WEATHER_LOC=44444

Gammastep

Variable Description
RS_LAT Latitude
RS_LON Longitude
RS_DAY Display temperature at day
RS_NIGHT Display temperature at night

Gammastep Example

# Gammastep
RS_LAT=51.16
RS_LON=6.34
RS_DAY=6500
RS_NIGHT=5000

Font config

This role is not going to alter your fontconfig because everyone chooses a different font.

But to get colored emojis in every application you can use the following fontconfig as an example. It needs to be placed into ~/.config/fontconfig/fonts.conf.

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

 <alias>
   <family>sans-serif</family>
   <prefer>
     <family>Noto Sans</family>
     <family>Noto Color Emoji</family>
     <family>Noto Emoji</family>
     <family>DejaVu Sans</family>
   </prefer>
 </alias>

 <alias>
   <family>serif</family>
   <prefer>
     <family>Noto Serif</family>
     <family>Noto Color Emoji</family>
     <family>Noto Emoji</family>
     <family>DejaVu Serif</family>
   </prefer>
 </alias>

 <alias>
  <family>monospace</family>
  <prefer>
    <family>Noto Mono</family>
    <family>Noto Color Emoji</family>
    <family>Noto Emoji</family>
   </prefer>
 </alias>

</fontconfig>

Mozilla Firefox and Thunderbird

Firefox and Thunderbird are started with native wayland support. For best performance in Firefox you need to enable the new WebRender.

about:config --> gfx.webrender.all --> Value: True
about:config --> layers.acceleration.force-enabled --> Value: True

To verify if it's enabled go to about:support and check if Compositing contains the value WebRender. This can lead to problems on some configurations because the WebRender is still in beta.

Chromium based

To enable screensharing in Chromium based browsers, pipewire needs to be enabled

chrome://flags --> pipewire --> Enable

Screensharing can be tested on the Mozilla GetUserMedia Test Page.

Further xdg-desktop-portal-wlr compatibility can be seen on the Screencast compatibility page.

Breaking changes

  • In the past it was enough to run sway as command. Now for a full experience you need to run the script $HOME/.local/bin/sway. Since the deprecation of .pam_environment this script will source all required environment variables.

  • There is now a script with the name "sway" that sources required environment variables. It should be usable from a display manager and tty.

Testing via molecule

Because I don't install my system that often this repository uses the ansible testframework molecule. It creates a vagrant vm with libvirt backend and runs the playbooks inside the vm.

Requirements on the host:

  • molecule
  • vagrant
  • libvirt
  • qemu

All commands are run in the root folder of this repository.

Installing testing framework in virtual python environment

#yay -Sy vagrant virtualbox
yay -Sy vagrant libvirt virt-manager qemu-base
sudo systemctl enable libvirtd.service --now
vagrant plugin install vagrant-libvirt
python3 -m venv --copies molecule
source molecule/bin/activate
# Updating all installed python packaes within the virtual environment
python3 -m pip list --outdated --format=json | jq -r '.[] | "\(.name)==\(.latest_version)"' | xargs --no-run-if-empty -n1 python3 -m pip install -U
# Installing molecule and dependencies
python3 -m pip install -r molecule/requirements.txt

Optionally give your user permission to use libvirtd

sudo sed -i -e 's/^#unix_sock_group\(.*\)/unix_sock_group\1/' -e 's/^#unix_sock_rw_perms\(.*\)/unix_sock_rw_perms\1/' /etc/libvirt/libvirtd.conf
sudo usermod -a -G libvirt $(whoami)
newgrp libvirt
sudo systemctl restart libvirtd.service

Workflow

Building scenario

molecule create

Tips after creating the VM. Haven't found a way to automate that in the molecule config. Help appreciated.

Set the following config via virtual machine manager:

  • Display Spice --> Type: Spice Server
  • Display Spice --> Listen Type: None
  • Add Sound Device

Linting

molecule lint

Testing / running playbooks

molecule converge

Logging into virtual machine

molecule login -h instance-1

Idempotence test

molecule idempotence

Destroying scenario

molecule destroy

Everything in one step, without possible login

molecule test

About

🏠 Sway desktop environment dotfile installation for Arch Linux

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 68.9%
  • Jinja 19.1%
  • CSS 12.0%