keymap-dump: use ActionTypeText
[platform/upstream/libxkbcommon.git] / src / state.c
index f321b1f..f527c90 100644 (file)
@@ -66,9 +66,9 @@
 struct xkb_filter {
     struct xkb_state *state;
     union xkb_action action;
-    xkb_keycode_t keycode;
+    xkb_keycode_t kc;
     uint32_t priv;
-    int (*func)(struct xkb_filter *filter, xkb_keycode_t key,
+    int (*func)(struct xkb_filter *filter, xkb_keycode_t kc,
                 enum xkb_key_direction direction);
     int refcnt;
     struct xkb_filter *next;
@@ -107,20 +107,24 @@ struct xkb_state {
 };
 
 static union xkb_action *
-xkb_key_get_action(struct xkb_state *state, xkb_keycode_t key)
+xkb_key_get_action(struct xkb_state *state, xkb_keycode_t kc)
 {
-    unsigned int group, level;
+    xkb_group_index_t group;
+    unsigned int level;
+    struct xkb_key *key = NULL;
 
-    if (!XkbKeyHasActions(state->keymap, key) ||
-        !XkbKeycodeInRange(state->keymap, key)) {
+    if (XkbKeycodeInRange(state->keymap, kc))
+        key = XkbKey(state->keymap, kc);
+
+    if (!key || !XkbKeyHasActions(key)) {
         static union xkb_action fake;
         memset(&fake, 0, sizeof(fake));
         fake.type = XkbSA_NoAction;
         return &fake;
     }
 
-    group = xkb_key_get_group(state, key);
-    level = xkb_key_get_level(state, key, group);
+    group = xkb_key_get_group(state, kc);
+    level = xkb_key_get_level(state, kc, group);
 
     return XkbKeyActionEntry(state->keymap, key, group, level);
 }
@@ -151,10 +155,10 @@ xkb_filter_new(struct xkb_state *state)
 /***====================================================================***/
 
 static int
-xkb_filter_group_set_func(struct xkb_filter *filter, xkb_keycode_t keycode,
+xkb_filter_group_set_func(struct xkb_filter *filter, xkb_keycode_t kc,
                           enum xkb_key_direction direction)
 {
-    if (keycode != filter->keycode) {
+    if (kc != filter->kc) {
         filter->action.group.flags &= ~XkbSA_ClearLocks;
         return 1;
     }
@@ -180,14 +184,14 @@ xkb_filter_group_set_func(struct xkb_filter *filter, xkb_keycode_t keycode,
 }
 
 static int
-xkb_filter_group_set_new(struct xkb_state *state, xkb_keycode_t keycode,
+xkb_filter_group_set_new(struct xkb_state *state, xkb_keycode_t kc,
                          union xkb_action *action)
 {
     struct xkb_filter *filter = xkb_filter_new(state);
 
     if (!filter) /* WSGO */
         return -1;
-    filter->keycode = keycode;
+    filter->kc = kc;
     filter->func = xkb_filter_group_set_func;
     filter->action = *action;
 
@@ -203,10 +207,10 @@ xkb_filter_group_set_new(struct xkb_state *state, xkb_keycode_t keycode,
 }
 
 static int
-xkb_filter_group_lock_func(struct xkb_filter *filter, xkb_keycode_t keycode,
+xkb_filter_group_lock_func(struct xkb_filter *filter, xkb_keycode_t kc,
                            enum xkb_key_direction direction)
 {
-    if (keycode != filter->keycode)
+    if (kc != filter->kc)
         return 1;
 
     if (direction == XKB_KEY_DOWN) {
@@ -221,7 +225,7 @@ xkb_filter_group_lock_func(struct xkb_filter *filter, xkb_keycode_t keycode,
 }
 
 static int
-xkb_filter_group_lock_new(struct xkb_state *state, xkb_keycode_t keycode,
+xkb_filter_group_lock_new(struct xkb_state *state, xkb_keycode_t kc,
                           union xkb_action *action)
 {
     struct xkb_filter *filter = xkb_filter_new(state);
@@ -229,7 +233,7 @@ xkb_filter_group_lock_new(struct xkb_state *state, xkb_keycode_t keycode,
     if (!filter)
         return 0;
 
-    filter->keycode = keycode;
+    filter->kc = kc;
     filter->func = xkb_filter_group_lock_func;
     filter->action = *action;
 
@@ -242,10 +246,10 @@ xkb_filter_group_lock_new(struct xkb_state *state, xkb_keycode_t keycode,
 }
 
 static int
-xkb_filter_mod_set_func(struct xkb_filter *filter, xkb_keycode_t keycode,
+xkb_filter_mod_set_func(struct xkb_filter *filter, xkb_keycode_t kc,
                         enum xkb_key_direction direction)
 {
-    if (keycode != filter->keycode) {
+    if (kc != filter->kc) {
         filter->action.mods.flags &= ~XkbSA_ClearLocks;
         return 1;
     }
@@ -268,14 +272,14 @@ xkb_filter_mod_set_func(struct xkb_filter *filter, xkb_keycode_t keycode,
 }
 
 static int
-xkb_filter_mod_set_new(struct xkb_state *state, xkb_keycode_t keycode,
+xkb_filter_mod_set_new(struct xkb_state *state, xkb_keycode_t kc,
                        union xkb_action *action)
 {
     struct xkb_filter *filter = xkb_filter_new(state);
 
     if (!filter) /* WSGO */
         return -1;
-    filter->keycode = keycode;
+    filter->kc = kc;
     filter->func = xkb_filter_mod_set_func;
     filter->action = *action;
 
@@ -285,10 +289,10 @@ xkb_filter_mod_set_new(struct xkb_state *state, xkb_keycode_t keycode,
 }
 
 static int
-xkb_filter_mod_lock_func(struct xkb_filter *filter, xkb_keycode_t keycode,
+xkb_filter_mod_lock_func(struct xkb_filter *filter, xkb_keycode_t kc,
                          enum xkb_key_direction direction)
 {
-    if (keycode != filter->keycode)
+    if (kc != filter->kc)
         return 1;
 
     if (direction == XKB_KEY_DOWN) {
@@ -304,7 +308,7 @@ xkb_filter_mod_lock_func(struct xkb_filter *filter, xkb_keycode_t keycode,
 }
 
 static int
-xkb_filter_mod_lock_new(struct xkb_state *state, xkb_keycode_t keycode,
+xkb_filter_mod_lock_new(struct xkb_state *state, xkb_keycode_t kc,
                         union xkb_action *action)
 {
     struct xkb_filter *filter = xkb_filter_new(state);
@@ -312,7 +316,7 @@ xkb_filter_mod_lock_new(struct xkb_state *state, xkb_keycode_t keycode,
     if (!filter) /* WSGO */
         return 0;
 
-    filter->keycode = keycode;
+    filter->kc = kc;
     filter->func = xkb_filter_mod_lock_func;
     filter->action = *action;
     filter->priv = state->locked_mods & action->mods.mask;
@@ -328,7 +332,7 @@ enum xkb_key_latch_state {
 };
 
 static int
-xkb_filter_mod_latch_func(struct xkb_filter *filter, xkb_keycode_t keycode,
+xkb_filter_mod_latch_func(struct xkb_filter *filter, xkb_keycode_t kc,
                           enum xkb_key_direction direction)
 {
     enum xkb_key_latch_state latch = filter->priv;
@@ -338,7 +342,7 @@ xkb_filter_mod_latch_func(struct xkb_filter *filter, xkb_keycode_t keycode,
          * keypress, then either break the latch if any random key is pressed,
          * or promote it to a lock or plain base set if it's the same
          * modifier. */
-        union xkb_action *action = xkb_key_get_action(filter->state, keycode);
+        union xkb_action *action = xkb_key_get_action(filter->state, kc);
         if (action->type == XkbSA_LatchMods &&
             action->mods.flags == filter->action.mods.flags &&
             action->mods.mask == filter->action.mods.mask) {
@@ -353,7 +357,7 @@ xkb_filter_mod_latch_func(struct xkb_filter *filter, xkb_keycode_t keycode,
                 filter->func = xkb_filter_mod_set_func;
                 filter->state->set_mods = filter->action.mods.mask;
             }
-            filter->keycode = keycode;
+            filter->kc = kc;
             filter->state->latched_mods &= ~filter->action.mods.mask;
             /* XXX beep beep! */
             return 0;
@@ -366,7 +370,7 @@ xkb_filter_mod_latch_func(struct xkb_filter *filter, xkb_keycode_t keycode,
             return 1;
         }
     }
-    else if (direction == XKB_KEY_UP && keycode == filter->keycode) {
+    else if (direction == XKB_KEY_UP && kc == filter->kc) {
         /* Our key got released.  If we've set it to clear locks, and we
          * currently have the same modifiers locked, then release them and
          * don't actually latch.  Else we've actually hit the latching
@@ -406,7 +410,7 @@ xkb_filter_mod_latch_func(struct xkb_filter *filter, xkb_keycode_t keycode,
 }
 
 static int
-xkb_filter_mod_latch_new(struct xkb_state *state, xkb_keycode_t keycode,
+xkb_filter_mod_latch_new(struct xkb_state *state, xkb_keycode_t kc,
                          union xkb_action *action)
 {
     struct xkb_filter *filter = xkb_filter_new(state);
@@ -414,7 +418,7 @@ xkb_filter_mod_latch_new(struct xkb_state *state, xkb_keycode_t keycode,
 
     if (!filter) /* WSGO */
         return -1;
-    filter->keycode = keycode;
+    filter->kc = kc;
     filter->priv = latch;
     filter->func = xkb_filter_mod_latch_func;
     filter->action = *action;
@@ -430,7 +434,7 @@ xkb_filter_mod_latch_new(struct xkb_state *state, xkb_keycode_t keycode,
  * apply a new filter from the key action.
  */
 static void
-xkb_filter_apply_all(struct xkb_state *state, xkb_keycode_t key,
+xkb_filter_apply_all(struct xkb_state *state, xkb_keycode_t kc,
                      enum xkb_key_direction direction)
 {
     struct xkb_filter *filter;
@@ -442,25 +446,25 @@ xkb_filter_apply_all(struct xkb_state *state, xkb_keycode_t key,
     darray_foreach(filter, state->filters) {
         if (!filter->func)
             continue;
-        send &= filter->func(filter, key, direction);
+        send &= filter->func(filter, kc, direction);
     }
 
     if (!send || direction == XKB_KEY_UP)
         return;
 
-    act = xkb_key_get_action(state, key);
+    act = xkb_key_get_action(state, kc);
     switch (act->type) {
     case XkbSA_SetMods:
-        send = xkb_filter_mod_set_new(state, key, act);
+        send = xkb_filter_mod_set_new(state, kc, act);
         break;
     case XkbSA_LatchMods:
-        send = xkb_filter_mod_latch_new(state, key, act);
+        send = xkb_filter_mod_latch_new(state, kc, act);
         break;
     case XkbSA_LockMods:
-        send = xkb_filter_mod_lock_new(state, key, act);
+        send = xkb_filter_mod_lock_new(state, kc, act);
         break;
     case XkbSA_SetGroup:
-        send = xkb_filter_group_set_new(state, key, act);
+        send = xkb_filter_group_set_new(state, kc, act);
         break;
 #if 0
     case XkbSA_LatchGroup:
@@ -468,14 +472,14 @@ xkb_filter_apply_all(struct xkb_state *state, xkb_keycode_t key,
         break;
 #endif
     case XkbSA_LockGroup:
-        send = xkb_filter_group_lock_new(state, key, act);
+        send = xkb_filter_group_lock_new(state, kc, act);
         break;
     }
 
     return;
 }
 
-_X_EXPORT struct xkb_state *
+XKB_EXPORT struct xkb_state *
 xkb_state_new(struct xkb_keymap *keymap)
 {
     struct xkb_state *ret;
@@ -493,14 +497,14 @@ xkb_state_new(struct xkb_keymap *keymap)
     return ret;
 }
 
-_X_EXPORT struct xkb_state *
+XKB_EXPORT struct xkb_state *
 xkb_state_ref(struct xkb_state *state)
 {
     state->refcnt++;
     return state;
 }
 
-_X_EXPORT void
+XKB_EXPORT void
 xkb_state_unref(struct xkb_state *state)
 {
     state->refcnt--;
@@ -513,7 +517,7 @@ xkb_state_unref(struct xkb_state *state)
     free(state);
 }
 
-_X_EXPORT struct xkb_keymap *
+XKB_EXPORT struct xkb_keymap *
 xkb_state_get_map(struct xkb_state *state)
 {
     return state->keymap;
@@ -589,8 +593,8 @@ xkb_state_update_derived(struct xkb_state *state)
  * Given a particular key event, updates the state structure to reflect the
  * new modifiers.
  */
-_X_EXPORT void
-xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
+XKB_EXPORT void
+xkb_state_update_key(struct xkb_state *state, xkb_keycode_t kc,
                      enum xkb_key_direction direction)
 {
     xkb_mod_index_t i;
@@ -599,7 +603,7 @@ xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
     state->set_mods = 0;
     state->clear_mods = 0;
 
-    xkb_filter_apply_all(state, key, direction);
+    xkb_filter_apply_all(state, kc, direction);
 
     for (i = 0, bit = 1; state->set_mods; i++, bit <<= 1) {
         if (state->set_mods & bit) {
@@ -630,7 +634,7 @@ xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
  * lossy, and should only be used to update a slave state mirroring the
  * master, e.g. in a client/server window system.
  */
-_X_EXPORT void
+XKB_EXPORT void
 xkb_state_update_mask(struct xkb_state *state,
                       xkb_mod_mask_t base_mods,
                       xkb_mod_mask_t latched_mods,
@@ -665,7 +669,7 @@ xkb_state_update_mask(struct xkb_state *state,
  * Serialises the requested modifier state into an xkb_mod_mask_t, with all
  * the same disclaimers as in xkb_state_update_mask.
  */
-_X_EXPORT xkb_mod_mask_t
+XKB_EXPORT xkb_mod_mask_t
 xkb_state_serialize_mods(struct xkb_state *state,
                          enum xkb_state_component type)
 {
@@ -688,7 +692,7 @@ xkb_state_serialize_mods(struct xkb_state *state,
  * Serialises the requested group state, with all the same disclaimers as
  * in xkb_state_update_mask.
  */
-_X_EXPORT xkb_group_index_t
+XKB_EXPORT xkb_group_index_t
 xkb_state_serialize_group(struct xkb_state *state,
                           enum xkb_state_component type)
 {
@@ -711,7 +715,7 @@ xkb_state_serialize_group(struct xkb_state *state,
  * Returns 1 if the given modifier is active with the specified type(s), 0 if
  * not, or -1 if the modifier is invalid.
  */
-_X_EXPORT int
+XKB_EXPORT int
 xkb_state_mod_index_is_active(struct xkb_state *state,
                               xkb_mod_index_t idx,
                               enum xkb_state_component type)
@@ -756,7 +760,7 @@ match_mod_masks(struct xkb_state *state, enum xkb_state_match match,
  * Returns 1 if the modifiers are active with the specified type(s), 0 if
  * not, or -1 if any of the modifiers are invalid.
  */
-_X_EXPORT int
+XKB_EXPORT int
 xkb_state_mod_indices_are_active(struct xkb_state *state,
                                  enum xkb_state_component type,
                                  enum xkb_state_match match,
@@ -789,7 +793,7 @@ xkb_state_mod_indices_are_active(struct xkb_state *state,
  * Returns 1 if the given modifier is active with the specified type(s), 0 if
  * not, or -1 if the modifier is invalid.
  */
-_X_EXPORT int
+XKB_EXPORT int
 xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,
                              enum xkb_state_component type)
 {
@@ -805,7 +809,7 @@ xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,
  * Returns 1 if the modifiers are active with the specified type(s), 0 if
  * not, or -1 if any of the modifiers are invalid.
  */
-_X_EXPORT int
+XKB_EXPORT int
 xkb_state_mod_names_are_active(struct xkb_state *state,
                                enum xkb_state_component type,
                                enum xkb_state_match match,
@@ -841,7 +845,7 @@ xkb_state_mod_names_are_active(struct xkb_state *state,
  * Returns 1 if the given group is active with the specified type(s), 0 if
  * not, or -1 if the group is invalid.
  */
-_X_EXPORT int
+XKB_EXPORT int
 xkb_state_group_index_is_active(struct xkb_state *state,
                                 xkb_group_index_t idx,
                                 enum xkb_state_component type)
@@ -865,7 +869,7 @@ xkb_state_group_index_is_active(struct xkb_state *state,
  * Returns 1 if the given modifier is active with the specified type(s), 0 if
  * not, or -1 if the modifier is invalid.
  */
-_X_EXPORT int
+XKB_EXPORT int
 xkb_state_group_name_is_active(struct xkb_state *state, const char *name,
                                enum xkb_state_component type)
 {
@@ -880,7 +884,7 @@ xkb_state_group_name_is_active(struct xkb_state *state, const char *name,
 /**
  * Returns 1 if the given LED is active, 0 if not, or -1 if the LED is invalid.
  */
-_X_EXPORT int
+XKB_EXPORT int
 xkb_state_led_index_is_active(struct xkb_state *state, xkb_led_index_t idx)
 {
     if (idx >= xkb_map_num_leds(state->keymap))
@@ -892,7 +896,7 @@ xkb_state_led_index_is_active(struct xkb_state *state, xkb_led_index_t idx)
 /**
  * Returns 1 if the given LED is active, 0 if not, or -1 if the LED is invalid.
  */
-_X_EXPORT int
+XKB_EXPORT int
 xkb_state_led_name_is_active(struct xkb_state *state, const char *name)
 {
     xkb_led_index_t idx = xkb_map_led_get_index(state->keymap, name);