Wayland support

This commit is contained in:
TEC 2024-04-01 22:42:40 +08:00
parent ddb092d88d
commit 2770c0cfef
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 13 additions and 4 deletions

View File

@ -539,10 +539,19 @@ If BODY starts with :no-img then `screenshot--process' is not called."
(screenshot--def-action copy
"Copy the current selection (BEG-END) as an image to the clipboard."
(call-process "xclip" nil nil nil
"-selection" "clipboard"
"-target" "image/png"
"-in" screenshot--tmp-file)
(let ((wayland-p (getenv "WAYLAND_DISPLAY")))
(cond
((and wayland-p (executable-find "wl-copy"))
(call-process "wl-copy" screenshot--tmp-file nil nil
"--type" "image/png"))
((and (not wayland-p) (executable-find "xclip"))
(call-process "xclip" nil nil nil
"-selection" "clipboard"
"-target" "image/png"
"-in" screenshot--tmp-file))
(t
(user-error "Missing `%s' executable, needed to copy images to the clipboard"
(if wayland-p "wl-copy" "xclip")))))
(delete-file screenshot--tmp-file)
(message "Screenshot copied"))