1 #ifndef EL__CONFIG_KBDBIND_H
2 #define EL__CONFIG_KBDBIND_H
4 #include "config/options.h"
5 #include "main/event.h"
6 #include "main/object.h"
7 #include "terminal/terminal.h"
8 #include "util/string.h"
13 /* Used for holding enum <keymap>_action values. */
14 typedef long action_id_T
;
27 enum keymap_id keymap_id
;
33 const struct action
*actions
;
38 enum keymap_id keymap_id
;
43 ACTION_RESTRICT_ANONYMOUS
= (1 << 16),
44 ACTION_REQUIRE_VIEW_STATE
= (1 << 17),
45 ACTION_REQUIRE_LOCATION
= (1 << 18),
46 ACTION_JUMP_TO_LINK
= (1 << 19),
47 ACTION_REQUIRE_LINK
= (1 << 20),
48 ACTION_REQUIRE_FORM
= (1 << 21),
49 ACTION_FLAGS_MASK
= (0xFF << 16),
52 /* Note: if you add anything here, please keep it in alphabetical order,
53 * and also update the table action_table[] in kbdbind.c. */
55 #define ACTION_(map, name, action, caption, flags) \
59 #include "config/actions-main.inc"
65 #include "config/actions-edit.inc"
71 #include "config/actions-menu.inc"
82 /* Marks whether the binding has a key that is used
83 * by one of the default bindings. */
86 /* Marks whether the binding itself (the combination of key
87 * _and_ action) is default. */
88 KBDB_DEFAULT_BINDING
= 8,
92 OBJECT_HEAD(struct keybinding
);
94 enum keymap_id keymap_id
;
95 action_id_T action_id
;
96 struct term_event_keyboard kbd
;
98 enum kbdbind_flags flags
;
99 struct listbox_item
*box_item
;
103 struct keybinding
*add_keybinding(enum keymap_id keymap_id
, action_id_T action_id
, struct term_event_keyboard
*kbd
, int event
);
104 int keybinding_exists(enum keymap_id keymap_id
, struct term_event_keyboard
*kbd
, action_id_T
*action_id
);
105 void free_keybinding(struct keybinding
*);
107 const struct action
*get_action(enum keymap_id keymap_id
, action_id_T action_id
);
108 unsigned char *get_action_name(enum keymap_id keymap_id
, action_id_T action_id
);
109 action_id_T
get_action_from_string(enum keymap_id keymap_id
, unsigned char *str
);
110 unsigned char *get_action_name_from_keystroke(enum keymap_id keymap_id
,
111 const unsigned char *keystroke_str
);
113 static inline unsigned int
114 action_is_anonymous_safe(enum keymap_id keymap_id
, action_id_T action_id
)
116 const struct action
*action
= get_action(keymap_id
, action_id
);
118 return action
&& !(action
->flags
& ACTION_RESTRICT_ANONYMOUS
);
121 static inline unsigned int
122 action_requires_view_state(enum keymap_id keymap_id
, action_id_T action_id
)
124 const struct action
*action
= get_action(keymap_id
, action_id
);
126 return action
&& (action
->flags
& ACTION_REQUIRE_VIEW_STATE
);
129 static inline unsigned int
130 action_requires_location(enum keymap_id keymap_id
, action_id_T action_id
)
132 const struct action
*action
= get_action(keymap_id
, action_id
);
134 return action
&& (action
->flags
& ACTION_REQUIRE_LOCATION
);
137 static inline unsigned int
138 action_prefix_is_link_number(enum keymap_id keymap_id
, action_id_T action_id
)
140 const struct action
*action
= get_action(keymap_id
, action_id
);
142 return action
&& (action
->flags
& ACTION_JUMP_TO_LINK
);
145 static inline unsigned int
146 action_requires_link(enum keymap_id keymap_id
, action_id_T action_id
)
148 const struct action
*action
= get_action(keymap_id
, action_id
);
150 return action
&& (action
->flags
& ACTION_REQUIRE_LINK
);
153 static inline unsigned int
154 action_requires_form(enum keymap_id keymap_id
, action_id_T action_id
)
156 const struct action
*action
= get_action(keymap_id
, action_id
);
158 return action
&& (action
->flags
& ACTION_REQUIRE_FORM
);
161 term_event_key_T
read_key(const unsigned char *);
162 unsigned char *get_keymap_name(enum keymap_id
);
164 int parse_keystroke(const unsigned char *, struct term_event_keyboard
*);
165 void add_keystroke_to_string(struct string
*str
, struct term_event_keyboard
*kbd
, int escape
);
167 /* void add_accesskey_to_string(struct string *str, unicode_val_T accesskey); */
168 #define add_accesskey_to_string(str, accesskey) do { \
169 struct term_event_keyboard kbd; \
170 /* FIXME: #ifndef CONFIG_UTF8, kbd.key is encoded in \
171 * the charset of the terminal, so accesskey should be \
172 * converted from unicode_val_T to that. \
173 * #ifdef CONFIG_UTF8, the code is correct. */ \
174 kbd.key = accesskey; \
175 /* try_document_key() recognizes only Alt-accesskey \
177 kbd.modifier = KBD_MOD_ALT; \
178 add_keystroke_to_string(str, &kbd, 0); \
181 action_id_T
kbd_action(enum keymap_id
, struct term_event
*, int *);
182 struct keybinding
*kbd_ev_lookup(enum keymap_id
, struct term_event_keyboard
*kbd
, int *);
183 struct keybinding
*kbd_nm_lookup(enum keymap_id
, unsigned char *);
185 int bind_do(unsigned char *, const unsigned char *, unsigned char *, int);
186 unsigned char *bind_act(unsigned char *, const unsigned char *);
187 void bind_config_string(struct string
*);
189 #ifdef CONFIG_SCRIPTING
190 int bind_key_to_event_name(unsigned char *, const unsigned char *, unsigned char *,
194 void add_keystroke_action_to_string(struct string
*string
, action_id_T action_id
, enum keymap_id keymap_id
);
195 unsigned char *get_keystroke(action_id_T action_id
, enum keymap_id keymap_id
);
197 void add_actions_to_string(struct string
*string
, action_id_T actions
[],
198 enum keymap_id keymap_id
, struct terminal
*term
);
200 extern struct module kbdbind_module
;