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"
|
|
|
|
|
2020-10-05 14:14:55 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
|
2022-01-28 08:20:06 -05:00
|
|
|
typedef long keymap_id_T;
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
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 {
|
2022-01-30 09:22:18 -05:00
|
|
|
union {
|
|
|
|
const char *str;
|
|
|
|
char *astr;
|
|
|
|
};
|
2005-09-15 09:58:31 -04:00
|
|
|
action_id_T num;
|
2022-01-28 08:20:06 -05:00
|
|
|
keymap_id_T keymap_id;
|
2022-01-30 09:22:18 -05:00
|
|
|
union {
|
|
|
|
const char *desc;
|
|
|
|
char *adesc;
|
|
|
|
};
|
2005-09-15 09:58:31 -04:00
|
|
|
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 {
|
2022-02-04 10:40:46 -05:00
|
|
|
const char *str;
|
2022-01-28 08:20:06 -05:00
|
|
|
keymap_id_T keymap_id;
|
2021-01-02 10:20:27 -05:00
|
|
|
char *desc;
|
2005-09-15 09:58:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2022-01-28 09:26:43 -05:00
|
|
|
typedef long main_action_T;
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2022-01-28 12:02:14 -05:00
|
|
|
typedef long edit_action_T;
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2022-01-28 09:02:37 -05:00
|
|
|
typedef unsigned short kbdbind_flags_T;
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
struct keybinding {
|
|
|
|
OBJECT_HEAD(struct keybinding);
|
|
|
|
|
2022-01-28 08:20:06 -05:00
|
|
|
keymap_id_T keymap_id;
|
2005-09-15 09:58:31 -04:00
|
|
|
action_id_T action_id;
|
|
|
|
struct term_event_keyboard kbd;
|
|
|
|
int event;
|
2022-01-28 09:02:37 -05:00
|
|
|
kbdbind_flags_T flags;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct listbox_item *box_item;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-01-28 08:20:06 -05:00
|
|
|
struct keybinding *add_keybinding(keymap_id_T keymap_id, action_id_T action_id, struct term_event_keyboard *kbd, int event);
|
|
|
|
int keybinding_exists(keymap_id_T keymap_id, struct term_event_keyboard *kbd, action_id_T *action_id);
|
2005-09-15 09:58:31 -04:00
|
|
|
void free_keybinding(struct keybinding *);
|
|
|
|
|
2022-01-28 08:20:06 -05:00
|
|
|
const struct action *get_action(keymap_id_T keymap_id, action_id_T action_id);
|
|
|
|
char *get_action_name(keymap_id_T keymap_id, action_id_T action_id);
|
2022-02-09 12:24:36 -05:00
|
|
|
action_id_T get_action_from_string(keymap_id_T keymap_id, const char *str);
|
2022-01-28 08:20:06 -05:00
|
|
|
char *get_action_name_from_keystroke(keymap_id_T keymap_id,
|
2021-01-02 10:20:27 -05:00
|
|
|
const char *keystroke_str);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
static inline unsigned int
|
2022-01-28 08:20:06 -05:00
|
|
|
action_is_anonymous_safe(keymap_id_T keymap_id, action_id_T action_id)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
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
|
2022-01-28 08:20:06 -05:00
|
|
|
action_requires_view_state(keymap_id_T keymap_id, action_id_T action_id)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
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
|
2022-01-28 08:20:06 -05:00
|
|
|
action_requires_location(keymap_id_T keymap_id, action_id_T action_id)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
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
|
2022-01-28 08:20:06 -05:00
|
|
|
action_prefix_is_link_number(keymap_id_T keymap_id, action_id_T action_id)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
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
|
2022-01-28 08:20:06 -05:00
|
|
|
action_requires_link(keymap_id_T keymap_id, action_id_T action_id)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
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
|
2022-01-28 08:20:06 -05:00
|
|
|
action_requires_form(keymap_id_T keymap_id, action_id_T action_id)
|
2005-12-26 16:22:03 -05:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
2021-01-02 10:20:27 -05:00
|
|
|
term_event_key_T read_key(const char *);
|
2022-02-04 10:40:46 -05:00
|
|
|
const char *get_keymap_name(keymap_id_T);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2021-01-02 10:20:27 -05:00
|
|
|
int parse_keystroke(const char *, struct term_event_keyboard *);
|
2019-04-21 06:27:40 -04: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-04-21 06:27:40 -04: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)
|
|
|
|
|
2022-01-28 08:20:06 -05:00
|
|
|
action_id_T kbd_action(keymap_id_T, struct term_event *, int *);
|
|
|
|
struct keybinding *kbd_ev_lookup(keymap_id_T, struct term_event_keyboard *kbd, int *);
|
2022-02-09 12:24:36 -05:00
|
|
|
struct keybinding *kbd_nm_lookup(keymap_id_T, const char *);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2022-06-17 09:55:05 -04:00
|
|
|
int bind_do(const char *, const char *, char *, int);
|
2021-01-02 10:20:27 -05:00
|
|
|
char *bind_act(char *, const char *);
|
2019-04-21 06:27:40 -04:00
|
|
|
void bind_config_string(struct string *);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
#ifdef CONFIG_SCRIPTING
|
2022-06-17 09:55:05 -04:00
|
|
|
int bind_key_to_event_name(const char *, const char *, char *,
|
2021-01-02 10:20:27 -05:00
|
|
|
char **);
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|
|
|
|
|
2022-01-28 08:20:06 -05:00
|
|
|
void add_keystroke_action_to_string(struct string *string, action_id_T action_id, keymap_id_T keymap_id);
|
|
|
|
char *get_keystroke(action_id_T action_id, keymap_id_T keymap_id);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2019-04-21 06:27:40 -04:00
|
|
|
void add_actions_to_string(struct string *string, action_id_T actions[],
|
2022-01-28 08:20:06 -05:00
|
|
|
keymap_id_T keymap_id, struct terminal *term);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2006-05-20 08:36:54 -04:00
|
|
|
extern struct module kbdbind_module;
|
2006-05-31 13:34:49 -04:00
|
|
|
|
2020-10-05 14:14:55 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|