Konstantin Nazarov

Playing with wayland

Wayland has been in development since 2008. I remember the initial hype around it: it was meant to be a better Xorg replacement in every aspect: from input management to rendering and code simplicity.

Fast forward 11 years, and it still is far from completion. Many apps lack support for anything except X, and Nvidia refuses to adopt GBM API, which means their drivers are not supported.

My previous attempt to use Wayland was almost 6 months ago, when I got myself a Linux laptop. Fortunately, it has Intel GPU, so I thought after all that time I won’t have many problems. I installed the latest Ubuntu and gave it a try. The results were disappointing: scrolling was janky (especially in XWayland), and there were occasional but very noticeable freezes and artifacts. After a few hours of usage, I just gave it up.

A week ago, I decided to give it another round with Ubuntu 20.04. Contrary to what I expected, I didn’t find any problems right away. After a few minutes of dragging windows around and clicking here and there in Firefox, I decided to give it a more thorough stress test. I tried to plug/unplug an external 4k thunderbolt monitor a few times, then played around with opening and closing notebook lid. It all worked correctly and switched outputs as I expected. Plugging and unplugging input devices didn’t cause any problems either.

Then I started experimenting with Firefox. I knew that Mozilla were taking Wayland seriously, and already ported their browser. In fact, the default Firefox supports Wayland out of the box. After setting MOZ_ENABLE_WAYLAND=1 in my session I was able to get it running natively.

In addition to just supporting Wayland, I heard that Firefox now can support hardware acceleration when decoding h264 videos (for example, in YouTube). This didn’t work under Xorg, because it was hard to get a real hardware context inside the browser process. But since Wayland is essentially a buffer manager with direct OpenGL rendering support, the problem became solvable. I flipped a few options in about:config, installed the “h24ify” plugin (since VP8 codec acceleration that is used by default in YouTube is only being implemented), and tested it on a few YouTube videos. The result was very pleasant: CPU utilization dropped to below 10% of one of my CPU cores. On Xorg it was closer to 30%.

When I was satisfied with regular apps, I decided to dive into some geekery. I knew that Xorg had tiling window managers for ages, but they were very tightly coupled to X API, so I doubted they could be ported. After a bit of googling, I’ve found Sway WM which claimed full compatibility with i3, while being native to Wayland.

To be honest, I was skeptical at first, because regular tiling window managers are relatively simple, making use of very stable and abundant Xorg APIs. On the other hand, in Wayland a window manager has to implement a lot of stuff that X WMs take for granted.

And again, I was very pleasantly surprised that it just worked out of the box. Looks like the creators of Sway put a tremendous effort to get it to this state.

It unites everything I used to set in a dozen config files into just one.

Here’s for example a configuration for dynamic multi-monitor support:

# configure display resolution
output eDP-1 resolution 3840x2160 position 0 0
output DP-2 resolution 3840x2160 position 3840 0

set $laptop eDP-1

# turn off internal display when the lid is closed
bindswitch --reload --locked lid:on output $laptop disable
bindswitch --reload --locked lid:off output $laptop enable

Here’s my input configuration:

# I like reverse scrolling the way it's implemented in OS X
input type:touchpad {
 natural_scroll enabled
 scroll_factor 0.5

# Keyboard layout switching and tweaks
input "1:1:AT_Translated_Set_2_keyboard" {
    xkb_layout "us,ru"
    xkb_options "grp:alt_space_toggle,altwin:swap_lalt_lwin,ctrl:nocaps"

There are other minor things like tuning hotkeys to your liking and tuning sleep/screen lock, but I won’t bother you with details.

To conclude all this, Wayland is definitely ready for tiling WM fans, and it is stable enough to finally give it a serious try.

Share this post

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email