[mutter] clutter: Enable negative offsets in delete surrounding text
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] clutter: Enable negative offsets in delete surrounding text
- Date: Sun, 29 Mar 2020 11:49:14 +0000 (UTC)
commit 2cfdbbd7305ff0bf06064538533b598292758c81
Author: Takao Fujiwara <tfujiwar redhat com>
Date: Thu Aug 15 18:47:03 2019 +0900
clutter: Enable negative offsets in delete surrounding text
The input method can assign a negative value to
clutter_input_method_delete_surrounding() to move the cursor to the left.
But Wayland protocol accepts positive values in delete_surrounding() and
GTK converts the values to the negative ones in
text_input_delete_surrounding_text_apply().
https://gitlab.gnome.org/GNOME/mutter/issues/539
clutter/clutter/clutter-input-focus-private.h | 2 +-
clutter/clutter/clutter-input-focus.c | 2 +-
clutter/clutter/clutter-input-focus.h | 2 +-
clutter/clutter/clutter-input-method.c | 4 ++--
clutter/clutter/clutter-input-method.h | 2 +-
clutter/clutter/clutter-text.c | 14 ++++++++++++--
src/wayland/meta-wayland-text-input-legacy.c | 10 ++++++++--
src/wayland/meta-wayland-text-input.c | 10 ++++++++--
8 files changed, 34 insertions(+), 12 deletions(-)
---
diff --git a/clutter/clutter/clutter-input-focus-private.h b/clutter/clutter/clutter-input-focus-private.h
index 563e58978..ccde45d0e 100644
--- a/clutter/clutter/clutter-input-focus-private.h
+++ b/clutter/clutter/clutter-input-focus-private.h
@@ -29,7 +29,7 @@ void clutter_input_focus_focus_out (ClutterInputFocus *focus);
void clutter_input_focus_commit (ClutterInputFocus *focus,
const gchar *text);
void clutter_input_focus_delete_surrounding (ClutterInputFocus *focus,
- guint offset,
+ int offset,
guint len);
void clutter_input_focus_request_surrounding (ClutterInputFocus *focus);
diff --git a/clutter/clutter/clutter-input-focus.c b/clutter/clutter/clutter-input-focus.c
index 7a004f259..ece1fa59a 100644
--- a/clutter/clutter/clutter-input-focus.c
+++ b/clutter/clutter/clutter-input-focus.c
@@ -217,7 +217,7 @@ clutter_input_focus_commit (ClutterInputFocus *focus,
void
clutter_input_focus_delete_surrounding (ClutterInputFocus *focus,
- guint offset,
+ int offset,
guint len)
{
g_return_if_fail (CLUTTER_IS_INPUT_FOCUS (focus));
diff --git a/clutter/clutter/clutter-input-focus.h b/clutter/clutter/clutter-input-focus.h
index 65736a799..008883af6 100644
--- a/clutter/clutter/clutter-input-focus.h
+++ b/clutter/clutter/clutter-input-focus.h
@@ -41,7 +41,7 @@ struct _ClutterInputFocusClass
void (* request_surrounding) (ClutterInputFocus *focus);
void (* delete_surrounding) (ClutterInputFocus *focus,
- guint offset,
+ int offset,
guint len);
void (* commit_text) (ClutterInputFocus *focus,
const gchar *text);
diff --git a/clutter/clutter/clutter-input-method.c b/clutter/clutter/clutter-input-method.c
index 4bf1b0ec8..031b103df 100644
--- a/clutter/clutter/clutter-input-method.c
+++ b/clutter/clutter/clutter-input-method.c
@@ -168,7 +168,7 @@ clutter_input_method_class_init (ClutterInputMethodClass *klass)
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
- G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
+ G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_UINT);
signals[REQUEST_SURROUNDING] =
g_signal_new ("request-surrounding",
G_TYPE_FROM_CLASS (object_class),
@@ -292,7 +292,7 @@ clutter_input_method_commit (ClutterInputMethod *im,
void
clutter_input_method_delete_surrounding (ClutterInputMethod *im,
- guint offset,
+ int offset,
guint len)
{
ClutterInputMethodPrivate *priv;
diff --git a/clutter/clutter/clutter-input-method.h b/clutter/clutter/clutter-input-method.h
index 92f960f0a..b7f9a474e 100644
--- a/clutter/clutter/clutter-input-method.h
+++ b/clutter/clutter/clutter-input-method.h
@@ -68,7 +68,7 @@ void clutter_input_method_commit (ClutterInputMethod *im,
const gchar *text);
CLUTTER_EXPORT
void clutter_input_method_delete_surrounding (ClutterInputMethod *im,
- guint offset,
+ int offset,
guint len);
CLUTTER_EXPORT
void clutter_input_method_request_surrounding (ClutterInputMethod *im);
diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c
index 8efbfa07c..e1947c437 100644
--- a/clutter/clutter/clutter-text.c
+++ b/clutter/clutter/clutter-text.c
@@ -348,13 +348,23 @@ clutter_text_input_focus_request_surrounding (ClutterInputFocus *focus)
static void
clutter_text_input_focus_delete_surrounding (ClutterInputFocus *focus,
- guint offset,
+ int offset,
guint len)
{
ClutterText *clutter_text = CLUTTER_TEXT_INPUT_FOCUS (focus)->text;
+ int cursor;
+ int start;
+ cursor = clutter_text_get_cursor_position (clutter_text);
+ start = cursor + offset;
+ if (start < 0)
+ {
+ g_warning ("The offset '%d' of deleting surrounding is larger than the cursor pos '%d'",
+ offset, cursor);
+ return;
+ }
if (clutter_text_get_editable (clutter_text))
- clutter_text_delete_text (clutter_text, offset, len);
+ clutter_text_delete_text (clutter_text, start, len);
}
static void
diff --git a/src/wayland/meta-wayland-text-input-legacy.c b/src/wayland/meta-wayland-text-input-legacy.c
index 3ad48988a..3b5624c36 100644
--- a/src/wayland/meta-wayland-text-input-legacy.c
+++ b/src/wayland/meta-wayland-text-input-legacy.c
@@ -94,17 +94,23 @@ meta_wayland_text_input_focus_request_surrounding (ClutterInputFocus *focus)
static void
meta_wayland_text_input_focus_delete_surrounding (ClutterInputFocus *focus,
- guint cursor,
+ int offset,
guint len)
{
MetaWaylandGtkTextInput *text_input;
+ uint32_t before_length;
+ uint32_t after_length;
struct wl_resource *resource;
text_input = META_WAYLAND_GTK_TEXT_INPUT_FOCUS (focus)->text_input;
+ before_length = offset <= 0 ? -offset : offset;
+ after_length = len >= before_length ? (len - before_length) : len + before_length;
wl_resource_for_each (resource, &text_input->focus_resource_list)
{
- gtk_text_input_send_delete_surrounding_text (resource, cursor, len);
+ gtk_text_input_send_delete_surrounding_text (resource,
+ before_length,
+ after_length);
}
}
diff --git a/src/wayland/meta-wayland-text-input.c b/src/wayland/meta-wayland-text-input.c
index 4e7d18b25..13a9741c7 100644
--- a/src/wayland/meta-wayland-text-input.c
+++ b/src/wayland/meta-wayland-text-input.c
@@ -166,17 +166,23 @@ meta_wayland_text_input_focus_defer_done (ClutterInputFocus *focus)
static void
meta_wayland_text_input_focus_delete_surrounding (ClutterInputFocus *focus,
- guint cursor,
+ int offset,
guint len)
{
MetaWaylandTextInput *text_input;
+ uint32_t before_length;
+ uint32_t after_length;
struct wl_resource *resource;
text_input = META_WAYLAND_TEXT_INPUT_FOCUS (focus)->text_input;
+ before_length = offset <= 0 ? -offset : offset;
+ after_length = len >= before_length ? (len - before_length) : len + before_length;
wl_resource_for_each (resource, &text_input->focus_resource_list)
{
- zwp_text_input_v3_send_delete_surrounding_text (resource, cursor, len);
+ zwp_text_input_v3_send_delete_surrounding_text (resource,
+ before_length,
+ after_length);
}
meta_wayland_text_input_focus_defer_done (focus);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]