emacs-framebuffer

Emacs library to show images and documents in console using Linux framebuffer
Log | Files | Refs

commit bc807977607b0076e4a0eef69893f990687ad86f
parent ccb366ddecfe72864305947ef1f299dfbef19ad7
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sun,  7 Jun 2020 23:46:53 +0200

draw only if buffer visible

Diffstat:
Memacs-framebuffer.el | 36+++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/emacs-framebuffer.el b/emacs-framebuffer.el @@ -224,31 +224,33 @@ (defvar framebuffer-image-mode-image-size) -(defun framebuffer-image-mode-draw-image () +(defun framebuffer-image-mode-draw-image (buffer) (interactive) (let ((file (buffer-file-name))) (destructuring-bind (w &rest h) framebuffer-image-mode-image-size (destructuring-bind (fbw &rest fbh) (framebuffer-size) - (destructuring-bind (x1 y1 x2 y2) (window-edges (get-buffer-window) t) ;; TODO for all visible windows - (let* ((fw (frame-width)) - (fh (frame-height)) - (cw (floor fbw fw)) - (ch (floor fbh fh)) - (wx (* x1 cw)) - (wy (* y1 ch)) - (ww (* (- x2 x1) cw)) - (wh (* (- y2 y1) ch)) - (scale (min (/ ww 1.0 w) (/ wh 1.0 h))) - (zw (floor (* scale w))) - (zh (floor (* scale h))) - (zx (+ wx (floor (- ww zw) 2))) - (zy (+ wy (floor (- wh zh) 2)))) - (framebuffer-draw zx zy zw zh file))))))) + (let ((window (get-buffer-window buffer 'visible))) ;; TODO for all visible windows + (when window + (destructuring-bind (x1 y1 x2 y2) (window-edges window t) + (let* ((fw (frame-width)) + (fh (frame-height)) + (cw (floor fbw fw)) + (ch (floor fbh fh)) + (wx (* x1 cw)) + (wy (* y1 ch)) + (ww (* (- x2 x1) cw)) + (wh (* (- y2 y1) ch)) + (scale (min (/ ww 1.0 w) (/ wh 1.0 h))) + (zw (floor (* scale w))) + (zh (floor (* scale h))) + (zx (+ wx (floor (- ww zw) 2))) + (zy (+ wy (floor (- wh zh) 2)))) + (framebuffer-draw zx zy zw zh file))))))))) (defun framebuffer-image-mode-draw-image-repeatedly (buffer) (when (buffer-live-p buffer) (with-current-buffer buffer - (framebuffer-image-mode-draw-image) + (framebuffer-image-mode-draw-image buffer) (run-at-time framebuffer-image-mode-refresh-delay nil 'framebuffer-image-mode-draw-image-repeatedly