state: call xkb_filter_new from the dispatcher Pass the new filter as a parameter instead of getting a new one in each action function, and introducing a failure condition there. 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
diff --git a/src/state.c b/src/state.c
index 9e7ee93..5415b05 100644
--- a/src/state.c
+++ b/src/state.c
@@ -184,13 +184,10 @@ xkb_filter_group_set_func(struct xkb_state *state,
static int
xkb_filter_group_set_new(struct xkb_state *state,
+ struct xkb_filter *filter,
const struct xkb_key *key,
const union xkb_action *action)
{
- struct xkb_filter *filter = xkb_filter_new(state);
- if (!filter)
- return -1;
-
filter->key = key;
filter->func = xkb_filter_group_set_func;
filter->action = *action;
@@ -228,13 +225,10 @@ xkb_filter_group_lock_func(struct xkb_state *state,
static int
xkb_filter_group_lock_new(struct xkb_state *state,
+ struct xkb_filter *filter,
const struct xkb_key *key,
const union xkb_action *action)
{
- struct xkb_filter *filter = xkb_filter_new(state);
- if (!filter)
- return -1;
-
filter->key = key;
filter->func = xkb_filter_group_lock_func;
filter->action = *action;
@@ -276,13 +270,10 @@ xkb_filter_mod_set_func(struct xkb_state *state,
static int
xkb_filter_mod_set_new(struct xkb_state *state,
+ struct xkb_filter *filter,
const struct xkb_key *key,
const union xkb_action *action)
{
- struct xkb_filter *filter = xkb_filter_new(state);
- if (!filter)
- return -1;
-
filter->key = key;
filter->func = xkb_filter_mod_set_func;
filter->action = *action;
@@ -316,13 +307,10 @@ xkb_filter_mod_lock_func(struct xkb_state *state,
static int
xkb_filter_mod_lock_new(struct xkb_state *state,
+ struct xkb_filter *filter,
const struct xkb_key *key,
const union xkb_action *action)
{
- struct xkb_filter *filter = xkb_filter_new(state);
- if (!filter)
- return -1;
-
filter->key = key;
filter->func = xkb_filter_mod_lock_func;
filter->action = *action;
@@ -439,13 +427,11 @@ xkb_filter_mod_latch_func(struct xkb_state *state,
static int
xkb_filter_mod_latch_new(struct xkb_state *state,
+ struct xkb_filter *filter,
const struct xkb_key *key,
const union xkb_action *action)
{
enum xkb_key_latch_state latch = LATCH_KEY_DOWN;
- struct xkb_filter *filter = xkb_filter_new(state);
- if (!filter)
- return -1;
filter->key = key;
filter->priv = latch;
@@ -458,6 +444,7 @@ xkb_filter_mod_latch_new(struct xkb_state *state,
}
typedef int (*filter_action_new_func_t)(struct xkb_state *state,
+ struct xkb_filter *filter,
const struct xkb_key *key,
const union xkb_action *action);
@@ -496,8 +483,15 @@ xkb_filter_apply_all(struct xkb_state *state,
return;
act = xkb_key_get_action(state, key);
- if (filter_action_new_funcs[act->type])
- send = filter_action_new_funcs[act->type](state, key, act);
+ if (filter_action_new_funcs[act->type]) {
+ filter = xkb_filter_new(state);
+ if (!filter)
+ goto err;
+ send = filter_action_new_funcs[act->type](state, filter, key, act);
+ }
+
+err:
+ return;
}
XKB_EXPORT struct xkb_state *