Up to now, I have shown how to get started with Sway with the initial configurations and some other configurations.
Now, I’ll show how to install another status bar in Sway: Waybar (which is more powerful than the default Sway bar). Again, I’m going to do that for Arch Linux. As in the previous posts, I will NOT focus on the look and feel configuration. (This post is similar to the post about Hyprland and Waybar, but it’s specific to Sway).
Before continuing, the Waybar module for keyboard status (Caps lock and Num lock) requires the user to be part of the “input” group. Ensure your user is part of that group by running “groups”. If not, then add it with
1 |
sudo usermod -aG input $USER |
Then, you must log out and log in.
Let’s install the package waybar:
1 |
sudo pacman -S waybar |
Let’s open a terminal and start Waybar (of course, it will appear on top of the current Sway bar at the moment).
1 |
waybar & |
The result is not that good-looking:
Waybar heavily relies on Nerd fonts for icons, and, currently, we don’t have any installed (unless you have already installed a few yourself).
The terminal will also be filled with warnings about a few missing things (related to Sway) and errors about failures to connect to MPD.
Let’s quit Waybar (close the terminal from where you launched it), and let’s fix the font problem by installing a few font packages:
1 |
sudo pacman -S otf-font-awesome ttf-arimo-nerd noto-fonts |
Let’s start Waybar again, and this time it looks better:
Try to click on the modules and see what happens. For some, the information shown will change (e.g., the time will turn into the date).
If you have “pavucontrol” installed (which should be the case for an EndeavourOS installation), clicking on the volume section will open the “pavucontrol” dialog for adjusting audio settings:
The “Caps” and “Num” locks should react according to the status of the corresponding keyboard keys. The section “it” shows that my current keyboard layout is “Italian.” if you configure several layouts and switch among them, that part in the bar will update automatically. And, of course, the workspace indicator works like in the default Sway bar.
Let’s quit Waybar again and change the Sway configuration to start Waybar instead of the default Sway bar. This section:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
bar { position top # When the status_command prints a new line to stdout, swaybar updates. # The default just shows the current date and time. status_command while date +'%Y-%m-%d %X'; do sleep 1; done colors { statusline #ffffff background #323232 inactive_workspace #32323200 #32323200 #5c5c5c } } |
must be changed as follows:
1 2 3 |
bar { swaybar_command waybar } |
Now, start Sway and enjoy Waybar.
Note that Waybar, by default, shows the Sway “mode”. For example, by default, SUPER+R enters the resize mode, where you can resize the current tiled window with arrow keys. The mode is indicated in the Waybar near the workspaces:
To customize the Waybar, create the configuration files for the Waybar (by default, they are searched for in “~/.config/waybar”). We can do that by using the default ones:
1 2 |
mkdir -p ~/.config/waybar cp /etc/xdg/waybar/* ~/.config/waybar/ |
The above command will copy “config.jsonc” (with the configuration of Waybar modules, i.e., the “boxes” shown in the bar; The configuration uses the JSON file format) and “style.css” (for the style).
At the time of writing, this is the initial part of the configuration file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
{ // "layer": "top", // Waybar at top layer // "position": "bottom", // Waybar position (top|bottom|left|right) "height": 30, // Waybar height (to be removed for auto height) // "width": 1280, // Waybar width "spacing": 4, // Gaps between modules (4px) // Choose the order of the modules "modules-left": [ "sway/workspaces", "sway/mode", "sway/scratchpad", "custom/media" ], "modules-center": [ "sway/window" ], "modules-right": [ "mpd", "idle_inhibitor", "pulseaudio", "network", "power-profiles-daemon", "cpu", "memory", "temperature", "backlight", "keyboard-state", "sway/language", "battery", "battery#bat2", "clock", "tray" ], ... |
The initial parts specify the position and other main configurations. You can edit as you see fit by removing a module, moving it to another position, or enabling new ones. You might want to have a look at the Waybar Wiki for an explanation of the modules.
NOTE: I’m testing this configuration in a virtual machine, so modules like “backlight” and “battery” are not shown because there’s nothing corresponding to them in the virtual machine.
Remember that for each module you mention here, you can have a configuration in the rest of the file, e.g.:
1 2 3 4 5 6 7 8 9 |
"tray": { // "icon-size": 21, "spacing": 10 }, "clock": { // "timezone": "America/New_York", "tooltip-format": "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>", "format-alt": "{:%Y-%m-%d}" }, |
Otherwise, you get the defaults for that module.
Let’s add a configuration for showing a Taskbar to show all the running applications from all workspaces. This can be useful for quickly looking at all the running applications and quickly switching\ to any of them, especially in many workspaces. I’ll add it to the left section and remove the “custom/media” block, which I don’t use:
1 2 3 4 5 6 |
"modules-left": [ "sway/workspaces", "sway/mode", "sway/scratchpad", "wlr/taskbar" ], |
The module must also be configured to get the functionality that clicking on an element activates that element, possibly switching to the containing workspace (in this example, middle-click will close the window):
1 2 3 4 5 6 7 8 |
"wlr/taskbar": { "format": "{icon}", "icon-size": 16, //"icon-theme": "Numix-Circle", "tooltip-format": "{title}", "on-click": "activate", "on-click-middle": "close" }, |
Save the file, and reload Sway to see the block in action (I opened four different applications in four different workspaces):
The right-most section in the bar is a Tray, showing icons of running applications like Dropbox, Skype, or the Network Applet. Let’s install the latter one:
1 |
sudo pacman -S network-manager-applet |
Let’s configure Sway to autostart the “nm-applet”:
1 |
exec nm-applet |
Let’s restart Sway, and now the Tray section is populated by the Network Manager Applet, which you can click and interact with, e.g., for editing connections or connecting to a WiFi network:
Let’s create a custom module for the Power menu, taking inspiration from the EndeavourOS Sway GitHub repository (I’ll change things a bit and simplify them; in particular, I’m going to use “rofi”, i.e., the package “rofi-wayland”, as shown in my previous posts, instead of “wofi”).
First, add the “custom/power” after the “tray” module:
1 2 3 4 5 6 |
"modules-right": [ ... "clock", "tray", "custom/power" ], |
Then, we define the module:
1 2 3 4 5 |
"custom/power": { "format":" ⏻ ", "on-click": "exec ~/.config/waybar/scripts/power-menu.sh", "tooltip": false, } |
Note that I’ve used a character using the installed Nerd font. Of course, you can choose anything you like.
Then, we add the script in the corresponding directory:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#!/bin/bash entries="Logout Suspend Reboot Shutdown" selected=$(printf '%s\n' $entries | rofi -dmenu | awk '{print tolower($1)}') case $selected in logout) swaymsg exit;; suspend) exec systemctl suspend;; reboot) exec systemctl reboot;; shutdown) exec systemctl poweroff -i;; esac |
Remember, the script must be made executable.
Reload Sway. Here’s the result after clicking on the new top-right power button:
That’s my “right” part’s configuration:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
"modules-right": [ "idle_inhibitor", "pulseaudio", //"network", //"power-profiles-daemon", "backlight", "keyboard-state", "sway/language", "battery", "clock", "tray", "custom/power" ], |
That’s all! Stay tuned for other posts about Sway.