[mutter/wip/carlosg/im-events: 78/81] clutter: Prepare input focus for IM event delivery




commit 4a43e295d236218e2f1fd775952abb65f1a09c90
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Feb 17 11:25:14 2020 +0100

    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

 clutter/clutter/clutter-input-focus.c        | 29 +++++++++++++++++++++++++---
 clutter/clutter/clutter-input-focus.h        |  4 ++--
 clutter/clutter/clutter-text.c               | 25 ++++++++++++++++++++++--
 src/wayland/meta-wayland-seat.c              | 10 ++++++++++
 src/wayland/meta-wayland-text-input-legacy.c |  3 +--
 src/wayland/meta-wayland-text-input.c        |  3 +--
 6 files changed, 63 insertions(+), 11 deletions(-)
---
diff --git a/clutter/clutter/clutter-input-focus.c b/clutter/clutter/clutter-input-focus.c
index ece1fa59ac..2aea51e24d 100644
--- a/clutter/clutter/clutter-input-focus.c
+++ b/clutter/clutter/clutter-input-focus.c
@@ -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
diff --git a/clutter/clutter/clutter-input-focus.h b/clutter/clutter/clutter-input-focus.h
index 008883af6b..77f5d90767 100644
--- a/clutter/clutter/clutter-input-focus.h
+++ b/clutter/clutter/clutter-input-focus.h
@@ -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);
diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c
index 082bcb3999..752676e99b 100644
--- a/clutter/clutter/clutter-text.c
+++ b/clutter/clutter/clutter-text.c
@@ -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:
diff --git a/src/wayland/meta-wayland-seat.c b/src/wayland/meta-wayland-seat.c
index 3a76a1b5b9..37614e3e3b 100644
--- a/src/wayland/meta-wayland-seat.c
+++ b/src/wayland/meta-wayland-seat.c
@@ -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;
diff --git a/src/wayland/meta-wayland-text-input-legacy.c b/src/wayland/meta-wayland-text-input-legacy.c
index d8f7d1d82c..442708e0f4 100644
--- a/src/wayland/meta-wayland-text-input-legacy.c
+++ b/src/wayland/meta-wayland-text-input-legacy.c
@@ -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);
 }
diff --git a/src/wayland/meta-wayland-text-input.c b/src/wayland/meta-wayland-text-input.c
index 570dba459b..1f7c8bc922 100644
--- a/src/wayland/meta-wayland-text-input.c
+++ b/src/wayland/meta-wayland-text-input.c
@@ -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);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]