fix: backend-size (TIOCGWINSZ), kitty keyboard enable, Wayland clipboard, SIGWINCH handler

This commit is contained in:
Hermes Agent
2026-05-12 13:49:23 +00:00
parent bb1717a43d
commit 26ec1dfbe8
4 changed files with 37 additions and 5 deletions

View File

@@ -140,18 +140,20 @@ as a fallback when a keyword is not in *named-colors*.")
(make-instance 'modern-backend :output-stream (or output-stream *standard-output*))) (make-instance 'modern-backend :output-stream (or output-stream *standard-output*)))
(defmethod initialize-backend ((b modern-backend)) (defmethod initialize-backend ((b modern-backend))
;; Enter raw mode, enable mouse, bracketed paste ;; Enter raw mode, enable mouse, bracketed paste, kitty keyboard
(backend-write b (format nil "~C[?1049h" #\Esc)) ; alt screen (backend-write b (format nil "~C[?1049h" #\Esc)) ; alt screen
(backend-write b (format nil "~C[?1000h" #\Esc)) ; mouse basic (backend-write b (format nil "~C[?1000h" #\Esc)) ; mouse basic
(backend-write b (format nil "~C[?1002h" #\Esc)) ; mouse drag (backend-write b (format nil "~C[?1002h" #\Esc)) ; mouse drag
(backend-write b (format nil "~C[?1006h" #\Esc)) ; SGR mouse (backend-write b (format nil "~C[?1006h" #\Esc)) ; SGR mouse
(backend-write b (format nil "~C[?2004h" #\Esc)) ; bracketed paste (backend-write b (format nil "~C[?2004h" #\Esc)) ; bracketed paste
(backend-write b (format nil "~C[?u" #\Esc)) ; kitty keyboard
(cursor-hide b) (cursor-hide b)
(finish-output (backend-output-stream b)) (finish-output (backend-output-stream b))
b) b)
(defmethod shutdown-backend ((b modern-backend)) (defmethod shutdown-backend ((b modern-backend))
(cursor-show b) (cursor-show b)
(backend-write b (format nil "~C[?u" #\Esc)) ; restore default keyboard
(backend-write b (format nil "~C[?2004l" #\Esc)) ; disable bracketed paste (backend-write b (format nil "~C[?2004l" #\Esc)) ; disable bracketed paste
(backend-write b (format nil "~C[?1006l" #\Esc)) ; disable SGR mouse (backend-write b (format nil "~C[?1006l" #\Esc)) ; disable SGR mouse
(backend-write b (format nil "~C[?1002l" #\Esc)) (backend-write b (format nil "~C[?1002l" #\Esc))
@@ -161,8 +163,17 @@ as a fallback when a keyword is not in *named-colors*.")
(values)) (values))
(defmethod backend-size ((b modern-backend)) (defmethod backend-size ((b modern-backend))
;; Default fallback — real implementation queries terminal ;; Query actual terminal dimensions via TIOCGWINSZ ioctl
(values 80 24)) (let* ((+tiocgwinsz+ 21523) ; 0x5413 on Linux
(winsize (sb-alien:make-alien sb-alien:unsigned-short 4)))
(unwind-protect
(progn
(sb-unix:unix-ioctl (sb-sys:fd-stream-fd (backend-output-stream b))
+tiocgwinsz+
winsize)
(values (sb-alien:deref winsize 1) ;; cols
(sb-alien:deref winsize 0))) ;; rows
(sb-alien:free-alien winsize))))
(defmethod backend-write ((b modern-backend) string) (defmethod backend-write ((b modern-backend) string)
(let ((stream (backend-output-stream b))) (let ((stream (backend-output-stream b)))

View File

@@ -15,6 +15,8 @@
#:with-raw-terminal #:with-raw-terminal
;; Event reading ;; Event reading
#:read-event #:read-event
;; Terminal resize flag
#:*terminal-resized-p*
;; TextInput ;; TextInput
#:text-input #:make-text-input #:text-input #:make-text-input
#:text-input-value #:text-input-cursor #:text-input-value #:text-input-cursor

View File

@@ -318,6 +318,20 @@ key event rather than blocking indefinitely."
(t (t
(make-key-event :key :unknown :code b :raw (string (code-char b))))))) (make-key-event :key :unknown :code b :raw (string (code-char b)))))))
;;; ---------------------------------------------------------------------------
;;; SIGWINCH handler for terminal resize
;;; ---------------------------------------------------------------------------
(defvar *terminal-resized-p* nil
"Set to T by SIGWINCH handler when terminal is resized.
Applications should check and clear this flag each frame.")
#+sbcl
(eval-when (:load-toplevel :execute)
(sb-sys:enable-interrupt sb-posix:sigwinch
(lambda (signal info context)
(declare (ignore signal info context))
(setf *terminal-resized-p* t))))
;;; --------------------------------------------------------------------------- ;;; ---------------------------------------------------------------------------
;;; Backend integration ;;; Backend integration
;;; --------------------------------------------------------------------------- ;;; ---------------------------------------------------------------------------

View File

@@ -49,8 +49,13 @@ Components without a layout-node or position return nil."
(when *selection* (sel-text *selection*))) (when *selection* (sel-text *selection*)))
(defun copy-to-clipboard (text) (defun copy-to-clipboard (text)
#+linux (sb-ext:run-program "xclip" (list "-selection" "clipboard") #+linux
:input text :wait nil) (cond
((sb-ext:posix-getenv "WAYLAND_DISPLAY")
(sb-ext:run-program "wl-copy" nil :input text :wait nil))
(t
(sb-ext:run-program "xclip" (list "-selection" "clipboard")
:input text :wait nil)))
#+darwin (sb-ext:run-program "pbcopy" nil :input text :wait nil)) #+darwin (sb-ext:run-program "pbcopy" nil :input text :wait nil))
;;; --- Selection tracking (mouse drag) --------------------------------------- ;;; --- Selection tracking (mouse drag) ---------------------------------------