From b3a916e474c87a905d83c4de54a9abf22b016bf0 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Thu, 6 Aug 2020 15:39:40 +0800 Subject: [PATCH 1/2] wayland/text-input: Support ibus update_preedit_string_with_mode feature --- clutter/clutter/clutter-event.h | 2 ++ clutter/clutter/clutter-input-focus-private.h | 4 +++ clutter/clutter/clutter-input-focus.c | 16 +++++++-- clutter/clutter/clutter-input-focus.h | 4 +++ clutter/clutter/clutter-input-method.c | 28 ++++++++++++--- clutter/clutter/clutter-input-method.h | 6 ++++ src/wayland/meta-wayland-text-input.c | 35 +++++++++++++++++-- 7 files changed, 85 insertions(+), 10 deletions(-) diff --git a/clutter/clutter/clutter-event.h b/clutter/clutter/clutter-event.h index e65463c65..7a2045fba 100644 --- a/clutter/clutter/clutter-event.h +++ b/clutter/clutter/clutter-event.h @@ -556,6 +556,8 @@ struct _ClutterIMEvent char *text; int32_t offset; uint32_t len; + /* preedit_commit_mode */ + uint32_t mode; }; /** diff --git a/clutter/clutter/clutter-input-focus-private.h b/clutter/clutter/clutter-input-focus-private.h index ccde45d0e..eb3ae4993 100644 --- a/clutter/clutter/clutter-input-focus-private.h +++ b/clutter/clutter/clutter-input-focus-private.h @@ -36,5 +36,9 @@ void clutter_input_focus_request_surrounding (ClutterInputFocus *focus); void clutter_input_focus_set_preedit_text (ClutterInputFocus *focus, const gchar *preedit, guint cursor); +void clutter_input_focus_set_preedit_text_with_mode (ClutterInputFocus *focus, + const gchar *preedit, + guint cursor, + guint mode); #endif /* __CLUTTER_INPUT_FOCUS_PRIVATE_H__ */ diff --git a/clutter/clutter/clutter-input-focus.c b/clutter/clutter/clutter-input-focus.c index 2aea51e24..010e000b9 100644 --- a/clutter/clutter/clutter-input-focus.c +++ b/clutter/clutter/clutter-input-focus.c @@ -175,8 +175,9 @@ clutter_input_focus_filter_event (ClutterInputFocus *focus, } else if (event->type == CLUTTER_IM_PREEDIT) { - clutter_input_focus_set_preedit_text (focus, event->im.text, - event->im.offset); + clutter_input_focus_set_preedit_text_with_mode (focus, event->im.text, + event->im.offset, + event->im.mode); return TRUE; } @@ -260,8 +261,17 @@ void clutter_input_focus_set_preedit_text (ClutterInputFocus *focus, const gchar *preedit, guint cursor) +{ + clutter_input_focus_set_preedit_text_with_mode (focus, preedit, cursor, 0); +} + +void +clutter_input_focus_set_preedit_text_with_mode (ClutterInputFocus *focus, + const gchar *preedit, + guint cursor, + guint mode) { 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_with_mode (focus, preedit, cursor, mode); } diff --git a/clutter/clutter/clutter-input-focus.h b/clutter/clutter/clutter-input-focus.h index 77f5d9076..4c12570e0 100644 --- a/clutter/clutter/clutter-input-focus.h +++ b/clutter/clutter/clutter-input-focus.h @@ -49,6 +49,10 @@ struct _ClutterInputFocusClass void (* set_preedit_text) (ClutterInputFocus *focus, const gchar *preedit, guint cursor); + void (* set_preedit_text_with_mode) (ClutterInputFocus *focus, + const gchar *preedit, + guint cursor, + guint mode); }; CLUTTER_EXPORT diff --git a/clutter/clutter/clutter-input-method.c b/clutter/clutter/clutter-input-method.c index 69d72f3de..6fe34ceaf 100644 --- a/clutter/clutter/clutter-input-method.c +++ b/clutter/clutter/clutter-input-method.c @@ -282,7 +282,8 @@ clutter_input_method_put_im_event (ClutterInputMethod *im, ClutterEventType event_type, const gchar *text, int32_t offset, - uint32_t len) + uint32_t len, + uint32_t 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 @@ -352,10 +354,28 @@ void clutter_input_method_set_preedit_text (ClutterInputMethod *im, const gchar *preedit, guint cursor) +{ + clutter_input_method_set_preedit_text_with_mode (im, preedit, cursor, 0); +} + +/** + * clutter_input_method_set_preedit_text_with_mode: + * @im: a #ClutterInputMethod + * @preedit: (nullable): the preedit text, or %NULL + * @cursor: the cursor + * @mode: the commit mode + * + * Sets the preedit with commit mode on the current input focus. + **/ +void +clutter_input_method_set_preedit_text_with_mode (ClutterInputMethod *im, + const gchar *preedit, + guint cursor, + guint 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 b7f9a474e..82742e80d 100644 --- a/clutter/clutter/clutter-input-method.h +++ b/clutter/clutter/clutter-input-method.h @@ -78,6 +78,12 @@ void clutter_input_method_set_preedit_text (ClutterInputMethod *im, const gchar *preedit, guint cursor); +CLUTTER_EXPORT +void clutter_input_method_set_preedit_text_with_mode (ClutterInputMethod *im, + const gchar *preedit, + guint cursor, + guint mode); + CLUTTER_EXPORT void clutter_input_method_notify_key_event (ClutterInputMethod *im, const ClutterEvent *event, diff --git a/src/wayland/meta-wayland-text-input.c b/src/wayland/meta-wayland-text-input.c index d4c377b73..739ffd62a 100644 --- a/src/wayland/meta-wayland-text-input.c +++ b/src/wayland/meta-wayland-text-input.c @@ -41,6 +41,7 @@ typedef enum META_WAYLAND_PENDING_STATE_SURROUNDING_TEXT = 1 << 2, META_WAYLAND_PENDING_STATE_CHANGE_CAUSE = 1 << 3, META_WAYLAND_PENDING_STATE_ENABLED = 1 << 4, + META_WAYLAND_PENDING_STATE_RESET = 1 << 5, } MetaWaylandTextInputPendingState; typedef struct _MetaWaylandTextInput MetaWaylandTextInput; @@ -221,6 +222,7 @@ meta_wayland_text_input_focus_commit_text (ClutterInputFocus *focus, wl_resource_for_each (resource, &text_input->focus_resource_list) { zwp_text_input_v3_send_preedit_string (resource, NULL, 0, 0); + zwp_text_input_v3_send_preedit_commit_mode (resource, ZWP_TEXT_INPUT_V3_COMMIT_MODE_CLEAR); zwp_text_input_v3_send_commit_string (resource, text); } @@ -228,9 +230,10 @@ 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) +meta_wayland_text_input_focus_set_preedit_text_with_mode (ClutterInputFocus *focus, + const gchar *text, + guint cursor, + guint mode) { MetaWaylandTextInput *text_input; struct wl_resource *resource; @@ -244,11 +247,20 @@ meta_wayland_text_input_focus_set_preedit_text (ClutterInputFocus *focus, wl_resource_for_each (resource, &text_input->focus_resource_list) { zwp_text_input_v3_send_preedit_string (resource, text, pos, pos); + zwp_text_input_v3_send_preedit_commit_mode (resource, mode); } meta_wayland_text_input_focus_defer_done (focus); } +static void +meta_wayland_text_input_focus_set_preedit_text (ClutterInputFocus *focus, + const gchar *text, + guint cursor) +{ + meta_wayland_text_input_focus_set_preedit_text_with_mode (focus, text, cursor, ZWP_TEXT_INPUT_V3_COMMIT_MODE_CLEAR); +} + static void meta_wayland_text_input_focus_class_init (MetaWaylandTextInputFocusClass *klass) { @@ -258,6 +270,7 @@ meta_wayland_text_input_focus_class_init (MetaWaylandTextInputFocusClass *klass) focus_class->delete_surrounding = meta_wayland_text_input_focus_delete_surrounding; focus_class->commit_text = meta_wayland_text_input_focus_commit_text; focus_class->set_preedit_text = meta_wayland_text_input_focus_set_preedit_text; + focus_class->set_preedit_text_with_mode = meta_wayland_text_input_focus_set_preedit_text_with_mode; } static void @@ -393,6 +406,17 @@ text_input_enable (struct wl_client *client, { MetaWaylandTextInput *text_input = wl_resource_get_user_data (resource); + /* check whether this is the disable/enable/commit sequence. + if so, then send the reset request. */ + + if (text_input->pending_state & META_WAYLAND_PENDING_STATE_ENABLED && + !text_input->enabled) + { + text_input->pending_state &= ~META_WAYLAND_PENDING_STATE_ENABLED; + text_input->pending_state |= META_WAYLAND_PENDING_STATE_RESET; + return; + } + text_input->enabled = TRUE; text_input->pending_state |= META_WAYLAND_PENDING_STATE_ENABLED; } @@ -621,6 +645,11 @@ text_input_commit_state (struct wl_client *client, &cursor_rect); } + if (text_input->pending_state & META_WAYLAND_PENDING_STATE_RESET) + { + clutter_input_focus_reset (text_input->input_focus); + } + meta_wayland_text_input_reset (text_input); if (enable_panel) -- 2.26.2 From 0deaeff80026f46e72617174f619400958bef630 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 3 Aug 2020 18:31:41 +0800 Subject: [PATCH 2/2] wayland/text-input: Support ibus update_preedit_string_with_mode in ClutterText --- clutter/clutter/clutter-text.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c index 3da410f2b..b85326a9c 100644 --- a/clutter/clutter/clutter-text.c +++ b/clutter/clutter/clutter-text.c @@ -383,9 +383,10 @@ 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) +clutter_text_input_focus_set_preedit_text_with_mode (ClutterInputFocus *focus, + const gchar *preedit_text, + guint cursor_pos, + guint mode) { ClutterText *clutter_text = CLUTTER_TEXT_INPUT_FOCUS (focus)->text; @@ -402,6 +403,16 @@ clutter_text_input_focus_set_preedit_text (ClutterInputFocus *focus, } } +static void +clutter_text_input_focus_set_preedit_text (ClutterInputFocus *focus, + const gchar *preedit_text, + guint cursor_pos) +{ + clutter_text_input_focus_set_preedit_text_with_mode (focus, + preedit_text, + cursor_pos, 0); +} + static void clutter_text_input_focus_class_init (ClutterTextInputFocusClass *klass) { @@ -411,6 +422,7 @@ clutter_text_input_focus_class_init (ClutterTextInputFocusClass *klass) focus_class->delete_surrounding = clutter_text_input_focus_delete_surrounding; focus_class->commit_text = clutter_text_input_focus_commit_text; focus_class->set_preedit_text = clutter_text_input_focus_set_preedit_text; + focus_class->set_preedit_text_with_mode = clutter_text_input_focus_set_preedit_text_with_mode; } static void -- 2.26.2