summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2020-03-27 17:01:17 +0100
committerCarlos Garnacho <mrgarnacho@gmail.com>2020-03-29 11:37:27 +0000
commitbb5ea0580ffab97dd3ede3e7e4af8bc19a316230 (patch)
treee08697e18e97c0602e94127653be514d8138c12c
parent2cfdbbd7305ff0bf06064538533b598292758c81 (diff)
downloadmutter-bb5ea0580ffab97dd3ede3e7e4af8bc19a316230.tar.gz
wayland: Translate delete-surrounding properly to protocols
IBusInputContext/ClutterInputFocus/GtkIMContext all go for offset+len for their ::delete-surrounding signals, with offset being a signed int (neg. to delete towards left of selection, pos. to delete towards right of selection) and len being an unsigned int from the offset (and presumably, skipping the current selection). The text-input protocols however pass in this event two unsigned integers, one being the length of text to delete towards the left of the selection, and another the length of text to delete towards the right of the selection. To translate properly these semantics, positive offsets shouldn't account for before_length, and negative offset+len shouldn't account for after_length. The offset/length approach may of course represent deletions that are detached from the current cursor/selection, we simply delete the whole range from the cursor/selection positions then. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/517
-rw-r--r--src/wayland/meta-wayland-text-input-legacy.c5
-rw-r--r--src/wayland/meta-wayland-text-input.c5
2 files changed, 6 insertions, 4 deletions
diff --git a/src/wayland/meta-wayland-text-input-legacy.c b/src/wayland/meta-wayland-text-input-legacy.c
index 3b5624c36..d8f7d1d82 100644
--- a/src/wayland/meta-wayland-text-input-legacy.c
+++ b/src/wayland/meta-wayland-text-input-legacy.c
@@ -103,8 +103,9 @@ meta_wayland_text_input_focus_delete_surrounding (ClutterInputFocus *focus,
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;
+ before_length = ABS (MIN (offset, 0));
+ after_length = MAX (0, offset + len);
+ g_warn_if_fail (ABS (offset) <= len);
wl_resource_for_each (resource, &text_input->focus_resource_list)
{
diff --git a/src/wayland/meta-wayland-text-input.c b/src/wayland/meta-wayland-text-input.c
index 13a9741c7..570dba459 100644
--- a/src/wayland/meta-wayland-text-input.c
+++ b/src/wayland/meta-wayland-text-input.c
@@ -175,8 +175,9 @@ meta_wayland_text_input_focus_delete_surrounding (ClutterInputFocus *focus,
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;
+ before_length = ABS (MIN (offset, 0));
+ after_length = MAX (0, offset + len);
+ g_warn_if_fail (ABS (offset) <= len);
wl_resource_for_each (resource, &text_input->focus_resource_list)
{