clutter: Prepare input focus for IM event delivery

The clutter_input_focus_filter_key_event() function has been made
a more generic filter_event(). Besides its old role about letting
key events go through the IM, it will also process the IM events
that are possibly injected as a result.

Users have been updated to these changes.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1286
This commit is contained in:
Carlos Garnacho 2020-02-17 11:25:14 +01:00
parent 612a17443a
commit 4a43e295d2
6 changed files with 63 additions and 11 deletions

View File

@ -147,8 +147,8 @@ clutter_input_focus_set_content_purpose (ClutterInputFocus *focus,
}
gboolean
clutter_input_focus_filter_key_event (ClutterInputFocus *focus,
const ClutterKeyEvent *key)
clutter_input_focus_filter_event (ClutterInputFocus *focus,
const ClutterEvent *event)
{
ClutterInputFocusPrivate *priv;
@ -157,7 +157,30 @@ clutter_input_focus_filter_key_event (ClutterInputFocus *focus,
priv = clutter_input_focus_get_instance_private (focus);
return clutter_input_method_filter_key_event (priv->im, key);
if (event->type == CLUTTER_KEY_PRESS ||
event->type == CLUTTER_KEY_RELEASE)
{
return clutter_input_method_filter_key_event (priv->im, &event->key);
}
else if (event->type == CLUTTER_IM_COMMIT)
{
clutter_input_focus_commit (focus, event->im.text);
return TRUE;
}
else if (event->type == CLUTTER_IM_DELETE)
{
clutter_input_focus_delete_surrounding (focus, event->im.offset,
event->im.len);
return TRUE;
}
else if (event->type == CLUTTER_IM_PREEDIT)
{
clutter_input_focus_set_preedit_text (focus, event->im.text,
event->im.offset);
return TRUE;
}
return FALSE;
}
void

View File

@ -72,8 +72,8 @@ CLUTTER_EXPORT
void clutter_input_focus_set_content_purpose (ClutterInputFocus *focus,
ClutterInputContentPurpose purpose);
CLUTTER_EXPORT
gboolean clutter_input_focus_filter_key_event (ClutterInputFocus *focus,
const ClutterKeyEvent *key);
gboolean clutter_input_focus_filter_event (ClutterInputFocus *focus,
const ClutterEvent *event);
CLUTTER_EXPORT
void clutter_input_focus_set_can_show_preedit (ClutterInputFocus *focus,
gboolean can_show_preedit);

View File

@ -2400,7 +2400,8 @@ clutter_text_key_press (ClutterActor *actor,
if (!(event->flags & CLUTTER_EVENT_FLAG_INPUT_METHOD) &&
clutter_input_focus_is_focused (priv->input_focus) &&
clutter_input_focus_filter_key_event (priv->input_focus, event))
clutter_input_focus_filter_event (priv->input_focus,
(ClutterEvent *) event))
return CLUTTER_EVENT_STOP;
/* we allow passing synthetic events that only contain
@ -2469,7 +2470,8 @@ clutter_text_key_release (ClutterActor *actor,
ClutterTextPrivate *priv = self->priv;
if (clutter_input_focus_is_focused (priv->input_focus) &&
clutter_input_focus_filter_key_event (priv->input_focus, event))
clutter_input_focus_filter_event (priv->input_focus,
(ClutterEvent *) event))
return CLUTTER_EVENT_STOP;
return CLUTTER_EVENT_PROPAGATE;
@ -3068,6 +3070,24 @@ clutter_text_resource_scale_changed (ClutterActor *actor)
clutter_actor_queue_immediate_relayout (actor);
}
static gboolean
clutter_text_event (ClutterActor *self,
ClutterEvent *event)
{
ClutterText *text = CLUTTER_TEXT (self);
ClutterTextPrivate *priv = text->priv;
if (clutter_input_focus_is_focused (priv->input_focus) &&
(event->type == CLUTTER_IM_COMMIT ||
event->type == CLUTTER_IM_DELETE ||
event->type == CLUTTER_IM_PREEDIT))
{
return clutter_input_focus_filter_event (priv->input_focus, event);
}
return CLUTTER_EVENT_PROPAGATE;
}
static void
clutter_text_im_focus (ClutterText *text)
{
@ -3818,6 +3838,7 @@ clutter_text_class_init (ClutterTextClass *klass)
actor_class->has_overlaps = clutter_text_has_overlaps;
actor_class->calculate_resource_scale = clutter_text_calculate_resource_scale;
actor_class->resource_scale_changed = clutter_text_resource_scale_changed;
actor_class->event = clutter_text_event;
/**
* ClutterText:buffer:

View File

@ -406,6 +406,16 @@ meta_wayland_seat_handle_event (MetaWaylandSeat *seat,
if (meta_wayland_seat_has_touch (seat))
return meta_wayland_touch_handle_event (seat->touch, event);
break;
case CLUTTER_IM_COMMIT:
case CLUTTER_IM_DELETE:
case CLUTTER_IM_PREEDIT:
if (meta_wayland_text_input_handle_event (seat->text_input, event))
return TRUE;
if (meta_wayland_gtk_text_input_handle_event (seat->gtk_text_input,
event))
return TRUE;
break;
default:
break;

View File

@ -629,6 +629,5 @@ meta_wayland_gtk_text_input_handle_event (MetaWaylandGtkTextInput *text_input,
!clutter_input_focus_is_focused (text_input->input_focus))
return FALSE;
return clutter_input_focus_filter_key_event (text_input->input_focus,
(const ClutterKeyEvent *) event);
return clutter_input_focus_filter_event (text_input->input_focus, event);
}

View File

@ -737,6 +737,5 @@ meta_wayland_text_input_handle_event (MetaWaylandTextInput *text_input,
!clutter_input_focus_is_focused (text_input->input_focus))
return FALSE;
return clutter_input_focus_filter_key_event (text_input->input_focus,
(const ClutterKeyEvent *) event);
return clutter_input_focus_filter_event (text_input->input_focus, event);
}