MC's journal

Setting Orange, the 22 day of Discord in the YOLD 3186

No more X11!

From my Sway configuration:

xwayland disable
20200310_21h39m08s_grim.png

In January I finally stopped using the X Window System.

I had found native Wayland programs for most of my needs, so I turned off the Xwayland X server in my Sway configuration and removed both the Xwayland and the X.org X server from my personal laptop.

I've been waiting for this moment a long time. I was never very happy with X and for a long time I refused to run what I perceived as a bloated, slow system with a strange design. At first I continued to use the old MGR window system on SunOS (even porting it to Solaris!), then trying to stay in the Linux console and/or the Plan 9 8½ window system, until I gave up like everyone else and even wrote my own X window manager, mcwm.

Acccepting X might have had something to do with the use of a rather nice fanless 1024x1024 NCD 16 X terminal. This terminal also supported the Xremote protocol that was rather usable even over 9600 or 19200 b/s from home. Here's a picture of me in front of the NCD 16 and flat mate Magnus in front of his much more fancy DEC VXT 2000:

magnus+mc.jpg
Figure 1: Magnus and MC in front of X terminals

The best image I found of my NCD 16 (sorry!):

ncd16.jpg
Figure 2: NCD 16

Of course, I would have preferred the contemporary A&T 630 (the successor of the Blit and 5620)!

att630.jpg
Figure 3: AT&T 630 MTG terminal

Back to Wayland… Sway on my personal Thinkpad x230 feels like a new computer! No tearing! So fast! Yes, of course I used compton when I had X to avoid tearing, but I got a lot of frames dropped when, say, playing video. No more!

Sway uses Pango to draw text. Pango recently lost support for bitmap fonts. This means ordinary bitmap fonts won't work anymore. No more sweet Terminus unless you can find it in or convert it to OTF… A workaround is to use the TTF version.

Here's a neat script to make unfocused windows partly transparent, in case you want to see your background or if you just want to dim unfocused windows:

https://github.com/swaywm/sway/commit/0d5aaf5359c671a51bd319bd7972e0f5e7bcde84

Toolkits

  • GTK3 supports Wayland directly so many GTK3 applications does as well.
  • Qt5 applications will use Wayland.
  • SDL 2 needs SDL_VIDEODRIVER=wayland. SDL 1 unfortunately doesn't support Wayland so I can't run SchismTracker anymore! Help!

Wayland terminal emulators

Since I've been using st for a long time I looked for an alternative with a Wayland backend. I found Michael Forney's Wayland st. It uses Michael's own drawing library, wld, to actually draw something in Wayland. There's a strange fork called wterm which mainly seems to have reindented the code and includes wld in the same repo.

Both of them have problems with cut & paste.

foot (Gitlab mirror) is a native Wayland terminal emulator. Rather minimalist. Written in C.

foot dynamically fixes the font when moving windows between different DPI screens! It also support SIXEL graphics! I added a trivial change to get M-RET to send ESC Return.

GNOME Terminal works in Wayland. But it has a lot of dependencies and stuff I don't care about.

sakura also uses libvte like GNOME Terminal and works in Wayland. Less dependencies than GNOME Terminal but still rather large.

alacritty works fine in Wayland. It still has the X11 backend, though, and it seems it's currently not able to be built as Wayland-only. It's written in Rust, though, which is interesting.

Specific apps

Web browser

Firefox needs the MOZ_ENABLE_WAYLAND=1 variable set. I've seen some crashes but it mostly works. But see below about screen sharing.

Lock the screen

swaylock. Set it in Sway's config file with something like:

set $lock 'swaylock -f -F -c 000000'

exec swayidle -w \
         timeout 600 $lock \
         timeout 900 'swaymsg "output * dpms off"' \
              resume 'swaymsg "output * dpms on"' \
        before-sleep $lock &

and call it directly if you want to lock.

Screen brightness

Notifications (dunst replacement)

mako, but also fnott.

Screenshots

grim & slurp.

PDF viewer

zathura works fine in Wayland.

Image viewers

imv for viewing a single image at the time. I use gthumb for thumbnails and photo handling. Would have liked an sxiv for Wayland but haven't found anything yet.

Watching movies

mpv needs:

gpu-context=wayland

PIN Entry for GPG Agent

~/.gnupg/gpg-agent:

pinentry-program /usr/bin/pinentry-gnome3

SSH password

Note that ssh-add won't start the askpass program unless DISPLAY is set, so fake it even though we don't have any X server running:

export SSH_ASKPASS=/usr/lib/openssh/gnome-ssh-askpass
export DISPLAY=:0

Then again, since we're no longer using X it's no longer a complete disaster to type passwords in the terminal…

Emacs

As you all know, Emacs is not a real GTK3 program. It uses X requests directly for most of what it does. This, of course, means it won't work in a pure-Wayland environment.

There has been some very impressive work on a pure GTK Emacs, however. It compiles and, yes, suddenly you have Emacs as a pure GTK app that runs under Wayland! Last I checked there were issues with input, though.

At the moment I live with an Emacs compiled with no window system support what so ever (and no libxml2, et cetera ad nauseam). I run it in a foot terminal. I will certainly follow what happens in the pgtk branch, though.

This is some really helpful elisp to make the internal cut & paste in Emacs play well with Wayland:

(setq wl-copy-process nil)

(defun wl-copy (text)
  (setq wl-copy-process (make-process :name "wl-copy"
                                      :buffer nil
                                      :command '("wl-copy" "-f" "-n")
                                      :connection-type 'pipe))
  (process-send-string wl-copy-process text)
  (process-send-eof wl-copy-process))

(defun wl-paste ()
  (if (and wl-copy-process (process-live-p wl-copy-process))
      nil ; should return nil if we're the current paste owner
    (shell-command-to-string "wl-paste -n | tr -d \r")))

(setq interprogram-cut-function 'wl-copy)
(setq interprogram-paste-function 'wl-paste)

Taken from https://gist.github.com/yorickvP/6132f237fbc289a45c808d8d75e0e1fb

Keyboard mapping

Sway can use your ordinary XKB definitions that you used with xkbcomp under X11. Put only the symbols file in ~/.xkb/symbols and add something like this to your Sway config:

input * {
      xkb_layout "thinkpad,hhkb"
      repeat_delay 240
      repeat_rate 40
      xkb_options "grp:alt_space_toggle"
}

This means I use my custom Thinkpad keyboard layout as default and change to the custom Happy Hacking Keyboard layout when I hit Alt+Space.

My article about XKB includes my HHKB layout.

Other interesting compositors

  • Hikari, cwm-like FreeBSD-first compositor.
  • tinywl: A tiny example compositor using the wlroots library. I forked it and added a simple tiling mode. Hopefully I'll find some more time to work on this.

Problems

  • Screen sharing in Firefox doesn't work out of the box. I did some experiments with Simon Ser's xdg-desktop-portal-wlr when it appeared but didn't get it to work. Some people on Reddit have reported success.

    This is mostly a problem at work, though. I don't use screen sharing on my personal computers.

  • The camera and microphone permissions popup in Firefox sometimes disappears! There's a workaround, though: Click the padlock by the URL, go to "More information", then to the "Permissions" tab, uncheck "Use default" on "Camera" and allow it.
  • No signal on DisplayPort on my Thinkpad x230. Sway detects the external screen just fine but the HP 27" monitor says "no signal". External screens works fine on my x270, both over DP over USB-C and HDMI.

Written by MC using Emacs and friends.