Use XKB_KEY_UP instead of 0 and XKB_KEY_DOWN instead of 1.
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Reported-by: Ran Benita <ran234@gmail.com>
_X_EXPORT void
xkb_state_unref(struct xkb_state *state);
+enum xkb_key_direction {
+ XKB_KEY_UP,
+ XKB_KEY_DOWN,
+};
+
/**
* Updates a state object to reflect the given key being pressed or released.
*/
_X_EXPORT void
-xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key, int down);
+xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
+ enum xkb_key_direction direction);
/**
* Modifier and group types for state objects. This enum is bitmaskable,
union xkb_action action;
xkb_keycode_t keycode;
uint32_t priv;
- int (*func)(struct xkb_filter *filter, xkb_keycode_t key, int down);
+ int (*func)(struct xkb_filter *filter, xkb_keycode_t key,
+ enum xkb_key_direction direction);
int refcnt;
struct xkb_filter *next;
};
static int
xkb_filter_group_set_func(struct xkb_filter *filter, xkb_keycode_t keycode,
- int down)
+ enum xkb_key_direction direction)
{
if (keycode != filter->keycode) {
filter->action.group.flags &= ~XkbSA_ClearLocks;
return 1;
}
- if (down) {
+ if (direction == XKB_KEY_DOWN) {
filter->refcnt++;
return 0;
}
static int
xkb_filter_mod_set_func(struct xkb_filter *filter, xkb_keycode_t keycode,
- int down)
+ enum xkb_key_direction direction)
{
if (keycode != filter->keycode) {
filter->action.mods.flags &= ~XkbSA_ClearLocks;
return 1;
}
- if (down) {
+ if (direction == XKB_KEY_DOWN) {
filter->refcnt++;
return 0;
}
static int
xkb_filter_mod_lock_func(struct xkb_filter *filter, xkb_keycode_t keycode,
- int down)
+ enum xkb_key_direction direction)
{
if (keycode != filter->keycode)
return 1;
- if (down) {
+ if (direction == XKB_KEY_DOWN) {
filter->refcnt++;
return 0;
}
static int
xkb_filter_mod_latch_func(struct xkb_filter *filter, xkb_keycode_t keycode,
- int down)
+ enum xkb_key_direction direction)
{
enum xkb_key_latch_state latch = filter->priv;
- if (down && latch == LATCH_PENDING) {
+ if (direction == XKB_KEY_DOWN && latch == LATCH_PENDING) {
/* If this is a new keypress and we're awaiting our single latched
* 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
return 1;
}
}
- else if (!down && keycode == filter->keycode) {
+ else if (direction == XKB_KEY_UP && keycode == filter->keycode) {
/* Our key got released. If we've set it to clear locks, and we
* currently have the same modifiers locked, then release them and
* don't actually latch. Else we've actually hit the latching
/* XXX beep beep! */
}
}
- else if (down && latch == LATCH_KEY_DOWN) {
+ else if (direction == XKB_KEY_DOWN && latch == LATCH_KEY_DOWN) {
/* Someone's pressed another key while we've still got the latching
* key held down, so keep the base modifier state active (from
* xkb_filter_mod_latch_new), but don't trip the latch, just clear
* apply a new filter from the key action.
*/
static void
-xkb_filter_apply_all(struct xkb_state *state, xkb_keycode_t key, int down)
+xkb_filter_apply_all(struct xkb_state *state, xkb_keycode_t key,
+ enum xkb_key_direction direction)
{
struct xkb_filter *filters = state->filters;
union xkb_action *act = NULL;
for (i = 0; i < state->num_filters; i++) {
if (!filters[i].func)
continue;
- send &= (*filters[i].func)(&filters[i], key, down);
+ send &= (*filters[i].func)(&filters[i], key, direction);
}
- if (!send || !down)
+ if (!send || direction == XKB_KEY_UP)
return;
act = xkb_key_get_action(state, key);
* new modifiers.
*/
void
-xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key, int down)
+xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
+ enum xkb_key_direction direction)
{
- xkb_filter_apply_all(state, key, down);
+ xkb_filter_apply_all(state, key, direction);
xkb_state_update_derived(state);
}
assert(state);
/* LCtrl down */
- xkb_state_update_key(state, KEY_LEFTCTRL + EVDEV_OFFSET, 1);
+ xkb_state_update_key(state, KEY_LEFTCTRL + EVDEV_OFFSET, XKB_KEY_DOWN);
fprintf(stderr, "dumping state for LCtrl down:\n");
print_state(state);
assert(xkb_state_mod_name_is_active(state, "Control",
XKB_STATE_DEPRESSED));
/* LCtrl + RAlt down */
- xkb_state_update_key(state, KEY_RIGHTALT + EVDEV_OFFSET, 1);
+ xkb_state_update_key(state, KEY_RIGHTALT + EVDEV_OFFSET, XKB_KEY_DOWN);
fprintf(stderr, "dumping state for LCtrl + RAlt down:\n");
print_state(state);
assert(xkb_state_mod_name_is_active(state, "Control",
XKB_STATE_DEPRESSED));
/* RAlt down */
- xkb_state_update_key(state, KEY_LEFTCTRL + EVDEV_OFFSET, 0);
+ xkb_state_update_key(state, KEY_LEFTCTRL + EVDEV_OFFSET, XKB_KEY_UP);
fprintf(stderr, "dumping state for RAlt down:\n");
print_state(state);
assert(!xkb_state_mod_name_is_active(state, "Control",
XKB_STATE_DEPRESSED));
/* none down */
- xkb_state_update_key(state, KEY_RIGHTALT + EVDEV_OFFSET, 0);
+ xkb_state_update_key(state, KEY_RIGHTALT + EVDEV_OFFSET, XKB_KEY_UP);
assert(!xkb_state_mod_name_is_active(state, "Mod1",
XKB_STATE_EFFECTIVE));
/* Caps locked */
- xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, 1);
- xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, 0);
+ xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_DOWN);
+ xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_UP);
fprintf(stderr, "dumping state for Caps Lock:\n");
print_state(state);
assert(xkb_state_mod_name_is_active(state, "Caps Lock",
assert(num_syms == 1 && syms[0] == XK_Q);
/* Caps unlocked */
- xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, 1);
- xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, 0);
+ xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_DOWN);
+ xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_UP);
assert(!xkb_state_mod_name_is_active(state, "Caps Lock",
XKB_STATE_EFFECTIVE));
assert(!xkb_state_led_name_is_active(state, "Caps Lock"));
ctrl = xkb_map_mod_get_index(state->xkb, "Control");
assert(ctrl != XKB_MOD_INVALID);
- xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, 1);
- xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, 0);
+ xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_DOWN);
+ xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_UP);
base_mods = xkb_state_serialise_mods(state, XKB_STATE_DEPRESSED);
assert(base_mods == 0);
latched_mods = xkb_state_serialise_mods(state, XKB_STATE_LATCHED);
effective_mods = xkb_state_serialise_mods(state, XKB_STATE_EFFECTIVE);
assert(effective_mods == locked_mods);
- xkb_state_update_key(state, KEY_LEFTSHIFT + EVDEV_OFFSET, 1);
+ xkb_state_update_key(state, KEY_LEFTSHIFT + EVDEV_OFFSET, XKB_KEY_DOWN);
base_mods = xkb_state_serialise_mods(state, XKB_STATE_DEPRESSED);
assert(base_mods == (1 << shift));
latched_mods = xkb_state_serialise_mods(state, XKB_STATE_LATCHED);