state: don't keep the xkb_state in the filters Just pass it as a parameter: to make state.c a bit less stateful. 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
diff --git a/src/state.c b/src/state.c
index 5d977ca..6e15c39 100644
--- a/src/state.c
+++ b/src/state.c
@@ -65,11 +65,11 @@
#include "xkb-priv.h"
struct xkb_filter {
- struct xkb_state *state;
union xkb_action action;
const struct xkb_key *key;
uint32_t priv;
- int (*func)(struct xkb_filter *filter,
+ int (*func)(struct xkb_state *state,
+ struct xkb_filter *filter,
const struct xkb_key *key,
enum xkb_key_direction direction);
int refcnt;
@@ -146,7 +146,6 @@ xkb_filter_new(struct xkb_state *state)
filter = &darray_item(state->filters, darray_size(state->filters) -1);
}
- filter->state = state;
filter->refcnt = 1;
return filter;
}
@@ -154,7 +153,8 @@ xkb_filter_new(struct xkb_state *state)
/***====================================================================***/
static int
-xkb_filter_group_set_func(struct xkb_filter *filter,
+xkb_filter_group_set_func(struct xkb_state *state,
+ struct xkb_filter *filter,
const struct xkb_key *key,
enum xkb_key_direction direction)
{
@@ -172,14 +172,13 @@ xkb_filter_group_set_func(struct xkb_filter *filter,
}
if (filter->action.group.flags & ACTION_ABSOLUTE_SWITCH)
- filter->state->base_group = filter->action.group.group;
+ state->base_group = filter->action.group.group;
else
- filter->state->base_group = -filter->action.group.group;
+ state->base_group = -filter->action.group.group;
if (filter->action.group.flags & ACTION_LOCK_CLEAR)
- filter->state->locked_group = 0;
+ state->locked_group = 0;
filter->func = NULL;
-
return 1;
}
@@ -197,18 +196,19 @@ xkb_filter_group_set_new(struct xkb_state *state,
filter->action = *action;
if (action->group.flags & ACTION_ABSOLUTE_SWITCH) {
- filter->action.group.group = filter->state->base_group;
- filter->state->base_group = action->group.group;
+ filter->action.group.group = state->base_group;
+ state->base_group = action->group.group;
}
else {
- filter->state->base_group += action->group.group;
+ state->base_group += action->group.group;
}
return 1;
}
static int
-xkb_filter_group_lock_func(struct xkb_filter *filter,
+xkb_filter_group_lock_func(struct xkb_state *state,
+ struct xkb_filter *filter,
const struct xkb_key *key,
enum xkb_key_direction direction)
{
@@ -240,15 +240,16 @@ xkb_filter_group_lock_new(struct xkb_state *state,
filter->action = *action;
if (action->group.flags & ACTION_ABSOLUTE_SWITCH)
- filter->state->locked_group = action->group.group;
+ state->locked_group = action->group.group;
else
- filter->state->locked_group += action->group.group;
+ state->locked_group += action->group.group;
return 1;
}
static int
-xkb_filter_mod_set_func(struct xkb_filter *filter,
+xkb_filter_mod_set_func(struct xkb_state *state,
+ struct xkb_filter *filter,
const struct xkb_key *key,
enum xkb_key_direction direction)
{
@@ -265,9 +266,9 @@ xkb_filter_mod_set_func(struct xkb_filter *filter,
return 0;
}
- filter->state->clear_mods = filter->action.mods.mods.mask;
+ state->clear_mods = filter->action.mods.mods.mask;
if (filter->action.mods.flags & ACTION_LOCK_CLEAR)
- filter->state->locked_mods &= ~filter->action.mods.mods.mask;
+ state->locked_mods &= ~filter->action.mods.mods.mask;
filter->func = NULL;
return 1;
@@ -286,13 +287,14 @@ xkb_filter_mod_set_new(struct xkb_state *state,
filter->func = xkb_filter_mod_set_func;
filter->action = *action;
- filter->state->set_mods = action->mods.mods.mask;
+ state->set_mods = action->mods.mods.mask;
return 1;
}
static int
-xkb_filter_mod_lock_func(struct xkb_filter *filter,
+xkb_filter_mod_lock_func(struct xkb_state *state,
+ struct xkb_filter *filter,
const struct xkb_key *key,
enum xkb_key_direction direction)
{
@@ -306,7 +308,7 @@ xkb_filter_mod_lock_func(struct xkb_filter *filter,
if (--filter->refcnt > 0)
return 0;
- filter->state->locked_mods &= ~filter->priv;
+ state->locked_mods &= ~filter->priv;
filter->func = NULL;
return 1;
@@ -326,7 +328,7 @@ xkb_filter_mod_lock_new(struct xkb_state *state,
filter->action = *action;
filter->priv = state->locked_mods & action->mods.mods.mask;
- filter->state->locked_mods |= action->mods.mods.mask;
+ state->locked_mods |= action->mods.mods.mask;
return 1;
}
@@ -356,7 +358,8 @@ xkb_action_breaks_latch(const union xkb_action *action)
}
static int
-xkb_filter_mod_latch_func(struct xkb_filter *filter,
+xkb_filter_mod_latch_func(struct xkb_state *state,
+ struct xkb_filter *filter,
const struct xkb_key *key,
enum xkb_key_direction direction)
{
@@ -367,7 +370,7 @@ xkb_filter_mod_latch_func(struct xkb_filter *filter,
* 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. */
- const union xkb_action *action = xkb_key_get_action(filter->state, key);
+ const union xkb_action *action = xkb_key_get_action(state, key);
if (action->type == ACTION_TYPE_MOD_LATCH &&
action->mods.flags == filter->action.mods.flags &&
action->mods.mods.mask == filter->action.mods.mods.mask) {
@@ -375,22 +378,22 @@ xkb_filter_mod_latch_func(struct xkb_filter *filter,
if (filter->action.mods.flags & ACTION_LATCH_TO_LOCK) {
filter->action.type = ACTION_TYPE_MOD_LOCK;
filter->func = xkb_filter_mod_lock_func;
- filter->state->locked_mods |= filter->action.mods.mods.mask;
+ state->locked_mods |= filter->action.mods.mods.mask;
}
else {
filter->action.type = ACTION_TYPE_MOD_SET;
filter->func = xkb_filter_mod_set_func;
- filter->state->set_mods = filter->action.mods.mods.mask;
+ state->set_mods = filter->action.mods.mods.mask;
}
filter->key = key;
- filter->state->latched_mods &= ~filter->action.mods.mods.mask;
+ state->latched_mods &= ~filter->action.mods.mods.mask;
/* XXX beep beep! */
return 0;
}
else if (xkb_action_breaks_latch(action)) {
/* XXX: This may be totally broken, we might need to break the
* latch in the next run after this press? */
- filter->state->latched_mods &= ~filter->action.mods.mods.mask;
+ state->latched_mods &= ~filter->action.mods.mods.mask;
filter->func = NULL;
return 1;
}
@@ -403,21 +406,21 @@ xkb_filter_mod_latch_func(struct xkb_filter *filter,
* latched. */
if (latch == NO_LATCH ||
((filter->action.mods.flags & ACTION_LOCK_CLEAR) &&
- (filter->state->locked_mods & filter->action.mods.mods.mask) ==
+ (state->locked_mods & filter->action.mods.mods.mask) ==
filter->action.mods.mods.mask)) {
/* XXX: We might be a bit overenthusiastic about clearing
* mods other filters have set here? */
if (latch == LATCH_PENDING)
- filter->state->latched_mods &= ~filter->action.mods.mods.mask;
+ state->latched_mods &= ~filter->action.mods.mods.mask;
else
- filter->state->clear_mods = filter->action.mods.mods.mask;
- filter->state->locked_mods &= ~filter->action.mods.mods.mask;
+ state->clear_mods = filter->action.mods.mods.mask;
+ state->locked_mods &= ~filter->action.mods.mods.mask;
filter->func = NULL;
}
else {
latch = LATCH_PENDING;
- filter->state->clear_mods = filter->action.mods.mods.mask;
- filter->state->latched_mods |= filter->action.mods.mods.mask;
+ state->clear_mods = filter->action.mods.mods.mask;
+ state->latched_mods |= filter->action.mods.mods.mask;
/* XXX beep beep! */
}
}
@@ -449,7 +452,7 @@ xkb_filter_mod_latch_new(struct xkb_state *state,
filter->func = xkb_filter_mod_latch_func;
filter->action = *action;
- filter->state->set_mods = action->mods.mods.mask;
+ state->set_mods = action->mods.mods.mask;
return 1;
}
@@ -473,7 +476,7 @@ xkb_filter_apply_all(struct xkb_state *state,
darray_foreach(filter, state->filters) {
if (!filter->func)
continue;
- send &= filter->func(filter, key, direction);
+ send &= filter->func(state, filter, key, direction);
}
if (!send || direction == XKB_KEY_UP)