Skip to content

Commit

Permalink
Refactor out new term-keys/x11-key-representable function
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed Dec 29, 2021
1 parent 55285bf commit 95367c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 1 addition & 6 deletions term-keys-st.el
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ just one half of the necessary configuration (see
(term-keys/iterate-keys
(lambda (index keymap mods)

;; Skip key combinations with unrepresentable modifiers
(unless (cl-reduce (lambda (x y) (or x y)) ; any
(mapcar (lambda (n) ; active modifier mapped to nil
(and (elt mods n)
(not (elt term-keys/x11-modifier-map n))))
(number-sequence 0 (1- (length mods))))) ; 0..5
(when (term-keys/x11-key-representable keymap mods)
(format "{ XK_%-16s, %-40s, \"%s\", 0, 0},\n"
(term-keys/x11-apply-mods keymap mods) ; X11 key name
(if (cl-reduce (lambda (x y) (or x y)) mods)
Expand Down
12 changes: 12 additions & 0 deletions term-keys-x11.el
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ that there is no mapping for this modifier."
:group 'term-keys/x11)


(defun term-keys/x11-key-representable (keymap mods)
"Return non-nil if the given KEYMAP + MODS vector is representable in X11."
(and
(elt keymap 1) ; Have X11 keysym?
;; Skip key combinations with unrepresentable modifiers
(cl-reduce (lambda (x y) (and x y)) ; all
(mapcar (lambda (n)
(or (not (elt mods n)) ; inactive modifier
(elt term-keys/x11-modifier-map n))) ; mapped
(number-sequence 0 (1- (length mods))))))) ; 0..5


(defun term-keys/x11-apply-mod-state (keymap shift lock control mod1 mod2 mod3 mod4 mod5)
"Apply modifier state flags to an X11 KeySym.
Expand Down

0 comments on commit 95367c5

Please sign in to comment.