state: dispatch actions from a table 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
diff --git a/src/state.c b/src/state.c
index 6e15c39..9e7ee93 100644
--- a/src/state.c
+++ b/src/state.c
@@ -457,6 +457,19 @@ xkb_filter_mod_latch_new(struct xkb_state *state,
return 1;
}
+typedef int (*filter_action_new_func_t)(struct xkb_state *state,
+ const struct xkb_key *key,
+ const union xkb_action *action);
+
+static const filter_action_new_func_t
+filter_action_new_funcs[_ACTION_TYPE_NUM_ENTRIES] = {
+ [ACTION_TYPE_MOD_SET] = xkb_filter_mod_set_new,
+ [ACTION_TYPE_MOD_LATCH] = xkb_filter_mod_latch_new,
+ [ACTION_TYPE_MOD_LOCK] = xkb_filter_mod_lock_new,
+ [ACTION_TYPE_GROUP_SET] = xkb_filter_group_set_new,
+ [ACTION_TYPE_GROUP_LOCK] = xkb_filter_group_lock_new,
+};
+
/**
* Applies any relevant filters to the key, first from the list of filters
* that are currently active, then if no filter has claimed the key, possibly
@@ -483,32 +496,8 @@ xkb_filter_apply_all(struct xkb_state *state,
return;
act = xkb_key_get_action(state, key);
- switch (act->type) {
- case ACTION_TYPE_MOD_SET:
- send = xkb_filter_mod_set_new(state, key, act);
- break;
- case ACTION_TYPE_MOD_LATCH:
- send = xkb_filter_mod_latch_new(state, key, act);
- break;
- case ACTION_TYPE_MOD_LOCK:
- send = xkb_filter_mod_lock_new(state, key, act);
- break;
- case ACTION_TYPE_GROUP_SET:
- send = xkb_filter_group_set_new(state, key, act);
- break;
-#if 0
- case ACTION_TYPE_GROUP_LATCH:
- send = xkb_filter_mod_latch_new(state, key, act);
- break;
-#endif
- case ACTION_TYPE_GROUP_LOCK:
- send = xkb_filter_group_lock_new(state, key, act);
- break;
- default:
- break;
- }
-
- return;
+ if (filter_action_new_funcs[act->type])
+ send = filter_action_new_funcs[act->type](state, key, act);
}
XKB_EXPORT struct xkb_state *