[mutter] wayland: Translate delete-surrounding properly to protocols
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] wayland: Translate delete-surrounding properly to protocols
- Date: Sun, 29 Mar 2020 11:49:19 +0000 (UTC)
commit bb5ea0580ffab97dd3ede3e7e4af8bc19a316230
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Mar 27 17:01:17 2020 +0100
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
src/wayland/meta-wayland-text-input-legacy.c | 5 +++--
src/wayland/meta-wayland-text-input.c | 5 +++--
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)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]