2005-09-15 09:58:31 -04:00
|
|
|
#ifndef EL__CONFIG_KBDBIND_H
|
|
|
|
#define EL__CONFIG_KBDBIND_H
|
|
|
|
|
|
|
|
#include "config/options.h"
|
|
|
|
#include "main/event.h"
|
|
|
|
#include "main/object.h"
|
|
|
|
#include "terminal/terminal.h"
|
|
|
|
#include "util/string.h"
|
|
|
|
|
2005-11-15 05:33:27 -05:00
|
|
|
struct listbox_item;
|
2006-05-20 08:36:54 -04:00
|
|
|
struct module;
|
2005-11-15 05:33:27 -05:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
/* Used for holding enum <keymap>_action values. */
|
|
|
|
typedef long action_id_T;
|
|
|
|
|
|
|
|
enum keymap_id {
|
2008-01-27 13:47:20 -05:00
|
|
|
KEYMAP_INVALID = -1,
|
2005-09-15 09:58:31 -04:00
|
|
|
KEYMAP_MAIN,
|
|
|
|
KEYMAP_EDIT,
|
|
|
|
KEYMAP_MENU,
|
|
|
|
KEYMAP_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
struct action {
|
|
|
|
unsigned char *str;
|
|
|
|
action_id_T num;
|
|
|
|
enum keymap_id keymap_id;
|
|
|
|
unsigned char *desc;
|
|
|
|
unsigned int flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct action_list {
|
2009-07-19 13:16:42 -04:00
|
|
|
const struct action *actions;
|
2005-09-15 09:58:31 -04:00
|
|
|
int num_actions;
|
|
|
|
};
|
|
|
|
struct keymap {
|
|
|
|
unsigned char *str;
|
|
|
|
enum keymap_id keymap_id;
|
|
|
|
unsigned char *desc;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum action_flags {
|
|
|
|
ACTION_RESTRICT_ANONYMOUS = (1 << 16),
|
|
|
|
ACTION_REQUIRE_VIEW_STATE = (1 << 17),
|
|
|
|
ACTION_REQUIRE_LOCATION = (1 << 18),
|
|
|
|
ACTION_JUMP_TO_LINK = (1 << 19),
|
|
|
|
ACTION_REQUIRE_LINK = (1 << 20),
|
2005-12-26 16:22:03 -05:00
|
|
|
ACTION_REQUIRE_FORM = (1 << 21),
|
2005-09-15 09:58:31 -04:00
|
|
|
ACTION_FLAGS_MASK = (0xFF << 16),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Note: if you add anything here, please keep it in alphabetical order,
|
|
|
|
* and also update the table action_table[] in kbdbind.c. */
|
|
|
|
|
|
|
|
#define ACTION_(map, name, action, caption, flags) \
|
Remove enum {main,edit,menu}_action_offset
Remove enum main_action_offset, enum edit_action_offset, and enum
menu_action_offset. It seems the original plan (in commit
174eabf1a448d3f084a318aab77805828f35c42e on 2005-05-16) was to include
the action flags in the action IDs, perhaps with something like:
ACT_##map##_##action = ACT_##map##_OFFSET_##action | flags
However, this OR operation was never implemented; each ACT_*_*
constant had the same value as the corresponding ACT_*_OFFSET_*,
and the code that looked for flags in action IDs found only zeroes.
Then on 2005-06-10, a separate action.flags member was added, and
the flag checks were corrected to read that instead. So, it seems
safe to say that the original plan has been discarded and the offset
enumerations won't be needed.
2009-07-18 19:09:38 -04:00
|
|
|
ACT_##map##_##action
|
2005-09-15 09:58:31 -04:00
|
|
|
|
Remove enum {main,edit,menu}_action_offset
Remove enum main_action_offset, enum edit_action_offset, and enum
menu_action_offset. It seems the original plan (in commit
174eabf1a448d3f084a318aab77805828f35c42e on 2005-05-16) was to include
the action flags in the action IDs, perhaps with something like:
ACT_##map##_##action = ACT_##map##_OFFSET_##action | flags
However, this OR operation was never implemented; each ACT_*_*
constant had the same value as the corresponding ACT_*_OFFSET_*,
and the code that looked for flags in action IDs found only zeroes.
Then on 2005-06-10, a separate action.flags member was added, and
the flag checks were corrected to read that instead. So, it seems
safe to say that the original plan has been discarded and the offset
enumerations won't be needed.
2009-07-18 19:09:38 -04:00
|
|
|
enum main_action {
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "config/actions-main.inc"
|
|
|
|
|
|
|
|
MAIN_ACTIONS,
|
|
|
|
};
|
|
|
|
|
Remove enum {main,edit,menu}_action_offset
Remove enum main_action_offset, enum edit_action_offset, and enum
menu_action_offset. It seems the original plan (in commit
174eabf1a448d3f084a318aab77805828f35c42e on 2005-05-16) was to include
the action flags in the action IDs, perhaps with something like:
ACT_##map##_##action = ACT_##map##_OFFSET_##action | flags
However, this OR operation was never implemented; each ACT_*_*
constant had the same value as the corresponding ACT_*_OFFSET_*,
and the code that looked for flags in action IDs found only zeroes.
Then on 2005-06-10, a separate action.flags member was added, and
the flag checks were corrected to read that instead. So, it seems
safe to say that the original plan has been discarded and the offset
enumerations won't be needed.
2009-07-18 19:09:38 -04:00
|
|
|
enum edit_action {
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "config/actions-edit.inc"
|
|
|
|
|
|
|
|
EDIT_ACTIONS
|
|
|
|
};
|
|
|
|
|
Remove enum {main,edit,menu}_action_offset
Remove enum main_action_offset, enum edit_action_offset, and enum
menu_action_offset. It seems the original plan (in commit
174eabf1a448d3f084a318aab77805828f35c42e on 2005-05-16) was to include
the action flags in the action IDs, perhaps with something like:
ACT_##map##_##action = ACT_##map##_OFFSET_##action | flags
However, this OR operation was never implemented; each ACT_*_*
constant had the same value as the corresponding ACT_*_OFFSET_*,
and the code that looked for flags in action IDs found only zeroes.
Then on 2005-06-10, a separate action.flags member was added, and
the flag checks were corrected to read that instead. So, it seems
safe to say that the original plan has been discarded and the offset
enumerations won't be needed.
2009-07-18 19:09:38 -04:00
|
|
|
enum menu_action {
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "config/actions-menu.inc"
|
|
|
|
|
|
|
|
MENU_ACTIONS
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef ACTION_
|
|
|
|
|
|
|
|
enum kbdbind_flags {
|
|
|
|
KBDB_WATERMARK = 1,
|
|
|
|
KBDB_TOUCHED = 2,
|
|
|
|
|
|
|
|
/* Marks whether the binding has a key that is used
|
|
|
|
* by one of the default bindings. */
|
|
|
|
KBDB_DEFAULT_KEY = 4,
|
|
|
|
|
|
|
|
/* Marks whether the binding itself (the combination of key
|
|
|
|
* _and_ action) is default. */
|
|
|
|
KBDB_DEFAULT_BINDING = 8,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct keybinding {
|
|
|
|
OBJECT_HEAD(struct keybinding);
|
|
|
|
|
|
|
|
enum keymap_id keymap_id;
|
|
|
|
action_id_T action_id;
|
|
|
|
struct term_event_keyboard kbd;
|
|
|
|
int event;
|
|
|
|
enum kbdbind_flags flags;
|
|
|
|
struct listbox_item *box_item;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct keybinding *add_keybinding(enum keymap_id keymap_id, action_id_T action_id, struct term_event_keyboard *kbd, int event);
|
|
|
|
int keybinding_exists(enum keymap_id keymap_id, struct term_event_keyboard *kbd, action_id_T *action_id);
|
|
|
|
void free_keybinding(struct keybinding *);
|
|
|
|
|
2009-07-19 13:16:42 -04:00
|
|
|
const struct action *get_action(enum keymap_id keymap_id, action_id_T action_id);
|
2005-09-15 09:58:31 -04:00
|
|
|
unsigned char *get_action_name(enum keymap_id keymap_id, action_id_T action_id);
|
|
|
|
action_id_T get_action_from_string(enum keymap_id keymap_id, unsigned char *str);
|
2005-12-24 01:54:01 -05:00
|
|
|
unsigned char *get_action_name_from_keystroke(enum keymap_id keymap_id,
|
2006-08-13 07:44:01 -04:00
|
|
|
const unsigned char *keystroke_str);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
static inline unsigned int
|
|
|
|
action_is_anonymous_safe(enum keymap_id keymap_id, action_id_T action_id)
|
|
|
|
{
|
2009-07-19 13:16:42 -04:00
|
|
|
const struct action *action = get_action(keymap_id, action_id);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
return action && !(action->flags & ACTION_RESTRICT_ANONYMOUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int
|
|
|
|
action_requires_view_state(enum keymap_id keymap_id, action_id_T action_id)
|
|
|
|
{
|
2009-07-19 13:16:42 -04:00
|
|
|
const struct action *action = get_action(keymap_id, action_id);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
return action && (action->flags & ACTION_REQUIRE_VIEW_STATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int
|
|
|
|
action_requires_location(enum keymap_id keymap_id, action_id_T action_id)
|
|
|
|
{
|
2009-07-19 13:16:42 -04:00
|
|
|
const struct action *action = get_action(keymap_id, action_id);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
return action && (action->flags & ACTION_REQUIRE_LOCATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int
|
|
|
|
action_prefix_is_link_number(enum keymap_id keymap_id, action_id_T action_id)
|
|
|
|
{
|
2009-07-19 13:16:42 -04:00
|
|
|
const struct action *action = get_action(keymap_id, action_id);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
return action && (action->flags & ACTION_JUMP_TO_LINK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int
|
|
|
|
action_requires_link(enum keymap_id keymap_id, action_id_T action_id)
|
|
|
|
{
|
2009-07-19 13:16:42 -04:00
|
|
|
const struct action *action = get_action(keymap_id, action_id);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
return action && (action->flags & ACTION_REQUIRE_LINK);
|
|
|
|
}
|
|
|
|
|
2005-12-26 16:22:03 -05:00
|
|
|
static inline unsigned int
|
|
|
|
action_requires_form(enum keymap_id keymap_id, action_id_T action_id)
|
|
|
|
{
|
2009-07-19 13:16:42 -04:00
|
|
|
const struct action *action = get_action(keymap_id, action_id);
|
2005-12-26 16:22:03 -05:00
|
|
|
|
|
|
|
return action && (action->flags & ACTION_REQUIRE_FORM);
|
|
|
|
}
|
|
|
|
|
2006-08-13 07:44:01 -04:00
|
|
|
term_event_key_T read_key(const unsigned char *);
|
2005-09-15 09:58:31 -04:00
|
|
|
unsigned char *get_keymap_name(enum keymap_id);
|
|
|
|
|
2006-08-13 07:44:01 -04:00
|
|
|
int parse_keystroke(const unsigned char *, struct term_event_keyboard *);
|
2019-02-17 14:46:16 -05:00
|
|
|
void add_keystroke_to_string(struct string_ *str, struct term_event_keyboard *kbd, int escape);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2019-02-17 14:46:16 -05:00
|
|
|
/* void add_accesskey_to_string(struct string_ *str, unicode_val_T accesskey); */
|
2005-09-15 09:58:31 -04:00
|
|
|
#define add_accesskey_to_string(str, accesskey) do { \
|
|
|
|
struct term_event_keyboard kbd; \
|
2006-09-17 09:12:47 -04:00
|
|
|
/* FIXME: #ifndef CONFIG_UTF8, kbd.key is encoded in \
|
2006-08-12 05:37:37 -04:00
|
|
|
* the charset of the terminal, so accesskey should be \
|
|
|
|
* converted from unicode_val_T to that. \
|
2006-09-17 09:12:47 -04:00
|
|
|
* #ifdef CONFIG_UTF8, the code is correct. */ \
|
2006-08-12 05:37:37 -04:00
|
|
|
kbd.key = accesskey; \
|
2006-08-27 06:14:30 -04:00
|
|
|
/* try_document_key() recognizes only Alt-accesskey \
|
|
|
|
* combos. */ \
|
|
|
|
kbd.modifier = KBD_MOD_ALT; \
|
2005-09-15 09:58:31 -04:00
|
|
|
add_keystroke_to_string(str, &kbd, 0); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
action_id_T kbd_action(enum keymap_id, struct term_event *, int *);
|
|
|
|
struct keybinding *kbd_ev_lookup(enum keymap_id, struct term_event_keyboard *kbd, int *);
|
|
|
|
struct keybinding *kbd_nm_lookup(enum keymap_id, unsigned char *);
|
|
|
|
|
2006-08-13 07:44:01 -04:00
|
|
|
int bind_do(unsigned char *, const unsigned char *, unsigned char *, int);
|
|
|
|
unsigned char *bind_act(unsigned char *, const unsigned char *);
|
2019-02-17 14:46:16 -05:00
|
|
|
void bind_config_string(struct string_ *);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
#ifdef CONFIG_SCRIPTING
|
2006-08-13 07:44:01 -04:00
|
|
|
int bind_key_to_event_name(unsigned char *, const unsigned char *, unsigned char *,
|
2005-09-15 09:58:31 -04:00
|
|
|
unsigned char **);
|
|
|
|
#endif
|
|
|
|
|
2019-02-17 14:46:16 -05:00
|
|
|
void add_keystroke_action_to_string(struct string_ *string, action_id_T action_id, enum keymap_id keymap_id);
|
2005-09-15 09:58:31 -04:00
|
|
|
unsigned char *get_keystroke(action_id_T action_id, enum keymap_id keymap_id);
|
|
|
|
|
2019-02-17 14:46:16 -05:00
|
|
|
void add_actions_to_string(struct string_ *string, action_id_T actions[],
|
2005-09-15 09:58:31 -04:00
|
|
|
enum keymap_id keymap_id, struct terminal *term);
|
|
|
|
|
2006-05-20 08:36:54 -04:00
|
|
|
extern struct module kbdbind_module;
|
2006-05-31 13:34:49 -04:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|