diff --git a/lisp/image-dired.el b/lisp/image-dired.el index f6a263749f..0b357332a1 100644 --- a/lisp/image-dired.el +++ b/lisp/image-dired.el @@ -117,8 +117,6 @@ ;; * From thumbs.el: Add an option for clean-up/max-size functionality ;; for thumbnail directory. ;; -;; * From thumbs.el: Add setroot function. -;; ;; * From thumbs.el: Add image resizing, if useful (image-dired's automatic ;; "image fit" might be enough) ;; @@ -2818,6 +2816,71 @@ image-dired-save-information-from-widgets (dolist (tag tag-list) (push (cons file tag) lst)))))) + +;;;; Setting background. + +(defcustom image-dired-set-background-program + (cond ((executable-find "feh") "feh") + ((executable-find "gm") "gm") + ((executable-find "display") "display") + ((executable-find "xloadimage") "xloadimage") + ((executable-find "xsetbg") "xsetbg")) + "Command to set the desktop background. +You must also set `image-dired-cmd-set-background-options' or +this will not work. + +Note: If you find that you need to use a different command on +your machine, we would like to hear about it! Please send an +email to bug-gnu-emacs@gnu.org and tell us which +command (including all options) that worked for you." + :type 'string + :version "29.1") + +(defcustom image-dired-cmd-set-background-options + (cond ((executable-find "feh") '("--bg-scale" "%f")) + ((executable-find "gm") '("display" "-resize" "%wx%h" "-window" "root" "%f")) + ((executable-find "display") '("-resize" "%wx%h" "-window" "root" "%f")) + ((executable-find "xloadimage") '("-onroot" "-fullscreen" "%f")) + ((executable-find "xsetbg") '"%f")) + "Options to pas to the program setting the desktop background. +The default scales the image to fit the background. + +To see which options are available, see the documentation for +your chosen `image-dired-cmd-set-background-program'." + :type '(repeat string) + :version "29.1") + +(defun image-dired-set-desktop-background (file) + "Set the desktop background to FILE in a graphical environment." + (interactive (list (or (image-dired-original-file-name) + (read-file-name "Set desktop background to:" + default-directory nil t nil + (lambda (fn) + (string-match (image-file-name-regexp) fn)))))) + (when (display-graphic-p) + (let* ((spec `((?f . ,file) + (?h . ,(display-pixel-height)) + (?w . ,(display-pixel-width)))) + (buf (format " *desktop-background-%s*" + (random))) + (process + (apply #'start-process "set-desktop-background" buf + image-dired-cmd-set-background-program + (mapcar (lambda (arg) (format-spec arg spec)) + image-dired-cmd-set-background-options)))) + (setf (process-sentinel process) + (lambda (process status) + (unwind-protect + (unless (and (eq (process-status process) 'exit) + (zerop (process-exit-status process))) + (message "command %S %s: %S" (string-join (process-command process) " ") + (string-replace "\n" "" status) + (with-current-buffer (process-buffer process) + (string-clean-whitespace (buffer-string))))) + (ignore-errors + (kill-buffer (process-buffer process)))))) + process))) + ;;;; bookmark.el support