Skip to content

Commit b31a966

Browse files
committed
* lisp/image-mode.el: Resize image on window resizing (bug#32672)
* lisp/image-mode.el (image--window-change): New function. (image--window-change-function): New variable. (image-mode--setup-mode): Add buffer-local hook image--window-change to window-size-change-functions, window-state-change-functions, window-selection-change-functions.
1 parent 2435f81 commit b31a966

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

etc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,6 +2623,9 @@ pointer is over. To change this behaviour, you can customize the user
26232623
option 'mouse-wheel-follow-mouse'. Note that this will also affect
26242624
scrolling.
26252625

2626+
** Mouse scroll up and down with control key modifier also works on images
2627+
where it scales the image under the mouse pointer.
2628+
26262629
---
26272630
** help-follow-symbol now signals 'user-error' if point (or the
26282631
position pointed to by the argument POS) is not in a symbol.

lisp/image-mode.el

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,10 @@ Key bindings:
599599

600600
(add-hook 'change-major-mode-hook #'image-toggle-display-text nil t)
601601
(add-hook 'after-revert-hook #'image-after-revert-hook nil t)
602+
(add-hook 'window-size-change-functions #'image--window-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+
602606
(run-mode-hooks 'image-mode-hook)
603607
(let ((image (image-get-display-property))
604608
(msg1 (substitute-command-keys
@@ -856,6 +860,27 @@ Otherwise, display the image by calling `image-mode'."
856860
(get-buffer-window-list (current-buffer) 'nomini 'visible))
857861
(image-toggle-display-image)))
858862

863+
(defvar image--window-change-function
864+
(debounce 1.0
865+
(lambda (window)
866+
(when (window-live-p window)
867+
(with-current-buffer (window-buffer)
868+
(when (derived-mode-p 'image-mode)
869+
(let ((spec (image-get-display-property)))
870+
(when (eq (car-safe spec) 'image)
871+
(let* ((image-width (plist-get (cdr spec) :max-width))
872+
(image-height (plist-get (cdr spec) :max-height))
873+
(edges (window-inside-pixel-edges window))
874+
(window-width (- (nth 2 edges) (nth 0 edges)))
875+
(window-height (- (nth 3 edges) (nth 1 edges))))
876+
(when (and image-width image-height
877+
(or (not (= image-width window-width))
878+
(not (= image-height window-height))))
879+
(image-toggle-display-image)))))))))))
880+
881+
(defun image--window-change (window)
882+
(funcall image--window-change-function window))
883+
859884

860885
;;; Animated images
861886

0 commit comments

Comments
 (0)