From 38228da550448b77668a4a82c950e7ecf131dfca Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 6 Nov 2023 11:42:12 +0100 Subject: [PATCH] clutter: Add ClutterModifierSet argument to key event constructor This struct contains the pressed/latched/locked set of modifiers applying to the event, and may be filled in by backends generating those events. Other places where we forward modified key events, state may be normally obtained from the original event. Since this constructor is used in a variety of places, this commit updates them all in one go. Part-of: --- clutter/clutter/clutter-event-private.h | 1 + clutter/clutter/clutter-event.c | 2 ++ clutter/clutter/clutter-input-method.c | 8 ++++++++ src/backends/native/meta-input-device-native.c | 15 +++++++++++++++ src/backends/native/meta-xkb-utils.c | 8 ++++++++ src/backends/x11/meta-seat-x11.c | 8 ++++++++ src/tests/clutter/conform/binding-pool.c | 1 + src/tests/clutter/conform/text.c | 2 ++ 8 files changed, 45 insertions(+) diff --git a/clutter/clutter/clutter-event-private.h b/clutter/clutter/clutter-event-private.h index 4edeb5be4..35740c9b7 100644 --- a/clutter/clutter/clutter-event-private.h +++ b/clutter/clutter/clutter-event-private.h @@ -18,6 +18,7 @@ ClutterEvent * clutter_event_key_new (ClutterEventType type, ClutterEventFlags flags, int64_t timestamp_us, ClutterInputDevice *source_device, + ClutterModifierSet raw_modifiers, ClutterModifierType modifiers, uint32_t keyval, uint32_t evcode, diff --git a/clutter/clutter/clutter-event.c b/clutter/clutter/clutter-event.c index 2e66fe560..4e2dceff2 100644 --- a/clutter/clutter/clutter-event.c +++ b/clutter/clutter/clutter-event.c @@ -1858,6 +1858,7 @@ clutter_event_key_new (ClutterEventType type, ClutterEventFlags flags, int64_t timestamp_us, ClutterInputDevice *source_device, + ClutterModifierSet raw_modifiers, ClutterModifierType modifiers, uint32_t keyval, uint32_t evcode, @@ -1877,6 +1878,7 @@ clutter_event_key_new (ClutterEventType type, event->key.time_us = timestamp_us; event->key.flags = flags; + event->key.raw_modifiers = raw_modifiers; event->key.modifier_state = modifiers; event->key.keyval = keyval; event->key.hardware_keycode = keycode; diff --git a/clutter/clutter/clutter-input-method.c b/clutter/clutter/clutter-input-method.c index 04d97ebc1..ec78ebe99 100644 --- a/clutter/clutter/clutter-input-method.c +++ b/clutter/clutter/clutter-input-method.c @@ -360,8 +360,14 @@ clutter_input_method_notify_key_event (ClutterInputMethod *im, { if (!filtered) { + ClutterModifierSet raw_modifiers; ClutterEvent *copy; + clutter_event_get_key_state (event, + &raw_modifiers.pressed, + &raw_modifiers.latched, + &raw_modifiers.locked); + /* XXX: we rely on the IM implementation to notify back of * key events in the exact same order they were given. */ @@ -370,6 +376,7 @@ clutter_input_method_notify_key_event (ClutterInputMethod *im, CLUTTER_EVENT_FLAG_INPUT_METHOD, clutter_event_get_time_us (event), clutter_event_get_device (event), + raw_modifiers, clutter_event_get_state (event), clutter_event_get_key_symbol (event), clutter_event_get_event_code (event), @@ -490,6 +497,7 @@ clutter_input_method_forward_key (ClutterInputMethod *im, CLUTTER_EVENT_FLAG_INPUT_METHOD, time_, keyboard, + (ClutterModifierSet) { 0, }, state, keyval, keycode - 8, diff --git a/src/backends/native/meta-input-device-native.c b/src/backends/native/meta-input-device-native.c index 2f46d0ad2..b8793825f 100644 --- a/src/backends/native/meta-input-device-native.c +++ b/src/backends/native/meta-input-device-native.c @@ -275,14 +275,21 @@ trigger_slow_keys (gpointer data) { SlowKeysEventPending *slow_keys_event = data; MetaInputDeviceNative *device = slow_keys_event->device; + ClutterModifierSet raw_modifiers; ClutterEvent *event = slow_keys_event->event; ClutterEvent *copy; + clutter_event_get_key_state (event, + &raw_modifiers.pressed, + &raw_modifiers.latched, + &raw_modifiers.locked); + /* Alter timestamp and emit the event */ copy = clutter_event_key_new (clutter_event_type (event), clutter_event_get_flags (event), g_get_monotonic_time (), clutter_event_get_source_device (event), + raw_modifiers, clutter_event_get_state (event), clutter_event_get_key_symbol (event), clutter_event_get_event_code (event), @@ -524,6 +531,7 @@ rewrite_stickykeys_event (ClutterEvent *event, { MetaSeatImpl *seat_impl = seat_impl_from_device_native (device); struct xkb_state *xkb_state; + ClutterModifierSet raw_modifiers; ClutterEvent *rewritten_event; ClutterModifierType modifiers; @@ -533,11 +541,18 @@ rewrite_stickykeys_event (ClutterEvent *event, xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_EFFECTIVE) | seat_impl->button_state; + raw_modifiers = (ClutterModifierSet) { + .pressed = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_DEPRESSED), + .latched = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_LATCHED), + .locked = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_LOCKED), + }; + rewritten_event = clutter_event_key_new (clutter_event_type (event), clutter_event_get_flags (event), clutter_event_get_time_us (event), clutter_event_get_source_device (event), + raw_modifiers, modifiers, clutter_event_get_key_symbol (event), clutter_event_get_event_code (event), diff --git a/src/backends/native/meta-xkb-utils.c b/src/backends/native/meta-xkb-utils.c index 7f80cca2e..e1fb944df 100644 --- a/src/backends/native/meta-xkb-utils.c +++ b/src/backends/native/meta-xkb-utils.c @@ -53,6 +53,7 @@ meta_key_event_new_from_evdev (ClutterInputDevice *device, char buffer[8]; gunichar unicode_value; ClutterModifierType modifiers; + ClutterModifierSet raw_modifiers; int n; /* We use a fixed offset of 8 because evdev starts KEY_* numbering from @@ -63,6 +64,12 @@ meta_key_event_new_from_evdev (ClutterInputDevice *device, sym = xkb_state_key_get_one_sym (xkb_state, key); + raw_modifiers = (ClutterModifierSet) { + .pressed = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_DEPRESSED), + .latched = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_LATCHED), + .locked = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_LOCKED), + }; + modifiers = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_EFFECTIVE) | button_state; @@ -85,6 +92,7 @@ meta_key_event_new_from_evdev (ClutterInputDevice *device, flags, time_us, device, + raw_modifiers, modifiers, sym, key - 8, diff --git a/src/backends/x11/meta-seat-x11.c b/src/backends/x11/meta-seat-x11.c index ca9fca789..8a3429a8f 100644 --- a/src/backends/x11/meta-seat-x11.c +++ b/src/backends/x11/meta-seat-x11.c @@ -2111,6 +2111,7 @@ meta_seat_x11_translate_event (MetaSeatX11 *seat, MetaKeymapX11 *keymap_x11 = seat->keymap; char buffer[7] = { 0, }; uint32_t keyval, evcode, keycode; + ClutterModifierSet raw_modifiers; ClutterModifierType state; int len; gunichar unicode_value; @@ -2119,6 +2120,12 @@ meta_seat_x11_translate_event (MetaSeatX11 *seat, if (!source_device) return NULL; + raw_modifiers = (ClutterModifierSet) { + .pressed = xev->mods.base, + .latched = xev->mods.latched, + .locked = xev->mods.locked, + }; + state = translate_state (&xev->buttons, &xev->mods, &xev->group); keycode = xev->detail; @@ -2156,6 +2163,7 @@ meta_seat_x11_translate_event (MetaSeatX11 *seat, CLUTTER_EVENT_NONE, ms2us (xev->time), source_device, + raw_modifiers, state, keyval, evcode, diff --git a/src/tests/clutter/conform/binding-pool.c b/src/tests/clutter/conform/binding-pool.c index 77853c5bc..0a210bb8a 100644 --- a/src/tests/clutter/conform/binding-pool.c +++ b/src/tests/clutter/conform/binding-pool.c @@ -235,6 +235,7 @@ send_keyval (KeyGroup *group, int keyval) CLUTTER_EVENT_FLAG_SYNTHETIC, CLUTTER_CURRENT_TIME, clutter_seat_get_keyboard (seat), + (ClutterModifierSet) { 0, }, 0, keyval, 0, 0, 0); diff --git a/src/tests/clutter/conform/text.c b/src/tests/clutter/conform/text.c index 79492d8f9..f377763f1 100644 --- a/src/tests/clutter/conform/text.c +++ b/src/tests/clutter/conform/text.c @@ -339,6 +339,7 @@ send_keyval (ClutterText *text, int keyval) CLUTTER_EVENT_FLAG_SYNTHETIC, CLUTTER_CURRENT_TIME, clutter_seat_get_keyboard (seat), + (ClutterModifierSet) { 0, }, 0, keyval, 0, 0, 0); clutter_actor_event (CLUTTER_ACTOR (text), event, FALSE); @@ -358,6 +359,7 @@ send_unichar (ClutterText *text, gunichar unichar) CLUTTER_EVENT_FLAG_SYNTHETIC, CLUTTER_CURRENT_TIME, clutter_seat_get_keyboard (seat), + (ClutterModifierSet) { 0, }, 0, 0, 0, 0, unichar); clutter_actor_event (CLUTTER_ACTOR (text), event, FALSE);