emacsclient 在 wayland 桌面环境的坑

问题描述

在 x11 桌面中,可以由 systemctl 启动 emacs 服务器:

systemctl --user enable emacs

然后即可启动 emacsclient:

emacsclient -c -a “”

但转到 wayland 桌面后却出了问题,即 systemctl 启动 emacs 服务器时,由于 wayland 机制问题,窗口初始化不能正常完成,导致 emacsclient 启动时无法初始化窗口而不能显示窗口,仅能在终端中启动。

解决方案

不通过 systemctl 启动 emacs 服务器:

systemctl --user disable emacs

~/.config/autostart 中创建 emacs-daemon.desktop 文件:

[Desktop Entry]
Type=Application
Exec=emacs --daemon
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Emacs Daemon
Comment=Start Emacs server on login

即在进入桌面后,完成了窗口系统的初始化,再在桌面线程中启动 emacs 服务器。自此,即可正常启动窗口 emacsclient 了。

:grinning_face: 我都是双击图标启动的,这个就很正常。

什么机制问题?我猜是启动太早没拿到WAYLAND_DISPLAY环境变量?

具体不清楚,但基本上是这个意思。

我看不懂你的意思。你可以直接描述你所看到的现象。

在 wayland 桌面上,emacsclient 启动不了,看不到窗口弹出。在终端里启动正常。

问了chatgpt,分析是 WAYLAND_DISPLAY 没准备好,emacs service 就启动了。

那看日志呀。

到底是WAYLAND_DISPLAY没准备好还是Wayland compositor没准备好?不过这不重要。你的Wayland compositor如果也是systemd启动的那只需要After它就好了。

这个我研究一下,受教了。