Commit Graph

60 Commits

Author SHA1 Message Date
Matthias Clasen
aa9a7a931d Merge branch 'wip/carlosg/shuffle-reset-take2' into 'main'
gtkimcontextwayland: Shuffle full resets after IM changes

Closes #5200

See merge request GNOME/gtk!5050
2022-09-28 01:39:49 +00:00
Matthias Clasen
e499a09759 Drop gtkintl.h
Include gtkprivate.h for I_() and glib-i18n.h for
gettext macros.
2022-09-24 10:03:37 -04:00
Carlos Garnacho
fb280e47d6 gtkimcontextwayland: Shuffle full resets after IM changes
Doing reset() on the text widgets after commit and delete_surrounding
is still too eager for some IMs (e.g. those that expect being able
to commit text while keeping a preedit buffer shown).

However, reset() is more of a "synchronize state" action on Wayland,
and it is still desirable to do that after changes that do come from
the IM (e.g. requesting the new surrounding text and cursor/anchor
positions). Notably here, the text_input protocol may still come up
with a preedit string after this state synchronization happens.

Shuffle the code so that the text widgets do not reset() the IM
context after text is deleted or committed, but the Wayland IM does
apply its practical effects after these actions happen. This keeps
the Wayland IM fully up-to-date wrt text widget state, while not
altering the ::commit and ::delete-surrounding-text behavior for
other IM context implementations.

Closes: https://gitlab.gnome.org/GNOME/gtk/-/issues/5200
Fixes: 5b78fe2721 (gtktextview: Also reset IM context after IM...)
Fixes: 7c0a395ff9 (gtktext: Also reset IM context after IM...)
Fixes: 52ac71b972 (gtktextview: Shuffle the places doing IM reset)
Fixes: 9e29739e66 (gtktext: Shuffle the places doing IM reset)
2022-09-24 11:52:16 +02:00
Matthias Clasen
32796cad10 Use gtk_event_controller_set_static_name
This avoids strdups.
2022-08-27 22:35:13 -04:00
Carlos Garnacho
f66ffde68d gtkimcontextwayland: Refactor handling of client updates
Currently, the wayland IM context sends zwp_text_input_v3.commit from
a number of places, and some of them with partial data. In order to
make client state updates "atomic" and complete, make the communication
happen over an unified notify_im_change() function that happens on
a narrower set of circumstances:

  - The GtkIMContext is reset
  - The GtkIMContext is just focused
  - The gesture to invoke the OSK is triggered
  - The IM context is reacting to changes coming from the compositor

Notably, setting the cursor location or the surrounding text do not try
to commit state on their own, and now will be flushed with the corresponding
IM update or reset. But also, these requests won't be prevented from
happening individually on serial mismatch, instead it will be the whole
state commit which is held off.

With these changes in place, all client-side updates are notified
atomically to the compositor under a single .commit request.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/5106
Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/5105
2022-08-18 19:19:53 +02:00
Carlos Garnacho
d6fe6f495a imcontextwayland: Ignore preedit updates from NULL to NULL
If we get consecutive preedit string updates that announce a NULL
string, we still do end up issuing ::preedit-changed with those.
Ignore changes from NULL to NULL, it is the other combinations which
must issue this signal.
2022-04-26 12:23:09 +02:00
Carlos Garnacho
eb7c78aa48 imwayland: Do not defer commit() after set_surrounding_text()
For reasons that only apply to the old serial handling, asking for
the surrounding after IM changes resulted in lazy handling of
commit() afterwards.

With the recent interpretation of serials, this problem became more
apparent, since it is in fact very likely that the last interaction
step after an IM change is notifying of the changed surrounding
text after the IM change was applied.

Make handling of surrounding text similar to caret position changes,
always commit() after the state change, but skip through non-changes.

