From 7716b62fa2ae04f432b4429c70f81b01cb85691a Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 1 Jun 2023 19:42:22 +0200 Subject: [PATCH] clutter: Separate ClutterInputFocus event processing and filtering Currently, we let the same function handle key event filtering as they are passed to the IM, and the IM events resulting in actions like text commit or preedit changes. Split these two aspects into filter/process functions, and port ClutterText to it. MetaWaylandTextInput still handles everything in a single place, but that will be split in later commits. Part-of: --- clutter/clutter/clutter-input-focus.c | 17 ++++++++++++++++- clutter/clutter/clutter-input-focus.h | 5 +++++ clutter/clutter/clutter-text.c | 2 +- src/wayland/meta-wayland-seat.c | 2 +- src/wayland/meta-wayland-text-input.c | 17 ++++++++++++++++- src/wayland/meta-wayland-text-input.h | 3 +++ 6 files changed, 42 insertions(+), 4 deletions(-) diff --git a/clutter/clutter/clutter-input-focus.c b/clutter/clutter/clutter-input-focus.c index af94e6afa..800b54f86 100644 --- a/clutter/clutter/clutter-input-focus.c +++ b/clutter/clutter/clutter-input-focus.c @@ -190,7 +190,22 @@ clutter_input_focus_filter_event (ClutterInputFocus *focus, { return clutter_input_method_filter_key_event (priv->im, &event->key); } - else if (event->type == CLUTTER_IM_COMMIT) + + return FALSE; +} + +gboolean +clutter_input_focus_process_event (ClutterInputFocus *focus, + const ClutterEvent *event) +{ + ClutterInputFocusPrivate *priv; + + g_return_val_if_fail (CLUTTER_IS_INPUT_FOCUS (focus), FALSE); + g_return_val_if_fail (clutter_input_focus_is_focused (focus), FALSE); + + priv = clutter_input_focus_get_instance_private (focus); + + if (event->type == CLUTTER_IM_COMMIT) { clutter_input_focus_commit (focus, event->im.text); return TRUE; diff --git a/clutter/clutter/clutter-input-focus.h b/clutter/clutter/clutter-input-focus.h index a2df71ee9..b9c5557c5 100644 --- a/clutter/clutter/clutter-input-focus.h +++ b/clutter/clutter/clutter-input-focus.h @@ -75,6 +75,11 @@ void clutter_input_focus_set_content_purpose (ClutterInputFocus *focus, CLUTTER_EXPORT gboolean clutter_input_focus_filter_event (ClutterInputFocus *focus, const ClutterEvent *event); + +CLUTTER_EXPORT +gboolean clutter_input_focus_process_event (ClutterInputFocus *focus, + const ClutterEvent *event); + CLUTTER_EXPORT void clutter_input_focus_set_can_show_preedit (ClutterInputFocus *focus, gboolean can_show_preedit); diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c index c27d61372..8b2076866 100644 --- a/clutter/clutter/clutter-text.c +++ b/clutter/clutter/clutter-text.c @@ -3080,7 +3080,7 @@ clutter_text_event (ClutterActor *self, event->type == CLUTTER_IM_DELETE || event->type == CLUTTER_IM_PREEDIT)) { - return clutter_input_focus_filter_event (priv->input_focus, event); + return clutter_input_focus_process_event (priv->input_focus, event); } return CLUTTER_EVENT_PROPAGATE; diff --git a/src/wayland/meta-wayland-seat.c b/src/wayland/meta-wayland-seat.c index 7f1a24c48..8901454de 100644 --- a/src/wayland/meta-wayland-seat.c +++ b/src/wayland/meta-wayland-seat.c @@ -384,7 +384,7 @@ meta_wayland_seat_handle_event (MetaWaylandSeat *seat, break; case CLUTTER_KEY_PRESS: case CLUTTER_KEY_RELEASE: - if (meta_wayland_text_input_handle_event (seat->text_input, event)) + if (meta_wayland_text_input_update (seat->text_input, event)) return TRUE; if (meta_wayland_seat_has_keyboard (seat)) diff --git a/src/wayland/meta-wayland-text-input.c b/src/wayland/meta-wayland-text-input.c index c12fe2024..c9e5b07dc 100644 --- a/src/wayland/meta-wayland-text-input.c +++ b/src/wayland/meta-wayland-text-input.c @@ -800,6 +800,21 @@ meta_wayland_text_input_init (MetaWaylandCompositor *compositor) bind_text_input) != NULL); } +gboolean +meta_wayland_text_input_update (MetaWaylandTextInput *text_input, + const ClutterEvent *event) +{ + if (!text_input->surface || + !clutter_input_focus_is_focused (text_input->input_focus)) + return FALSE; + + if (event->type == CLUTTER_KEY_PRESS || + event->type == CLUTTER_KEY_RELEASE) + return clutter_input_focus_filter_event (text_input->input_focus, event); + + return FALSE; +} + gboolean meta_wayland_text_input_handle_event (MetaWaylandTextInput *text_input, const ClutterEvent *event) @@ -815,7 +830,7 @@ meta_wayland_text_input_handle_event (MetaWaylandTextInput *text_input, clutter_event_get_flags (event) & CLUTTER_EVENT_FLAG_INPUT_METHOD) meta_wayland_text_input_focus_flush_done (text_input->input_focus); - retval = clutter_input_focus_filter_event (text_input->input_focus, event); + retval = clutter_input_focus_process_event (text_input->input_focus, event); if (event->type == CLUTTER_BUTTON_PRESS || event->type == CLUTTER_TOUCH_BEGIN) diff --git a/src/wayland/meta-wayland-text-input.h b/src/wayland/meta-wayland-text-input.h index 7e3544d95..49555732a 100644 --- a/src/wayland/meta-wayland-text-input.h +++ b/src/wayland/meta-wayland-text-input.h @@ -41,6 +41,9 @@ gboolean meta_wayland_text_input_init (MetaWaylandCompositor *compositor); void meta_wayland_text_input_set_focus (MetaWaylandTextInput *text_input, MetaWaylandSurface *surface); +gboolean meta_wayland_text_input_update (MetaWaylandTextInput *text_input, + const ClutterEvent *event); + gboolean meta_wayland_text_input_handle_event (MetaWaylandTextInput *text_input, const ClutterEvent *event);