Emacs supports wayland since 29.1, if compiled with the --with-pgtk config flag. Currently, this flag is only enabled when USE="gtk -X". When attempting to boot up emacs on sway, GTK complains about not being able to find DISPLAY=:0, even if Xwayland is running on :0 (and works, as confirmed with xeyes). I'm not sure if this is a bug on my end. unexporting DISPLAY, and running emacs, runs it in the terminal (e.g doing the same as emacs -nw). Sufficient to say, even if I add USE=X, it doesn't seem like I can run emacs on Xwayland. Looking at the ebuild, I realized I could fix the problem by rebuilding with USE=-X. As expected, it works out-of-the-box natively on Wayland now. I suggest we add IUSE=wayland, and add something like REQUIRED_USE="wayland? (!X)" if it's actually incompatible to have both X and pgtk enabled at once. Reproducible: Always
Created attachment 892260 [details, diff] suggested fix I made a PR with the attached patch on ::gentoo.
> Sufficient to say, even if I add USE=X, it doesn't seem like I can run emacs on Xwayland I don't see how this part follows, yet. The relevant ebuild block, which you mentioned, is https://gitweb.gentoo.org/repo/gentoo.git/tree/app-editors/emacs/emacs-29.3-r2.ebuild#n247. With USE="-gtk X", I would expect Xwayland to work OK, but using one of the ugly toolkits. With USE="gtk X", I would expect it to use gtk, but not pgtk, like it did < Emacs 29. With USE="gtk -X", I would expect it to use pgtk. What am I missing? (I'm not the Emacs maintainer, though.)
> With USE="gtk X", I would expect it to use gtk, but not pgtk, like it did < Emacs 29. It doesn't, on my Sway machine. That could be an error on my end, though. xeyes works with the same DISPLAY=:0, so I'm not sure. > With USE="gtk -X", I would expect it to use pgtk. Yes, that works. The issue is that it's not obvious that you have to disable X support to get Wayland/pgtk support, hence the proposed patch. Having to peek into the ebuild is not great, I think. Is it incorrect to think that USE=wayland and USE=-X, both being global flags, mean different things, and should really be compatible?
> With USE="-gtk X", I would expect Xwayland to work OK, but using one of the ugly toolkits. Yep, this works with Xwayland.
(In reply to Sam James from comment #2) > With USE="-gtk X", I would expect Xwayland to work OK, but using one of the > ugly toolkits. > With USE="gtk X", I would expect it to use gtk, but not pgtk, like it did < > Emacs 29. > With USE="gtk -X", I would expect it to use pgtk. > > What am I missing? You aren't missing anything. This is exactly how it is supposed to work. Note that rhe upstream configure doesn't have any option for wayland. We assume that if the user specifies USE="X" then they want X11. Adding another flag for wayland and restricting it via REQUIRED_USE doesn't make much sense and just adds complications for users. Especially "^^ ( )" is awkward and IMHO should be avoided. We don't want users having to solve a Zebra Puzzle before they will be able to emerge a package. Policy reference: https://devmanual.gentoo.org/general-concepts/use-flags/index.html#conflicting-use-flags "Note: In order to avoid forcing users to micro-manage flags too much, REQUIRED_USE should be used sparingly. Follow the normal policy whenever it is possible to do a build that will presumably suit the user's needs."
I understand now REQUIRED_USE should be used sparingly, I hadn't seen that policy before. Could we at least have USE=pgtk (or USE="gtk wayland", which is what I would expect) to specify if we want to enable pgtk? Explicitly requiring X support to be disabled in order to enable another feature seems like the zebra puzzle which we want to avoid. I know this is documented in the ebuild, but IMHO both USE=wayland (which should enable pgtk) and USE=X (which should enable X) should be respected independently.
(In reply to Mazunki Hoksaas from comment #6) > [...] IMHO both USE=wayland (which should enable pgtk) and USE=X > (which should enable X) should be respected independently. Two flags for the same purpose, so they're redundant. We should have only one of either wayland or X. Since the upstream configure has a --with-x option but no --with-wayland option, the choice is pretty clear.
Upstream has a --with-pgtk flag which effectively acts as adding Wayland support. If you also want --with-x, this is currently not possible. The only way you'll get pgtk support currently is by disabling X support. Upstream treats these as different flags, but the ebuild does not.
(In reply to Mazunki Hoksaas from comment #8) > Upstream has a --with-pgtk flag which effectively acts as adding Wayland > support. If you also want --with-x, this is currently not possible. > > The only way you'll get pgtk support currently is by disabling X support. > Upstream treats these as different flags, but the ebuild does not. The following are with the vanilla build system from upstream: emacs-29.3 $ ./configure --without-x --with-pgtk && make -j16 [...] emacs-29.3 $ scanelf -n src/emacs TYPE NEEDED FILE ET_DYN libgtk-3.so.0,libgdk-3.so.0,libpangocairo-1.0.so.0,libpango-1.0.so.0,libharfbuzz.so.0,libatk-1.0.so.0,libcairo-gobject.so.2,libcairo.so.2,libgdk_pixbuf-2.0.so.0,libgio-2.0.so.0,libgobject-2.0.so.0,libglib-2.0.so.0,libtiff.so.6,libjpeg.so.62,libpng16.so.16,libgif.so.7,libwebpdemux.so.2,libwebpdecoder.so.3,libasound.so.2,librsvg-2.so.2,libm.so.6,libacl.so.1,libdbus-1.so.3,libxml2.so.2,libgpm.so.1,libtinfo.so.6,libfreetype.so.6,libfontconfig.so.1,libotf.so.1,libgnutls.so.30,libanl.so.1,liblcms2.so.2,liblcms2_fast_float.so,liblcms2_threaded.so,libz.so.1,libjansson.so.4,libgmp.so.10,libtree-sitter.so.0,libsqlite3.so.0,libc.so.6 src/emacs emacs-29.3 $ ./configure --with-x --with-pgtk && make -j16 [...] emacs-29.3 $ scanelf -n src/emacs TYPE NEEDED FILE ET_DYN libgtk-3.so.0,libgdk-3.so.0,libpangocairo-1.0.so.0,libpango-1.0.so.0,libharfbuzz.so.0,libatk-1.0.so.0,libcairo-gobject.so.2,libcairo.so.2,libgdk_pixbuf-2.0.so.0,libgio-2.0.so.0,libgobject-2.0.so.0,libglib-2.0.so.0,libtiff.so.6,libjpeg.so.62,libpng16.so.16,libgif.so.7,libwebpdemux.so.2,libwebpdecoder.so.3,libasound.so.2,librsvg-2.so.2,libm.so.6,libacl.so.1,libdbus-1.so.3,libxml2.so.2,libgpm.so.1,libtinfo.so.6,libfreetype.so.6,libfontconfig.so.1,libotf.so.1,libgnutls.so.30,libanl.so.1,liblcms2.so.2,liblcms2_fast_float.so,liblcms2_threaded.so,libz.so.1,libjansson.so.4,libgmp.so.10,libtree-sitter.so.0,libsqlite3.so.0,libc.so.6 src/emacs No linkage against X libraries (in particular, no libX11.so) in either case, i.e. the --with-x option has no effect when --with-pgtk has been specified.
Note that upstream also clearly say that pgtk must not be used with X.
We should consider local USE descriptions to avoid people needing to read the ebuild, though.