Ui, main: the input method, the app id, and touch through the pointer path

With the Crafter.Graphics branch delivering touch (the first finger as the
pointer), zwp_text_input_v3 and xdg app ids, the app:
- sets its app id on the window;
- tells the compositor which field has the focus and where its caret is,
  after every frame that changed it: the number field at once (purpose
  phone), the message field on a tap or a key; a sheet or leaving the
  screen takes it back;
- shows the input method's composing text in the accent colour at the
  cursor, each run placed at the advance the one before it was drawn
  with, applies its deletions by code point and leaves the composing
  text to the input method, and takes its committed text as typed (the
  composing text and its deletions are the core's Edit, in tests/Edit; a
  draft kept for a conversation that is left keeps a word still being
  composed as text); a tap inside the composing text leaves the cursor
  where it is, a tap elsewhere in the field commits the word where it
  was typed and resets the input method, as Send does, so the half-typed
  word does not move to the tap; a sheet, a hide and leaving a screen by
  Open (over the number screen or over another conversation), by Back or
  by the + end the composition the same way and at once (EndComposition:
  the word committed, the input method told), since the input method
  starts afresh after, and left on until the next frame it would send
  its next commit to the screen that opens or have it dropped. The
  message field starts unfocused, as on a phone, and the caret blinks
  only in a focused field;
- sends what the field shows: Send, like Start, reads the shown text
  once, the composing word included, and clears the field only once the
  store took it (a field of nothing but spaces and line breaks is
  cleared with nothing sent); the field keeps the focus while the input
  method is reset (disabled, enabled again the next frame) — a refused
  text leaves the field and the composing word as they are; Start reads
  the shown text once — the key and the address dialled come from it —
  so a refused number leaves the composing word to the input method;
- logs the window's size on every resize, and which conversation was
  opened — under --headless; a plain start names no correspondent in its
  log, as the rest of the app does not.
Touch takes the mouse's gesture path, and a touch the compositor cancels
(a gesture of its own) arrives as a release without the finger's
touch-up: it is fed to the gestures as a cancel, so it taps nothing.

Tested: tests/Edit (the composing text kept by a deletion, and put into
the field's text by ComposeCommitPreedit).
This commit is contained in:
Jorijn van der Graaf 2026-10-18 02:30:01 +02:00
commit f93144ae2f
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
7 changed files with 325 additions and 66 deletions

View file

@ -2,7 +2,8 @@
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
// The message field's editing by code point: one to four bytes of UTF-8,
// and the lines of a text with newlines.
// the lines of a text with newlines, and the input method's composing
// text and deletions.
import std;
import ImsdMessages;
using namespace ImsdMessages;
@ -89,6 +90,37 @@ int main() {
Check(s.cursor == 3, "an insert moves the cursor past its bytes");
CheckEqual(s.value, "aéb", "the text after an insert");
// The input method's composing text: shown at the cursor, not in the value.
s = At("hello", 2);
s.preedit = "XY";
CheckEqual(ComposeShown(s), "heXYllo", "the composing text shows at the cursor");
Check(ShownCursor(s) == 4, "the shown cursor follows the composing text");
// Its deletions: byte counts around the cursor, rounded out to code points.
s = At(mixed, 6);
s.preedit = "z";
ComposeDeleteAround(s, 1, 1);
Check(s.cursor == 3 && s.preedit == "z", "one byte each side takes the € before and the 😀 after; the composing text stays");
CheckEqual(s.value, "a\u00e9", "what is left after the deletion");
s = At("abc", 1);
ComposeDeleteAround(s, 5, 0);
Check(s.cursor == 0, "a deletion past the start stops at the start");
CheckEqual(s.value, "bc", "what is left after it");
s = At("abc", 2);
ComposeDeleteAround(s, 0, 0);
Check(s.cursor == 2 && s.value == "abc", "a deletion of nothing leaves the text");
// The composition ends into the field when the text input goes off
// (a sheet, a tap elsewhere): the word as shown.
s = At("hello wor", 9);
s.preedit = "ld";
ComposeCommitPreedit(s);
Check(s.cursor == 11 && s.preedit.empty(), "committing the composing text moves the cursor past it");
CheckEqual(s.value, "hello world", "and puts it into the value");
s = At("a", 0);
ComposeCommitPreedit(s);
Check(s.value == "a" && s.cursor == 0, "with no composing text nothing changes");
// A tap at or past a line's end: the text's end on the last line, the
// newline after a hung space before a hard break, the line's end at a
// soft wrap (the lines as tests/Wrap pins them, 10 px a glyph, 50 px wide).
@ -140,6 +172,12 @@ int main() {
drafts.Drop("+31612345678");
drafts.Drop("no such conversation");
Check(drafts.Size() == 0, "a deleted conversation's draft goes with it");
ComposeState composing;
ComposeInsert(composing, "hello ");
composing.preedit = "wor";
drafts.Keep("1234", composing);
const ComposeState kept = drafts.Take("1234");
Check(kept.value == "hello wor" && kept.preedit.empty() && kept.cursor == 9, "a word still being composed is kept as text");
}
// A kept typed address follows imsd's status as an open conversation's
// key does: typed before the country code was known, found after.