summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2020-07-29 08:38:52 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2020-07-29 08:38:52 +0200
commitdb1b1f09b820efeefa60a49684c06d511b70eecb (patch)
tree83b2c63b01d47bb18126ffd1dd332452b3000785 /lisp
parent76f71e39f583b7f8bb47a47b315f49af6f23886e (diff)
downloademacs-db1b1f09b820efeefa60a49684c06d511b70eecb.tar.gz
Use a new method to determine when to auto-stop image animations
* lisp/image.el (image-animate-timeout): Make the animation auto-stop use a decaying average to determine when to stop (bug#40685). The default stop condition will probably require some tweaking -- the current default may be too aggressive.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/image.el10
1 files changed, 8 insertions, 2 deletions
diff --git a/lisp/image.el b/lisp/image.el
index 4ea8594a974..4b2faa992fc 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -784,6 +784,7 @@ number, play until that number of seconds has elapsed."
(if (setq timer (image-animate-timer image))
(cancel-timer timer))
(plist-put (cdr image) :animate-buffer (current-buffer))
+ (plist-put (cdr image) :animate-tardiness 0)
(run-with-timer 0.2 nil #'image-animate-timeout
image (or index 0) (car animation)
0 limit (+ (float-time) 0.2)))))
@@ -848,9 +849,14 @@ The minimum delay between successive frames is `image-minimum-frame-delay'.
If the image has a non-nil :speed property, it acts as a multiplier
for the animation speed. A negative value means to animate in reverse."
+ ;; We keep track of "how late" image frames arrive. We decay the
+ ;; previous cumulative value by 10% and then add the current delay.
+ (plist-put (cdr image) :animate-tardiness
+ (+ (* (plist-get (cdr image) :animate-tardiness) 0.9)
+ (float-time (time-since target-time))))
(when (and (buffer-live-p (plist-get (cdr image) :animate-buffer))
- ;; Delayed more than two seconds more than expected.
- (or (time-less-p (time-since target-time) 2)
+ ;; Cumulatively delayed two seconds more than expected.
+ (or (< (plist-get (cdr image) :animate-tardiness) 2)
(progn
(message "Stopping animation; animation possibly too big")
nil)))