[mutter/wip/carlosg/im-update-preedit-with-mode: 19/21] clutter: Add ClutterPreeditResetMode hint to preedit text
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/carlosg/im-update-preedit-with-mode: 19/21] clutter: Add ClutterPreeditResetMode hint to preedit text
- Date: Fri, 30 Jul 2021 15:18:20 +0000 (UTC)
commit 8fa1eccb3c4d4e0efa490ec2c9f5f83f395ba891
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Jul 30 16:40:17 2021 +0200
clutter: Add ClutterPreeditResetMode hint to preedit text
This mode is passed along by the ClutterInputMethod, the
ClutterInputFocus will preserve it and ensure it is honored
whenever the IM is being reset.
This is mode is immediate. The ClutterInputFocus commits the
text directly without queueing a CLUTTER_IM_COMMIT event.
clutter/clutter/clutter-enums.h | 6 ++++++
clutter/clutter/clutter-event.h | 1 +
clutter/clutter/clutter-input-focus.c | 13 +++++++++++++
clutter/clutter/clutter-input-method.c | 25 ++++++++++++++-----------
clutter/clutter/clutter-input-method.h | 7 ++++---
5 files changed, 38 insertions(+), 14 deletions(-)
---
diff --git a/clutter/clutter/clutter-enums.h b/clutter/clutter/clutter-enums.h
index 458d0fd2cc..54344248f4 100644
--- a/clutter/clutter/clutter-enums.h
+++ b/clutter/clutter/clutter-enums.h
@@ -1638,6 +1638,12 @@ typedef enum
CLUTTER_INPUT_PANEL_STATE_TOGGLE,
} ClutterInputPanelState;
+typedef enum
+{
+ CLUTTER_PREEDIT_RESET_CLEAR,
+ CLUTTER_PREEDIT_RESET_COMMIT,
+} ClutterPreeditResetMode;
+
G_END_DECLS
#endif /* __CLUTTER_ENUMS_H__ */
diff --git a/clutter/clutter/clutter-event.h b/clutter/clutter/clutter-event.h
index b77e64d15c..a14b2eca38 100644
--- a/clutter/clutter/clutter-event.h
+++ b/clutter/clutter/clutter-event.h
@@ -561,6 +561,7 @@ struct _ClutterIMEvent
char *text;
int32_t offset;
uint32_t len;
+ ClutterPreeditResetMode mode;
};
/**
diff --git a/clutter/clutter/clutter-input-focus.c b/clutter/clutter/clutter-input-focus.c
index 005e441e9f..0b5903986e 100644
--- a/clutter/clutter/clutter-input-focus.c
+++ b/clutter/clutter/clutter-input-focus.c
@@ -30,6 +30,8 @@ typedef struct _ClutterInputFocusPrivate ClutterInputFocusPrivate;
struct _ClutterInputFocusPrivate
{
ClutterInputMethod *im;
+ gchar *preedit;
+ ClutterPreeditResetMode mode;
};
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ClutterInputFocus, clutter_input_focus, G_TYPE_OBJECT)
@@ -85,6 +87,14 @@ clutter_input_focus_reset (ClutterInputFocus *focus)
priv = clutter_input_focus_get_instance_private (focus);
+ if (priv->preedit &&
+ priv->mode == CLUTTER_PREEDIT_RESET_COMMIT)
+ clutter_input_focus_commit (focus, priv->preedit);
+
+ clutter_input_focus_set_preedit_text (focus, NULL, 0);
+ g_clear_pointer (&priv->preedit, g_free);
+ priv->mode = CLUTTER_PREEDIT_RESET_CLEAR;
+
clutter_input_method_reset (priv->im);
}
@@ -175,6 +185,9 @@ clutter_input_focus_filter_event (ClutterInputFocus *focus,
}
else if (event->type == CLUTTER_IM_PREEDIT)
{
+ g_clear_pointer (&priv->preedit, g_free);
+ 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);
return TRUE;
diff --git a/clutter/clutter/clutter-input-method.c b/clutter/clutter/clutter-input-method.c
index ff62925a51..f193af54a7 100644
--- a/clutter/clutter/clutter-input-method.c
+++ b/clutter/clutter/clutter-input-method.c
@@ -278,11 +278,12 @@ clutter_input_method_get_focus (ClutterInputMethod *im)
}
static void
-clutter_input_method_put_im_event (ClutterInputMethod *im,
- ClutterEventType event_type,
- const char *text,
- int32_t offset,
- uint32_t len)
+clutter_input_method_put_im_event (ClutterInputMethod *im,
+ ClutterEventType event_type,
+ const char *text,
+ int32_t offset,
+ uint32_t len,
+ ClutterPreeditResetMode mode)
{
ClutterInputDevice *keyboard;
ClutterSeat *seat;
@@ -299,6 +300,7 @@ clutter_input_method_put_im_event (ClutterInputMethod *im,
event->im.text = g_strdup (text);
event->im.offset = offset;
event->im.len = len;
+ event->im.mode = mode;
clutter_event_set_device (event, keyboard);
clutter_event_set_source_device (event, keyboard);
clutter_event_set_flags (event, CLUTTER_EVENT_FLAG_INPUT_METHOD);
@@ -315,7 +317,7 @@ clutter_input_method_commit (ClutterInputMethod *im,
{
g_return_if_fail (CLUTTER_IS_INPUT_METHOD (im));
- clutter_input_method_put_im_event (im, CLUTTER_IM_COMMIT, text, 0, 0);
+ clutter_input_method_put_im_event (im, CLUTTER_IM_COMMIT, text, 0, 0, 0);
}
void
@@ -325,7 +327,7 @@ clutter_input_method_delete_surrounding (ClutterInputMethod *im,
{
g_return_if_fail (CLUTTER_IS_INPUT_METHOD (im));
- clutter_input_method_put_im_event (im, CLUTTER_IM_DELETE, NULL, offset, len);
+ clutter_input_method_put_im_event (im, CLUTTER_IM_DELETE, NULL, offset, len, 0);
}
void
@@ -349,13 +351,14 @@ clutter_input_method_request_surrounding (ClutterInputMethod *im)
* Sets the preedit text on the current input focus.
**/
void
-clutter_input_method_set_preedit_text (ClutterInputMethod *im,
- const gchar *preedit,
- guint cursor)
+clutter_input_method_set_preedit_text (ClutterInputMethod *im,
+ const gchar *preedit,
+ guint cursor,
+ ClutterPreeditResetMode mode)
{
g_return_if_fail (CLUTTER_IS_INPUT_METHOD (im));
- clutter_input_method_put_im_event (im, CLUTTER_IM_PREEDIT, preedit, cursor, 0);
+ clutter_input_method_put_im_event (im, CLUTTER_IM_PREEDIT, preedit, cursor, 0, mode);
}
void
diff --git a/clutter/clutter/clutter-input-method.h b/clutter/clutter/clutter-input-method.h
index b7f9a474e1..10faa6cb32 100644
--- a/clutter/clutter/clutter-input-method.h
+++ b/clutter/clutter/clutter-input-method.h
@@ -74,9 +74,10 @@ CLUTTER_EXPORT
void clutter_input_method_request_surrounding (ClutterInputMethod *im);
CLUTTER_EXPORT
-void clutter_input_method_set_preedit_text (ClutterInputMethod *im,
- const gchar *preedit,
- guint cursor);
+void clutter_input_method_set_preedit_text (ClutterInputMethod *im,
+ const gchar *preedit,
+ guint cursor,
+ ClutterPreeditResetMode mode);
CLUTTER_EXPORT
void clutter_input_method_notify_key_event (ClutterInputMethod *im,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]