diff --git a/emacs-everywhere.el b/emacs-everywhere.el index 92a949a..c47f3ab 100644 --- a/emacs-everywhere.el +++ b/emacs-everywhere.el @@ -69,7 +69,10 @@ (list "powershell" "-NoProfile" "-Command" "& {(New-Object -ComObject wscript.shell).SendKeys(\"^v\")}")) ('x11 (list "xdotool" "key" "--clearmodifiers" "Shift+Insert")) - ('wayland (list "ydotool" "key" "42:1" "110:1" "42:0" "110:0")) + ('wayland (cond ((executable-find "dotool") (list "dotool")) + ;; Note: for ydotool to work you need to have the ydotoold daemon running: + ((executable-find "ydotool") (list "ydotool" "key" "42:1" "110:1" "42:0" "110:0")) + ((executable-find "wtype") (list "wtype" "-M" "Shift" "-P" "Insert" "-m" "Shift" "-p" "Insert")))) ('unknown (list "notify-send" "No paste command defined for emacs-everywhere" @@ -107,6 +110,7 @@ it worked can be a good idea." (`(windows . ,_) (list "powershell" "-NoProfile" "-command" "& {Add-Type 'using System; using System.Runtime.InteropServices; public class Tricks { [DllImport(\"user32.dll\")] public static extern bool SetForegroundWindow(IntPtr hWnd); }'; [tricks]::SetForegroundWindow(%w) }")) (`(x11 . ,_) (list "xdotool" "windowactivate" "--sync" "%w")) + (`(wayland . sway) (list "swaymsg" "[con_id=%w]" "focus")) (`(wayland . KDE) (list "kdotool" "windowactivate" "%w"))) ; No --sync "Command to refocus the active window when emacs-everywhere was triggered. This is given as a list in the form (CMD ARGS...). @@ -232,6 +236,7 @@ Make sure that it will be matched by `emacs-everywhere-file-patterns'." (`(quartz . ,_) #'emacs-everywhere--app-info-osx) (`(windows . ,_) #'emacs-everywhere--app-info-windows) (`(x11 . ,_) #'emacs-everywhere--app-info-linux-x11) + (`(wayland . sway) #'emacs-everywhere--app-info-linux-sway) (`(wayland . KDE) #'emacs-everywhere--app-info-linux-kde)) "Function that asks the system for information on the current foreground app. On most systems, this should be set to a sensible default, but it @@ -425,7 +430,9 @@ Never paste content when ABORT is non-nil." emacs-everywhere-paste-command (not abort)) (apply #'call-process (car emacs-everywhere-paste-command) - nil nil nil (cdr emacs-everywhere-paste-command))))) + (if (cdr emacs-everywhere-paste-command) nil + (make-temp-file nil nil nil "key shift+insert")) nil nil + (cdr emacs-everywhere-paste-command))))) ;; Clean up after ourselves in case the buffer survives `server-buffer-done' ;; (b/c `server-existing-buffer' is non-nil). (emacs-everywhere-mode -1) @@ -475,8 +482,30 @@ Please go to 'System Preferences > Security & Privacy > Privacy > Accessibility' (pcase emacs-everywhere--display-server (`(x11 . ,_) (emacs-everywhere--app-info-linux-x11)) (`(wayland . KDE) (emacs-everywhere--app-info-linux-kde)) + (`(wayland . sway) (emacs-everywhere--app-info-linux-sway)) (_ (user-error "Unable to fetch app info with display server %S" emacs-everywhere--display-server)))) + +(defun emacs-everywhere--app-info-linux-sway () + "Return information on the current active window, on a Linux Sway session." + (let* ((json-string (emacs-everywhere--call "sh" "-c" "swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true)'")) + (json-object (json-read-from-string json-string)) + (window-id (number-to-string (cdr (assoc 'id json-object)))) + (app-name (cdr (assoc 'app_id json-object))) + (window-title (cdr (assoc 'name json-object))) + (tmp-window-geometry (cdr (assoc 'geometry json-object))) + (window-geometry (list + (cdr (assoc 'x tmp-window-geometry)) + (cdr (assoc 'y tmp-window-geometry)) + (cdr (assoc 'width tmp-window-geometry)) + (cdr (assoc 'height tmp-window-geometry))))) + (make-emacs-everywhere-app + :id window-id + :class app-name + :title window-title + :geometry window-geometry))) + + (defun emacs-everywhere--app-info-linux-x11 () "Return information on the current active window, on a Linux X11 sessions." (let ((window-id (emacs-everywhere--call "xdotool" "getactivewindow")))