12

I am running Wayland on Ubuntu 18.04.

According to the Wayland FAX, one of it's advantages, compared to X11, is that

Wayland allows better isolation between processes: one window cannot access resources from, or inject keystrokes into, another window.

That same Wayland document also says that

because Emacs is not a real GTK apps, it still talks with X11 and therefore will use XWayland

where XWayland is described as:

Note that any X program will still run, as there is a XWayland server that provides backwards compatibility with X program. Those programs will not, however, benefit from the security and performance improvements Wayland provides.

There is a 2016 devlevel discussion thread which considers removing X11 dependency from Emacs - notably a condition already achieved in Win23 and NS versions of Emacs.

It's now 2019 and so my question is, as the title states:
Is there an X11-free build of Emacs that can run on Wayland (not going through XWayland)?

If the answer is no, I do have another question which is probably off topic for this list:
Why can't Wayland just intercept all X11 calls in XWayland and convert them into proper Wayland calls?


Edit Background Info: Apparently Electron (which the editor Atom uses to interface with Linux) has some X-call dependencies which require a setting DISABLE_WAYLAND=1 causing it to run via XWayland when running on Wayland. Also see Arch docs on Wayland which suggests setting GDK_BACKEND=x11 for Electron. So it's by no means an Emacs only issue.


Edit: Clarification (c.f. @phils very helpful and through provoking comments)

Wayland does intercept X11-calls, and of course Wayland-calls. However, the Wayland documention suggests only the Wayland calls enjoy the security benefits that Wayland has to offer.

As @phils and @wasamasa point out, emacs-nox makes no X-calls, so it should theoretically be able to run on a terminal-emulator (e.g. terminology, termite) which itself is using only Wayland protocol, and not X-protocol.

Testing that on Ubuntu has turned out not to simple, as even with a Wayland desktop on 18.04 it seems to use XWayland as the default. So the dual Wayland/X compatible terminology terminal emulator runs in X mode by default. From terminology:

~$ echo $XDG_SESSION_TYPE
x11

FINISHED

Emacs-nox runs well in Fedora 29 (personally ran it), and Fedora 29 doesn't support X at all. By default it seems to not share the system clipboard - the same as seen in emacs-nox on Ubuntu. But emacs-nox can be modified easily enough to work with @wasamasa' s answer below and custom emacs calls to external clipboardhere and here.

Craig Hicks
  • 304
  • 2
  • 9
  • "Is there an X11-free build of Emacs that can run on Wayland" -- Yes, you can compile it without X, or use a pre-compiled build without X. You can run Emacs in a terminal in any system, including under Wayland. I don't *think* this is what you were asking, but it's a valid answer to your question as phrased, so please clarify the question if necessary. – phils Mar 24 '19 at 21:49
  • 2
    "Why can't Wayland just intercept all X11 calls in XWayland and convert them into proper Wayland calls?" -- I'm pretty sure that is what XWayland is doing -- Wikipedia says it's an X.Org server implemented on top of Wayland. – phils Mar 24 '19 at 21:52
  • @phils - The Wayland documention quoted in my question: "XWayland server provides backwards compatibility with X program ... will not, however, benefit from the security ... improvements Wayland provides." - that's the point I'm getting at. I am running: `/usr/bin/emacs25-nox` in a gnome terminal running as part of the `gnome-terminal-server` process. I'm not clear on whether not that will result in no calls to XWayland, either directly or indirectly. At least in name `-nox` implies no X-calls will be directly by emacs - although I suppose come terminal-calls could be translated in X. – Craig Hicks Mar 24 '19 at 23:01
  • I imagine there is at least one Wayland-native terminal emulator available? – phils Mar 25 '19 at 00:40
  • And yes, a `-nox` build of Emacs will almost certainly have been compiled without X support, so would not be making any X calls of its own. – phils Mar 25 '19 at 00:41
  • @philes - Thanks for even more helpful advice. Ubuntu maintains a package for "terminology" which is Wayland and X compatible. You are right - "terminology" is wayland compatible, "termite" is Wayland only. "terminology" is an Ubuntu supported package, so I tried that. But despite starting from a Ubuntu with Wayland desktop, "terminology" chooses to connect to XWayland. ---- I will try to set up a container with Wayland, and no XWayland, only in order to test further without destroying my working environment. (when I get a chance). – Craig Hicks Mar 25 '19 at 17:34
  • At one time there was a Wayland native port of GNUstep, but I think it's been abandoned. Anyway, in theory you could build the NS port against wayland-native GNUstep. I doubt it would work very well even if you could get it to build. – Alan Third Mar 27 '19 at 14:35
  • Can you try this fork, which is mine? https://github.com/masm11/emacs – masm Apr 19 '19 at 18:28

2 Answers2

10

As of early 2021, the previously accepted answer is no longer the case. Emacs can now be ran in Wayland without XWayland. Core Emacs code has been (quite labouriously!) updated to use pure GTK, and this should be available to the general public as of Emacs 28. For now, Arch Linux users can use the updated Emacs by switching to this AUR package. Other distributions may have similar luck by searching for "emacs pgtk" builds.

For more information, see this news article.

Colin Woodbury
  • 291
  • 2
  • 7
  • Are there any instructions for how to build the master branch to work with wayland? - or has this not yet been merged? I checked the AUR package, it doesn't seem to contain build steps. – ideasman42 Feb 28 '21 at 07:42
  • 1
    It hasn't been merged to master yet, it's on the 'feature/pgtk' branch. './configure --with-pgtk' should get you started. – rpluim Feb 28 '21 at 16:21
  • Consider also this alternate package: https://aur.archlinux.org/packages/emacs-pgtk-native-comp-git/ – Colin Woodbury Feb 28 '21 at 18:39
3

There is no graphical Emacs build for Linux without X, no. As suggested in the commentary, you can use textual Emacs instead and customize the parts interacting with the clipboard to use wl-clipboard instead.

wasamasa
  • 21,803
  • 1
  • 65
  • 97
  • Good tip, I will try it. So far it's harder than I expected to get an terminal to run with Wayland on Ubuntu. The purpose of Wayland on Ubuntu seems to be to prove that XWayland can provide back compatibility. So I'm going to try to set up a Wayland only env on a container and test from there, eventually. – Craig Hicks Mar 25 '19 at 17:42