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
;
26 enum keymap_id keymap_id
;
32 struct action
*actions
;
37 enum keymap_id keymap_id
;
42 ACTION_RESTRICT_ANONYMOUS
= (1 << 16),
43 ACTION_REQUIRE_VIEW_STATE
= (1 << 17),
44 ACTION_REQUIRE_LOCATION
= (1 << 18),
45 ACTION_JUMP_TO_LINK
= (1 << 19),
46 ACTION_REQUIRE_LINK
= (1 << 20),
47 ACTION_REQUIRE_FORM
= (1 << 21),
48 ACTION_FLAGS_MASK
= (0xFF << 16),
51 /* Note: if you add anything here, please keep it in alphabetical order,
52 * and also update the table action_table[] in kbdbind.c. */
54 #define ACTION_(map, name, action, caption, flags) \
55 ACT_##map##_OFFSET_##action
57 enum main_action_offset
{
58 #include "config/actions-main.inc"
63 enum edit_action_offset
{
64 #include "config/actions-edit.inc"
69 enum menu_action_offset
{
70 #include "config/actions-menu.inc"
76 #define ACTION_(map, name, action, caption, flags) \
80 #include "config/actions-main.inc"
84 #include "config/actions-edit.inc"
88 #include "config/actions-menu.inc"
97 /* Marks whether the binding has a key that is used
98 * by one of the default bindings. */
101 /* Marks whether the binding itself (the combination of key
102 * _and_ action) is default. */
103 KBDB_DEFAULT_BINDING
= 8,
107 OBJECT_HEAD(struct keybinding
);
109 enum keymap_id keymap_id
;
110 action_id_T action_id
;
111 struct term_event_keyboard kbd
;
113 enum kbdbind_flags flags
;
114 struct listbox_item
*box_item
;
118 struct keybinding
*add_keybinding(enum keymap_id keymap_id
, action_id_T action_id
, struct term_event_keyboard
*kbd
, int event
);
119 int keybinding_exists(enum keymap_id keymap_id
, struct term_event_keyboard
*kbd
, action_id_T
*action_id
);
120 void free_keybinding(struct keybinding
*);
122 struct action
*get_action(enum keymap_id keymap_id
, action_id_T action_id
);
123 unsigned char *get_action_name(enum keymap_id keymap_id
, action_id_T action_id
);
124 action_id_T
get_action_from_string(enum keymap_id keymap_id
, unsigned char *str
);
125 unsigned char *get_action_name_from_keystroke(enum keymap_id keymap_id
,
126 const unsigned char *keystroke_str
);
128 static inline unsigned int
129 action_is_anonymous_safe(enum keymap_id keymap_id
, action_id_T action_id
)
131 struct action
*action
= get_action(keymap_id
, action_id
);
133 return action
&& !(action
->flags
& ACTION_RESTRICT_ANONYMOUS
);
136 static inline unsigned int
137 action_requires_view_state(enum keymap_id keymap_id
, action_id_T action_id
)
139 struct action
*action
= get_action(keymap_id
, action_id
);
141 return action
&& (action
->flags
& ACTION_REQUIRE_VIEW_STATE
);
144 static inline unsigned int
145 action_requires_location(enum keymap_id keymap_id
, action_id_T action_id
)
147 struct action
*action
= get_action(keymap_id
, action_id
);
149 return action
&& (action
->flags
& ACTION_REQUIRE_LOCATION
);
152 static inline unsigned int
153 action_prefix_is_link_number(enum keymap_id keymap_id
, action_id_T action_id
)
155 struct action
*action
= get_action(keymap_id
, action_id
);
157 return action
&& (action
->flags
& ACTION_JUMP_TO_LINK
);
160 static inline unsigned int
161 action_requires_link(enum keymap_id keymap_id
, action_id_T action_id
)
163 struct action
*action
= get_action(keymap_id
, action_id
);
165 return action
&& (action
->flags
& ACTION_REQUIRE_LINK
);
168 static inline unsigned int
169 action_requires_form(enum keymap_id keymap_id
, action_id_T action_id
)
171 struct action
*action
= get_action(keymap_id
, action_id
);
173 return action
&& (action
->flags
& ACTION_REQUIRE_FORM
);
176 term_event_key_T
read_key(const unsigned char *);
177 unsigned char *get_keymap_name(enum keymap_id
);
179 int parse_keystroke(const unsigned char *, struct term_event_keyboard
*);
180 void add_keystroke_to_string(struct string
*str
, struct term_event_keyboard
*kbd
, int escape
);
182 /* void add_accesskey_to_string(struct string *str, unicode_val_T accesskey); */
183 #define add_accesskey_to_string(str, accesskey) do { \
184 struct term_event_keyboard kbd; \
185 /* FIXME: #ifndef CONFIG_UTF8, kbd.key is encoded in \
186 * the charset of the terminal, so accesskey should be \
187 * converted from unicode_val_T to that. \
188 * #ifdef CONFIG_UTF8, the code is correct. */ \
189 kbd.key = accesskey; \
190 /* try_document_key() recognizes only Alt-accesskey \
192 kbd.modifier = KBD_MOD_ALT; \
193 add_keystroke_to_string(str, &kbd, 0); \
196 action_id_T
kbd_action(enum keymap_id
, struct term_event
*, int *);
197 struct keybinding
*kbd_ev_lookup(enum keymap_id
, struct term_event_keyboard
*kbd
, int *);
198 struct keybinding
*kbd_nm_lookup(enum keymap_id
, unsigned char *);
200 int bind_do(unsigned char *, const unsigned char *, unsigned char *, int);
201 unsigned char *bind_act(unsigned char *, const unsigned char *);
202 void bind_config_string(struct string
*);
204 #ifdef CONFIG_SCRIPTING
205 int bind_key_to_event_name(unsigned char *, const unsigned char *, unsigned char *,
209 void add_keystroke_action_to_string(struct string
*string
, action_id_T action_id
, enum keymap_id keymap_id
);
210 unsigned char *get_keystroke(action_id_T action_id
, enum keymap_id keymap_id
);
212 void add_actions_to_string(struct string
*string
, action_id_T actions
[],
213 enum keymap_id keymap_id
, struct terminal
*term
);
215 extern struct module kbdbind_module
;