diff options
Diffstat (limited to 'lisp/image-mode.el')
| -rw-r--r-- | lisp/image-mode.el | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/lisp/image-mode.el b/lisp/image-mode.el index 09d7828047e..b9ba376cafc 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el | |||
| @@ -599,9 +599,7 @@ Key bindings: | |||
| 599 | 599 | ||
| 600 | (add-hook 'change-major-mode-hook #'image-toggle-display-text nil t) | 600 | (add-hook 'change-major-mode-hook #'image-toggle-display-text nil t) |
| 601 | (add-hook 'after-revert-hook #'image-after-revert-hook nil t) | 601 | (add-hook 'after-revert-hook #'image-after-revert-hook nil t) |
| 602 | (add-hook 'window-size-change-functions #'image--window-change nil t) | 602 | (add-hook 'window-state-change-functions #'image--window-state-change nil t) |
| 603 | (add-hook 'window-state-change-functions #'image--window-change nil t) | ||
| 604 | (add-hook 'window-selection-change-functions #'image--window-change nil t) | ||
| 605 | 603 | ||
| 606 | (run-mode-hooks 'image-mode-hook) | 604 | (run-mode-hooks 'image-mode-hook) |
| 607 | (let ((image (image-get-display-property)) | 605 | (let ((image (image-get-display-property)) |
| @@ -860,26 +858,31 @@ Otherwise, display the image by calling `image-mode'." | |||
| 860 | (get-buffer-window-list (current-buffer) 'nomini 'visible)) | 858 | (get-buffer-window-list (current-buffer) 'nomini 'visible)) |
| 861 | (image-toggle-display-image))) | 859 | (image-toggle-display-image))) |
| 862 | 860 | ||
| 863 | (defvar image--window-change-function | 861 | (defun image--window-state-change (window) |
| 864 | (debounce 1.0 | 862 | ;; Wait for a bit of idle-time before actually performing the change, |
| 865 | (lambda (window) | 863 | ;; so as to batch together sequences of closely consecutive size changes. |
| 866 | (when (window-live-p window) | 864 | ;; `image-fit-to-window' just changes one value in a plist. The actual |
| 867 | (with-current-buffer (window-buffer) | 865 | ;; image resizing happens later during redisplay. So if those |
| 868 | (when (derived-mode-p 'image-mode) | 866 | ;; consecutive calls happen without any redisplay between them, |
| 869 | (let ((spec (image-get-display-property))) | 867 | ;; the costly operation of image resizing should happen only once. |
| 870 | (when (eq (car-safe spec) 'image) | 868 | (run-with-idle-timer 1 nil #'image-fit-to-window window)) |
| 871 | (let* ((image-width (plist-get (cdr spec) :max-width)) | 869 | |
| 872 | (image-height (plist-get (cdr spec) :max-height)) | 870 | (defun image-fit-to-window (window) |
| 873 | (edges (window-inside-pixel-edges window)) | 871 | "Adjust size of image to display it exactly in WINDOW boundaries." |
| 874 | (window-width (- (nth 2 edges) (nth 0 edges))) | 872 | (when (window-live-p window) |
| 875 | (window-height (- (nth 3 edges) (nth 1 edges)))) | 873 | (with-current-buffer (window-buffer) |
| 876 | (when (and image-width image-height | 874 | (when (derived-mode-p 'image-mode) |
| 877 | (or (not (= image-width window-width)) | 875 | (let ((spec (image-get-display-property))) |
| 878 | (not (= image-height window-height)))) | 876 | (when (eq (car-safe spec) 'image) |
| 879 | (image-toggle-display-image))))))))))) | 877 | (let* ((image-width (plist-get (cdr spec) :max-width)) |
| 880 | 878 | (image-height (plist-get (cdr spec) :max-height)) | |
| 881 | (defun image--window-change (window) | 879 | (edges (window-inside-pixel-edges window)) |
| 882 | (funcall image--window-change-function window)) | 880 | (window-width (- (nth 2 edges) (nth 0 edges))) |
| 881 | (window-height (- (nth 3 edges) (nth 1 edges)))) | ||
| 882 | (when (and image-width image-height | ||
| 883 | (or (not (= image-width window-width)) | ||
| 884 | (not (= image-height window-height)))) | ||
| 885 | (image-toggle-display-image))))))))) | ||
| 883 | 886 | ||
| 884 | 887 | ||
| 885 | ;;; Animated images | 888 | ;;; Animated images |