Site Tools


Sidebar

Action disabled: revisions
software:sway

What is this about?

sway is a tiling window manager, active project, working on Wayland. Modelled after i3 which runs on Xorg. Sway was just the right thing for me coming from Window Maker, which seems to stay on Xorg forever. Phoronix sees gnome/Wayland consuming less power than gnome/Xorg.

Running Sway on Fedora

# I do a LXDE-desktop or minimal installation 
# of Fedora, and then:

dnf -y install sway sddm
for i in lxdm kdm gdm lightdm xdm; do
  systemctl disable $i
done
systemctl enable sddm
systemctl set-default graphical.target

reboot

# After this, sddm starts and allows to directly run sway

Configuration and first steps

After you got sway running, it's time to familiarize yourself with the keyboard shortcuts and modify the configuration. The default config can be seen at https://github.com/swaywm/sway/blob/master/config.in or in file /etc/sway/config . The config file teaches you all shortcuts you need at this moment.

On my thinkpad, the english keyboard layout was configured by default. The $mod-key is the windows-key, which is on Linux not used anyway. Sway uses that key heavily. For the start, you should use the config suggested by Sway, and can then adapt it to your needs.

The default config is /etc/sway/config. If you want to customize, do this:

mkdir -p ~/.config/sway
cp /etc/sway/config ~/.config/sway
vi ~/.config/sway/config

Terminal settings

Terminals are started in pressing $mod + <return>. Currently I use mostly 'alacritty' and sometimes 'kitty'. Status of various terminals on Fedora, with sway and for my needs:

  • alacritty: works, including input-method support via fcitx5, doubleclick on URLs opens them in firefox
  • kitty: works, including input-method support via fcitx5
  • foot: works, as of foot-1.14.0-1.fc38 there is also input-method support
  • xterm:
    • works, including input-method support via fcitx (so I can input Japanese)
    • automatic url selection works, so double-clicking a URL in a terminal selects it. Yet, opening that directly in the browser does not work for me.
    • increasing font with the keyboard works with extra config, but I need to find a good font for the different sizes
  • terminator:
    • works, including input-method support via fcitx5
    • automatic url selection works nicely (doubleclicking a url)
    • increasing font with the keyboard works out of the box, with German keyboard layout: <crtl>+<+>, <crtl>+<->

My terminal config:

$ grep term ~/.config/sway/config
set $term /home/chris/bin/myterm.sh
$ cat /home/chris/bin/myterm.sh
xterm -en UTF-8 -fg white -bg black -fn \
  -Misc-Fixed-Medium-R-Normal--18-120-100-100-C-90-ISO10646-1 +sb -e bash

Changing workspace

A workspace in Sway is what I called “virtual screen” in Window Maker. Regarding workspaces, I mostly go with the default config from Sway. I just added this: Ctrl+Left changes to the previous workspace, and Ctrl+Right to the next workspace. By default, one can with $mod+1 jump to the first workspace, with $mod+2 to the second workspace, and so on. So I added this in ~/.config/sway/config:

    bindsym Ctrl+Left workspace prev    # on default keyboards
    bindsym Ctrl+Right workspace next
    bindsym Prior workspace prev        # Thinkpad keys above cursor keys
    bindsym Next workspace next
    bindsym Hangul_Hanja+Left workspace prev # on the keyboard from Korea
    bindsym Hangul_Hanja+Right workspace next

The last 2 lines utilize a certain key on this keyboard here which I bought in Korea. When running 'xev' and then pressing the key, one sees the identifier for the key, in my case 'Hangul_Hanja'. Typically, this key is used to switch input methods between for example English/Hangul.

Firefox notes

  • When simply running 'firefox', you get the Xorg version with Xwayland. As of Fedora39, package 'firefox-wayland' installs bash script /usr/bin/firefox-wayland which is running firefox with MOZ_ENABLE_WAYLAND=1. So pressing <modkey>+<d> and running 'firefox-wayland' should be used. In the past, I used an own script ~/bin/wfirefox which did the same.
  • In 2022, I encountered an issue in Firefox where the mouse pointer changed for example to a magnifying glass, but then never changed back to the normal pointer. This turned out GDK related, starting Firefox as follows fixes the issue: “env GDK_BACKEND=x11 MOZ_ENABLE_WAYLAND=0 firefox”. As of Fedora 38/Firefox 112 the issue is gone, and I use again “env MOZ_ENABLE_WAYLAND=1 firefox”.
  • You can activate WebRender functionality for performance reasons: https://wiki.archlinux.org/title/Firefox/Tweaks#Enable_WebRender_compositor
  • To receive notifications from websites (i.e. Mastodon, Slack), I use 'mako'. 'dnf install mako' installs it, and “exec /usr/bin/mako” in ~/.config/sway/config ensures it is run and properly started.

Locking the screen

I have a habit of locking the screen when leaving the workplace, by pressing F9. Easy to implement:

