Wayland tips and tricks

Post Reply
User avatar
mctom
Posts: 236
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polish
ODROIDs: N2+, Game Advance, a few XU4
Location: Gdansk, Poland
Has thanked: 27 times
Been thanked: 16 times
Contact:

Wayland tips and tricks

Post by mctom »

I've been meaning to compile a bunch of Wayland tips, as I switched to Wayland full-time a month ago or so.
And I can tell, there are ways to live with it without flipping your desk too often, but I still recommend keeping your desk firmly against a wall, just in case :D
Personally I can't stand Gnome with its GUI designed for 7" screens, so I adopted Sway as my DM. That's why some of my tips may not apply or work for others, and probably will be redundant in most cases, as I set up Sway manually.

Anyway, hopefully someone finds them useful and I'd gladly see the others joining in the discussion. I'll try to keep the most relevant findings in this post for newcomers. If the topic gets momentum, I may gather all our combined knowledge and put it in Odroid Wiki, where it should be.

-------------------------------------------------

Compatibility with X ("legacy") software
In order to make legacy software work on Wayland, there are two options.
1) Either software is run using "xwayland" compatibility layer, which runs okay in most cases these days.
All that needs to be done is to install xwayland from default repo.
This is always recommended as a fallback option if the following approach fails.
2) Or it may turn out that the software has been built using a toolkit that already has Wayland support.
Most toolkits need explicit instruction to run software in Wayland mode, in form of env variables. Here's a collection that works fine in most cases:

Code: Select all

export GDK_BACKEND=wayland
export CLUTTER_BACKEND=wayland
# make Clutter default to GLES 2.0 driver, or fall back to default driver list
export CLUTTER_DRIVER=gles2,*
export QT_QPA_PLATFORM=wayland
# the following needs qt5ct package to work
export QT_QPA_PLATFORMTHEME=qt5ct
# the following may break older proprietary games
export SDL_VIDEODRIVER=wayland
# additional package libglfw3-wayland may be needed to run some software
Software-specific tweaks
Firefox (and possibly Thunderbird) can be forced to use native Wayland mode using the following variable:

Code: Select all

export MOZ_ENABLE_WAYLAND=1
glmark2-es2-wayland from tobetter's repo doesn't work in Sway for reasons unknown to us. However it does work when compiled from source.

Running legacy software as root
Wayland by design does not support running GUI as other user than the session owner - it's a safety feature. However some programs, like gparted or synaptic, insist on running their GUI portion as root. In that case, the workaround is to invoke the following command before starting said program. This command lets other user access your Wayland session (root in this case), until cancelled or rebooted.
It is also worth noting this method works for xwayland only - it won't work if application attempts to use wayland backend.

Code: Select all

xhost si:localuser:root
To undo this operation, run:

Code: Select all

xhost -si:localuser:root
Recommended software
Here is a very helpful list of Wayland-friendly or native software.
Some of these are better than others in my opinion, and some failed to work at all.

Personally I recommend:
Falkon - a modern web browser without X dependencies
Zathura - PDF viewer with vim-like control
Sway or Wayfire as the two arguably leading Wayland-native compositors, with Sway available in Ubuntu repos and Wayfire quite easy to build
Grim + Slurp - screenshot software
Foot - lightweight and functional terminal (not available in Ubuntu repos before hirsute)
Waypipe - proxy for Wayland clients, works pretty much like "ssh -X"
Thunar - an xfce file manager. Not built specifically for Wayland, but runs natively very well.
Engrampa - Archive manager from MATE

Sway-specific:
waybar - very flexible desktop "bar" for session management
swayidle, swaylock - providers for screen lock and energy saving mode
Last edited by mctom on Mon May 31, 2021 1:44 pm, edited 3 times in total.
These users thanked the author mctom for the post (total 2):
odroid (Mon May 24, 2021 2:03 pm) • tobetter (Mon May 24, 2021 3:31 pm)
Punk ain't no religious cult, punk means thinking for yourself!

Maintainer of PiStackMon

User avatar
mad_ady
Posts: 9483
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, C4, N1, N2, H2, Go, Go Advance
Location: Bucharest, Romania
Has thanked: 604 times
Been thanked: 682 times
Contact:

Re: Wayland tips and tricks

Post by mad_ady »

Nice collection of tips!
I haven't had time to explore wayland, and living with x11 for 22 years makes me a bit reluctant to switch, but things like waypipe and wayland-enabled firefox/thunderbird makes things more compelling. Having an xpra-like alternative (runs x11 applications in a headless x11 server that you can attach to/detach from, like screen/tmux) would be interesting.

I know there is also a vnc client/server for wayland discussed around the forum.

User avatar
mctom
Posts: 236
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polish
ODROIDs: N2+, Game Advance, a few XU4
Location: Gdansk, Poland
Has thanked: 27 times
Been thanked: 16 times
Contact:

Re: Wayland tips and tricks

Post by mctom »

I tried waypipe once or twice recently, and it works, but I tried that with Firefox over 100Mbps bottleneck so it was far from perfect. :) There are more build options including compression, opengl / video support and whatnot, but I didn't play with that just yet.
However it is worth noting that the server side apparently doesn't need Wayland to run a program through waypipe. Not 100% sure about that though, and even if, Wayland doesn't take much space anyway.

