[mutter/wip/carlosg/im-events: 20/20] clutter: Push commit/delete_sourrounding as IM events



commit 668165b52f0c9438a2a6577d563d07da5bdbdca4
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Feb 17 11:03:51 2020 +0100

    clutter: Push commit/delete_sourrounding as IM events
    
    These are not given directly to the input focus anymore, instead
    queued up as events.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1286

 clutter/clutter/clutter-input-method.c | 44 ++++++++++++++++++++++++++--------
 1 file changed, 34 insertions(+), 10 deletions(-)
---
diff --git a/clutter/clutter/clutter-input-method.c b/clutter/clutter/clutter-input-method.c
index 031b103df5..2906efee9d 100644
--- a/clutter/clutter/clutter-input-method.c
+++ b/clutter/clutter/clutter-input-method.c
@@ -277,17 +277,45 @@ clutter_input_method_get_focus (ClutterInputMethod *im)
   return priv->focus;
 }
 
+static void
+clutter_input_method_put_im_event (ClutterInputMethod *im,
+                                   ClutterEventType    event_type,
+                                   const gchar        *text,
+                                   int32_t             offset,
+                                   uint32_t            len)
+{
+  ClutterInputDevice *keyboard;
+  ClutterSeat *seat;
+  ClutterStage *stage;
+  ClutterEvent *event;
+
+  seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
+  keyboard = clutter_seat_get_keyboard (seat);
+  stage = _clutter_input_device_get_stage (keyboard);
+  if (stage == NULL)
+    return;
+
+  event = clutter_event_new (event_type);
+  event->im.text = g_strdup (text);
+  event->im.offset = offset;
+  event->im.len = len;
+  clutter_event_set_device (event, keyboard);
+  clutter_event_set_source_device (event, keyboard);
+  clutter_event_set_flags (event, CLUTTER_EVENT_FLAG_INPUT_METHOD);
+
+  clutter_event_set_stage (event, stage);
+
+  clutter_event_put (event);
+  clutter_event_free (event);
+}
+
 void
 clutter_input_method_commit (ClutterInputMethod *im,
                              const gchar        *text)
 {
-  ClutterInputMethodPrivate *priv;
-
   g_return_if_fail (CLUTTER_IS_INPUT_METHOD (im));
 
-  priv = clutter_input_method_get_instance_private (im);
-  if (priv->focus)
-    clutter_input_focus_commit (priv->focus, text);
+  clutter_input_method_put_im_event (im, CLUTTER_IM_COMMIT, text, 0, 0);
 }
 
 void
@@ -295,13 +323,9 @@ clutter_input_method_delete_surrounding (ClutterInputMethod *im,
                                          int                 offset,
                                          guint               len)
 {
-  ClutterInputMethodPrivate *priv;
-
   g_return_if_fail (CLUTTER_IS_INPUT_METHOD (im));
 
-  priv = clutter_input_method_get_instance_private (im);
-  if (priv->focus)
-    clutter_input_focus_delete_surrounding (priv->focus, offset, len);
+  clutter_input_method_put_im_event (im, CLUTTER_IM_DELETE, NULL, offset, len);
 }
 
 void


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