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>master
parent
c2570d51d1
commit
16425ffad9
73
src/state.c
73
src/state.c
|
@ -65,11 +65,11 @@
|
||||||
#include "xkb-priv.h"
|
#include "xkb-priv.h"
|
||||||
|
|
||||||
struct xkb_filter {
|
struct xkb_filter {
|
||||||
struct xkb_state *state;
|
|
||||||
union xkb_action action;
|
union xkb_action action;
|
||||||
const struct xkb_key *key;
|
const struct xkb_key *key;
|
||||||
uint32_t priv;
|
uint32_t priv;
|
||||||
int (*func)(struct xkb_filter *filter,
|
int (*func)(struct xkb_state *state,
|
||||||
|
struct xkb_filter *filter,
|
||||||
const struct xkb_key *key,
|
const struct xkb_key *key,
|
||||||
enum xkb_key_direction direction);
|
enum xkb_key_direction direction);
|
||||||
int refcnt;
|
int refcnt;
|
||||||
|
@ -146,7 +146,6 @@ xkb_filter_new(struct xkb_state *state)
|
||||||
filter = &darray_item(state->filters, darray_size(state->filters) -1);
|
filter = &darray_item(state->filters, darray_size(state->filters) -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
filter->state = state;
|
|
||||||
filter->refcnt = 1;
|
filter->refcnt = 1;
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
@ -154,7 +153,8 @@ xkb_filter_new(struct xkb_state *state)
|
||||||
/***====================================================================***/
|
/***====================================================================***/
|
||||||
|
|
||||||
static int
|
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,
|
const struct xkb_key *key,
|
||||||
enum xkb_key_direction direction)
|
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)
|
if (filter->action.group.flags & ACTION_ABSOLUTE_SWITCH)
|
||||||
filter->state->base_group = filter->action.group.group;
|
state->base_group = filter->action.group.group;
|
||||||
else
|
else
|
||||||
filter->state->base_group = -filter->action.group.group;
|
state->base_group = -filter->action.group.group;
|
||||||
if (filter->action.group.flags & ACTION_LOCK_CLEAR)
|
if (filter->action.group.flags & ACTION_LOCK_CLEAR)
|
||||||
filter->state->locked_group = 0;
|
state->locked_group = 0;
|
||||||
|
|
||||||
filter->func = NULL;
|
filter->func = NULL;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,18 +196,19 @@ xkb_filter_group_set_new(struct xkb_state *state,
|
||||||
filter->action = *action;
|
filter->action = *action;
|
||||||
|
|
||||||
if (action->group.flags & ACTION_ABSOLUTE_SWITCH) {
|
if (action->group.flags & ACTION_ABSOLUTE_SWITCH) {
|
||||||
filter->action.group.group = filter->state->base_group;
|
filter->action.group.group = state->base_group;
|
||||||
filter->state->base_group = action->group.group;
|
state->base_group = action->group.group;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
filter->state->base_group += action->group.group;
|
state->base_group += action->group.group;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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,
|
const struct xkb_key *key,
|
||||||
enum xkb_key_direction direction)
|
enum xkb_key_direction direction)
|
||||||
{
|
{
|
||||||
|
@ -240,15 +240,16 @@ xkb_filter_group_lock_new(struct xkb_state *state,
|
||||||
filter->action = *action;
|
filter->action = *action;
|
||||||
|
|
||||||
if (action->group.flags & ACTION_ABSOLUTE_SWITCH)
|
if (action->group.flags & ACTION_ABSOLUTE_SWITCH)
|
||||||
filter->state->locked_group = action->group.group;
|
state->locked_group = action->group.group;
|
||||||
else
|
else
|
||||||
filter->state->locked_group += action->group.group;
|
state->locked_group += action->group.group;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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,
|
const struct xkb_key *key,
|
||||||
enum xkb_key_direction direction)
|
enum xkb_key_direction direction)
|
||||||
{
|
{
|
||||||
|
@ -265,9 +266,9 @@ xkb_filter_mod_set_func(struct xkb_filter *filter,
|
||||||
return 0;
|
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)
|
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;
|
filter->func = NULL;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -286,13 +287,14 @@ xkb_filter_mod_set_new(struct xkb_state *state,
|
||||||
filter->func = xkb_filter_mod_set_func;
|
filter->func = xkb_filter_mod_set_func;
|
||||||
filter->action = *action;
|
filter->action = *action;
|
||||||
|
|
||||||
filter->state->set_mods = action->mods.mods.mask;
|
state->set_mods = action->mods.mods.mask;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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,
|
const struct xkb_key *key,
|
||||||
enum xkb_key_direction direction)
|
enum xkb_key_direction direction)
|
||||||
{
|
{
|
||||||
|
@ -306,7 +308,7 @@ xkb_filter_mod_lock_func(struct xkb_filter *filter,
|
||||||
if (--filter->refcnt > 0)
|
if (--filter->refcnt > 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
filter->state->locked_mods &= ~filter->priv;
|
state->locked_mods &= ~filter->priv;
|
||||||
|
|
||||||
filter->func = NULL;
|
filter->func = NULL;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -326,7 +328,7 @@ xkb_filter_mod_lock_new(struct xkb_state *state,
|
||||||
filter->action = *action;
|
filter->action = *action;
|
||||||
filter->priv = state->locked_mods & action->mods.mods.mask;
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -356,7 +358,8 @@ xkb_action_breaks_latch(const union xkb_action *action)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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,
|
const struct xkb_key *key,
|
||||||
enum xkb_key_direction direction)
|
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,
|
* 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
|
* or promote it to a lock or plain base set if it's the same
|
||||||
* modifier. */
|
* 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 &&
|
if (action->type == ACTION_TYPE_MOD_LATCH &&
|
||||||
action->mods.flags == filter->action.mods.flags &&
|
action->mods.flags == filter->action.mods.flags &&
|
||||||
action->mods.mods.mask == filter->action.mods.mods.mask) {
|
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) {
|
if (filter->action.mods.flags & ACTION_LATCH_TO_LOCK) {
|
||||||
filter->action.type = ACTION_TYPE_MOD_LOCK;
|
filter->action.type = ACTION_TYPE_MOD_LOCK;
|
||||||
filter->func = xkb_filter_mod_lock_func;
|
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 {
|
else {
|
||||||
filter->action.type = ACTION_TYPE_MOD_SET;
|
filter->action.type = ACTION_TYPE_MOD_SET;
|
||||||
filter->func = xkb_filter_mod_set_func;
|
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->key = key;
|
||||||
filter->state->latched_mods &= ~filter->action.mods.mods.mask;
|
state->latched_mods &= ~filter->action.mods.mods.mask;
|
||||||
/* XXX beep beep! */
|
/* XXX beep beep! */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (xkb_action_breaks_latch(action)) {
|
else if (xkb_action_breaks_latch(action)) {
|
||||||
/* XXX: This may be totally broken, we might need to break the
|
/* XXX: This may be totally broken, we might need to break the
|
||||||
* latch in the next run after this press? */
|
* 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;
|
filter->func = NULL;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -403,21 +406,21 @@ xkb_filter_mod_latch_func(struct xkb_filter *filter,
|
||||||
* latched. */
|
* latched. */
|
||||||
if (latch == NO_LATCH ||
|
if (latch == NO_LATCH ||
|
||||||
((filter->action.mods.flags & ACTION_LOCK_CLEAR) &&
|
((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)) {
|
filter->action.mods.mods.mask)) {
|
||||||
/* XXX: We might be a bit overenthusiastic about clearing
|
/* XXX: We might be a bit overenthusiastic about clearing
|
||||||
* mods other filters have set here? */
|
* mods other filters have set here? */
|
||||||
if (latch == LATCH_PENDING)
|
if (latch == LATCH_PENDING)
|
||||||
filter->state->latched_mods &= ~filter->action.mods.mods.mask;
|
state->latched_mods &= ~filter->action.mods.mods.mask;
|
||||||
else
|
else
|
||||||
filter->state->clear_mods = filter->action.mods.mods.mask;
|
state->clear_mods = filter->action.mods.mods.mask;
|
||||||
filter->state->locked_mods &= ~filter->action.mods.mods.mask;
|
state->locked_mods &= ~filter->action.mods.mods.mask;
|
||||||
filter->func = NULL;
|
filter->func = NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
latch = LATCH_PENDING;
|
latch = LATCH_PENDING;
|
||||||
filter->state->clear_mods = filter->action.mods.mods.mask;
|
state->clear_mods = filter->action.mods.mods.mask;
|
||||||
filter->state->latched_mods |= filter->action.mods.mods.mask;
|
state->latched_mods |= filter->action.mods.mods.mask;
|
||||||
/* XXX beep beep! */
|
/* XXX beep beep! */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -449,7 +452,7 @@ xkb_filter_mod_latch_new(struct xkb_state *state,
|
||||||
filter->func = xkb_filter_mod_latch_func;
|
filter->func = xkb_filter_mod_latch_func;
|
||||||
filter->action = *action;
|
filter->action = *action;
|
||||||
|
|
||||||
filter->state->set_mods = action->mods.mods.mask;
|
state->set_mods = action->mods.mods.mask;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -473,7 +476,7 @@ xkb_filter_apply_all(struct xkb_state *state,
|
||||||
darray_foreach(filter, state->filters) {
|
darray_foreach(filter, state->filters) {
|
||||||
if (!filter->func)
|
if (!filter->func)
|
||||||
continue;
|
continue;
|
||||||
send &= filter->func(filter, key, direction);
|
send &= filter->func(state, filter, key, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!send || direction == XKB_KEY_UP)
|
if (!send || direction == XKB_KEY_UP)
|
||||||
|
|
Loading…
Reference in New Issue