diff options
| author | Stefan Kangas | 2022-09-14 10:52:39 +0200 |
|---|---|---|
| committer | Stefan Kangas | 2022-09-14 11:00:29 +0200 |
| commit | bfafe4aacceb213fbfd7d92bfd6362a13cbdc667 (patch) | |
| tree | 78ddc18f404b819d6afea3a15628dd07c76ce51a /lisp/image | |
| parent | ac479598f127b02d34f8c2f784386462605a4ba7 (diff) | |
| download | emacs-bfafe4aacceb213fbfd7d92bfd6362a13cbdc667.tar.gz emacs-bfafe4aacceb213fbfd7d92bfd6362a13cbdc667.zip | |
Allow setting wallpaper from TTY
* lisp/image/wallpaper.el (wallpaper-set): Allow setting wallpaper
when 'display-graphic-p' is nil.
(wallpaper-default-width, wallpaper-default-height):
New variables.
(wallpaper--get-height-or-width): New helper function.
Diffstat (limited to 'lisp/image')
| -rw-r--r-- | lisp/image/wallpaper.el | 79 |
1 files changed, 50 insertions, 29 deletions
diff --git a/lisp/image/wallpaper.el b/lisp/image/wallpaper.el index 1e921dc2c4c..a2b51d68d7a 100644 --- a/lisp/image/wallpaper.el +++ b/lisp/image/wallpaper.el | |||
| @@ -112,8 +112,23 @@ You can also use \\[report-emacs-bug]." | |||
| 112 | (executable-find (car cmd))) | 112 | (executable-find (car cmd))) |
| 113 | (throw 'found cmd))))) | 113 | (throw 'found cmd))))) |
| 114 | 114 | ||
| 115 | (defvar wallpaper-default-width 1080 | ||
| 116 | "Default width used by `wallpaper-set'. | ||
| 117 | This is only used when it can't be detected automatically. | ||
| 118 | See also `wallpaper-default-height'.") | ||
| 119 | |||
| 120 | (defvar wallpaper-default-height 1920 | ||
| 121 | "Default height used by `wallpaper-set'. | ||
| 122 | This is only used when it can't be detected automatically. | ||
| 123 | See also `wallpaper-default-width'.") | ||
| 124 | |||
| 115 | (declare-function haiku-set-wallpaper "term/haiku-win.el") | 125 | (declare-function haiku-set-wallpaper "term/haiku-win.el") |
| 116 | 126 | ||
| 127 | (defun wallpaper--get-height-or-width (desc fun default) | ||
| 128 | (if (display-graphic-p) | ||
| 129 | (funcall fun) | ||
| 130 | (read-number (format "Wallpaper %s in pixels: " desc) default))) | ||
| 131 | |||
| 117 | (defun wallpaper-set (file) | 132 | (defun wallpaper-set (file) |
| 118 | "Set the desktop background to FILE in a graphical environment." | 133 | "Set the desktop background to FILE in a graphical environment." |
| 119 | (interactive (list (and | 134 | (interactive (list (and |
| @@ -129,35 +144,41 @@ You can also use \\[report-emacs-bug]." | |||
| 129 | (error "No such file: %s" file)) | 144 | (error "No such file: %s" file)) |
| 130 | (unless (file-readable-p file) | 145 | (unless (file-readable-p file) |
| 131 | (error "File is not readable: %s" file)) | 146 | (error "File is not readable: %s" file)) |
| 132 | (when (display-graphic-p) | 147 | (cond ((featurep 'haiku) |
| 133 | (if (featurep 'haiku) | 148 | (haiku-set-wallpaper file)) |
| 134 | (haiku-set-wallpaper file) | 149 | (t |
| 135 | (let* ((command (wallpaper--find-command)) | 150 | (let* ((command (wallpaper--find-command)) |
| 136 | (fmt-spec `((?f . ,(expand-file-name file)) | 151 | (fmt-spec `((?f . ,(expand-file-name file)) |
| 137 | (?h . ,(display-pixel-height)) | 152 | (?h . ,(wallpaper--get-height-or-width |
| 138 | (?w . ,(display-pixel-width)))) | 153 | "height" |
| 139 | (bufname (format " *wallpaper-%s*" (random))) | 154 | #'display-pixel-height |
| 140 | (process | 155 | wallpaper-default-height)) |
| 141 | (and command | 156 | (?w . ,(wallpaper--get-height-or-width |
| 142 | (apply #'start-process "set-wallpaper" bufname | 157 | "width" |
| 143 | (car command) | 158 | #'display-pixel-width |
| 144 | (mapcar (lambda (arg) (format-spec arg fmt-spec)) | 159 | wallpaper-default-width)))) |
| 145 | (cdr command)))))) | 160 | (bufname (format " *wallpaper-%s*" (random))) |
| 146 | (unless command | 161 | (process |
| 147 | (error "Can't find a suitable command for setting the wallpaper")) | 162 | (and command |
| 148 | (wallpaper-debug "Using command %s" (car command)) | 163 | (apply #'start-process "set-wallpaper" bufname |
| 149 | (setf (process-sentinel process) | 164 | (car command) |
| 150 | (lambda (process status) | 165 | (mapcar (lambda (arg) (format-spec arg fmt-spec)) |
| 151 | (unwind-protect | 166 | (cdr command)))))) |
| 152 | (unless (and (eq (process-status process) 'exit) | 167 | (unless command |
| 153 | (zerop (process-exit-status process))) | 168 | (error "Can't find a suitable command for setting the wallpaper")) |
| 154 | (message "command %S %s: %S" (string-join (process-command process) " ") | 169 | (wallpaper-debug "Using command %s" (car command)) |
| 155 | (string-replace "\n" "" status) | 170 | (setf (process-sentinel process) |
| 156 | (with-current-buffer (process-buffer process) | 171 | (lambda (process status) |
| 157 | (string-clean-whitespace (buffer-string))))) | 172 | (unwind-protect |
| 158 | (ignore-errors | 173 | (unless (and (eq (process-status process) 'exit) |
| 159 | (kill-buffer (process-buffer process)))))) | 174 | (zerop (process-exit-status process))) |
| 160 | process)))) | 175 | (message "command %S %s: %S" (string-join (process-command process) " ") |
| 176 | (string-replace "\n" "" status) | ||
| 177 | (with-current-buffer (process-buffer process) | ||
| 178 | (string-clean-whitespace (buffer-string))))) | ||
| 179 | (ignore-errors | ||
| 180 | (kill-buffer (process-buffer process)))))) | ||
| 181 | process)))) | ||
| 161 | 182 | ||
| 162 | (provide 'wallpaper) | 183 | (provide 'wallpaper) |
| 163 | 184 | ||