emacs-framebuffer

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

commit af7c69c39262202e00680bfcbba3bc5b8c83a3a7
parent ae6ceb067b8622ad5182b90a2c0c2e99eb3d0d3c
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sun, 24 May 2020 05:16:49 +0200

detect framebuffer-size

Diffstat:
Memacs-framebuffer.el | 41++++++++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/emacs-framebuffer.el b/emacs-framebuffer.el @@ -19,16 +19,36 @@ ;;; (define-key dired-mode-map "N" 'framebuffer-image-file-dired-next) ;;; (define-key dired-mode-map "P" 'framebuffer-image-file-dired-previous))) -(defcustom framebuffer-width 1366 +(defcustom framebuffer-width nil "Specify the framebuffer width." :type 'number :group 'framebuffer) -(defcustom framebuffer-height 768 +(defcustom framebuffer-height nil "Specify the framebuffer height." :type 'number :group 'framebuffer) +(defcustom framebuffer-default-width 1024 + "Specify the framebuffer default width." + :type 'number + :group 'framebuffer) + +(defcustom framebuffer-default-height 768 + "Specify the framebuffer height." + :type 'number + :group 'framebuffer) + +(defun framebuffer-size () + (if (and framebuffer-width framebuffer-height) + (cons framebuffer-width framebuffer-height) + (or + (with-temp-buffer + (insert-file-contents "/sys/class/graphics/fb0/modes") + (search-forward-regexp "\\([0-9]+\\)+x\\([0-9]+\\)") + (cons (read (match-string 1)) (read (match-string 2)))) + (cons framebuffer-default-width framebuffer-default-height)))) + (defun framebuffer-draw (x y w h file) (with-temp-buffer (insert (format "0;1;%d;%d;%d;%d;;;;;%s\n" x y w h (expand-file-name file))) @@ -104,17 +124,12 @@ (defun framebuffer-image-file (file) (interactive "fFile: ") - (let* ((size (framebuffer-image-size file)) - (w (car size)) - (h (cdr size)) - (scale (min (/ framebuffer-width 1.0 w) (/ framebuffer-height 1.0 h))) - (ww (* scale w)) - (hh (* scale h))) - (framebuffer-draw (/ (- framebuffer-width ww) 2) - (/ (- framebuffer-height hh) 2) - ww - hh - file))) + (destructuring-bind (w &rest h) (framebuffer-image-size file) + (destructuring-bind (fw &rest fh) (framebuffer-size) + (let* ((scale (min (/ fw 1.0 w) (/ fh 1.0 h))) + (ww (* scale w)) + (hh (* scale h))) + (framebuffer-draw (/ (- fw ww) 2) (/ (- fh hh) 2) ww hh file))))) (defun framebuffer-image-buffer () (interactive)