I think you can still use xpra in Wayland, with xwayland layer - it's working fine for most scenarios. I did a lot of "ssh host pavucontrol" to turn down the music in the kitchen ;)

xwayland is transparent, you don't need to call it explicitly to use it - Wayland compositor takes care of that.

I've been using X11 for 6 years, give or take, but the snappiness and lightness of Wayland compositors bought me (currently Sway takes up 171MB of RAM on my machine).
I also run Sway on dual core 1.2GHz Atom netbook and it is perfectly usable - something that couldn't be said about anything X-dependent. Before that, Puppy Linux was the sole option that actually ran well on this thing.
Punk ain't no religious cult, punk means thinking for yourself!

Maintainer of PiStackMon

User avatar
mctom
Posts: 236
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polish
ODROIDs: N2+, Game Advance, a few XU4
Location: Gdansk, Poland
Has thanked: 27 times
Been thanked: 16 times
Contact:

Re: Wayland tips and tricks

Post by mctom »

Did you know that most Linux distros (including Ubuntu and derivatives) start ssh-agent through X11 init scripts or, even through alias of startx?
That's reasonable and convenient, because that ensures only one ssh-agent copy is active per user session, BUT! That also means that ssh-agent on Wayland (or X-less system in general) doesn't work by default! :lol:
(That is, unless you use X-based greeter..)

Here's a workaround from smart guys at arch wiki. Add this script to your .bashrc, so it starts ssh-agent if not started yet:

Code: Select all

if ! pgrep -u "$USER" ssh-agent > /dev/null; then
    ssh-agent -t 1h > "$XDG_RUNTIME_DIR/ssh-agent.env"
fi
if [[ ! "$SSH_AUTH_SOCK" ]]; then
    source "$XDG_RUNTIME_DIR/ssh-agent.env" >/dev/null
fi
Punk ain't no religious cult, punk means thinking for yourself!

Maintainer of PiStackMon

User avatar
mctom
Posts: 236
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polish
ODROIDs: N2+, Game Advance, a few XU4
Location: Gdansk, Poland
Has thanked: 27 times
Been thanked: 16 times
Contact:

Re: Wayland tips and tricks

Post by mctom »

Building Sway 1.6

Sway 1.5 is available in Ubuntu Hirsute repos, so it's going to be a long time before any newer version become mainstream among Ubuntu users.
Sway 1.6 fixes many visual glitches, most notably Firefox's rendering of drop down menus etc. I also noticed generally lower demand for RAM, but can't say for sure if this helped.

The following instructions may be incomplete in terms of dependencies, I didn't track them along the process. Just install whatever it complaints about. Library headers in Ubuntu repositories have "lib" prefix and "-dev" suffix, but sometimes dependencies are binaries. For example, to install "pango", sudo apt install libpango1.0-dev.
You will most likely repeat meson build/ a few times to satisfy all dependencies, each time discovering yet another missing library. In order to force it to redo its work, use meson build/ --reconfigure.

The dependency chain goes down to building Wayland 1.19.0:

Code: Select all

git clone --branch=1.19.0 https://gitlab.freedesktop.org/wayland/wayland
cd wayland
meson build/ --disable-documentation
ninja -C build/ install
I recommend disabling documentation, because it needs 800+MB of extra binaries to generate it, and it's available online anyway.

You will also need seatd:

Code: Select all

git clone --single-branch --branch 0.5.0 https://git.sr.ht/~kennylevinsen/seatd
cd seatd/
meson build/
cd build
sudo ninja install
Next stop, the libxcb-errors, that for whatever reason is missing in Ubuntu repos:

Code: Select all

git clone https://gitlab.freedesktop.org/xorg/lib/libxcb-errors.git
cd libxcb-errors
git submodule update --init
./autogen.sh
make
sudo make install
One of the tricky dependencies is xorg-macros, which is a part of xutils-dev package.

Now it's time to build and install wlroots:

Code: Select all

git clone --branch 0.13.0 https://github.com/swaywm/wlroots.git
cd wlroots/
meson build/ --libdir=/usr/local/lib
ninja -C build/
sudo ninja -C build/ install
Meson has a long standing bug that sometimes stuffs libraries into a subdirectory rather than the target dir directly. Explicit --libdir parameter is said to mitigate this problem, but make sure libwlroots.so.8 is there after finishing these steps.

And finally, Sway:

Code: Select all

git clone --single-branch --branch 1.6 https://github.com/swaywm/sway.git
cd sway
meson build
cd build
sudo ninja install
If you had Sway installed before, everything should be ready by now. If not, you may need to add some variables to your .profile:

Code: Select all

export PATH=/usr/local/bin:$PATH
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:$PKG_CONFIG_PATH
export PKG_CONFIG_PATH=/usr/local/share/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/lib64/:$LD_LIBRARY_PATH
In order to run Sway, simply type sway into the tty terminal. Don't run it as root, it won't work. :)
Punk ain't no religious cult, punk means thinking for yourself!

Maintainer of PiStackMon

Post Reply

Return to “Ubuntu (All Linux'es)”

Who is online

Users browsing this forum: mctom and 3 guests