;;; xterm-kitty.el --- kitty terminal support ;; Copyright (C) 2021 Ravi Kiran ;; Author: Ravi Kiran ;; Keywords: ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; Work-in-progress to support kitty terminal with all modifiers ;; - still need to ;; + ensure proper 24-bit color support ;; + add all keys specified in private unicode space ;; + figure out a way to split keybindings between kitty and non-kitty ;; frames ;;; Code: (require 'term/xterm) (require 'kitty-keyboard-protocol) (defun xterm-kitty-in-use (&optional frame) "Check whether FRAME is running under kitty terminal." (terminal-parameter frame 'kitty-window-id)) (defun xterm-kitty-make-binding-sequence (default key &rest modifiers) "Make a key vector for KEY with VECTORS suitable for binding with 'define-key' if xterm-kitty is active. DEFAULT is the value to be returned if xterm-kitty is not active. KEY is the key to be used. MODIFIERS is a list of modifiers, or modifiers specified explicitly. 'define-key' uses 'event-convert-list' internally, which strips off shift modifiers for alphabetic characters. The only way to avoid it is to provide the key vector itself to 'define-key', which this function explicitly creates. In that sense, this function is almost equivalent to 'event-convert-list'." (if (xterm-kitty-in-use) (vector (kitty-kbp--add-modifier-list modifiers key)) default)) ;; To do: debug the reason that the table method does not work ;; - the table does not seem to be reflected in input-decode-map ;; - the table method is needed for those packages which advice ;; low-level functions such as read-char, e.g., multiple-cursors (defvar xterm-kitty-use-table-method nil "Use table method to handle character map") (defun xterm-kitty-apply-keyboard (&optional keymap alternate-keymap) "Apply keyboard defintion; optionally to KEYMAP and ALTERNATE-KEYMAP." (let* ((kmap (or keymap (and (xterm-kitty-in-use) input-decode-map))) (alternate-kmap (or alternate-keymap (and kmap (not keymap) key-translation-map)))) (when kmap (unless keymap ; default keymap was used (message "Applying xterm-kitty changes") (send-string-to-terminal "\e[>1;u") (push "\e[>1;u" (terminal-parameter nil 'tty-mode-set-strings)) (push "\e[