在 KDE Wayland emacs-pgtk 上运行 EAF

emacs-pgtk 在 KDE 下应该是无法直接运行 EAF 的(但是 xwayland 可以)。

我在这个 issue 中找到了一种可能的解决方案,eaf 不能在 KDE 下使用,可能是因为 eaf.el 中的 eaf--topmost-switch-to-python 函数需要获得前台程序的名称,而不同 WM 获得名称的方式不同,eaf.el 中没有处理 KDE 的逻辑。

因此我利用 kdotools 补充了这部分逻辑,代码如下所示:

(defun eaf--on-kde-p ()
  "Check if running on a KDE Plasma desktop."
  (string-equal (getenv "XDG_SESSION_DESKTOP") "KDE"))

(let* ((front (cond ((eq system-type 'darwin)
                           (shell-command-to-string "app-frontmost --name"))
                          ((eaf--on-kde-p)
                           (if (executable-find "kdotool") ; Check for kdotool first
                               (string-trim (shell-command-to-string "kdotool getactivewindow getwindowclassname"))
                             (message "Please install kdotool for KDE support.")
                             ))
                          ((eaf--on-sway-p)
                           (if (executable-find "jq")
                               (shell-command-to-string "swaymsg -t get_tree | jq -r '..|try select(.focused == true).app_id'")
                             (message "Please install jq for swaywm support.")))
                          ((eaf--on-hyprland-p)
                           (or
                            (gethash "class" (json-parse-string (shell-command-to-string "hyprctl -j activewindow")))
                            ""))
                          ((eaf--on-unity-p)
                           (if (executable-find "xdotool")
                               (shell-command-to-string "xdotool getactivewindow getwindowname")
                             (message "Please install xdotool for Unity support.")))
                          (t
                           (require 'dbus)
                           (dbus-call-method :session "org.gnome.Shell" "/org/eaf/wayland" "org.eaf.wayland" "get_active_window" :timeout 1000))))
             (front-app-name (string-trim front)))

这段代码工作应该是正常的,能够正确返回前台程序的名称,比如 "emacs"

但是 EAF 仍然无法工作,打开一个 PDF 后,只在 *Message* 中显示:

[EAF/pdf-viewer] Opening /home/thysrael/desktop/main.pdf

*eaf**eaf-epc con 4* 中均没有输出。

想请教大家一下该如何解决,或者有没有其他方法在 KDE 下运行 emacs-pgtk?

不要用pgtk,因为这样获取不了emacs的xid

1 个赞