state: use stdbool in filters 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
diff --git a/src/state.c b/src/state.c
index d61bed7..ac4576f 100644
--- a/src/state.c
+++ b/src/state.c
@@ -65,10 +65,10 @@ struct xkb_filter {
union xkb_action action;
const struct xkb_key *key;
uint32_t priv;
- int (*func)(struct xkb_state *state,
- struct xkb_filter *filter,
- const struct xkb_key *key,
- enum xkb_key_direction direction);
+ bool (*func)(struct xkb_state *state,
+ struct xkb_filter *filter,
+ const struct xkb_key *key,
+ enum xkb_key_direction direction);
int refcnt;
};
@@ -256,7 +256,7 @@ xkb_filter_new(struct xkb_state *state)
/***====================================================================***/
-static int
+static bool
xkb_filter_group_set_func(struct xkb_state *state,
struct xkb_filter *filter,
const struct xkb_key *key,
@@ -264,15 +264,15 @@ xkb_filter_group_set_func(struct xkb_state *state,
{
if (key != filter->key) {
filter->action.group.flags &= ~ACTION_LOCK_CLEAR;
- return 1;
+ return true;
}
if (direction == XKB_KEY_DOWN) {
filter->refcnt++;
- return 0;
+ return false;
}
else if (--filter->refcnt > 0) {
- return 0;
+ return false;
}
state->components.base_group = filter->priv;
@@ -281,7 +281,7 @@ xkb_filter_group_set_func(struct xkb_state *state,
state->components.locked_group = 0;
filter->func = NULL;
- return 1;
+ return true;
}
static void
@@ -294,24 +294,24 @@ xkb_filter_group_set_new(struct xkb_state *state, struct xkb_filter *filter)
state->components.base_group += filter->action.group.group;
}
-static int
+static bool
xkb_filter_group_lock_func(struct xkb_state *state,
struct xkb_filter *filter,
const struct xkb_key *key,
enum xkb_key_direction direction)
{
if (key != filter->key)
- return 1;
+ return true;
if (direction == XKB_KEY_DOWN) {
filter->refcnt++;
- return 0;
+ return false;
}
if (--filter->refcnt > 0)
- return 0;
+ return false;
filter->func = NULL;
- return 1;
+ return true;
}
static void
@@ -323,7 +323,7 @@ xkb_filter_group_lock_new(struct xkb_state *state, struct xkb_filter *filter)
state->components.locked_group += filter->action.group.group;
}
-static int
+static bool
xkb_filter_mod_set_func(struct xkb_state *state,
struct xkb_filter *filter,
const struct xkb_key *key,
@@ -331,15 +331,15 @@ xkb_filter_mod_set_func(struct xkb_state *state,
{
if (key != filter->key) {
filter->action.mods.flags &= ~ACTION_LOCK_CLEAR;
- return 1;
+ return true;
}
if (direction == XKB_KEY_DOWN) {
filter->refcnt++;
- return 0;
+ return false;
}
else if (--filter->refcnt > 0) {
- return 0;
+ return false;
}
state->clear_mods = filter->action.mods.mods.mask;
@@ -347,7 +347,7 @@ xkb_filter_mod_set_func(struct xkb_state *state,
state->components.locked_mods &= ~filter->action.mods.mods.mask;
filter->func = NULL;
- return 1;
+ return true;
}
static void
@@ -356,28 +356,28 @@ xkb_filter_mod_set_new(struct xkb_state *state, struct xkb_filter *filter)
state->set_mods = filter->action.mods.mods.mask;
}
-static int
+static bool
xkb_filter_mod_lock_func(struct xkb_state *state,
struct xkb_filter *filter,
const struct xkb_key *key,
enum xkb_key_direction direction)
{
if (key != filter->key)
- return 1;
+ return true;
if (direction == XKB_KEY_DOWN) {
filter->refcnt++;
- return 0;
+ return false;
}
if (--filter->refcnt > 0)
- return 0;
+ return false;
state->clear_mods |= filter->action.mods.mods.mask;
if (!(filter->action.mods.flags & ACTION_LOCK_NO_UNLOCK))
state->components.locked_mods &= ~filter->priv;
filter->func = NULL;
- return 1;
+ return true;
}
static void
@@ -414,7 +414,7 @@ xkb_action_breaks_latch(const union xkb_action *action)
}
}
-static int
+static bool
xkb_filter_mod_latch_func(struct xkb_state *state,
struct xkb_filter *filter,
const struct xkb_key *key,
@@ -445,14 +445,14 @@ xkb_filter_mod_latch_func(struct xkb_state *state,
filter->key = key;
state->components.latched_mods &= ~filter->action.mods.mods.mask;
/* XXX beep beep! */
- return 0;
+ return false;
}
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? */
state->components.latched_mods &= ~filter->action.mods.mods.mask;
filter->func = NULL;
- return 1;
+ return true;
}
}
else if (direction == XKB_KEY_UP && key == filter->key) {
@@ -492,7 +492,7 @@ xkb_filter_mod_latch_func(struct xkb_state *state,
filter->priv = latch;
- return 1;
+ return true;
}
static void
@@ -504,8 +504,8 @@ xkb_filter_mod_latch_new(struct xkb_state *state, struct xkb_filter *filter)
static const struct {
void (*new)(struct xkb_state *state, struct xkb_filter *filter);
- int (*func)(struct xkb_state *state, struct xkb_filter *filter,
- const struct xkb_key *key, enum xkb_key_direction direction);
+ bool (*func)(struct xkb_state *state, struct xkb_filter *filter,
+ const struct xkb_key *key, enum xkb_key_direction direction);
} filter_action_funcs[_ACTION_TYPE_NUM_ENTRIES] = {
[ACTION_TYPE_MOD_SET] = { xkb_filter_mod_set_new,
xkb_filter_mod_set_func },
@@ -531,14 +531,14 @@ xkb_filter_apply_all(struct xkb_state *state,
{
struct xkb_filter *filter;
const union xkb_action *action;
- int send = 1;
+ bool send = true;
/* First run through all the currently active filters and see if any of
* them have claimed this event. */
darray_foreach(filter, state->filters) {
if (!filter->func)
continue;
- send &= filter->func(state, filter, key, direction);
+ send = filter->func(state, filter, key, direction) && send;
}
if (!send || direction == XKB_KEY_UP)