Install Spectrwm, a small dynamic TWM for X11
After installing Arch Linux, you may want to add some features to your installation and become more productive. To do this we are going to see how to install Spectrwm
, a small dynamic tiling window manager. TWM is an approach to organize windows without stacking them. The main advantage of using this type of window manager is that it increases productivity (you almost no longer need to use the mouse because everything is done via keyboard shortcuts) and improves workflow.
Update the system
yay -Syyuu
Clone my dotfiles
My configuration files (dotfiles) are available for free. Clone them in your home directory.
git clone https://gitea.illuad.fr/adrien/dotfiles.git
Install required packages
Some explanations about the packages that are going to be installed:
spectrwm
: the small dynamic windows manager for Xorg,fish
: a pretty nice commandline shell,openssh
: SSH tools,rofi
: a window switcher, run dialog, ssh-launcher,xorg
andxorg-*
: open source implementation of the X Window System,scrot
: tool to take screenshot,alacritty
: GPU-accelerated terminal emulator,ranger
: a text-based file manager,feh
: an image viewer and tool to manage the desktop wallpaper,nerd-fonts-complete
: set of fonts and icons,xf86-video-intel
: 2D accelerated driver for X11 Window System,cifs-utils
: set of tools to mount SMB/CIFS shares,pulseaudio-alsa
: the well known sound server,pulseaudio-ctl
: control pulseaudio,slock
: a display locker for X11,xautolock
: an automatic X11 screen-locker/screen-saver,alsa-utils
: the ALSA (Advanced Linux Sound Architecture) utilities,redshift-minimal
: tool to adjust the color temperature of your screen,numlockx
: tool to turn on the numlock key in X11,usbutils
: USB device utilities,netctl
: a CLI and profile-based network manager,dhcpcd
: a DHCP and DHCPv6 client.
yay -S spectrwm fish openssh rofi xorg xorg-server scrot xorg-xinit alacritty ranger feh nerd-fonts-complete xf86-video-intel librewolf-bin cifs-utils pulseaudio-alsa pulseaudio-ctl slock xautolock zip unzip alsa-utils redshift-minimal numlockx usbutils netctl dhcpcd
X11 configurations
The xinit
program allows a user to manually start an Xorg display server. The startx
script is a front-end for xinit
.
sudo cp /etc/X11/xinit/xinitrc ~/.xinitrc
sudo chown $(whoami):users ~/.xinitrc
The following thing will be explained later.
cp ~/dotfiles/.fehbg ~/.fehbg
Now we can get the lines that don’t need to be there.
sed -i "/twm*/d" ~/.xinitrc
sed -i "/xclock*/d" ~/.xinitrc
sed -i "/xterm*/d" ~/.xinitrc
Copy the following snippet into ~/.xinitrc
. If you don’t have a French keyboard, modify fr
with your country code. Finally, replace <username>
with your own username.
/usr/bin/setxkbmap fr
/usr/bin/numlockx
/usr/bin/xautolock -time 3 -locker slock &
~/.fehbg
exec spectrwm
The xautolock
binary will lock your system if no activity is detected during three minutes, by executing slock
. Later, we will see the slock
configuration.
The script .fehbg
sets the desktop wallpaper with the picture located at ~/Pictures/wallpaper.jpg
. Create the directory and put the file inside.
You may want to launch Spectrwm
once logged to your account? Copy the snippet below to ~/.bash_profile
file, otherwise you’d have to run startx
every time…
if systemctl -q is-active graphical.target && [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then
exec startx
fi
Spectrwm configurations
The configuration directory of Spectrwm
is located at ~/.config/spectrwm/
.
mkdir -p ~/.config/spectrwm
cp ~/dotfiles/.config/spectrwm/* ~/.config/spectrwm/
The file:
bar
defines what you want to see in your action bar,spectrwm_fr.conf
sets the correct keyboard key mapping for a French keyboard. You can retrieve the one that fits to your keyboard in/etc/spectrwm/
. I’ve modified a lot of things in it to fit my keybinding requirements,spectrm.conf
sets other shortcuts to launch programs, display the action bar…
Keyboard locale and timezone configurations
If your keyboard is the same as mine (French with 104 keys), you can use the following configuration. If not, you can list all variants and options with list-keymaps
, list-locales
, list-x11-keymap-layouts
, list-x11-keymap-models
, list-x11-keymap-options
or list-x11-keymap-variants
.
sudo localectl set-keymap fr
sudo localectl --no-convert set-x11-keymap fr pc104
sudo localectl set-locale LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8
sudo timedatectl set-timezone Europe/Paris
If your timezone is not this one, list all timezones with timedatectl list-timezones
.
Block VT switching and prevent killing X11
I recommend that you block VT (Virtual Terminal) switching so that the screen lock cannot be bypassed. For the same reason, slock
recommends that you prevent users from killing the X11 server. Copy the following snippet into /etc/X11/xorg.conf
.
Section "ServerFlags"
Option "DontVTSwitch" "True"
Option "DontZap" "True"
EndSection"
Screen lock configuration
Below, the configuration for slock
. Copy the following snippet into /etc/systemd/system/slock@.service
[Unit]
Description=Lock X11 session using slock for user %i
Before=sleep.target
[Service]
User=%i
Environment=DISPLAY=:0
ExecStartPre=/usr/bin/xset dpms force suspend
ExecStart=/usr/bin/slock
[Install]
WantedBy=sleep.target
Enable the slock
service. Replace
sudo systemctl enable slock@<username>.service
Fix tearing, pixel and text issues
My laptop have an Intel GPU based and I encounter many issues with it. Copy the following snippet into /etc/X11/xorg.conf.d/20-intel.conf
to fix these issues.
Section "Device"
Identifier "Intel Graphics"
Driver "intel"
Option "AccelMethod" "sna"
Option "TearFree" "true"
EndSection
Alacritty configuration
As for the Spectrwm
configuration, the one above fits my requirements. You can adjust the value as you wish.
mkdir ~/.config/alacritty
cp ~/dotfiles/alacritty/alacritty.yml ~/.config/alacritty/alacritty.yml
Rofi configuration
Rofi (with the configuration below) can launch a program (MOD+r
) or initiate a SSH connection (MOD+s
). The hosts listed in the SSH mode are retrieved from the SSH config file (~/.ssh/config
).
mkdir ~/.config/rofi
cp ~/dotfiles/.config/rofi/config ~/.config/rofi/config
Pulseaudio configuration
sudo sed -i "s/autospawn = no/autospawn = yes/" /etc/pulse/client.conf
By doing this, you enable Pulseaudio
at boot. So, you can increase or decrease the volume with your keybinding without starting any other program.
Fish configuration
As always, modify the following file according to your preferences.
cp ~/dotfiles/.config/fish/config.fish .config/fish/config.fish
mkdir ~/.config/fish/functions
cp ~/dotfiles/.config/fish/functions/* ~/.config/fish/functions/
Miscellaneous
Mount a Freebox share
If you have a Freebox and you have the NAS feature enabled on it, you can do the following things to access the filesystem.
sudo mkdir -p /mnt/data
sudo mkdir /etc/samba/credentials
sudo chown root:root /etc/samba/credentials
If you have correctly set up your Freebox share, you’ve enabled the authentication (if not, do it now). Create the above file located at /etc/samba/credentials/data
and fill your credentials.
username=<username>
password=<password>
Set the correct permissions.
sudo chmod 700 /etc/samba/credentials/
sudo chmod 600 /etc/samba/credentials/data
We’ll use systemd
to mount our share, copy the following snippet into /etc/systemd/system/mnt-data.mount
. Be careful, the filename mnt-data.mount
must correspond to the mount path, in this case /mnt/data
.
[Unit]
Description=Freebox share
Wants=network-online.target
After=network-online.target
[Mount]
Environment="SERVER='//<router_IP_address>/<share_name>'"
What=$SERVER
Where=/mnt/data
Type=cifs
Options=credentials=/etc/samba/credentials/data,_netdev,cache=none,users,user,noacl,guest,rw,,uid=1000,gid=985,iocharset=utf8,vers=1.0
SloppyOptions=On
DirectoryMode=0755
TimeoutSec=10
[Install]
WantedBy=multi-user.target
If you want to mount this share automatically when you want to access it, create the file /etc/systemd/system/mnt-data.automount
and put the following content.
[Unit]
Description=Auto mount Freebox share
[Automount]
Where=/mnt/data
[Install]
WantedBy=multi-user.target
Enable and start this service.
sudo systemctl enable --now mnt-data.automount
Connect to an access point
You can manage network connections with netctl
and profiles. Those profiles are located at /etc/netctl/
. The secure way to configure a Wi-Fi connection is to generate a Wi-Fi Protected Access Pre-Shared Key (WPA-PSK) from an ASCII passphrase for a SSID.
wpa_passphrase <SSID>
# reading passphrase from stdin
<passphrase>
Now you have your PSK, create a configuration file (called wlanHome
for example) and set the following content.
Description="Wi-Fi configuration for home"
Interface=wlp2s0
Connection=wireless
Security=wpa
ESSID=<SSID>
IP=dhcp
Key=\"<psk>
For a better understanding, here some explanations:
Interface
value corresponds to your wireless interface name (useiwconfig
to find this information),Connection
value corresponds to the link type, if it’s wireless, it’swireless
, is it’s wired, it’sEthernet
,Security
value corresponds to the mecanism to use to connect to the network,ESSID
value corresponds to theSSID
of your access point,IP
value corresponds to the technique that needs to be used to retrieve an IP address. This value can also set tostatic
, if so, the keysAddress
,Gateway
andDNS
must be defined as explained here,Key
value corresponds to the PSK previously computed. Make sure to prefix it with\"
.
To start this profile, you must execute the following command.
sudo netctl start wlanHome
Final things
Spectrwm
and tools are now configured! Obviously, it is my configuration, you can always modify colors, keybindings by consulting documentation of the concerned tools… Concerning the keybinding, below you’ll find a list to have a quick start (MOD
corresponds to the Windows
key):
- toogle the bar on all workspaces:
MOD+b
, - toggle the bar on the actual workspace:
MOD+Shift+b
, - toggle focused window in floating mode:
MOD+t
, - focus the next window (clockwise direction):
MOD+Tab
, - focus the previous windows (counterclockwise):
MOD+Shift+Tab
, - grow up the master window (the first program executed):
MOD+z
, - shrink the master window:
MOD+a
, - toggle focused window in fullscreen mode:
MOD+f
, - move focused windows to workspace 1:
MOD+Shift+ampersand
, - move focused windows to workspace 2:
MOD+Shift+eacute
, - move focused windows to workspace 3:
MOD+Shift+quotedbl
, - move focused windows to workspace 4:
MOD+Shift+apostrophe
, - move focused windows to workspace 5:
MOD+Shift+parentleft
, - move focused windows to workspace 6:
MOD+Shift+minus
, - move focused windows to workspace 7:
MOD+Shift+egrave
, - move focused windows to workspace 8:
MOD+Shift+underscore
, - move focused windows to workspace 9:
MOD+Shift+ccedilla
, - quit Spectrwm:
MOD+Shift+q
, - restart Spectrwm:
MOD+Shift+r
, - increase stack:
MOD+semicolon
, - decrease stack:
MOD+comma
, - swap focused window (clockwise direction):
MOD+Shift+j
, - swap focused window (counterclockwise):
MOD+Shift+k
, - close focused window:
MOD+c
, - switch to workspace 1:
MOD+ampersand
, - switch to workspace 2:
MOD+eacute
, - switch to workspace 3:
MOD+quotedbl
, - switch to workspace 4:
MOD+apostrophe
, - switch to workspace 5:
MOD+parentleft
, - switch to workspace 6:
MOD+minus
, - switch to workspace 7:
MOD+egrave
, - switch to workspace 8:
MOD+underscore
, - switch to workspace 9:
MOD+ccedilla
.
Keep in mind to restart Spectrwm
(MOD+Shift+r
) after modifying its configuration.