Skip to content

Commit

Permalink
video/out/wayland_common: set key state only on keyboard_enter keys
Browse files Browse the repository at this point in the history
These keys should be considered "being pressed" instead of an action of
press. This way, the keypress action won't be triggered; it now triggers
only when the key binding is repeatable and after the initial ar delay.
  • Loading branch information
na-na-hi authored and Dudemanguy committed Sep 7, 2024
1 parent c4ff675 commit e169302
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions video/out/wayland_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static void add_feedback(struct vo_wayland_feedback_pool *fback_pool,
static void apply_keepaspect(struct vo_wayland_state *wl, int *width, int *height);
static void get_shape_device(struct vo_wayland_state *wl, struct vo_wayland_seat *s);
static void guess_focus(struct vo_wayland_state *wl);
static void handle_key_input(struct vo_wayland_seat *s, uint32_t key, uint32_t state);
static void handle_key_input(struct vo_wayland_seat *s, uint32_t key, uint32_t state, bool no_emit);
static void prepare_resize(struct vo_wayland_state *wl);
static void remove_feedback(struct vo_wayland_feedback_pool *fback_pool,
struct wp_presentation_feedback *fback);
Expand Down Expand Up @@ -557,7 +557,7 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard,
uint32_t state)
{
struct vo_wayland_seat *s = data;
handle_key_input(s, key, state);
handle_key_input(s, key, state, false);
}

static void keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard,
Expand All @@ -576,8 +576,11 @@ static void keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboar
// Handle keys pressed during the enter event.
if (s->keyboard_entering) {
s->keyboard_entering = false;
for (int n = 0; n < s->num_keyboard_entering_keys; n++)
handle_key_input(s, s->keyboard_entering_keys[n], WL_KEYBOARD_KEY_STATE_PRESSED);
// Only handle entering keys if only one key is pressed since
// Wayland doesn't guarantee that these keys are in order.
if (s->num_keyboard_entering_keys == 1)
for (int n = 0; n < s->num_keyboard_entering_keys; n++)
handle_key_input(s, s->keyboard_entering_keys[n], WL_KEYBOARD_KEY_STATE_PRESSED, true);
s->num_keyboard_entering_keys = 0;
} else if (s->xkb_state && s->mpkey) {
mp_input_put_key(wl->vo->input_ctx, s->mpkey | MP_KEY_STATE_DOWN | s->mpmod);
Expand Down Expand Up @@ -1850,7 +1853,7 @@ static int lookupkey(int key)
}

static void handle_key_input(struct vo_wayland_seat *s, uint32_t key,
uint32_t state)
uint32_t state, bool no_emit)
{
struct vo_wayland_state *wl = s->wl;

Expand All @@ -1865,6 +1868,9 @@ static void handle_key_input(struct vo_wayland_seat *s, uint32_t key,
return;
}

if (no_emit)
state = state | MP_KEY_STATE_SET_ONLY;

s->keyboard_code = key + 8;
xkb_keysym_t sym = xkb_state_key_get_one_sym(s->xkb_state, s->keyboard_code);
int mpkey = lookupkey(sym);
Expand All @@ -1879,16 +1885,16 @@ static void handle_key_input(struct vo_wayland_seat *s, uint32_t key,
// Assume a modifier was pressed and handle it in the mod event instead.
// If a modifier is released before a regular key, also release that
// key to not activate it again by accident.
if (state == MP_KEY_STATE_UP) {
if (state & MP_KEY_STATE_UP) {
s->mpkey = 0;
mp_input_put_key(wl->vo->input_ctx, MP_INPUT_RELEASE_ALL);
}
return;
}
}
if (state == MP_KEY_STATE_DOWN)
if (state & MP_KEY_STATE_DOWN)
s->mpkey = mpkey;
if (mpkey && state == MP_KEY_STATE_UP)
if (mpkey && (state & MP_KEY_STATE_UP))
s->mpkey = 0;
}

Expand Down

0 comments on commit e169302

Please sign in to comment.