-
Notifications
You must be signed in to change notification settings - Fork 10
/
term-keys-glfw-mods.el
79 lines (60 loc) · 2.64 KB
/
term-keys-glfw-mods.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
;;; term-keys-glfw-mods.el --- term-keys support for terminals with glfw mods
;; This file is not part of GNU Emacs.
;; 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 2 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; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; This file contains supplementary code for aiding in the
;; configuration of terminal emulators to interoperate with
;; the term-keys package.
;; For more information, please see the accompanying README.md file.
;;; Code:
(require 'term-keys)
(defgroup term-keys/glfw nil
"`term-keys' options for GLFW-based terminal emulators."
:group 'term-keys)
(define-widget 'term-keys/glfw-modifier 'lazy
"Choice for GLFW key modifier state flags."
:type '(choice (const "SHIFT")
(const "CONTROL")
(const "ALT")
(const "SUPER")
(const "CAPS_LOCK")
(const "NUM_LOCK")
(const :tag "(none)" nil)))
(defcustom term-keys/glfw-modifier-map ["SHIFT" "CTRL" "ALT" "SUPER" nil nil]
"Map of GLFW modifier state flags to Emacs modifiers.
This should be a vector of 6 elements, with each element being a
string indicating the name of the GLFW modifier name (sans the
\"GLFW_MOD_\" prefix) corresponding to the Emacs modifiers Shift,
Control, Meta, Super, Hyper and Alt respectively. nil indicates
that there is no mapping for this modifier.
https://www.glfw.org/docs/latest/group__mods.html"
:type '(vector
(term-keys/glfw-modifier :tag "Shift")
(term-keys/glfw-modifier :tag "Control")
(term-keys/glfw-modifier :tag "Meta")
(term-keys/glfw-modifier :tag "Super")
(term-keys/glfw-modifier :tag "Hyper")
(term-keys/glfw-modifier :tag "Alt"))
:group 'term-keys/glfw)
(defun term-keys/glfw-mods-representable (mods)
"Return non-nil if the given MODS vector is representable in GLFW."
(cl-reduce (lambda (x y) (and x y)) ; all
(mapcar (lambda (n)
(or (not (elt mods n)) ; inactive modifier
(elt term-keys/glfw-modifier-map n))) ; mapped
(number-sequence 0 (1- (length mods)))))) ; 0..5
(provide 'term-keys-glfw-mods)
;;; term-keys-glfw-mods.el ends here