* Dan Nicholson <dbn.lists@gmail.com>
*/
-#ifndef MAP_H
-#define MAP_H
+#ifndef KEYMAP_H
+#define KEYMAP_H
/* Don't use compat names in internal code. */
#define _XKBCOMMON_COMPAT_H
#include "utils.h"
#include "context.h"
-#define XKB_KEY_NAME_LENGTH 4
+/* This limit is artificially enforced, we do not depend on it any where.
+ * The reason it's still here is that the rules file format does not
+ * support multiple groups very well, and the rules shipped with
+ * xkeyboard-config (see rules/evdev) depend on this limit extensively.
+ * So just lifting this limit would cause problems for people who will use
+ * more than 4 layouts.
+ * TODO: Fix the group index syntax in the rules format, preferably in a
+ * backwards compatible way.
+ * See e.g. https://bugs.freedesktop.org/show_bug.cgi?id=14372
+ * Note: A limit on the number of groups we *do* depend on is imposed by
+ * the size of the xkb_layout_mask_t type (32). This is more than enough
+ * though.
+ */
+#define XKB_MAX_GROUPS 4
+
+/* Don't allow more modifiers than we can hold in xkb_mod_mask_t. */
+#define XKB_MAX_MODS ((xkb_mod_index_t) (sizeof(xkb_mod_mask_t) * 8))
+
+/* Don't allow more leds than we can hold in xkb_led_mask_t. */
+#define XKB_MAX_LEDS ((xkb_led_index_t) (sizeof(xkb_led_mask_t) * 8))
-/* These should all be dynamic. */
-#define XKB_NUM_GROUPS 4
-#define XKB_NUM_INDICATORS 32
-#define XKB_NUM_VIRTUAL_MODS 16
-#define XKB_NUM_CORE_MODS 8
+/* These should all go away. */
+enum mod_type {
+ MOD_REAL = (1 << 0),
+ MOD_VIRT = (1 << 1),
+ MOD_BOTH = (MOD_REAL | MOD_VIRT),
+};
+#define MOD_REAL_MASK_ALL ((xkb_mod_mask_t) 0x000000ff)
enum xkb_action_type {
ACTION_TYPE_NONE = 0,
ACTION_TYPE_SWITCH_VT,
ACTION_TYPE_CTRL_SET,
ACTION_TYPE_CTRL_LOCK,
- ACTION_TYPE_KEY_REDIRECT,
ACTION_TYPE_PRIVATE,
_ACTION_TYPE_NUM_ENTRIES
};
ACTION_ABSOLUTE_SWITCH = (1 << 5),
ACTION_ABSOLUTE_X = (1 << 6),
ACTION_ABSOLUTE_Y = (1 << 7),
- ACTION_NO_ACCEL = (1 << 8),
+ ACTION_ACCEL = (1 << 8),
ACTION_SAME_SCREEN = (1 << 9),
};
};
enum xkb_match_operation {
- MATCH_NONE = 0,
- MATCH_ANY_OR_NONE = 1,
- MATCH_ANY = 2,
- MATCH_ALL = 3,
- MATCH_EXACTLY = 4,
- MATCH_OP_MASK = \
- (MATCH_NONE | MATCH_ANY_OR_NONE | MATCH_ANY | MATCH_ALL | \
- MATCH_EXACTLY),
- MATCH_LEVEL_ONE_ONLY = (1 << 7),
+ MATCH_NONE,
+ MATCH_ANY_OR_NONE,
+ MATCH_ANY,
+ MATCH_ALL,
+ MATCH_EXACTLY,
};
struct xkb_mods {
int8_t screen;
};
-struct xkb_redirect_key_action {
- enum xkb_action_type type;
- enum xkb_action_flags flags;
- xkb_keycode_t new_kc;
- uint8_t mods_mask;
- uint8_t mods;
- uint16_t vmods_mask;
- uint16_t vmods;
-};
-
struct xkb_pointer_action {
enum xkb_action_type type;
enum xkb_action_flags flags;
enum xkb_action_type type;
enum xkb_action_flags flags;
uint8_t count;
- int8_t button;
+ uint8_t button;
};
struct xkb_private_action {
enum xkb_action_type type;
- enum xkb_action_flags flags;
uint8_t data[7];
};
struct xkb_controls_action ctrls;
struct xkb_pointer_default_action dflt;
struct xkb_switch_screen_action screen;
- struct xkb_redirect_key_action redirect; /* XXX wholly unnecessary? */
struct xkb_pointer_action ptr;
struct xkb_pointer_button_action btn;
struct xkb_private_action priv;
};
-struct xkb_kt_map_entry {
+struct xkb_key_type_entry {
xkb_level_index_t level;
struct xkb_mods mods;
struct xkb_mods preserve;
};
struct xkb_key_type {
+ xkb_atom_t name;
struct xkb_mods mods;
xkb_level_index_t num_levels;
- struct xkb_kt_map_entry *map;
- unsigned int num_entries;
- xkb_atom_t name;
+ unsigned int num_level_names;
xkb_atom_t *level_names;
+ unsigned int num_entries;
+ struct xkb_key_type_entry *entries;
};
struct xkb_sym_interpret {
xkb_keysym_t sym;
- bool repeat;
enum xkb_match_operation match;
- uint8_t mods;
+ xkb_mod_mask_t mods;
xkb_mod_index_t virtual_mod;
- union xkb_action act;
+ union xkb_action action;
+ bool level_one_only;
+ bool repeat;
};
-struct xkb_indicator_map {
+struct xkb_led {
xkb_atom_t name;
enum xkb_state_component which_groups;
- uint32_t groups;
+ xkb_layout_mask_t groups;
enum xkb_state_component which_mods;
struct xkb_mods mods;
enum xkb_action_controls ctrls;
};
struct xkb_key_alias {
- char real[XKB_KEY_NAME_LENGTH];
- char alias[XKB_KEY_NAME_LENGTH];
+ xkb_atom_t real;
+ xkb_atom_t alias;
};
struct xkb_controls {
/* Such an awkward name. Oh well. */
enum xkb_range_exceed_type {
+ RANGE_WRAP = 0,
RANGE_SATURATE,
- RANGE_WRAP,
RANGE_REDIRECT,
};
EXPLICIT_REPEAT = (1 << 2),
};
+struct xkb_level {
+ union xkb_action action;
+ unsigned int num_syms;
+ union {
+ xkb_keysym_t sym; /* num_syms == 1 */
+ xkb_keysym_t *syms; /* num_syms > 1 */
+ } u;
+};
+
+struct xkb_group {
+ bool explicit_type;
+ /* Points to a type in keymap->types. */
+ const struct xkb_key_type *type;
+ /* Use XkbKeyNumLevels for the number of levels. */
+ struct xkb_level *levels;
+};
+
struct xkb_key {
xkb_keycode_t keycode;
- char name[XKB_KEY_NAME_LENGTH];
+ xkb_atom_t name;
enum xkb_explicit_components explicit;
- xkb_layout_mask_t explicit_groups;
- unsigned char modmap;
+ xkb_mod_mask_t modmap;
xkb_mod_mask_t vmodmap;
bool repeats;
- union xkb_action *actions;
-
- unsigned kt_index[XKB_NUM_GROUPS];
+ enum xkb_range_exceed_type out_of_range_group_action;
+ xkb_layout_index_t out_of_range_group_number;
xkb_layout_index_t num_groups;
- /* How many levels the largest group has. */
- xkb_level_index_t width;
+ struct xkb_group *groups;
+};
- enum xkb_range_exceed_type out_of_range_group_action;
- xkb_layout_index_t out_of_range_group_number;
+struct xkb_mod {
+ xkb_atom_t name;
+ enum mod_type type;
+ xkb_mod_mask_t mapping; /* vmod -> real mod mapping */
+};
- /* per level/group index into 'syms' */
- int *sym_index;
- /* per level/group */
- unsigned int *num_syms;
- xkb_keysym_t *syms;
+struct xkb_mod_set {
+ struct xkb_mod mods[XKB_MAX_MODS];
+ unsigned int num_mods;
};
/* Common keyboard description structure */
int refcnt;
enum xkb_keymap_compile_flags flags;
+ enum xkb_keymap_format format;
- unsigned int enabled_ctrls;
+ enum xkb_action_controls enabled_ctrls;
xkb_keycode_t min_key_code;
xkb_keycode_t max_key_code;
-
- darray(struct xkb_key) keys;
+ struct xkb_key *keys;
/* aliases in no particular order */
- darray(struct xkb_key_alias) key_aliases;
+ unsigned int num_key_aliases;
+ struct xkb_key_alias *key_aliases;
struct xkb_key_type *types;
unsigned int num_types;
- darray(struct xkb_sym_interpret) sym_interpret;
+ unsigned int num_sym_interprets;
+ struct xkb_sym_interpret *sym_interprets;
- /* vmod -> mod mapping */
- xkb_mod_mask_t vmods[XKB_NUM_VIRTUAL_MODS];
- xkb_atom_t vmod_names[XKB_NUM_VIRTUAL_MODS];
+ struct xkb_mod_set mods;
/* Number of groups in the key with the most groups. */
xkb_layout_index_t num_groups;
- xkb_atom_t group_names[XKB_NUM_GROUPS];
+ /* Not all groups must have names. */
+ xkb_layout_index_t num_group_names;
+ xkb_atom_t *group_names;
- struct xkb_indicator_map indicators[XKB_NUM_INDICATORS];
+ struct xkb_led leds[XKB_MAX_LEDS];
+ unsigned int num_leds;
char *keycodes_section_name;
char *symbols_section_name;
char *compat_section_name;
};
+#define xkb_keys_foreach(iter, keymap) \
+ for ((iter) = (keymap)->keys + (keymap)->min_key_code; \
+ (iter) <= (keymap)->keys + (keymap)->max_key_code; \
+ (iter)++)
+
+#define xkb_mods_foreach(iter, mods_) \
+ for ((iter) = (mods_)->mods; \
+ (iter) < (mods_)->mods + (mods_)->num_mods; \
+ (iter)++)
+
+#define xkb_mods_enumerate(idx, iter, mods_) \
+ for ((idx) = 0, (iter) = (mods_)->mods; \
+ (idx) < (mods_)->num_mods; \
+ (idx)++, (iter)++)
+
+#define xkb_leds_foreach(iter, keymap) \
+ for ((iter) = (keymap)->leds; \
+ (iter) < (keymap)->leds + (keymap)->num_leds; \
+ (iter)++)
+
+#define xkb_leds_enumerate(idx, iter, keymap) \
+ for ((idx) = 0, (iter) = (keymap)->leds; \
+ (idx) < (keymap)->num_leds; \
+ (idx)++, (iter)++)
+
static inline const struct xkb_key *
XkbKey(struct xkb_keymap *keymap, xkb_keycode_t kc)
{
if (kc < keymap->min_key_code || kc > keymap->max_key_code)
return NULL;
- return &darray_item(keymap->keys, kc);
-}
-
-#define xkb_foreach_key(iter, keymap) \
- darray_foreach(iter, keymap->keys)
-
-static inline struct xkb_key_type *
-XkbKeyType(struct xkb_keymap *keymap, const struct xkb_key *key,
- xkb_layout_index_t layout)
-{
- return &keymap->types[key->kt_index[layout]];
+ return &keymap->keys[kc];
}
static inline xkb_level_index_t
-XkbKeyGroupWidth(struct xkb_keymap *keymap, const struct xkb_key *key,
- xkb_layout_index_t layout)
-{
- return XkbKeyType(keymap, key, layout)->num_levels;
-}
-
-static inline unsigned int
-XkbKeyNumSyms(const struct xkb_key *key, xkb_layout_index_t layout,
- xkb_level_index_t level)
-{
- return key->num_syms[layout * key->width + level];
-}
-
-static inline const xkb_keysym_t *
-XkbKeySymEntry(const struct xkb_key *key, xkb_layout_index_t layout,
- xkb_level_index_t level)
+XkbKeyNumLevels(const struct xkb_key *key, xkb_layout_index_t layout)
{
- return &key->syms[key->sym_index[layout * key->width + level]];
+ return key->groups[layout].type->num_levels;
}
-static inline const union xkb_action *
-XkbKeyActionEntry(const struct xkb_key *key, xkb_layout_index_t layout,
- xkb_level_index_t level)
+/*
+ * If the virtual modifiers are not bound to anything, the entry
+ * is not active and should be skipped. xserver does this with
+ * cached entry->active field.
+ */
+static inline bool
+entry_is_active(const struct xkb_key_type_entry *entry)
{
- return &key->actions[key->width * layout + level];
+ return entry->mods.mods == 0 || entry->mods.mask != 0;
}
struct xkb_keymap *
-xkb_keymap_new(struct xkb_context *ctx);
+xkb_keymap_new(struct xkb_context *ctx,
+ enum xkb_keymap_format format,
+ enum xkb_keymap_compile_flags flags);
+
+struct xkb_key *
+XkbKeyByName(struct xkb_keymap *keymap, xkb_atom_t name, bool use_aliases);
+
+xkb_atom_t
+XkbResolveKeyAlias(const struct xkb_keymap *keymap, xkb_atom_t name);
+
+void
+XkbEscapeMapName(char *name);
+
+xkb_mod_index_t
+XkbModNameToIndex(const struct xkb_mod_set *mods, xkb_atom_t name,
+ enum mod_type type);
+
+bool
+XkbLevelsSameSyms(const struct xkb_level *a, const struct xkb_level *b);
+
+xkb_layout_index_t
+XkbWrapGroupIntoRange(int32_t group,
+ xkb_layout_index_t num_groups,
+ enum xkb_range_exceed_type out_of_range_group_action,
+ xkb_layout_index_t out_of_range_group_number);
+
+xkb_mod_mask_t
+mod_mask_get_effective(struct xkb_keymap *keymap, xkb_mod_mask_t mods);
+
+struct xkb_keymap_format_ops {
+ bool (*keymap_new_from_names)(struct xkb_keymap *keymap,
+ const struct xkb_rule_names *names);
+ bool (*keymap_new_from_string)(struct xkb_keymap *keymap,
+ const char *string, size_t length);
+ bool (*keymap_new_from_file)(struct xkb_keymap *keymap, FILE *file);
+ char *(*keymap_get_as_string)(struct xkb_keymap *keymap);
+};
+
+extern const struct xkb_keymap_format_ops text_v1_keymap_format_ops;
#endif