This makes the compositor state fully up-to-date after an IM change.
2022-04-06 13:52:05 +02:00
Carlos Garnacho
7ab39b5461 imwayland: Connect OSK activating gesture to parent widget on editables
The gesture as connected currently on the child GtkText is easily overridden
by the parent editables (and gently done so in the attempt to consume all
clicks).

Connect this gesture to the parent editable widget in these cases, so the
gesture can cohabit with the click-consuming one. It's not part of the same
group, but it won't be abruptly cancelled.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/4795
2022-04-06 13:52:05 +02:00
Carlos Garnacho
581461c2b5 Merge branch 'wip/carlosg/im-wayland-serials' into 'main'
gtk/imwayland: Use serial to control outbound messages

Closes #3641

See merge request GNOME/gtk!4398
2022-03-16 18:52:24 +00:00
Carlos Garnacho
f108f053d4 gtk/imwayland: Use serial to control outbound messages
Following the text-input protocol changes at
https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/115,
use the serial number to have the client push changes to the
zwp_text_input_v3 object only after compositor/client states match.

This specifically is more lenient to compositors pushing multiple
.done events ahead of the client replying to them.

Closes: https://gitlab.gnome.org/GNOME/gtk/-/issues/3641
2022-03-16 17:38:14 +01:00
Carlos Garnacho
4dcd011486 gtkimcontextwayland: Add native surface offset to input coordinates
We were missing the surface offset (e.g. shadows) at the time of expressing
the text caret location in surface coordinates. Add this offset so the
coordinates are as expected by the compositor.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/4668
2022-03-16 09:57:42 +01:00
Guido Günther
45397534eb gtkimcontextwayland: Save context even when text_input isn't around yet
Remember the current context on focus-in even though the text-input
isn't set up yet. This helps in the case where the text-input is not yet
created but a widget already got focused. Without that the enable()
invocation in text_input_enter() woulnd't be invoked leaving the input
method disabled.

This fixes

    gtk4-demo --run=search_entry

which would initially not show the on-screen keyboard when e.g using
phoc/sway as compositor.
2022-01-19 10:20:46 +00:00
Carlos Garnacho
ce1b970b46 gtkimcontextwayland: Set a higher IO extension priority
We want this to take precedence in the wayland platform to other
modules that might be loaded via the IO extension point. None of
those is going to bode well in this platform.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/4443
2021-12-04 00:21:53 +01:00
Matthias Clasen
51f953a1aa Revert "imwayland: Tweak preedit text"
This reverts commit d84a028455.

IBus uses the same character now.

Fixes: #4123
2021-08-24 12:53:48 -04:00
Matthias Clasen
a228b2de64 imwayland: Name event controllers
This helps with debugging.
2021-04-02 22:24:00 -04:00
Matthias Clasen
35fceca157 imwayland: Pass anchor with surrounding
This was missing in the initial implementation since
GtkIMContext did not have it in its api, but it was
added now, so we can send the information.
2021-03-04 15:18:30 -05:00
Matthias Clasen
3ee5354e0f imwayland: Be careful about cursor positions
We don't want to hand out cursor positions based on
the original preedit text and then tweak the text to
be different.
2021-02-18 15:33:01 -05:00
Matthias Clasen
d84a028455 imwayland: Tweak preedit text
Tweak the preedit text we get from IBus (via the compositor) to
match what GtkIMContextSimple produces for Compose sequences now.

This provides a unified experience.
2021-02-18 11:44:09 -05:00
Matthias Clasen
da71a37945 imwayland: Return limited preedit attributes
It should not matter, but it is the right thing to
do to limit the preedit attributes to the length
of the preedit text.
2021-02-17 22:57:41 -05:00
Matthias Clasen
05fe2441a7 imcontext: Enable font fallback for preedit
Not doing so only invites hexboxes.

Fixes: #3678
2021-02-17 22:11:57 -05:00
Alexander Mikhaylenko
f63e6394ac dragsource: Use double coordinates for checking drag threshold
If multiple nested widgets have drag sources on them, both using bubble
phase, we need to reliably pick the inner one. Both of them will try to
start dragging, and we need to make sure there are no situations where the
outer widget starts drag earlier and cancels the inner one.

