From fbdcd42b0a2aadb4f3e27cd2a75c863d2f67eb39 Mon Sep 17 00:00:00 2001 From: Chris Feng Date: Sun, 1 Apr 2018 23:30:19 +0800 Subject: [PATCH] Add support for various key processing variables * exwm-input.el (exwm-input--mimic-read-event): New function for handling `extra-keyboard-modifiers' and `keyboard-translate-table'. (exwm-input--cache-event): Do not unread events here. (exwm-input--on-KeyPress-line-mode) (exwm-input--on-KeyPress-char-mode): Compare with preprocessed events and unread raw ones. * exwm-input.el (exwm-input--on-KeyPress-line-mode): Add support for `overriding-terminal-local-map'. --- exwm-input.el | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/exwm-input.el b/exwm-input.el index dae0153..1534108 100644 --- a/exwm-input.el +++ b/exwm-input.el @@ -522,6 +522,19 @@ instead." (setq unread-command-events (append unread-command-events `((t . ,event))))))) +(defun exwm-input--mimic-read-event (event) + "Process EVENT as if it were returned by `read-event'." + (unless (eq 0 extra-keyboard-modifiers) + (setq event (event-convert-list (append (event-modifiers + extra-keyboard-modifiers) + event)))) + (when (characterp event) + (let ((event* (when keyboard-translate-table + (aref keyboard-translate-table event)))) + (when event* + (setq event event*)))) + event) + (cl-defun exwm-input--translate (key) (let (translation) (dolist (map (list input-decode-map @@ -546,18 +559,18 @@ instead." (setq exwm-input--line-mode-cache nil) (when exwm-input--temp-line-mode (setq exwm-input--temp-line-mode nil) - (exwm-input--release-keyboard))) - (exwm-input--unread-event event)) + (exwm-input--release-keyboard)))) (defun exwm-input--on-KeyPress-line-mode (key-press raw-data) "Parse X KeyPress event to Emacs key event and then feed the command loop." (with-slots (detail state) key-press (let ((keysym (xcb:keysyms:keycode->keysym exwm--connection detail state)) - event mode) + event raw-event mode) (when (and (/= 0 (car keysym)) - (setq event (xcb:keysyms:keysym->event - exwm--connection (car keysym) - (logand state (lognot (cdr keysym))))) + (setq raw-event (xcb:keysyms:keysym->event + exwm--connection (car keysym) + (logand state (lognot (cdr keysym))))) + (setq event (exwm-input--mimic-read-event raw-event)) (or exwm-input-line-mode-passthrough exwm-input--during-command ;; Forward the event when there is an incomplete key @@ -567,10 +580,14 @@ instead." ;; (memq event exwm-input--global-prefix-keys) (memq event exwm-input-prefix-keys) + (when overriding-terminal-local-map + (lookup-key overriding-terminal-local-map + (vector event))) (lookup-key (current-local-map) (vector event)) (gethash event exwm-input--simulation-keys))) (setq mode xcb:Allow:AsyncKeyboard) - (exwm-input--cache-event event)) + (exwm-input--cache-event event) + (exwm-input--unread-event raw-event)) (unless mode (if (= 0 (logand #x6000 state)) ;Check the 13~14 bits. ;; Not an XKB state; just replay it. @@ -599,17 +616,19 @@ instead." "Handle KeyPress event in char-mode." (with-slots (detail state) key-press (let ((keysym (xcb:keysyms:keycode->keysym exwm--connection detail state)) - event) + event raw-event) (when (and (/= 0 (car keysym)) - (setq event (xcb:keysyms:keysym->event - exwm--connection (car keysym) - (logand state (lognot (cdr keysym)))))) + (setq raw-event (xcb:keysyms:keysym->event + exwm--connection (car keysym) + (logand state (lognot (cdr keysym))))) + (setq event (exwm-input--mimic-read-event raw-event))) (if (not (eq major-mode 'exwm-mode)) - (exwm-input--unread-event event) + (exwm-input--unread-event raw-event) ;; Grab keyboard temporarily. (setq exwm-input--temp-line-mode t) (exwm-input--grab-keyboard) - (exwm-input--cache-event event))))) + (exwm-input--cache-event event) + (exwm-input--unread-event raw-event))))) (xcb:+request exwm--connection (make-instance 'xcb:AllowEvents :mode xcb:Allow:AsyncKeyboard