From fc0414ac20dcb9acb07f941dd8b3c90589bb257b Mon Sep 17 00:00:00 2001 From: MitchMarq42 Date: Tue, 6 Jun 2023 13:27:59 -0800 Subject: [PATCH] eaf: fix window position on Hyprland (see my article as well) --- lisp/mitch-packages.el | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lisp/mitch-packages.el b/lisp/mitch-packages.el index f0b9951..06f4a12 100644 --- a/lisp/mitch-packages.el +++ b/lisp/mitch-packages.el @@ -1144,6 +1144,35 @@ Taken from https://howardism.org/Technical/Emacs/eshell-why.html" "--install" "pdf-viewer" "browser" "--ignore-sys-deps"))) :config (add-to-list 'load-path (expand-file-name "app/" eaf-source-dir)) + (if (and (string= (getenv "XDG_CURRENT_DESKTOP") "Hyprland") + (featurep 'hypop)) + (defun eaf--get-frame-coordinate () + "We need fetch Emacs coordinate to adjust coordinate of EAF if it running on system not support cross-process reparent technology. + +Such as, wayland native, macOS etc. + +This is redefined for use with `hypop' library because multiple Emacs frames may be open." + (cond ((string-equal (getenv "XDG_CURRENT_DESKTOP") "sway") + (eaf--split-number (shell-command-to-string (concat eaf-build-dir "swaymsg-treefetch/swaymsg-rectfetcher.sh emacs")))) + ((string-equal (getenv "XDG_CURRENT_DESKTOP") "Hyprland") + (let ((clients (json-parse-string (shell-command-to-string "hyprctl -j clients"))) + (coordinate)) + (dotimes (i (length clients)) + (when (and (equal (gethash "pid" (aref clients i)) (emacs-pid)) + (not (string= (gethash "title" (aref clients i)) hypop--frame-name))) + (setq coordinate (gethash "at" (aref clients i))))) + (list (aref coordinate 0) (aref coordinate 1)))) + ((eaf-emacs-running-in-wayland-native) + (require 'dbus) + (let* ((coordinate (eaf--split-number + (dbus-call-method :session "org.gnome.Shell" "/org/eaf/wayland" "org.eaf.wayland" "get_emacs_window_coordinate" :timeout 1000) + ",")) + ;; HiDPI need except by `frame-scale-factor'. + (frame-x (truncate (/ (car coordinate) (frame-scale-factor)))) + (frame-y (truncate (/ (cadr coordinate) (frame-scale-factor))))) + (list frame-x frame-y))) + (t + (list 0 0))))) ) (use-package eaf-browser :elpaca nil