Move xkb_state functions from map.c to state.c Seems more appropriate. Only change is to turn some xkb_state_get_map functions to direct state->keymap. Signed-off-by: Ran Benita <ran234@gmail.com>
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 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
diff --git a/src/map.c b/src/map.c
index 1d8159d..06e7fe6 100644
--- a/src/map.c
+++ b/src/map.c
@@ -289,83 +289,6 @@ xkb_keymap_led_get_index(struct xkb_keymap *keymap, const char *name)
return XKB_LED_INVALID;
}
-static struct xkb_kt_map_entry *
-get_entry_for_key_state(struct xkb_state *state, const struct xkb_key *key,
- xkb_layout_index_t group)
-{
- struct xkb_key_type *type;
- xkb_mod_mask_t active_mods;
- unsigned int i;
-
- type = XkbKeyType(xkb_state_get_keymap(state), key, group);
- active_mods = xkb_state_serialize_mods(state, XKB_STATE_EFFECTIVE);
- active_mods &= type->mods.mask;
-
- for (i = 0; i < type->num_entries; i++)
- if (type->map[i].mods.mask == active_mods)
- return &type->map[i];
-
- return NULL;
-}
-
-/**
- * Returns the level to use for the given key and state, or
- * XKB_LEVEL_INVALID.
- */
-xkb_level_index_t
-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, layout);
- if (!entry)
- return 0;
-
- return entry->level;
-}
-
-/**
- * Returns the layout to use for the given key and state, taking
- * wrapping/clamping/etc into account, or XKB_LAYOUT_INVALID.
- */
-XKB_EXPORT xkb_layout_index_t
-xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t kc)
-{
- 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_LAYOUT_INVALID;
-
- if (ret < key->num_groups)
- return ret;
-
- switch (key->out_of_range_group_action) {
- case RANGE_REDIRECT:
- ret = key->out_of_range_group_number;
- if (ret >= key->num_groups)
- ret = 0;
- break;
-
- case RANGE_SATURATE:
- ret = key->num_groups - 1;
- break;
-
- case RANGE_WRAP:
- default:
- ret %= key->num_groups;
- break;
- }
-
- return ret;
-}
-
/**
* As below, but takes an explicit layout/level rather than state.
*/
@@ -397,37 +320,6 @@ err:
}
/**
- * Provides the symbols to use for the given key and state. Returns the
- * number of symbols pointed to in syms_out.
- */
-XKB_EXPORT int
-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_keymap(state);
- xkb_layout_index_t layout;
- xkb_level_index_t level;
- const struct xkb_key *key = XkbKey(keymap, kc);
- if (!key)
- return -1;
-
- layout = xkb_state_key_get_layout(state, kc);
- if (layout == XKB_LAYOUT_INVALID)
- goto err;
-
- level = xkb_state_key_get_level(state, kc, layout);
- if (level == XKB_LEVEL_INVALID)
- goto err;
-
- return xkb_keymap_key_get_syms_by_level(keymap, kc, layout, level,
- syms_out);
-
-err:
- *syms_out = NULL;
- return 0;
-}
-
-/**
* Simple boolean specifying whether or not the key should repeat.
*/
XKB_EXPORT int
@@ -439,62 +331,3 @@ xkb_keymap_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t kc)
return key->repeats;
}
-
-static xkb_mod_mask_t
-key_get_consumed(struct xkb_state *state, const struct xkb_key *key)
-{
- struct xkb_kt_map_entry *entry;
- xkb_layout_index_t group;
-
- group = xkb_state_key_get_layout(state, key->keycode);
- if (group == XKB_LAYOUT_INVALID)
- return 0;
-
- entry = get_entry_for_key_state(state, key, group);
- if (!entry)
- return 0;
-
- return entry->mods.mask & ~entry->preserve.mask;
-}
-
-/**
- * Tests to see if a modifier is used up by our translation of a
- * keycode to keysyms, taking note of the current modifier state and
- * the appropriate key type's preserve information, if any. This allows
- * the user to mask out the modifier in later processing of the
- * modifiers, e.g. when implementing hot keys or accelerators.
- *
- * See also, for example:
- * - XkbTranslateKeyCode(3), mod_rtrn retrun value, from libX11.
- * - gdk_keymap_translate_keyboard_state, consumed_modifiers return value,
- * from gtk+.
- */
-XKB_EXPORT int
-xkb_state_mod_index_is_consumed(struct xkb_state *state, xkb_keycode_t kc,
- xkb_mod_index_t idx)
-{
- const struct xkb_key *key = XkbKey(xkb_state_get_keymap(state), kc);
- if (!key)
- return 0;
-
- return !!((1 << idx) & key_get_consumed(state, key));
-}
-
-/**
- * Calculates which modifiers should be consumed during key processing,
- * and returns the mask with all these modifiers removed. e.g. if
- * given a state of Alt and Shift active for a two-level alphabetic
- * key containing plus and equal on the first and second level
- * respectively, will return a mask of only Alt, as Shift has been
- * consumed by the type handling.
- */
-XKB_EXPORT xkb_mod_mask_t
-xkb_state_mod_mask_remove_consumed(struct xkb_state *state, xkb_keycode_t kc,
- xkb_mod_mask_t mask)
-{
- const struct xkb_key *key = XkbKey(xkb_state_get_keymap(state), kc);
- if (!key)
- return 0;
-
- return mask & ~key_get_consumed(state, key);
-}
diff --git a/src/state.c b/src/state.c
index 69993b0..1b0a213 100644
--- a/src/state.c
+++ b/src/state.c
@@ -104,6 +104,81 @@ struct xkb_state {
struct xkb_keymap *keymap;
};
+static struct xkb_kt_map_entry *
+get_entry_for_key_state(struct xkb_state *state, const struct xkb_key *key,
+ xkb_layout_index_t group)
+{
+ struct xkb_key_type *type;
+ xkb_mod_mask_t active_mods;
+ unsigned int i;
+
+ type = XkbKeyType(state->keymap, key, group);
+ active_mods = xkb_state_serialize_mods(state, XKB_STATE_EFFECTIVE);
+ active_mods &= type->mods.mask;
+
+ for (i = 0; i < type->num_entries; i++)
+ if (type->map[i].mods.mask == active_mods)
+ return &type->map[i];
+
+ return NULL;
+}
+
+/**
+ * Returns the level to use for the given key and state, or
+ * XKB_LEVEL_INVALID.
+ */
+xkb_level_index_t
+xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
+ xkb_layout_index_t layout)
+{
+ const struct xkb_key *key = XkbKey(state->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, layout);
+ if (!entry)
+ return 0;
+
+ return entry->level;
+}
+
+/**
+ * Returns the layout to use for the given key and state, taking
+ * wrapping/clamping/etc into account, or XKB_LAYOUT_INVALID.
+ */
+XKB_EXPORT xkb_layout_index_t
+xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t kc)
+{
+ const struct xkb_key *key = XkbKey(state->keymap, kc);
+ xkb_layout_index_t ret =
+ xkb_state_serialize_layout(state, XKB_STATE_EFFECTIVE);
+
+ if (key->num_groups == 0)
+ return XKB_LAYOUT_INVALID;
+
+ if (ret < key->num_groups)
+ return ret;
+
+ switch (key->out_of_range_group_action) {
+ case RANGE_REDIRECT:
+ ret = key->out_of_range_group_number;
+ if (ret >= key->num_groups)
+ ret = 0;
+ break;
+
+ case RANGE_SATURATE:
+ ret = key->num_groups - 1;
+ break;
+
+ case RANGE_WRAP:
+ default:
+ ret %= key->num_groups;
+ break;
+ }
+
+ return ret;
+}
+
static const union xkb_action fake = { .type = ACTION_TYPE_NONE };
static const union xkb_action *
@@ -628,6 +703,36 @@ xkb_state_update_mask(struct xkb_state *state,
}
/**
+ * Provides the symbols to use for the given key and state. Returns the
+ * number of symbols pointed to in syms_out.
+ */
+XKB_EXPORT int
+xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t kc,
+ const xkb_keysym_t **syms_out)
+{
+ xkb_layout_index_t layout;
+ xkb_level_index_t level;
+ const struct xkb_key *key = XkbKey(state->keymap, kc);
+ if (!key)
+ return -1;
+
+ layout = xkb_state_key_get_layout(state, kc);
+ if (layout == XKB_LAYOUT_INVALID)
+ goto err;
+
+ level = xkb_state_key_get_level(state, kc, layout);
+ if (level == XKB_LEVEL_INVALID)
+ goto err;
+
+ return xkb_keymap_key_get_syms_by_level(state->keymap, kc, layout, level,
+ syms_out);
+
+err:
+ *syms_out = NULL;
+ return 0;
+}
+
+/**
* Serialises the requested modifier state into an xkb_mod_mask_t, with all
* the same disclaimers as in xkb_state_update_mask.
*/
@@ -870,3 +975,62 @@ xkb_state_led_name_is_active(struct xkb_state *state, const char *name)
return xkb_state_led_index_is_active(state, idx);
}
+
+static xkb_mod_mask_t
+key_get_consumed(struct xkb_state *state, const struct xkb_key *key)
+{
+ struct xkb_kt_map_entry *entry;
+ xkb_layout_index_t group;
+
+ group = xkb_state_key_get_layout(state, key->keycode);
+ if (group == XKB_LAYOUT_INVALID)
+ return 0;
+
+ entry = get_entry_for_key_state(state, key, group);
+ if (!entry)
+ return 0;
+
+ return entry->mods.mask & ~entry->preserve.mask;
+}
+
+/**
+ * Tests to see if a modifier is used up by our translation of a
+ * keycode to keysyms, taking note of the current modifier state and
+ * the appropriate key type's preserve information, if any. This allows
+ * the user to mask out the modifier in later processing of the
+ * modifiers, e.g. when implementing hot keys or accelerators.
+ *
+ * See also, for example:
+ * - XkbTranslateKeyCode(3), mod_rtrn retrun value, from libX11.
+ * - gdk_keymap_translate_keyboard_state, consumed_modifiers return value,
+ * from gtk+.
+ */
+XKB_EXPORT int
+xkb_state_mod_index_is_consumed(struct xkb_state *state, xkb_keycode_t kc,
+ xkb_mod_index_t idx)
+{
+ const struct xkb_key *key = XkbKey(state->keymap, kc);
+ if (!key)
+ return 0;
+
+ return !!((1 << idx) & key_get_consumed(state, key));
+}
+
+/**
+ * Calculates which modifiers should be consumed during key processing,
+ * and returns the mask with all these modifiers removed. e.g. if
+ * given a state of Alt and Shift active for a two-level alphabetic
+ * key containing plus and equal on the first and second level
+ * respectively, will return a mask of only Alt, as Shift has been
+ * consumed by the type handling.
+ */
+XKB_EXPORT xkb_mod_mask_t
+xkb_state_mod_mask_remove_consumed(struct xkb_state *state, xkb_keycode_t kc,
+ xkb_mod_mask_t mask)
+{
+ const struct xkb_key *key = XkbKey(state->keymap, kc);
+ if (!key)
+ return 0;
+
+ return mask & ~key_get_consumed(state, key);
+}