Promote keymap enumeration API to public Rename the functions to get keysyms by key/layout/level to fit with the recent public API renames, and expose them. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
diff --git a/src/keymap-dump.c b/src/keymap-dump.c
index f3ff1ed..b0ec338 100644
--- a/src/keymap-dump.c
+++ b/src/keymap-dump.c
@@ -568,8 +568,8 @@ write_keysyms(struct xkb_keymap *keymap, struct buf *buf,
for (level = 0; level < XkbKeyGroupWidth(keymap, key, group); level++) {
if (level != 0)
write_buf(buf, ", ");
- num_syms = xkb_key_get_syms_by_level(keymap, key, group, level,
- &syms);
+ num_syms = xkb_keymap_key_get_syms_by_level(keymap, key->keycode,
+ group, level, &syms);
if (num_syms == 0) {
write_buf(buf, "%15s", "NoSymbol");
}
diff --git a/src/map.c b/src/map.c
index 31f4717..1ffcb0d 100644
--- a/src/map.c
+++ b/src/map.c
@@ -226,6 +226,20 @@ xkb_keymap_num_layouts_for_key(struct xkb_keymap *keymap, xkb_keycode_t kc)
}
/**
+ * Returns the number of levels active for a particular key and layout.
+ */
+XKB_EXPORT xkb_level_index_t
+xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t kc,
+ xkb_layout_index_t layout)
+{
+ const struct xkb_key *key = XkbKey(keymap, kc);
+ if (!key)
+ return 0;
+
+ return XkbKeyGroupWidth(keymap, key, layout);
+}
+
+/**
* Return the total number of active LEDs in the keymap.
*/
XKB_EXPORT xkb_led_index_t
@@ -299,13 +313,15 @@ get_entry_for_key_state(struct xkb_state *state, const struct xkb_key *key,
* XKB_LEVEL_INVALID.
*/
xkb_level_index_t
-xkb_key_get_level(struct xkb_state *state, const struct xkb_key *key,
- xkb_group_index_t group)
+xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
+ xkb_layout_index_t layout)
{
+ struct xkb_keymap *keymap = xkb_state_get_keymap(state);
+ const struct xkb_key *key = XkbKey(keymap, kc);
struct xkb_kt_map_entry *entry;
/* If we don't find an explicit match the default is 0. */
- entry = get_entry_for_key_state(state, key, group);
+ entry = get_entry_for_key_state(state, key, layout);
if (!entry)
return 0;
@@ -313,17 +329,19 @@ xkb_key_get_level(struct xkb_state *state, const struct xkb_key *key,
}
/**
- * Returns the group to use for the given key and state, taking
- * wrapping/clamping/etc into account, or XKB_GROUP_INVALID.
+ * Returns the layout to use for the given key and state, taking
+ * wrapping/clamping/etc into account, or XKB_LAYOUT_INVALID.
*/
-xkb_group_index_t
-xkb_key_get_group(struct xkb_state *state, const struct xkb_key *key)
+XKB_EXPORT xkb_layout_index_t
+xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t kc)
{
- xkb_group_index_t ret = xkb_state_serialize_group(state,
- XKB_STATE_EFFECTIVE);
+ struct xkb_keymap *keymap = xkb_state_get_keymap(state);
+ const struct xkb_key *key = XkbKey(keymap, kc);
+ xkb_layout_index_t ret =
+ xkb_state_serialize_layout(state, XKB_STATE_EFFECTIVE);
if (key->num_groups == 0)
- return XKB_GROUP_INVALID;
+ return XKB_LAYOUT_INVALID;
if (ret < key->num_groups)
return ret;
@@ -349,26 +367,28 @@ xkb_key_get_group(struct xkb_state *state, const struct xkb_key *key)
}
/**
- * As below, but takes an explicit group/level rather than state.
+ * As below, but takes an explicit layout/level rather than state.
*/
-int
-xkb_key_get_syms_by_level(struct xkb_keymap *keymap,
- const struct xkb_key *key,
- xkb_group_index_t group, xkb_level_index_t level,
- const xkb_keysym_t **syms_out)
+XKB_EXPORT int
+xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,
+ xkb_keycode_t kc,
+ xkb_layout_index_t layout,
+ xkb_level_index_t level,
+ const xkb_keysym_t **syms_out)
{
+ const struct xkb_key *key = XkbKey(keymap, kc);
int num_syms;
- if (group >= key->num_groups)
+ if (layout >= key->num_groups)
goto err;
- if (level >= XkbKeyGroupWidth(keymap, key, group))
+ if (level >= XkbKeyGroupWidth(keymap, key, layout))
goto err;
- num_syms = XkbKeyNumSyms(key, group, level);
+ num_syms = XkbKeyNumSyms(key, layout, level);
if (num_syms == 0)
goto err;
- *syms_out = XkbKeySymEntry(key, group, level);
+ *syms_out = XkbKeySymEntry(key, layout, level);
return num_syms;
err:
@@ -385,21 +405,22 @@ xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t kc,
const xkb_keysym_t **syms_out)
{
struct xkb_keymap *keymap = xkb_state_get_map(state);
- xkb_group_index_t group;
+ xkb_layout_index_t layout;
xkb_level_index_t level;
const struct xkb_key *key = XkbKey(keymap, kc);
if (!key)
return -1;
- group = xkb_key_get_group(state, key);
- if (group == XKB_GROUP_INVALID)
+ layout = xkb_state_key_get_layout(state, kc);
+ if (layout == XKB_LAYOUT_INVALID)
goto err;
- level = xkb_key_get_level(state, key, group);
+ level = xkb_state_key_get_level(state, kc, layout);
if (level == XKB_LEVEL_INVALID)
goto err;
- return xkb_key_get_syms_by_level(keymap, key, group, level, syms_out);
+ return xkb_keymap_key_get_syms_by_level(keymap, kc, layout, level,
+ syms_out);
err:
*syms_out = NULL;
@@ -425,7 +446,7 @@ key_get_consumed(struct xkb_state *state, const struct xkb_key *key)
struct xkb_kt_map_entry *entry;
xkb_group_index_t group;
- group = xkb_key_get_group(state, key);
+ group = xkb_state_key_get_layout(state, key->keycode);
if (group == XKB_GROUP_INVALID)
return 0;
diff --git a/src/map.h b/src/map.h
index 6f65f9c..7c2be1b 100644
--- a/src/map.h
+++ b/src/map.h
@@ -85,10 +85,6 @@
#include "utils.h"
#include "context.h"
-typedef uint32_t xkb_level_index_t;
-
-#define XKB_LEVEL_INVALID 0xffffffff
-
#define XKB_KEY_NAME_LENGTH 4
/* These should all be dynamic. */
@@ -308,6 +304,7 @@ enum xkb_explicit_components {
};
struct xkb_key {
+ xkb_keycode_t keycode;
char name[XKB_KEY_NAME_LENGTH];
enum xkb_explicit_components explicit;
@@ -430,17 +427,4 @@ XkbKeyActionEntry(const struct xkb_key *key, xkb_layout_index_t layout,
struct xkb_keymap *
xkb_map_new(struct xkb_context *ctx);
-xkb_layout_index_t
-xkb_key_get_group(struct xkb_state *state, const struct xkb_key *key);
-
-xkb_level_index_t
-xkb_key_get_level(struct xkb_state *state, const struct xkb_key *key,
- xkb_layout_index_t layout);
-
-int
-xkb_key_get_syms_by_level(struct xkb_keymap *keymap,
- const struct xkb_key *key,
- xkb_layout_index_t layout, xkb_level_index_t level,
- const xkb_keysym_t **syms_out);
-
#endif
diff --git a/src/state.c b/src/state.c
index a89d365..8529f4e 100644
--- a/src/state.c
+++ b/src/state.c
@@ -109,21 +109,21 @@ static const union xkb_action fake = { .type = ACTION_TYPE_NONE };
static const union xkb_action *
xkb_key_get_action(struct xkb_state *state, const struct xkb_key *key)
{
- xkb_group_index_t group;
+ xkb_layout_index_t layout;
xkb_level_index_t level;
if (!key->actions)
return &fake;
- group = xkb_key_get_group(state, key);
- if (group == XKB_GROUP_INVALID)
+ layout = xkb_state_key_get_layout(state, key->keycode);
+ if (layout == XKB_LAYOUT_INVALID)
return &fake;
- level = xkb_key_get_level(state, key, group);
+ level = xkb_state_key_get_level(state, key->keycode, layout);
if (level == XKB_LEVEL_INVALID)
return &fake;
- return XkbKeyActionEntry(key, group, level);
+ return XkbKeyActionEntry(key, layout, level);
}
static struct xkb_filter *
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index c80787b..cfd8bd9 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -696,9 +696,12 @@ CopyKeyNamesToKeymap(struct xkb_keymap *keymap, KeyNamesInfo *info)
keymap->max_key_code = info->max_key_code;
darray_resize0(keymap->keys, keymap->max_key_code + 1);
- for (kc = info->min_key_code; kc <= info->max_key_code; kc++)
+ for (kc = info->min_key_code; kc <= info->max_key_code; kc++) {
+ struct xkb_key *key = &darray_item(keymap->keys, kc);
+ key->keycode = kc;
LongToKeyName(darray_item(info->key_names, kc).name,
- darray_item(keymap->keys, kc).name);
+ key->name);
+ }
keymap->keycodes_section_name = strdup_safe(info->name);
diff --git a/src/xkbcomp/keymap.c b/src/xkbcomp/keymap.c
index 6e9c911..a10d834 100644
--- a/src/xkbcomp/keymap.c
+++ b/src/xkbcomp/keymap.c
@@ -75,7 +75,8 @@ FindInterpForKey(struct xkb_keymap *keymap, struct xkb_key *key,
const xkb_keysym_t *syms;
int num_syms;
- num_syms = xkb_key_get_syms_by_level(keymap, key, group, level, &syms);
+ num_syms = xkb_keymap_key_get_syms_by_level(keymap, key->keycode, group,
+ level, &syms);
if (num_syms == 0)
return NULL;
diff --git a/xkbcommon/xkbcommon.h b/xkbcommon/xkbcommon.h
index f464c21..995771f 100644
--- a/xkbcommon/xkbcommon.h
+++ b/xkbcommon/xkbcommon.h
@@ -93,12 +93,14 @@ typedef uint32_t xkb_mod_index_t;
typedef uint32_t xkb_mod_mask_t;
typedef uint32_t xkb_layout_index_t;
typedef uint32_t xkb_layout_mask_t;
+typedef uint32_t xkb_level_index_t;
typedef uint32_t xkb_led_index_t;
typedef uint32_t xkb_led_mask_t;
#define XKB_MOD_INVALID (0xffffffff)
#define XKB_LAYOUT_INVALID (0xffffffff)
#define XKB_KEYCODE_INVALID (0xffffffff)
+#define XKB_LEVEL_INVALID (0xffffffff)
#define XKB_LED_INVALID (0xffffffff)
#define XKB_KEYCODE_MAX (0xffffffff - 1)
@@ -454,6 +456,13 @@ xkb_layout_index_t
xkb_keymap_num_layouts_for_key(struct xkb_keymap *keymap, xkb_keycode_t key);
/**
+ * Returns the number of levels active for the specified key and layout.
+ */
+xkb_level_index_t
+xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t key,
+ xkb_layout_index_t layout);
+
+/**
* Returns 1 if the key should repeat, or 0 otherwise.
*/
int
@@ -539,6 +548,36 @@ xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t key,
const xkb_keysym_t **syms_out);
/**
+ * Returns the layout number that would be active for a particular key with
+ * the given state.
+ */
+xkb_layout_index_t
+xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t key);
+
+/**
+ * Returns the level number that would be active for a particular key with
+ * the given state and layout number, usually obtained from
+ * xkb_state_key_get_layout.
+ */
+xkb_level_index_t
+xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t key,
+ xkb_layout_index_t layout);
+
+/**
+ * Gives the symbols obtained from pressing a particular key with the given
+ * layout and level. *syms_out will be set to point to an array of keysyms,
+ * with the return value being the number of symbols in *syms_out. If the
+ * return value is 0, *syms_out will be set to NULL, as there are no symbols
+ * produced by this event.
+ */
+int
+xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,
+ xkb_keycode_t key,
+ xkb_layout_index_t layout,
+ xkb_level_index_t level,
+ const xkb_keysym_t **syms_out);
+
+/**
* Modifier and group types for state objects. This enum is bitmaskable,
* e.g. (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED) is valid to exclude
* locked modifiers.