Ui, Edit: a keyboard sent away stays away until the field is tapped
All checks were successful
Flatpak / check (push) Has been skipped
Flatpak / publish (push) Successful in 4m15s

On Plasma Mobile the on-screen keyboard came straight back after its own
hide key. The key makes the compositor give the keyboard's room back:
the window grows, the message field moves down with the window's lower
edge, and UpdateTextInput told the compositor the caret's new place, as
it does after every frame in which the caret moved. No focus had changed
and no enable went out again (the library sends one per focus); 120 ms
after that state was committed the keyboard was back, nothing else
having been sent.

A caret that only followed the window's growth is no longer told at
once: its box as it was, lower by what the window gained
(CaretFollowedGrowth, in Edit with its tests). It is told with the next
thing that is — a key that moves the caret, the field's tap — and a
window that shrinks back makes the old place true again. The compositor
keeps the old place meanwhile, which lies inside the taller window.

With that telling gone nothing would bring the keyboard back, so a tap
on a field that kept the focus while the window grew asks for it
(AskKeyboard): the text input goes off, the composing word going into
the field as at any reset, and the next frame turns it on again, which
is the request a compositor shows its keyboard for. A tap with the
keyboard up places the cursor as before. The number field of the
new-conversation screen takes the same tap.

Tested: tests/Edit (a caret lower by the window's growth, and one within
a pixel of that; and what is still told: a caret that stayed, one that
moved along its line or by another amount, a window as tall as it was or
lower, a box of another size). On a Fairphone 6 (Plasma Mobile 6.8.2,
plasma-keyboard 6.8.2), by the protocol's trace (WAYLAND_DEBUG): before,
the hide key's resize is followed by set_cursor_rectangle and commit,
and by the keyboard's resize 120 ms after them; with this, nothing is
sent after the hide key's resize and the keyboard stays away, and a tap
on the field sends disable, then enable with the caret's place, the
keyboard is back 85 ms later, and typing goes on. The number field's tap
was not tried on the phone, and no bench on the workstation has an
on-screen keyboard.
This commit is contained in:
Jorijn van der Graaf 2026-11-18 04:20:42 +01:00
commit ca5cd72d65
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
3 changed files with 71 additions and 2 deletions

View file

@ -86,6 +86,7 @@ export namespace ImsdMessages::Ui {
hitMessages.clear();
textSinceFrame.clear();
frameFailed = false;
keyboardGone = false;
}
static gboolean OnHideIdle(gpointer data) {
@ -852,20 +853,34 @@ export namespace ImsdMessages::Ui {
// Tells the compositor which field has the focus and where its caret
// is, after every frame, when that changed: the number field at once,
// the message field after a tap or a key; a sheet or leaving the
// screen takes it back.
// screen takes it back. A window taller than at the last telling has
// lost its on-screen keyboard (the keyboard's own hide key: the
// compositor gives the room back), and a caret that only followed
// that growth is not told (Edit's CaretFollowedGrowth): the telling
// would bring the keyboard straight back. A tap on the field asks
// for it (AskKeyboard).
void UpdateTextInput() {
TextInputState want;
if (!sheet) {
if (fresh) want = { true, fresh->fieldLayout.caret, Crafter::TextInputPurpose::Phone };
else if (view && view->compose.focused) want = { true, view->composeLayout.caret, Crafter::TextInputPurpose::Normal };
}
const float height = static_cast<float>(canvas->Window().height);
const bool sameCaret = want.caret.x == lastTextInput.caret.x && want.caret.y == lastTextInput.caret.y && want.caret.w == lastTextInput.caret.w && want.caret.h == lastTextInput.caret.h;
if (want.active == lastTextInput.active && want.purpose == lastTextInput.purpose && (!want.active || sameCaret)) return;
if (want.active == lastTextInput.active && want.purpose == lastTextInput.purpose) {
if (!want.active) return;
if (height < toldHeight) toldHeight = height; // the keyboard is up, or up again
keyboardGone = height > toldHeight;
if (sameCaret) return;
if (CaretFollowedGrowth({ lastTextInput.caret.x, lastTextInput.caret.y, lastTextInput.caret.w, lastTextInput.caret.h, toldHeight }, { want.caret.x, want.caret.y, want.caret.w, want.caret.h, height })) return;
}
if (want.active != lastTextInput.active) Log(want.active ? (want.purpose == Crafter::TextInputPurpose::Phone ? "text input on (a number)" : "text input on") : "text input off");
// Turning the input off ends the composition on the input
// method's side; the field keeps the word it showed.
if (!want.active && lastTextInput.active) CommitComposition();
lastTextInput = want;
toldHeight = height;
keyboardGone = false;
canvas->Window().SetTextInput(want.active, static_cast<std::int32_t>(want.caret.x), static_cast<std::int32_t>(want.caret.y), static_cast<std::int32_t>(want.caret.w), static_cast<std::int32_t>(want.caret.h), want.purpose);
}
@ -1043,6 +1058,17 @@ export namespace ImsdMessages::Ui {
lastTextInput = {};
}
// A tap on a field that kept the focus while its keyboard went
// (UpdateTextInput saw the window grow) asks for the keyboard again:
// the text input goes off now and the next frame turns it on, which
// is the request a compositor shows its keyboard for. With the
// keyboard up a tap only places the cursor.
void AskKeyboard() {
if (!keyboardGone) return;
keyboardGone = false;
EndComposition();
}
// The caret shows at once after an edit and blinks from there while a
// field has the focus and the window is up (without one nothing
// draws it; Show starts the blink again).
@ -1148,11 +1174,13 @@ export namespace ImsdMessages::Ui {
} else if (*id == Hit::newField) {
if (!fresh) return;
TapField(fresh->field, fresh->fieldLayout, at);
AskKeyboard();
ShowCaret();
} else if (*id == Hit::compose) {
if (!view) return;
view->compose.focused = true;
TapField(view->compose, view->composeLayout, at);
AskKeyboard();
ShowCaret();
} else if (*id == Hit::send) {
SendDraft();
@ -1237,6 +1265,8 @@ export namespace ImsdMessages::Ui {
std::optional<Crafter::EventListener<const std::string_view>> preeditSub;
std::optional<Crafter::EventListener<Crafter::TextDelete>> deleteSub;
TextInputState lastTextInput;
float toldHeight = 0; // the window's height when the compositor was last told of the text input: lower since, the keyboard is up
bool keyboardGone = false; // the window is taller than that: the keyboard gave its room back while the field kept the focus (UpdateTextInput)
std::optional<Crafter::EventListener<void>> resizeSub;
std::optional<Crafter::EventListener<void>> closeSub;
std::optional<Crafter::EventListener<void>> seenSub;