ToolsMachine translation, not yet reviewed

Linux Fu: Rebuilding Two Workflows After Wayland

After openSUSE dropped the X11 session, xremap and waypipe cover key remaps and remote apps.

X11 was originally built for multi-user, networked machines, and it really did have gaps in some areas that mattered less at the time. Then something odd happened: most people forgot about X11’s multi-user networking and treated it as the display driver for a single-user workstation. That works, but it is like riding a motorcycle from the living room to the kitchen. You can do it. You just accept the tradeoffs.

I had hoped X11 would keep getting patched for security and performance. That did not happen, and what arrived instead was Wayland. I held out as long as I could, until a recent system update left me unable to log into a graphical session. Only then did I notice that openSUSE had decided, on this machine, to replace X11 with Wayland, and it did not offer a choice. I spent a day looking for a realistic way to roll back or wire X11 back in. The cost looked too high, and every new release would add more maintenance, so I decided to go through with it.

Why I did not want Wayland

If you are like me, you mostly do not care what software is underneath as long as the display layer works. The problem is exactly that: I have two workflows I use all the time, and Wayland does not seem to handle them well.

  • I use autokey to remap keys for specific apps, especially the browser, so I can keep Emacs keybindings in the browser too.
  • I have several networked computers, and I often open an ssh tunnel to forward X11 traffic and run remote programs locally. I used to log into those machines remotely, but for security reasons most login screens turned that off long ago, and setting it up in a modern environment is unreliable. So I just forward the whole window.

There is good news and bad news. First, there is no single answer that fully replaces the tools I used before. The good news is that some options cover most of what I need. The bad news is that they do not work for every application, though that should improve over time. After all, Wayland is only 13 years old.

Replacing autokey with xremap

The replacement for autokey is xremap: once it is configured, you start it as a service. It is not as polished as autokey, but it is just as powerful. You can remap chords and bind rules to a specific application or device. It cannot do everything autokey does, but it can also do things that are awkward in autokey. A simple case is clear from the config file.

Keymap:
- name: Emacs-style keys in Zen
  application:
    only:
      - zen
      - firefox
      - google-chrome
      - chromium-browser
  remap:
    # Character and line movement
    C-b: left
    C-f: right
    C-p: up
    C-n: down
    C-a: home
    C-e: end
    # Page and document movement
    C-v: pagedown
    A-v: pageup
    A-S-comma: C-home
    A-S-dot: C-end
    # Editing
    C-d: delete
    C-w: C-x
    A-w: C-c
    C-y: C-v
    C-k: [S-end, C-x]
    # Browser and formatting commands
    C-q: C-w
    A-b: C-b
    C-g: esc
    C-s: C-f
    A-y: C-y

If you need the application name, the project README explains how to identify it for different operating system and compositor combinations. Under Wayland, do not count on xwindowinfo. That is another casualty.

You also need a way to start it. Here is my systemd unit. Names such as plasma-core.target may differ on your system.

[Unit]
Description=xremap keyboard remapping
Documentation=https://github.com/xremap/xremap
After=plasma-core.target
PartOf=graphical-session.target

[Service]
Type=simple
ExecStart=/usr/local/bin/xremap --desktop kde --watch %h/.config/xremap/config.yml
Restart=on-failure
RestartSec=3

[Install]
WantedBy=plasma-workspace-wayland.target

Running graphical programs remotely with waypipe

To run an X11 program over ssh, you can pass -X or -Y to turn on X11 forwarding, and a program running on the remote machine shows up on your local screen. In the ideal case you would not need this at all: X11’s DISPLAY variable can point straight at another machine on the network. The problem is that the traffic is plaintext, and someone else could push a window onto your screen without a complicated authentication setup. Using ssh as the pipe between machines is worth it: you have to authenticate, and the traffic is encrypted.

Many applications still support both X11 and Wayland, so this probably still works for now. As X11 recedes, that may not stay true. A pure Wayland program that wants this path has to nest a Wayland compositor with an X11 backend, which is a lot of trouble. Fortunately you do not have to.

waypipe can attach to a Wayland-capable program and carry it to another machine, usually over ssh. It does not actually care which transport you use. socat and similar tools can work with it too, but from a security point of view ssh is still the usual choice.

Take pcmanfm: a headless server might have this lightweight file manager installed. You can run it like this:

waypipe ssh my_remote_host pcmanfm

Or:

ssh -X my_remote_host pcmanfm

This assumes my_remote_host is an alias in ~/.ssh/config. You can also write user@host directly. Both commands work, because pcmanfm understands X11 and Wayland. In my case, emacs on the remote machine will not use Wayland natively, so only the second command works.

Programs can usually pick the right backend themselves, but sometimes you have to help. To make sure pcmanfm uses Wayland:

waypipe ssh my_remote_host env QT_QPA_PLATFORM=wayland pcmanfm

That is for a Qt program. Other programs may need GDK_BACKEND=wayland, or, like Chromium, a flag such as --ozone-platform=wayland.

Potholes

If GPU problems keep showing up, you can pass --no-gpu to waypipe. Most of my problems, though, came from ssh and how my environment is configured.

ssh can let the first connection to a remote host finish the setup, then reuse that same underlying setup for later connections and save some overhead. The problem is that if the first session is not the configuration you want (for example it set DISPLAY for -X), you get strange behavior: an X program runs once, and then it will not run again.

You can turn multiplexing off, or you can do this:

waypipe ssh -S none my_remote_host pcmanfm

Either works.

Other replacements

A few other tools fill in parts of the old usage. ydotool, for example, can handle some desktop automation, and there are tools aimed at specific compositors.

ssh seems able to do almost anything. Even so, I still miss X11. What I have watched over these years is a shift: it used to be that users were given a choice, and when a new option was good enough, people moved. Now, even if you do not want to, you get pushed.

Listed

Comments

0 comments

More in this category

Tools