Currently, this can easily happen via integer rounding: start and current
coordinates passed into gtk_drag_check_threshold() are initially doubles
(other than in GtkNotebook and GtkIconView), and are casted to ints. Then
those rounded values are used to calculate deltas to compare to the drag
threshold, losing quite a lot of precision along the way, and often
resulting in the outer widget getting larger deltas.

To avoid it, just don't round it. Introduce a variant of the function that
operates on doubles: gtk_drag_check_threshold_double() and use it instead
of the original everywhere.
2021-01-29 12:01:34 +05:00
Carlos Garnacho
fa5fa3a881 gtk/imcontextwayland: Unset focus when unsetting widget
In destruction paths of a focused entry, the IM context might first
end up detached from its widget, then destroyed. This currently prevents
the IM context from detaching itself from the GtkIMContextWaylandGlobal.

Make it do so when unsetting the client widget, so the IM context gets
properly unfocused before destruction.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/3176
2020-11-05 21:29:20 +01:00
Benjamin Otte
3078b180fe Replace "gdouble" with "double" 2020-07-25 00:47:36 +02:00
Benjamin Otte
d375dce9f5 Replace "gchar" with "char" 2020-07-25 00:47:36 +02:00
Benjamin Otte
d7266b25ba Replace "gint" with "int" 2020-07-25 00:47:36 +02:00
Jehan
7ccf32db57 gtk: focus out the GtkIMContextWayland upon finalization.
In particular, it will NULL-ified the current global context if this is
the finalized one, avoiding dangling invalid pointers.

Would have been a cherry-pick from branch gtk-3-24 of commit
b592ded80a, but files moved.
2020-06-29 22:17:08 +02:00
Matthias Clasen
75d9310986 Change coordinate translation apis to take doubles
Change gtk_widget_translate_coordinates and
gtk_native_get_surface_transform to operate
on doubles. Update all callers.
2020-05-17 17:17:31 -04:00
Carlos Garnacho
e5d23aaaaf imwayland: Clamp the surrounding string end correctly
In the paths where len > MAX_LEN and cursor/anchor are separated by
at least MAX_LEN from text edges, we were clamping the right end of
the surrounding string at MAX_LEN. Oops.

This end anchor may go as far as the string length, although just
up to len - MAX_LEN in real terms (due to the condition above that
caches cursor/anchor positions being near enough the text end).

Closes: https://gitlab.gnome.org/GNOME/gtk/-/issues/2565

(cherry-picked from commit d7fb15c822)
2020-04-03 19:55:55 +02:00
Robert Mader
5343ec3345 imcontextwayland: Honour len argument in gtk_im_context_wayland_set_surrounding
Clients may pass not `NULL`-terminated strings as the function takes a
`len` argument. Use that argument.
2020-03-16 16:53:33 +01:00
Benjamin Otte
8fc360dac5 imcontextwayland: Fix copy/paste error 2020-03-05 04:03:02 +01:00
Matthias Clasen
8823882f97 gtk: Stop using GdkEventKey
We should just use GdkEvent, instead of taking
a GdkEventKey, and then cast it everywhere.
2020-02-21 00:51:03 -05:00
xdavidwu
9576222b47
imwayland: Fix get_preedit_string cursor position
GtkIMContext get_preedit_string should return cursor position counted
in characters, but cursor_begin here is counted in bytes. This add the
missing conversion.
2020-01-17 16:16:13 +08:00
Dorota Czaplejewicz
e331b39ca5 imwayland: Suppport terminal purpose 2019-12-12 14:37:51 +00:00
Matthias Clasen
7f65e5f96b Rename GtkGestureMultiPress to GtkGestureClick
The name just made it hard for people to find the
right gesture to use.
2019-05-29 17:10:46 +00:00
Matthias Clasen
7447abb52b Stop using gtk_widget_get_toplevel
All uses of it can be replaced by gtk_widget_get_root.
2019-05-28 20:25:16 +00:00
Carlos Garnacho
37d218b160 imwayland: Toggle OSK more sparingly
Specifically it is avoided to be toggled if:
- Just received focus (in order to preserve OSK state across focus changes)
- Moving cursor around. Still allow some jitter as perfect accuracy is not
  possible.

