mirror of
https://github.com/emacs-exwm/exwm.git
synced 2024-11-27 14:57:59 +01:00
Sync with XELB
* exwm-input.el (exwm-input--update-global-prefix-keys) (exwm-input--on-KeyPress-line-mode, exwm-input--on-KeyPress-char-mode) (exwm-input--fake-key, exwm-input--init): Sync with XELB. * exwm-input.el (exwm-input--on-KeyPress) (exwm-input--on-KeyPress-line-mode): Resend XKB events with SendEvent since AllowEvents in ReplayKeyboard mode doesn't seem to work.
This commit is contained in:
parent
2220c8cea2
commit
719b825bc4
2 changed files with 36 additions and 20 deletions
|
@ -79,7 +79,7 @@
|
||||||
"Event mask set on all managed windows.")
|
"Event mask set on all managed windows.")
|
||||||
|
|
||||||
(declare-function exwm-input--on-KeyPress-line-mode "exwm-input.el"
|
(declare-function exwm-input--on-KeyPress-line-mode "exwm-input.el"
|
||||||
(key-press))
|
(key-press raw-data))
|
||||||
|
|
||||||
;; Internal variables
|
;; Internal variables
|
||||||
(defvar-local exwm--id nil) ;window ID
|
(defvar-local exwm--id nil) ;window ID
|
||||||
|
|
|
@ -265,7 +265,7 @@ This value should always be overwritten.")
|
||||||
(xcb:unmarshal obj data)
|
(xcb:unmarshal obj data)
|
||||||
(setq exwm-input--timestamp (slot-value obj 'time))
|
(setq exwm-input--timestamp (slot-value obj 'time))
|
||||||
(if (eq major-mode 'exwm-mode)
|
(if (eq major-mode 'exwm-mode)
|
||||||
(funcall exwm--on-KeyPress obj)
|
(funcall exwm--on-KeyPress obj data)
|
||||||
(exwm-input--on-KeyPress-char-mode obj))))
|
(exwm-input--on-KeyPress-char-mode obj))))
|
||||||
|
|
||||||
(defvar exwm-input--global-keys nil "Global key bindings.")
|
(defvar exwm-input--global-keys nil "Global key bindings.")
|
||||||
|
@ -307,9 +307,9 @@ This value should always be overwritten.")
|
||||||
keycode (xcb:keysyms:keysym->keycode exwm--connection
|
keycode (xcb:keysyms:keysym->keycode exwm--connection
|
||||||
(car keysym)))
|
(car keysym)))
|
||||||
(setf (slot-value grab-key 'grab-window) workspace
|
(setf (slot-value grab-key 'grab-window) workspace
|
||||||
(slot-value grab-key 'modifiers) (cadr keysym)
|
(slot-value grab-key 'modifiers) (cdr keysym)
|
||||||
(slot-value grab-key 'key) keycode)
|
(slot-value grab-key 'key) keycode)
|
||||||
(when (or (not keycode)
|
(when (or (= 0 keycode)
|
||||||
(xcb:+request-checked+request-check exwm--connection
|
(xcb:+request-checked+request-check exwm--connection
|
||||||
grab-key))
|
grab-key))
|
||||||
(user-error "[EXWM] Failed to grab key: %s"
|
(user-error "[EXWM] Failed to grab key: %s"
|
||||||
|
@ -344,14 +344,15 @@ This value should always be overwritten.")
|
||||||
(defvar exwm-input--during-command nil
|
(defvar exwm-input--during-command nil
|
||||||
"Indicate whether between `pre-command-hook' and `post-command-hook'.")
|
"Indicate whether between `pre-command-hook' and `post-command-hook'.")
|
||||||
|
|
||||||
(defun exwm-input--on-KeyPress-line-mode (key-press)
|
(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."
|
"Parse X KeyPress event to Emacs key event and then feed the command loop."
|
||||||
(with-slots (detail state) key-press
|
(with-slots (detail state) key-press
|
||||||
(let ((keysym (xcb:keysyms:keycode->keysym exwm--connection detail state))
|
(let ((keysym (xcb:keysyms:keycode->keysym exwm--connection detail state))
|
||||||
event minibuffer-window mode)
|
event minibuffer-window mode)
|
||||||
(when (and keysym
|
(when (and (/= 0 (car keysym))
|
||||||
(setq event (xcb:keysyms:keysym->event exwm--connection
|
(setq event (xcb:keysyms:keysym->event
|
||||||
keysym state))
|
exwm--connection (car keysym)
|
||||||
|
(logand state (lognot (cdr keysym)))))
|
||||||
(or exwm-input--during-key-sequence
|
(or exwm-input--during-key-sequence
|
||||||
exwm-input--during-command
|
exwm-input--during-command
|
||||||
(setq minibuffer-window (active-minibuffer-window))
|
(setq minibuffer-window (active-minibuffer-window))
|
||||||
|
@ -363,20 +364,35 @@ This value should always be overwritten.")
|
||||||
;; Feed this event to command loop. Also force it to be added to
|
;; Feed this event to command loop. Also force it to be added to
|
||||||
;; `this-command-keys'.
|
;; `this-command-keys'.
|
||||||
(exwm-input--unread-event event))
|
(exwm-input--unread-event event))
|
||||||
|
(unless mode
|
||||||
|
(if (= 0 (logand #x6000 state)) ;Check the 13~14 bits.
|
||||||
|
;; Not an XKB state; just replay it.
|
||||||
|
(setq mode xcb:Allow:ReplayKeyboard)
|
||||||
|
;; An XKB state; sent it with SendEvent.
|
||||||
|
;; FIXME: Can this also be replayed?
|
||||||
|
;; FIXME: KeyRelease events are lost.
|
||||||
|
(setq mode xcb:Allow:AsyncKeyboard)
|
||||||
|
(xcb:+request exwm--connection
|
||||||
|
(make-instance 'xcb:SendEvent
|
||||||
|
:propagate 0
|
||||||
|
:destination (slot-value key-press 'event)
|
||||||
|
:event-mask xcb:EventMask:NoEvent
|
||||||
|
:event raw-data))))
|
||||||
(xcb:+request exwm--connection
|
(xcb:+request exwm--connection
|
||||||
(make-instance 'xcb:AllowEvents
|
(make-instance 'xcb:AllowEvents
|
||||||
:mode (or mode xcb:Allow:ReplayKeyboard)
|
:mode mode
|
||||||
:time xcb:Time:CurrentTime))
|
:time xcb:Time:CurrentTime))
|
||||||
(xcb:flush exwm--connection))))
|
(xcb:flush exwm--connection))))
|
||||||
|
|
||||||
(defun exwm-input--on-KeyPress-char-mode (key-press)
|
(defun exwm-input--on-KeyPress-char-mode (key-press &optional _raw-data)
|
||||||
"Handle KeyPress event in char-mode."
|
"Handle KeyPress event in char-mode."
|
||||||
(with-slots (detail state) key-press
|
(with-slots (detail state) key-press
|
||||||
(let ((keysym (xcb:keysyms:keycode->keysym exwm--connection detail state))
|
(let ((keysym (xcb:keysyms:keycode->keysym exwm--connection detail state))
|
||||||
event)
|
event)
|
||||||
(when (and keysym
|
(when (and (/= 0 (car keysym))
|
||||||
(setq event (xcb:keysyms:keysym->event exwm--connection
|
(setq event (xcb:keysyms:keysym->event
|
||||||
keysym state)))
|
exwm--connection (car keysym)
|
||||||
|
(logand state (lognot (cdr keysym))))))
|
||||||
(when (eq major-mode 'exwm-mode)
|
(when (eq major-mode 'exwm-mode)
|
||||||
;; FIXME: This functionality seems not working, e.g. when this
|
;; FIXME: This functionality seems not working, e.g. when this
|
||||||
;; command would activate the minibuffer, the temporary
|
;; command would activate the minibuffer, the temporary
|
||||||
|
@ -476,11 +492,11 @@ This value should always be overwritten.")
|
||||||
"Fake a key event equivalent to Emacs event EVENT."
|
"Fake a key event equivalent to Emacs event EVENT."
|
||||||
(let* ((keysym (xcb:keysyms:event->keysym exwm--connection event))
|
(let* ((keysym (xcb:keysyms:event->keysym exwm--connection event))
|
||||||
keycode id)
|
keycode id)
|
||||||
(unless keysym
|
(when (= 0 (car keysym))
|
||||||
(user-error "[EXWM] Invalid key: %s" (single-key-description event)))
|
(user-error "[EXWM] Invalid key: %s" (single-key-description event)))
|
||||||
(setq keycode (xcb:keysyms:keysym->keycode exwm--connection
|
(setq keycode (xcb:keysyms:keysym->keycode exwm--connection
|
||||||
(car keysym)))
|
(car keysym)))
|
||||||
(when keycode
|
(when (/= 0 keycode)
|
||||||
(setq id (exwm--buffer->id (window-buffer (selected-window))))
|
(setq id (exwm--buffer->id (window-buffer (selected-window))))
|
||||||
(dolist (class '(xcb:KeyPress xcb:KeyRelease))
|
(dolist (class '(xcb:KeyPress xcb:KeyRelease))
|
||||||
(xcb:+request exwm--connection
|
(xcb:+request exwm--connection
|
||||||
|
@ -495,7 +511,7 @@ This value should always be overwritten.")
|
||||||
:child 0
|
:child 0
|
||||||
:root-x 0 :root-y 0
|
:root-x 0 :root-y 0
|
||||||
:event-x 0 :event-y 0
|
:event-x 0 :event-y 0
|
||||||
:state (cadr keysym)
|
:state (cdr keysym)
|
||||||
:same-screen 1)
|
:same-screen 1)
|
||||||
exwm--connection)))))
|
exwm--connection)))))
|
||||||
(xcb:flush exwm--connection)))
|
(xcb:flush exwm--connection)))
|
||||||
|
@ -592,16 +608,16 @@ Its usage is the same with `exwm-input-set-simulation-keys'."
|
||||||
exwm-input-move-event))
|
exwm-input-move-event))
|
||||||
(resize-key (xcb:keysyms:event->keysym exwm--connection
|
(resize-key (xcb:keysyms:event->keysym exwm--connection
|
||||||
exwm-input-resize-event)))
|
exwm-input-resize-event)))
|
||||||
(unless move-key
|
(when (= 0 (car move-key))
|
||||||
(user-error "[EXWM] Invalid key: %s"
|
(user-error "[EXWM] Invalid key: %s"
|
||||||
(single-key-description exwm-input-move-event)))
|
(single-key-description exwm-input-move-event)))
|
||||||
(unless resize-key
|
(when (= 0 (car resize-key))
|
||||||
(user-error "[EXWM] Invalid key: %s"
|
(user-error "[EXWM] Invalid key: %s"
|
||||||
(single-key-description exwm-input-resize-event)))
|
(single-key-description exwm-input-resize-event)))
|
||||||
(setq exwm-input--move-keysym (car move-key)
|
(setq exwm-input--move-keysym (car move-key)
|
||||||
exwm-input--move-mask (cadr move-key)
|
exwm-input--move-mask (cdr move-key)
|
||||||
exwm-input--resize-keysym (car resize-key)
|
exwm-input--resize-keysym (car resize-key)
|
||||||
exwm-input--resize-mask (cadr resize-key)))
|
exwm-input--resize-mask (cdr resize-key)))
|
||||||
;; Attach event listeners
|
;; Attach event listeners
|
||||||
(xcb:+event exwm--connection 'xcb:KeyPress #'exwm-input--on-KeyPress)
|
(xcb:+event exwm--connection 'xcb:KeyPress #'exwm-input--on-KeyPress)
|
||||||
(xcb:+event exwm--connection 'xcb:ButtonPress #'exwm-input--on-ButtonPress)
|
(xcb:+event exwm--connection 'xcb:ButtonPress #'exwm-input--on-ButtonPress)
|
||||||
|
|
Loading…
Reference in a new issue