[mutter/wip/carlosg/input-focus-anchor: 4/5] clutter: Pass anchor position to ClutterInputFocus




commit ffac294520c36aa1294820ac728e50a2c3febe9d
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Jul 18 15:06:22 2022 +0200

    clutter: Pass anchor position to ClutterInputFocus
    
    Some implementations may need this (namely, the one that drives
    the Wayland protocol), so pass this along from the IM events.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2517>

 clutter/clutter/clutter-input-focus-private.h |  3 ++-
 clutter/clutter/clutter-input-focus.c         | 11 +++++++----
 clutter/clutter/clutter-input-focus.h         |  3 ++-
 clutter/clutter/clutter-text.c                |  3 ++-
 src/wayland/meta-wayland-text-input.c         |  5 +++--
 5 files changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/clutter/clutter/clutter-input-focus-private.h b/clutter/clutter/clutter-input-focus-private.h
index ccde45d0e2..5bc7e94941 100644
--- a/clutter/clutter/clutter-input-focus-private.h
+++ b/clutter/clutter/clutter-input-focus-private.h
@@ -35,6 +35,7 @@ void clutter_input_focus_request_surrounding (ClutterInputFocus *focus);
 
 void clutter_input_focus_set_preedit_text (ClutterInputFocus *focus,
                                            const gchar       *preedit,
-                                           guint              cursor);
+                                           unsigned int       cursor,
+                                           unsigned int       anchor);
 
 #endif /* __CLUTTER_INPUT_FOCUS_PRIVATE_H__ */
diff --git a/clutter/clutter/clutter-input-focus.c b/clutter/clutter/clutter-input-focus.c
index bf4f15ab8b..af94e6afa0 100644
--- a/clutter/clutter/clutter-input-focus.c
+++ b/clutter/clutter/clutter-input-focus.c
@@ -108,7 +108,7 @@ clutter_input_focus_reset (ClutterInputFocus *focus)
       if (priv->mode == CLUTTER_PREEDIT_RESET_COMMIT)
         clutter_input_focus_commit (focus, priv->preedit);
 
-      clutter_input_focus_set_preedit_text (focus, NULL, 0);
+      clutter_input_focus_set_preedit_text (focus, NULL, 0, 0);
       g_clear_pointer (&priv->preedit, g_free);
     }
 
@@ -207,7 +207,8 @@ clutter_input_focus_filter_event (ClutterInputFocus  *focus,
       priv->preedit = g_strdup (event->im.text);
       priv->mode = event->im.mode;
       clutter_input_focus_set_preedit_text (focus, event->im.text,
-                                            event->im.offset);
+                                            event->im.offset,
+                                            event->im.anchor);
       return TRUE;
     }
 
@@ -290,9 +291,11 @@ clutter_input_focus_request_surrounding (ClutterInputFocus *focus)
 void
 clutter_input_focus_set_preedit_text (ClutterInputFocus *focus,
                                       const gchar       *preedit,
-                                      guint              cursor)
+                                      unsigned int       cursor,
+                                      unsigned int       anchor)
 {
   g_return_if_fail (CLUTTER_IS_INPUT_FOCUS (focus));
 
-  CLUTTER_INPUT_FOCUS_GET_CLASS (focus)->set_preedit_text (focus, preedit, cursor);
+  CLUTTER_INPUT_FOCUS_GET_CLASS (focus)->set_preedit_text (focus, preedit,
+                                                           cursor, anchor);
 }
diff --git a/clutter/clutter/clutter-input-focus.h b/clutter/clutter/clutter-input-focus.h
index 77f5d90767..a2df71ee96 100644
--- a/clutter/clutter/clutter-input-focus.h
+++ b/clutter/clutter/clutter-input-focus.h
@@ -48,7 +48,8 @@ struct _ClutterInputFocusClass
 
   void (* set_preedit_text) (ClutterInputFocus *focus,
                              const gchar       *preedit,
-                             guint              cursor);
+                             guint              cursor,
+                             guint              anchor);
 };
 
 CLUTTER_EXPORT
diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c
index a437afbef8..b3c430b36c 100644
--- a/clutter/clutter/clutter-text.c
+++ b/clutter/clutter/clutter-text.c
@@ -398,7 +398,8 @@ clutter_text_input_focus_commit_text (ClutterInputFocus *focus,
 static void
 clutter_text_input_focus_set_preedit_text (ClutterInputFocus *focus,
                                            const gchar       *preedit_text,
-                                           guint              cursor_pos)
+                                           unsigned int       cursor_pos,
+                                           unsigned int       anchor_pos)
 {
   ClutterText *clutter_text = CLUTTER_TEXT_INPUT_FOCUS (focus)->text;
 
diff --git a/src/wayland/meta-wayland-text-input.c b/src/wayland/meta-wayland-text-input.c
index cf40f02183..949ec4dda7 100644
--- a/src/wayland/meta-wayland-text-input.c
+++ b/src/wayland/meta-wayland-text-input.c
@@ -248,7 +248,8 @@ meta_wayland_text_input_focus_commit_text (ClutterInputFocus *focus,
 static void
 meta_wayland_text_input_focus_set_preedit_text (ClutterInputFocus *focus,
                                                 const gchar       *text,
-                                                guint              cursor)
+                                                unsigned int       cursor,
+                                                unsigned int       anchor)
 {
   MetaWaylandTextInput *text_input;
   gsize pos = 0;
@@ -265,7 +266,7 @@ meta_wayland_text_input_focus_set_preedit_text (ClutterInputFocus *focus,
     pos = g_utf8_offset_to_pointer (text, cursor) - text;
 
   text_input->preedit.cursor = pos;
-  text_input->preedit.anchor = pos;
+  text_input->preedit.anchor = anchor;
   text_input->preedit.changed = TRUE;
 
   meta_wayland_text_input_focus_defer_done (focus);


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