Closes: https://gitlab.gnome.org/GNOME/gtk/issues/1277
2019-02-09 01:08:35 +01:00
Benjamin Otte
c875465477 imcontextwayland: Get rid of global variable
Attach it to the GdkDisplay.
Also fixes -Wshadow complaining about "global" being shadowed.
2019-01-22 04:33:11 +01:00
Benjamin Otte
bbd1532f84 imcontext: Fix priorities of modules
All built-in backend modules get a priority of 0 because they are the
default ones.
GtkIMContextSimple gets a priority of G_MININT because it's the fallback
one.

This mirrors the media modules code.
2019-01-22 04:33:11 +01:00
Timm Bäder
f9a5a474f0 imcontextwayland: (Hopefully) fix if expression 2019-01-04 05:55:26 +01:00
Carlos Garnacho
8ce6d03c7b imwayland: Respect maximum length of 4000 Bytes on strings being sent.
Hitting the limit will raise protocol errors.
2018-12-18 20:38:44 +01:00
Carlos Garnacho
904202a636 imwayland: Plug leaks
The various strings (pending/current preedit, surrounding, and commit
buffer) are being leaked in the case of GtkIMContext destruction.
2018-12-18 20:38:44 +01:00
Dorota Czaplejewicz
7a0b6a3639 imwayland.c: fix formatting 2018-12-18 20:38:44 +01:00
Dorota Czaplejewicz
b465e04ae2 imwayland: rearrange functions to remove prototypes 2018-12-18 20:38:41 +01:00
Dorota Czaplejewicz
f67627875f imwayland: Handle enter and leave events
Before this patch, imwayland would assume that text-input enter and leave events follow the general (wl_keyboard) focus, and was unable to handle the situation where they would not be provided at the same time.
2018-12-18 20:27:12 +01:00
Carlos Garnacho
8912dc226c imwayland: Collect return value from ::delete-surrounding signal
There's not much we can do about the signal not being handled, but
we should fetch the return value anyway.
2018-12-18 20:27:12 +01:00
Dorota Czaplejewicz
12ac9f351e imwayland: Don't reset serial while text-input is alive
The serial number is a persistent property of the text-input object.
2018-12-18 20:27:12 +01:00
Dorota Czaplejewicz
c4b4e90f98 imwayland: Fix clearing of preedit text in webkitgtk
Fixes webkitgtk misbehaviour as outlined in https://gitlab.gnome.org/GNOME/gtk/issues/1316#note_312942 , which was introduced in 49b17e6c.
The preedit will be cleared on exit only if it is already present.
2018-12-18 20:27:12 +01:00
Dorota Czaplejewicz
fcf28ded42 imwayland: Fix clearing of preedit text
Fixes terminal emulator misbehaviour as outlined in https://gitlab.gnome.org/GNOME/gtk/issues/1316, which was introduced in 49b17e6c. The original commit cleared preedit text by setting it to an empty string, which still counted as existing preedit. The fix sets preedit string to null, which is correctly understood as not present.
2018-12-18 20:27:12 +01:00
Carlos Garnacho
1e69d248cb modules: Check current context before retrieving surrounding
There may be situations where this might get called while the
currently focused context just went away (eg. after setting the
text widget unsensitive).

Closes: #1317
2018-12-18 20:27:12 +01:00
Dorota Czaplejewicz
c49b29fa53 imwayland: clear preedit on focus out 2018-12-18 20:27:12 +01:00