# install xlock
dnf -y install xlockmore
# add the config
echo 'bindsym F9 exec /usr/bin/xlock -mode blank' >>~/.config/sway/config
# reload config
press <modkey> + <Shift> + <c>
press F9 for testing

Controlling brightness

On laptops, package `light` should be installed, and this be added to ~/.config/sway/config:

  bindsym $mod+Shift+o exec light -U 5
  bindsym $mod+Shift+p exec light -A 5

With this, one can press <mod>+<Shift>+<o/p> to control brightness.

Internal/external screens

Using xrandr is not recommended, wlr-randr should be used instead. I frequently dock/undock my system, and use the following key binding to toggle the internal screen on/off.

# lets look at the names for our outputs
swaymsg -t get_outputs
Output DP-4 'Dell Inc. DELL U2412M RPT5T2372ADL' (focused)
  Current mode: 1920x1200 @ 59.950001 Hz
  [..]
Output eDP-1 'Unknown 0x21ED 0x00000000'
  [..]
  
# Entry in ~/.config/sway/config
bindsym $mod+t output "eDP-1" toggle

Alternatively, the internal screen can be activated/deacrivated in ~/.config/sway/config:

# Internal display disabled:
output DP-4 enable
output eDP-1 disable

# Internal display enabled:
output DP-4 enable
output eDP-1 enable

Custom statusbar

Using the following status bar with network down/up, volume, cpu load, used memory, fan, battery, weather, time/germany and time/Japan.

dnf install -y python3-psutil python3-netifaces fontawesome-fonts \
  git-core python3-requests python3-pytz python3-tzlocal \
  lm_sensors
cd /opt
git clone https://github.com/tobi-wan-kenobi/bumblebee-status

# now modify the users ~/.config/sway/config, change
status_command while date +'%Y-%m-%d %l:%M:%S %p'; do sleep 1; done
  into
status_command /opt/bumblebee-status/bumblebee-status \
  -m traffic pipewire cpu memory sensors2 battery weather datetimetz time \
  -p cpu.format={:.00f}% \
     traffic.exclude=virbr,lo,redhat,nebula traffic.showname=False \
     traffic.format={:.0f} \
     time.format="日本 %H:%M" \
     datetimetz.format="独 %H:%M" datetimetz.timezone="Europe/Berlin" \
     memory.format="{used}" \
     sensors2.showtemp=false sensors2.showcpu=false sensors2.field_exclude=fan2 \
     traffic.interval=5s cpu.interval=5s sensors2.interval=5s \
     memory.interval=1m weather.interval=30m battery.interval=1m \
  -t powerline

Details: https://github.com/tobi-wan-kenobi/bumblebee-status .

For the Macbook pro M2 with Fedora Asahi remix I use 'battery-upower' instead of 'battery', and 'shell' to count new mails:

status_command /opt/bumblebee-status/bumblebee-status \
  -m traffic pipewire cpu memory sensors2 battery-upower shell weather datetimetz time \
  -p cpu.format={:.00f}% \
     traffic.exclude=virbr,lo,redhat,nebula traffic.showname=False traffic.format={:.0f} \
     time.format="日本 %H:%M" \
     datetimetz.format="独 %H:%M" datetimetz.timezone="Europe/Berlin" \
     memory.format="{used}" \
     sensors2.showtemp=false sensors2.showcpu=false  sensors2.field_exclude=fan2 \
     traffic.interval=5s cpu.interval=5s sensors2.interval=5s \
     memory.interval=1m weather.interval=30m battery.interval=1m \
     shell.command="echo -n '📨 '; ls -1 /home/chris/Maildir/new/|wc -l" shell.interval=60 \
  -t powerline

Japanese input: ibus

Until Fedora37/ibus-1.5.27, ibus did not work for me on sway/wayland. From Fedora37 on the issue is solved.

dnf -y install ibus ibus-setup ibus-gtk3 ibus-wayland \
  ibus-skk ibus-mozc ibus-kkc ibus-qt
  
# run ibus-daemon at sway startup
echo 'exec /usr/bin/ibus-daemon --xim --daemonize' \
  >>~/.config/sway/config
  
# set environment variables, i.e. in ~/.bashrc
export IMSETTINGS_INTEGRATE_DESKTOP=yes
export IMSETTINGS_MODULE=ibus
export QT_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
export GTK_IM_MODULE=ibus

# then exit sway with <modkey>+<Shift>+<e>
# and start sway again, then
ibus-setup

Japanese input: Fcitx5

At the moment I use Fcitx5, not ibus.

dnf -y install fcitx5-configtool fcitx5-kkc fcitx5-mozc

# run fcitx at sway startup
echo 'exec --no-startup-id fcitx5 -d' >>~/.config/sway/config

# set environment variables, i.e. in ~/.bashrc
export IMSETTINGS_INTEGRATE_DESKTOP=yes
export IMSETTINGS_MODULE=fcitx
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx

# then exit sway with <modkey>+<Shift>+<e>
# and start sway again, then
imsettings-switch fcitx5
fcitx5-configtool

Screenshots

# As of Fedora37, grim is packaged.
# If not packaged on your distro, build from https://github.com/emersion/grim
dnf install grim

# lets take a screenshot
grim screenshot.png

# if error "failed to create display"
env WAYLAND_DISPLAY='wayland-1' grim screenshot.png

# After issuing the command, I usually want s few seconds delay to
# change to the virtual screen I want to screenshot, so I use this:
alias takepic='export WAYLAND_DISPLAY=wayland-1; sleep 3; grim'
takepic screenshot.png

Video chat Screen sharing

As of Fedora35, xdg-desktop-portal-wlr seems like the best way for screen sharing - but it requires to use a browser based videoconf software, does not work with the stand alone Skype program.

  • Chromium might need this config change: open chrome://flags/#enable-webrtc-pipewire-capturer
  • xdg-desktop-portal-wlr is supported since 2018
  • Comments for single video chat softwares, as of March 2023:
    • Skype stand alone software: video chat works, but no screen share offered
    • Skype via https://web.skype.com : video chat works, including screen share
    • Bluejeans: video chat works, including screen share
    • Google meet: video chat works, including screen share

Way 1: xdg-desktop-portal-wlr

Note: Google chrome and chromium in version 112 can not share screen via xdg-desktop-portal-wlr-0.6.0, see here. Downgrade to 111 is required.

  • con: does not work with stand alone Skype application
  • pro: low cpu load
sudo dnf -y install xdg-desktop-portal-wlr

# add the following to ~/.config/sway/config
exec dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
# then reload sway with <mod-key>+<shift>+<c>

Then access this URL, and click “screen capture” to test.

Way 2: Full screen capture as video stream

From video: openSUSEway_is_a_full_Wayland_DE_based_on_Sway, this is recording the screen activity and making it available on a video device like /dev/video0. You can then feed that into Jitsi/bluejeans/skype. This workaround will transmit your normal desktop, but the constant recording causes quite some cpu load.

# install packages
dnf install v4l2loopback wf-recorder wlr-randr \
    akmod-v4l2loopback kmod-v4l2loopback
    
# ensure module is loaded
modprobe v4l2loopback
# Note: on Asahi-Fedora-remix I had to manually build
# the module:
# sudo dnf install kernel-16k-devel
# git clone https://github.com/umlaeute/v4l2loopback
# cd v4l2loopback && make && sudo make install
# sudo modprobe v4l2loopback

# find out which device loopback uses, for next command
v4l2-ctl --list-devices

# start recording screen, using v4l2 loopback device
wf-recorder --muxer=v4l2 --codec=rawvideo \
  --file=/dev/video0 --pixel-format yuyv422

wlr-randr
mplayer tv:// -tv driver=v4l2:device=/dev/video0

Way 3: Container desktop in browser tab

webtops container. This runs a desktop in a container, and you can access that desktop in a browser tab, which you can for example share in google meet. This uses memory, but less cpu load than “way 2”.

podman run -d --name=webtop \
  -e PUID=1000 -e PGID=1000 -e TZ=Asia/Tokyo -p 3000:3000 \
  -v /home/chris/sync:/sync:Z,ro --shm-size="1gb" \
  --restart unless-stopped ghcr.io/linuxserver/webtop:fedora-xfce

Then access the container destop via http://localhost:3000/ .

Hall of shame for apps

I've hit some applications doing particularly bad under sway/wayland.

  • gimp: complete system lockups when trying to save pictures, as of 2023. I've moved to 'krita' and couldn't be happier!
  • dia (diagram software): freezes every now and then. Using now sometimes ascii-art diagrams, painted with online services.
  • X11 apps forwarding via SSH: Logging into remote systems using i.e. 'ssh -Y rhel8u2b', and having on the remote system for example xauth and xterm installed, I can run xterm remotely and get it forwarded. $DISPLAY in the session is set to “localhost:10.0”.
  • alacritty not working with fcitx5 for input method switching? Start it like this:
    • WAYLAND_DISPLAY= alacritty
    • or WINIT_UNIX_BACKEND=x11 alacritty
  • Hanging menu issue: I have experienced hanging menus: so after pressing $mod + D, the menu for running applications stays and can not be removed. In that case, “killall dmenu” removed the menu, and $mod + Shift + c can reload the normal top bar.
  • Additional software: My reminder for additional software. All from Fedora or rpmfusion repos.
    • firefox, google-chrome
    • evince - pdf viewer
    • mplayer, qiv - video, picture viewer
    • wf-recorder - record screen. env WAYLAND_DISPLAY=wayland-1 wf-recorder -f out.mkv
  • Links:
software/sway.txt · Last modified: 2024/03/03 10:07 by chris