state: use global static const for fake action Requires constifying some arguments. 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
diff --git a/src/state.c b/src/state.c
index 312813b..4006872 100644
--- a/src/state.c
+++ b/src/state.c
@@ -106,7 +106,9 @@ struct xkb_state {
struct xkb_keymap *keymap;
};
-static union xkb_action *
+static const union xkb_action fake = { .type = XkbSA_NoAction };
+
+static const union xkb_action *
xkb_key_get_action(struct xkb_state *state, xkb_keycode_t kc)
{
xkb_group_index_t group;
@@ -116,12 +118,8 @@ xkb_key_get_action(struct xkb_state *state, xkb_keycode_t kc)
if (XkbKeycodeInRange(state->keymap, kc))
key = XkbKey(state->keymap, kc);
- if (!key || !XkbKeyHasActions(key)) {
- static union xkb_action fake;
- memset(&fake, 0, sizeof(fake));
- fake.type = XkbSA_NoAction;
+ if (!key || !XkbKeyHasActions(key))
return &fake;
- }
group = xkb_key_get_group(state, kc);
level = xkb_key_get_level(state, kc, group);
@@ -185,7 +183,7 @@ xkb_filter_group_set_func(struct xkb_filter *filter, xkb_keycode_t kc,
static int
xkb_filter_group_set_new(struct xkb_state *state, xkb_keycode_t kc,
- union xkb_action *action)
+ const union xkb_action *action)
{
struct xkb_filter *filter = xkb_filter_new(state);
@@ -226,7 +224,7 @@ xkb_filter_group_lock_func(struct xkb_filter *filter, xkb_keycode_t kc,
static int
xkb_filter_group_lock_new(struct xkb_state *state, xkb_keycode_t kc,
- union xkb_action *action)
+ const union xkb_action *action)
{
struct xkb_filter *filter = xkb_filter_new(state);
@@ -273,7 +271,7 @@ xkb_filter_mod_set_func(struct xkb_filter *filter, xkb_keycode_t kc,
static int
xkb_filter_mod_set_new(struct xkb_state *state, xkb_keycode_t kc,
- union xkb_action *action)
+ const union xkb_action *action)
{
struct xkb_filter *filter = xkb_filter_new(state);
@@ -309,7 +307,7 @@ xkb_filter_mod_lock_func(struct xkb_filter *filter, xkb_keycode_t kc,
static int
xkb_filter_mod_lock_new(struct xkb_state *state, xkb_keycode_t kc,
- union xkb_action *action)
+ const union xkb_action *action)
{
struct xkb_filter *filter = xkb_filter_new(state);
@@ -342,7 +340,7 @@ xkb_filter_mod_latch_func(struct xkb_filter *filter, xkb_keycode_t kc,
* 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. */
- union xkb_action *action = xkb_key_get_action(filter->state, kc);
+ const union xkb_action *action = xkb_key_get_action(filter->state, kc);
if (action->type == XkbSA_LatchMods &&
action->mods.flags == filter->action.mods.flags &&
action->mods.mods.mask == filter->action.mods.mods.mask) {
@@ -411,7 +409,7 @@ xkb_filter_mod_latch_func(struct xkb_filter *filter, xkb_keycode_t kc,
static int
xkb_filter_mod_latch_new(struct xkb_state *state, xkb_keycode_t kc,
- union xkb_action *action)
+ const union xkb_action *action)
{
struct xkb_filter *filter = xkb_filter_new(state);
enum xkb_key_latch_state latch = LATCH_KEY_DOWN;
@@ -438,7 +436,7 @@ xkb_filter_apply_all(struct xkb_state *state, xkb_keycode_t kc,
enum xkb_key_direction direction)
{
struct xkb_filter *filter;
- union xkb_action *act = NULL;
+ const union xkb_action *act = NULL;
int send = 1;
/* First run through all the currently active filters and see if any of