User Tools

Site Tools


software:sway

What is it?

sway is a tiling window manager, active project, working on Wayland. Just the right thing to try out for me after using Window Maker, which seems to stay on Xorg forever. Phoronix sees gnome/Wayland consuming less power than gnome/Xorg.

Running Sway on Fedora

  • Setup sway on Fedora - my notes below should include most of that
  • https://github.com/swaywm/sway recommends to run sway directly from the TTY. That means to set multi-user target as default target, login there, and run sway from there. One can do that, but I use the minimal display manager sddm here.
# I did a LXDE-desktop 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.

Custom config file

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

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

Terminal settings

Status of various terminals on Fedora, with sway and for my needs:

  • 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 fctx5 (so I can input Japanese)
    • automatic url selection works nicely (doubleclicking a url)
    • increasing font with the keyboard works out of the box, with German keyboard layout: <crtl>+<+>, <crtl>+<->
  • alacritty: works, but has no imsupport, so no Japanese input possible
  • foot: works, but apparently no imsupport as of foot-1.9.1-1.fc35.x86_64

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 one detail: $mod+Left changes to the previous workspace, and $mod+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 Hangul_Hanja+Left workspace prev # on the keyboard from Korea
    bindsym Hangul_Hanja+Right workspace next
    bindsym Prior workspace prev        # Thinkpad keys above cursor keys
    bindsym Next workspace next

The last 2 lines are for the “right CTRL 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'.

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+F5 exec light -U 5
  bindsym $mod+F6 exec light -A 5

With this, one can press $mod+F5/F6 to control brightness.

Internal/external screens

Using xrandr is not recommended, but so far the replacements actually look good. I frequently dock/undock my system. When docked, I only want to use an external screen.

# 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'
  [..]

# In the sway config, I refer to these entries.  So I frequently
# modify the config, then reload with <modkey>+<Shift>+<c>, and 
# have the new setup active.

# in ~/.config/sway/config, for 'docked'config:
output DP-4 enable
output eDP-1 disable

# in ~/.config/sway/config, for all monitors active:
output DP-4 enable
output eDP-1 enable

Custom statusbar

dnf install -y python3-psutil python3-netifaces fontawesome-fonts
cd /opt
git clone git://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 cpu memory sensors2 battery weather time \
  -p cpu.format={:.00f}% \
     traffic.exclude=wlp,virbr,lo,redhat traffic.showname=False traffic.format={:.0f}\
     sensors2.showtemp=false sensors2.showcpu=false \
     time.format="%H:%M" memory.format="{used}" \
  -t powerline

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

Japanese input: ibus

I got sway/ibus to run only with a hack, see next section. Nowadays I just use fcitx5.

These are the pieces how it's supposed to work ideally. Duck-san regarding the topic, Fedora bugzilla against ibus.

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

# Once ibus-daemon is running, one is supposed to execute
/usr/libexec/ibus-wayland
# ..but this bails out with "No input_method global" currently.

Japanese input: ibus, hack

After executing above steps for ibus installation and configuration, add the following in ~/.config/sway/config:

bindsym Shift+space exec sh -c 'if [ "$(ibus engine)" = "anthy" ]; then ibus engine xkb:us::eng; else ibus engine anthy; fi'

You can at a terminal at sway use “ibus engine” so see the currently activated engine, and “ibus engine anthy” for example to activate anthy:

[chris@космос ~]$ ibus engine
xkb:us::eng
[chris@космос ~]$ ibus engine anthy
[chris@космос ~]$ ibus engine
anthy
[chris@космос ~]$

After a Sway restart with $mod+Shift+C the combination of Shift+space should do this switching. Normally ibus should do this. Also, with this I can still not input Japanese in xterm, but for example on Firefox, gtk based programs, or the terminator terminal. Details are here.

Japanese input: fcitx5

This works nicely for me, Fedora now also has the fcitx5-mozc package.

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

grim is not yet packaged..

sudo dnf install -y meson cairo-devel.x86_64 libwayland-client.x86_64 \
  wayland-devel.x86_64 wayland-protocols-devel.noarch \
  libjpeg-turbo-devel.x86_64
git clone https://github.com/emersion/grim
cd grim
meson build
ninja -C build

# lets take a screenshot
build/grim myscreenshot.jpg

# if error "failed to create display"
export WAYLAND_DISPLAY='wayland-1'
build/grim myscreenshot.jpg

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
  • see also related blogposts from Jan, link
server software / service client software Way 1 (xdg) Way 2 (video stream) Way 3 (tabs)
Jitsi 2.0.6433-1@Debian Bullseye selfhostedFirefox 94@Fedora35 no no
Jitsi 2.0.6433-1@Debian Bullseye selfhostedChrome 95@Fedora35 yes yes
Skype skypeforlinux-8.77.0.97-1 no no
https://web.skype.com Nov-2021 Firefox 94@Fedora35 no no
https://web.skype.com Nov-2021 Chrome 95@Fedora35 yes yes (unsharp) yes
Bluejeans Nov-2021 Firefox 94@Fedora35 yes yes (unsharp) no
Bluejeans Nov-2021 Chrome 95@Fedora35 yes yes (unsharp) yes
google hangouts Chrome 95@Fedora35 yes
google meet Chrome 95@Fedora35 yes

Way 1: xdg-desktop-portal-wlr

  • 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

# 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 workaround 1.

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
software/sway.txt · Last modified: 2022/08/03 13:16 by 127.0.0.1