Ui: the compose field and the send bar
A text message needs several lines and UTF-8, and the library's
InputField is one line edited by byte, so the field is the app's own.
Its state and editing are the core's (ImsdMessages:Edit, tested without
a window): a plain struct, insertion at the cursor, Backspace and Delete
by code point, Home and End within the line, a newline. Ui:Compose turns
the keys into those edits and draws the field one to five lines tall —
as many as half the area under the header and the banner holds, and one
at the least — with the canvas's word wrapper (a longer text shows the
lines that end at the caret's, or the first ones while the caret is
among them), a placeholder when empty, the caret at the cursor, and a
tap placing the cursor at the nearest byte by the widths the glyphs are
drawn at, in the text as it is when the tap lands (an edit since the
last frame only asked for one; a field no frame has laid out yet takes a
tap as one at its text's end; a tap at or past the last line's end asks
for the text's end, where a space the wrapper hung off the line may be).
The bar under a conversation holds the field and Send, enabled only with
text, a sendable status and an address to send to; Send hands the text
to Sync with that address and clears the field (a store that refuses the
text keeps the draft) (Model's SendAddress: as a link gave it, else the
latest message's — the network's form of a received text, the dialled
form of ours — never the key, whose completed country code is a guess
that groups; a conversation with neither has Send off, and so has one
whose address is not international — a national number, a short code;
typed, linked or the message's — and was typed or written under another
SIM's plan than the one known now, which the plan each row and the view
carry tells (the view's is that of the SIM the address was typed under,
which Number's AfterStatus keeps; Number's AnotherPlan, its second
caller)); Sync's StateChanged moves the bubble's caption. Keys reach the
field while a conversation is open (Escape goes back, Ctrl+Enter sends),
a held key repeats through a timer since frames are on demand, and the
caret blinks on one. A text typed and not sent is its conversation's,
not the view's: leaving the conversation (Back, another one opened by a
notification or a link) keeps it by the conversation's key for the run,
and opening the conversation again takes it up (Edit's Drafts: an empty
field keeps nothing and drops nothing; the draft of a typed or linked
address follows imsd's status as the open conversation's key does —
Number's AfterStatus over the address and the plan kept with it — so one
left before the status brought the country code is found under the key
the address makes afterwards; and a second text kept under one key — two
keys that became one — goes after the first on a line of its own).
Tested: tests/Model, the address a text goes to (the typed or linked
one, the latest message's, none for an emptied conversation, none under
another SIM's plan than it was typed or written under — a national
number with or without a trunk prefix under another country's SIM, a
short code under another operator's too, though dialled under the same
operator, the own number read when it was typed or not; a national
number typed before the own number was read, none under another operator
— an international one under any — and a typed address judged by its own
plan, whatever the latest row's); tests/Edit (code points of one to four
bytes, the moves within a line, the edits that change nothing, the first
line shown as the caret moves down a long text; the drafts: kept and
taken up by key with the cursor, taken once, an empty field keeping and
dropping nothing, one per conversation, a second text under one key on a
line of its own; a typed address's following the status — moved when the
code comes, not while texts are stored under its key, not under another
SIM's status, a list conversation's left alone and the store not asked,
the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
// The message field's editing by code point: one to four bytes of UTF-8,
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).
2026-10-18 02:30:01 +02:00
// the lines of a text with newlines, and the input method's composing
// text and deletions.
Ui: the compose field and the send bar
A text message needs several lines and UTF-8, and the library's
InputField is one line edited by byte, so the field is the app's own.
Its state and editing are the core's (ImsdMessages:Edit, tested without
a window): a plain struct, insertion at the cursor, Backspace and Delete
by code point, Home and End within the line, a newline. Ui:Compose turns
the keys into those edits and draws the field one to five lines tall —
as many as half the area under the header and the banner holds, and one
at the least — with the canvas's word wrapper (a longer text shows the
lines that end at the caret's, or the first ones while the caret is
among them), a placeholder when empty, the caret at the cursor, and a
tap placing the cursor at the nearest byte by the widths the glyphs are
drawn at, in the text as it is when the tap lands (an edit since the
last frame only asked for one; a field no frame has laid out yet takes a
tap as one at its text's end; a tap at or past the last line's end asks
for the text's end, where a space the wrapper hung off the line may be).
The bar under a conversation holds the field and Send, enabled only with
text, a sendable status and an address to send to; Send hands the text
to Sync with that address and clears the field (a store that refuses the
text keeps the draft) (Model's SendAddress: as a link gave it, else the
latest message's — the network's form of a received text, the dialled
form of ours — never the key, whose completed country code is a guess
that groups; a conversation with neither has Send off, and so has one
whose address is not international — a national number, a short code;
typed, linked or the message's — and was typed or written under another
SIM's plan than the one known now, which the plan each row and the view
carry tells (the view's is that of the SIM the address was typed under,
which Number's AfterStatus keeps; Number's AnotherPlan, its second
caller)); Sync's StateChanged moves the bubble's caption. Keys reach the
field while a conversation is open (Escape goes back, Ctrl+Enter sends),
a held key repeats through a timer since frames are on demand, and the
caret blinks on one. A text typed and not sent is its conversation's,
not the view's: leaving the conversation (Back, another one opened by a
notification or a link) keeps it by the conversation's key for the run,
and opening the conversation again takes it up (Edit's Drafts: an empty
field keeps nothing and drops nothing; the draft of a typed or linked
address follows imsd's status as the open conversation's key does —
Number's AfterStatus over the address and the plan kept with it — so one
left before the status brought the country code is found under the key
the address makes afterwards; and a second text kept under one key — two
keys that became one — goes after the first on a line of its own).
Tested: tests/Model, the address a text goes to (the typed or linked
one, the latest message's, none for an emptied conversation, none under
another SIM's plan than it was typed or written under — a national
number with or without a trunk prefix under another country's SIM, a
short code under another operator's too, though dialled under the same
operator, the own number read when it was typed or not; a national
number typed before the own number was read, none under another operator
— an international one under any — and a typed address judged by its own
plan, whatever the latest row's); tests/Edit (code points of one to four
bytes, the moves within a line, the edits that change nothing, the first
line shown as the caret moves down a long text; the drafts: kept and
taken up by key with the cursor, taken once, an empty field keeping and
dropping nothing, one per conversation, a second text under one key on a
line of its own; a typed address's following the status — moved when the
code comes, not while texts are stored under its key, not under another
SIM's status, a list conversation's left alone and the store not asked,
the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
import std ;
import ImsdMessages ;
using namespace ImsdMessages ;
namespace {
std : : int32_t failures = 0 ;
void Check ( bool ok , std : : string_view what ) {
std : : println ( " {} {} " , ok ? " PASS " : " FAIL " , what ) ;
if ( ! ok ) + + failures ;
}
void CheckEqual ( std : : string_view actual , std : : string_view expected , std : : string_view what ) {
const bool ok = actual = = expected ;
if ( ok ) std : : println ( " PASS {} " , what ) ;
else std : : println ( " FAIL {} — expected \" {} \" , got \" {} \" " , what , expected , actual ) ;
if ( ! ok ) + + failures ;
}
ComposeState At ( std : : string value , std : : size_t cursor ) {
ComposeState s ;
s . value = std : : move ( value ) ;
s . cursor = cursor ;
return s ;
}
}
int main ( ) {
// a, é, € and 😀: one, two, three and four bytes; boundaries 0 1 3 6 10.
const std : : string mixed = " aé€ \U0001F600 " ;
Check ( mixed . size ( ) = = 10 , " the sample is ten bytes " ) ;
Check ( NextCodepoint ( mixed , 0 ) = = 1 & & NextCodepoint ( mixed , 1 ) = = 3 & & NextCodepoint ( mixed , 3 ) = = 6 & & NextCodepoint ( mixed , 6 ) = = 10 , " NextCodepoint steps over one to four bytes " ) ;
Check ( NextCodepoint ( mixed , 10 ) = = 10 , " NextCodepoint stays at the end " ) ;
Check ( PreviousCodepoint ( mixed , 10 ) = = 6 & & PreviousCodepoint ( mixed , 6 ) = = 3 & & PreviousCodepoint ( mixed , 3 ) = = 1 & & PreviousCodepoint ( mixed , 1 ) = = 0 , " PreviousCodepoint steps back over one to four bytes " ) ;
Check ( PreviousCodepoint ( mixed , 0 ) = = 0 , " PreviousCodepoint stays at the start " ) ;
ComposeState s = At ( mixed , 10 ) ;
Check ( ComposeEdit ( s , EditKey : : Backspace ) & & s . cursor = = 6 , " Backspace takes the four-byte emoji " ) ;
CheckEqual ( s . value , " aé€ " , " what is left after Backspace " ) ;
s = At ( mixed , 1 ) ;
Check ( ComposeEdit ( s , EditKey : : Delete ) & & s . cursor = = 1 , " Delete takes the two-byte é " ) ;
CheckEqual ( s . value , " a€ \U0001F600 " , " what is left after Delete " ) ;
s = At ( " abc " , 0 ) ;
Check ( ! ComposeEdit ( s , EditKey : : Backspace ) & & s . value = = " abc " & & s . cursor = = 0 , " Backspace at the start deletes nothing and says so " ) ;
s = At ( " abc " , 3 ) ;
Check ( ! ComposeEdit ( s , EditKey : : Delete ) & & s . value = = " abc " & & s . cursor = = 3 , " Delete at the end deletes nothing and says so " ) ;
s = At ( mixed , 6 ) ;
Check ( ComposeEdit ( s , EditKey : : Left ) & & s . cursor = = 3 , " Left moves back over the three-byte € " ) ;
Check ( ComposeEdit ( s , EditKey : : Right ) & & s . cursor = = 6 , " Right moves over it again " ) ;
s = At ( " ab " , 0 ) ;
Check ( ComposeEdit ( s , EditKey : : Left ) & & s . cursor = = 0 , " Left at the start stays, and is still a move " ) ;
s = At ( " ab " , 2 ) ;
Check ( ComposeEdit ( s , EditKey : : Right ) & & s . cursor = = 2 , " Right at the end stays, and is still a move " ) ;
// "one\ntwo\nthree": the lines start at 0, 4 and 8; the newlines are at 3 and 7.
s = At ( " one \n two \n three " , 6 ) ;
ComposeEdit ( s , EditKey : : Home ) ;
Check ( s . cursor = = 4 , " Home goes to the start of the cursor's line " ) ;
ComposeEdit ( s , EditKey : : End ) ;
Check ( s . cursor = = 7 , " End goes to the end of the line, before its newline " ) ;
ComposeEdit ( s , EditKey : : Home ) ;
Check ( s . cursor = = 4 , " Home from the end of a line " ) ;
s = At ( " one \n two \n three " , 4 ) ;
ComposeEdit ( s , EditKey : : Home ) ;
Check ( s . cursor = = 4 , " Home at the start of a line stays " ) ;
s = At ( " one \n two \n three " , 3 ) ;
ComposeEdit ( s , EditKey : : Home ) ;
Check ( s . cursor = = 0 , " Home from the end of the first line " ) ;
s = At ( " one \n two \n three " , 9 ) ;
ComposeEdit ( s , EditKey : : End ) ;
Check ( s . cursor = = 13 , " End on the last line goes to the end of the text " ) ;
s = At ( " \n x " , 0 ) ;
ComposeEdit ( s , EditKey : : Home ) ;
Check ( s . cursor = = 0 , " Home at the very start, before a newline, stays " ) ;
s = At ( " ab " , 1 ) ;
Check ( ComposeEdit ( s , EditKey : : Newline ) & & s . cursor = = 2 , " Newline inserts at the cursor and moves past it " ) ;
CheckEqual ( s . value , " a \n b " , " the text after Newline " ) ;
s = At ( " ab " , 1 ) ;
ComposeInsert ( s , " é " ) ;
Check ( s . cursor = = 3 , " an insert moves the cursor past its bytes " ) ;
CheckEqual ( s . value , " aéb " , " the text after an insert " ) ;
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).
2026-10-18 02:30:01 +02:00
// 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 " ) ;
Ui: the compose field and the send bar
A text message needs several lines and UTF-8, and the library's
InputField is one line edited by byte, so the field is the app's own.
Its state and editing are the core's (ImsdMessages:Edit, tested without
a window): a plain struct, insertion at the cursor, Backspace and Delete
by code point, Home and End within the line, a newline. Ui:Compose turns
the keys into those edits and draws the field one to five lines tall —
as many as half the area under the header and the banner holds, and one
at the least — with the canvas's word wrapper (a longer text shows the
lines that end at the caret's, or the first ones while the caret is
among them), a placeholder when empty, the caret at the cursor, and a
tap placing the cursor at the nearest byte by the widths the glyphs are
drawn at, in the text as it is when the tap lands (an edit since the
last frame only asked for one; a field no frame has laid out yet takes a
tap as one at its text's end; a tap at or past the last line's end asks
for the text's end, where a space the wrapper hung off the line may be).
The bar under a conversation holds the field and Send, enabled only with
text, a sendable status and an address to send to; Send hands the text
to Sync with that address and clears the field (a store that refuses the
text keeps the draft) (Model's SendAddress: as a link gave it, else the
latest message's — the network's form of a received text, the dialled
form of ours — never the key, whose completed country code is a guess
that groups; a conversation with neither has Send off, and so has one
whose address is not international — a national number, a short code;
typed, linked or the message's — and was typed or written under another
SIM's plan than the one known now, which the plan each row and the view
carry tells (the view's is that of the SIM the address was typed under,
which Number's AfterStatus keeps; Number's AnotherPlan, its second
caller)); Sync's StateChanged moves the bubble's caption. Keys reach the
field while a conversation is open (Escape goes back, Ctrl+Enter sends),
a held key repeats through a timer since frames are on demand, and the
caret blinks on one. A text typed and not sent is its conversation's,
not the view's: leaving the conversation (Back, another one opened by a
notification or a link) keeps it by the conversation's key for the run,
and opening the conversation again takes it up (Edit's Drafts: an empty
field keeps nothing and drops nothing; the draft of a typed or linked
address follows imsd's status as the open conversation's key does —
Number's AfterStatus over the address and the plan kept with it — so one
left before the status brought the country code is found under the key
the address makes afterwards; and a second text kept under one key — two
keys that became one — goes after the first on a line of its own).
Tested: tests/Model, the address a text goes to (the typed or linked
one, the latest message's, none for an emptied conversation, none under
another SIM's plan than it was typed or written under — a national
number with or without a trunk prefix under another country's SIM, a
short code under another operator's too, though dialled under the same
operator, the own number read when it was typed or not; a national
number typed before the own number was read, none under another operator
— an international one under any — and a typed address judged by its own
plan, whatever the latest row's); tests/Edit (code points of one to four
bytes, the moves within a line, the edits that change nothing, the first
line shown as the caret moves down a long text; the drafts: kept and
taken up by key with the cursor, taken once, an empty field keeping and
dropping nothing, one per conversation, a second text under one key on a
line of its own; a typed address's following the status — moved when the
code comes, not while texts are stored under its key, not under another
SIM's status, a list conversation's left alone and the store not asked,
the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
// 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).
const std : : vector < WrappedLine > hung = { { 0 , 5 , 50 } , { 7 , 8 , 10 } } ; // "abcde \nx"
Check ( ComposeLineEnd ( hung , 0 , " abcde \n x " ) = = 6 , " past the end of a line that a hung space and a newline follow: before the newline, after the space " ) ;
Check ( ComposeLineEnd ( hung , 1 , " abcde \n x " ) = = 8 , " past the end of the last line: the text's end " ) ;
const std : : vector < WrappedLine > soft = { { 0 , 5 , 50 } , { 6 , 8 , 20 } } ; // "ab cd ef"
Check ( ComposeLineEnd ( soft , 0 , " ab cd ef " ) = = 5 , " at a soft wrap the line's end, before the space that broke it " ) ;
const std : : vector < WrappedLine > trailing = { { 0 , 5 , 50 } } ; // "abcde "
Check ( ComposeLineEnd ( trailing , 0 , " abcde " ) = = 6 , " a trailing hung space: the text's end " ) ;
const std : : vector < WrappedLine > ended = { { 0 , 2 , 20 } , { 3 , 3 , 0 } } ; // "ab\n"
Check ( ComposeLineEnd ( ended , 0 , " ab \n " ) = = 2 , " past the end of the line before a text's empty last line: before the newline, not on the empty line below " ) ;
Check ( ComposeLineEnd ( ended , 1 , " ab \n " ) = = 3 , " past the empty last line: the text's end " ) ;
const std : : vector < WrappedLine > hungEnd = { { 0 , 5 , 50 } , { 7 , 7 , 0 } } ; // "abcde \n"
Check ( ComposeLineEnd ( hungEnd , 0 , " abcde \n " ) = = 6 , " the same with a hung space: after the space, before the newline " ) ;
// The field shows five lines at most and keeps the caret's line among them.
Check ( ComposeFirstLine ( 0 , 5 ) = = 0 & & ComposeFirstLine ( 4 , 5 ) = = 0 , " a caret within the first five lines: the field starts at the first " ) ;
Check ( ComposeFirstLine ( 5 , 5 ) = = 1 & & ComposeFirstLine ( 6 , 5 ) = = 2 , " a caret below them: its line is the fifth shown " ) ;
Check ( ComposeFirstLine ( 19 , 5 ) = = 15 , " the same far down a long text " ) ;
Check ( ComposeFirstLine ( 0 , 1 ) = = 0 & & ComposeFirstLine ( 7 , 1 ) = = 7 , " a one-line field shows the caret's line " ) ;
Ui, Edit: a keyboard sent away stays away until the field is tapped
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.
2026-11-18 04:20:42 +01:00
// --- a caret that only followed the window's growth: the keyboard went -
{
const CaretReport told { 76 , 1002 , 4 , 24 , 1068 } ; // the message field's caret above the keyboard
Check ( CaretFollowedGrowth ( told , { 76 , 1526 , 4 , 24 , 1592 } ) , " the window grew and the caret went down by as much: it only followed the growth " ) ;
Check ( CaretFollowedGrowth ( told , { 76.5f , 1526.8f , 4 , 24 , 1592 } ) , " within a pixel of it, as a rounded layout gives " ) ;
Check ( ! CaretFollowedGrowth ( told , { 76 , 1002 , 4 , 24 , 1592 } ) , " a caret that stayed where it was in a window that grew (a field at the top) did not move at all: nothing held " ) ;
Check ( ! CaretFollowedGrowth ( told , { 94 , 1526 , 4 , 24 , 1592 } ) , " a caret that moved along its line as well is told " ) ;
Check ( ! CaretFollowedGrowth ( told , { 76 , 1502 , 4 , 24 , 1592 } ) , " one that moved by another amount (a line more or less) is told " ) ;
Check ( ! CaretFollowedGrowth ( told , { 76 , 1002 , 4 , 24 , 1068 } ) & & ! CaretFollowedGrowth ( told , { 76 , 1026 , 4 , 24 , 1068 } ) , " the window as tall as it was: every move is told " ) ;
Check ( ! CaretFollowedGrowth ( { 76 , 1526 , 4 , 24 , 1592 } , { 76 , 1002 , 4 , 24 , 1068 } ) , " the window shrank (the keyboard came up): the caret's new place is told " ) ;
Check ( ! CaretFollowedGrowth ( told , { 76 , 1526 , 4 , 30 , 1592 } ) , " a box of another size is told " ) ;
}
Ui: the compose field and the send bar
A text message needs several lines and UTF-8, and the library's
InputField is one line edited by byte, so the field is the app's own.
Its state and editing are the core's (ImsdMessages:Edit, tested without
a window): a plain struct, insertion at the cursor, Backspace and Delete
by code point, Home and End within the line, a newline. Ui:Compose turns
the keys into those edits and draws the field one to five lines tall —
as many as half the area under the header and the banner holds, and one
at the least — with the canvas's word wrapper (a longer text shows the
lines that end at the caret's, or the first ones while the caret is
among them), a placeholder when empty, the caret at the cursor, and a
tap placing the cursor at the nearest byte by the widths the glyphs are
drawn at, in the text as it is when the tap lands (an edit since the
last frame only asked for one; a field no frame has laid out yet takes a
tap as one at its text's end; a tap at or past the last line's end asks
for the text's end, where a space the wrapper hung off the line may be).
The bar under a conversation holds the field and Send, enabled only with
text, a sendable status and an address to send to; Send hands the text
to Sync with that address and clears the field (a store that refuses the
text keeps the draft) (Model's SendAddress: as a link gave it, else the
latest message's — the network's form of a received text, the dialled
form of ours — never the key, whose completed country code is a guess
that groups; a conversation with neither has Send off, and so has one
whose address is not international — a national number, a short code;
typed, linked or the message's — and was typed or written under another
SIM's plan than the one known now, which the plan each row and the view
carry tells (the view's is that of the SIM the address was typed under,
which Number's AfterStatus keeps; Number's AnotherPlan, its second
caller)); Sync's StateChanged moves the bubble's caption. Keys reach the
field while a conversation is open (Escape goes back, Ctrl+Enter sends),
a held key repeats through a timer since frames are on demand, and the
caret blinks on one. A text typed and not sent is its conversation's,
not the view's: leaving the conversation (Back, another one opened by a
notification or a link) keeps it by the conversation's key for the run,
and opening the conversation again takes it up (Edit's Drafts: an empty
field keeps nothing and drops nothing; the draft of a typed or linked
address follows imsd's status as the open conversation's key does —
Number's AfterStatus over the address and the plan kept with it — so one
left before the status brought the country code is found under the key
the address makes afterwards; and a second text kept under one key — two
keys that became one — goes after the first on a line of its own).
Tested: tests/Model, the address a text goes to (the typed or linked
one, the latest message's, none for an emptied conversation, none under
another SIM's plan than it was typed or written under — a national
number with or without a trunk prefix under another country's SIM, a
short code under another operator's too, though dialled under the same
operator, the own number read when it was typed or not; a national
number typed before the own number was read, none under another operator
— an international one under any — and a typed address judged by its own
plan, whatever the latest row's); tests/Edit (code points of one to four
bytes, the moves within a line, the edits that change nothing, the first
line shown as the caret moves down a long text; the drafts: kept and
taken up by key with the cursor, taken once, an empty field keeping and
dropping nothing, one per conversation, a second text under one key on a
line of its own; a typed address's following the status — moved when the
code comes, not while texts are stored under its key, not under another
SIM's status, a list conversation's left alone and the store not asked,
the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
// The drafts of the conversations left: kept by key, taken up at the
// next opening.
{
Drafts drafts ;
ComposeState typed ;
ComposeInsert ( typed , " half a thought " ) ;
typed . cursor = 4 ;
typed . focused = ! ComposeState { } . focused ;
drafts . Keep ( " +31612345678 " , typed ) ;
Check ( drafts . Size ( ) = = 1 , " a left conversation's text is kept " ) ;
const ComposeState back = drafts . Take ( " +31612345678 " ) ;
Check ( back . value = = " half a thought " & & back . cursor = = 4 & & back . focused = = ComposeState { } . focused , " and taken up as typed, the cursor where it was, the focus as a field is opened " ) ;
Check ( drafts . Size ( ) = = 0 & & drafts . Take ( " +31612345678 " ) . value . empty ( ) , " taken, it is the field's: nothing is kept twice " ) ;
drafts . Keep ( " +31612345678 " , typed ) ;
drafts . Keep ( " +31612345678 " , ComposeState { } ) ;
Check ( drafts . Take ( " +31612345678 " ) . value = = " half a thought " , " an empty field keeps nothing and drops nothing " ) ;
ComposeState other ;
ComposeInsert ( other , " to another " ) ;
drafts . Keep ( " +31612345678 " , typed ) ;
drafts . Keep ( " 1234 " , other ) ;
Check ( drafts . Size ( ) = = 2 & & drafts . Take ( " 1234 " ) . value = = " to another " & & drafts . Take ( " +31612345678 " ) . value = = " half a thought " , " each conversation has its own " ) ;
drafts . Keep ( " +31612345678 " , typed ) ;
drafts . Keep ( " +31612345678 " , other ) ;
const ComposeState both = drafts . Take ( " +31612345678 " ) ;
Check ( both . value = = " half a thought \n to another " & & both . cursor = = both . value . size ( ) , " a second text kept under one key goes after the first, on a line of its own " ) ;
Ui, main: the new-conversation screen and the long-press sheets
The + opens a screen with a number field (its placeholder "Number", a
parameter of the compose field now) and Start; the number becomes a
conversation key through Number's ConversationKey, as an sms: link's
does (E.164 through the country code, a short code as digits), anything
else is refused in place. A long press on a conversation row offers to
delete the conversation, on a message to copy its text to the clipboard
or delete it; only those two have one: App tells the recogniser before
each press whether what it lands on has a long press (GestureDetector's
longPress), and without one a press held as long — on a button, a field,
a sheet's row — stays a tap at its release, so a slow finger presses the
button all the same. A sheet draws on the overlay layer over a scrim and
pushes its regions last, so they win the hit test, and the wheel scrolls
nothing under it; Escape, the back arrow and a tap outside dismiss it.
Deleting a conversation also closes its notification and drops its
draft; the + keeps the draft of the conversation it leaves, as Back
does, and so does a view that closes because its last message was
deleted. The deletes go through Sync (Erase, EraseConversation: the
commit before, which keeps a deleted text deleted). The number field's
box is drawn by its screen, as the send bar's is by the bar: the shared
field drawing paints no background of its own. Opening a conversation,
from a notification or a link, leaves the new-conversation screen and
any sheet, and the + leaves any sheet. A key whose press changed the
screen acts once: held, its repeats are not the new screen's — Enter,
which started the conversation, would type line breaks into its field,
and Escape would go on back, from a sheet through the conversation and
its draft. A sheet that asks to delete a conversation goes when a text
arrives for it: a yes would delete that text unread. A press on the
conversation's row opens no such sheet either while the row it aimed at
had not shown the text — the regions are a frame's: the press that is
down when the text arrives, and one that comes down before the next
frame is drawn, have no long press; a release before the long-press time
is still the row's tap, while the row stays under the finger.
--new and --bench-sheet put either on screen for the bench
(--bench-sheet conversation or message, each on the screen a long press
opens it over: another value is refused, and one that finds nothing to
press says so in the log), and are window flags as --screenshot is.
Tested: the screens and the sheets by the bench (--new, --bench-sheet)
and the phone step's screenshots; the deletes' logic with the commit
before, in tests/Store and tests/Sync; the press without a long press in
tests/Gesture (the timer gives no long press and a move within the slop
nothing; the release is the tap, however late; a slide off the control
is a drag); a deleted conversation's draft dropped, in tests/Edit. The
press on a row a text arrived for has no bench: none holds a finger on a
row.
2026-11-01 18:11:40 +01:00
drafts . Keep ( " +31612345678 " , typed ) ;
drafts . Drop ( " +31612345678 " ) ;
drafts . Drop ( " no such conversation " ) ;
Check ( drafts . Size ( ) = = 0 , " a deleted conversation's draft goes with it " ) ;
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).
2026-10-18 02:30:01 +02:00
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 " ) ;
Ui: the compose field and the send bar
A text message needs several lines and UTF-8, and the library's
InputField is one line edited by byte, so the field is the app's own.
Its state and editing are the core's (ImsdMessages:Edit, tested without
a window): a plain struct, insertion at the cursor, Backspace and Delete
by code point, Home and End within the line, a newline. Ui:Compose turns
the keys into those edits and draws the field one to five lines tall —
as many as half the area under the header and the banner holds, and one
at the least — with the canvas's word wrapper (a longer text shows the
lines that end at the caret's, or the first ones while the caret is
among them), a placeholder when empty, the caret at the cursor, and a
tap placing the cursor at the nearest byte by the widths the glyphs are
drawn at, in the text as it is when the tap lands (an edit since the
last frame only asked for one; a field no frame has laid out yet takes a
tap as one at its text's end; a tap at or past the last line's end asks
for the text's end, where a space the wrapper hung off the line may be).
The bar under a conversation holds the field and Send, enabled only with
text, a sendable status and an address to send to; Send hands the text
to Sync with that address and clears the field (a store that refuses the
text keeps the draft) (Model's SendAddress: as a link gave it, else the
latest message's — the network's form of a received text, the dialled
form of ours — never the key, whose completed country code is a guess
that groups; a conversation with neither has Send off, and so has one
whose address is not international — a national number, a short code;
typed, linked or the message's — and was typed or written under another
SIM's plan than the one known now, which the plan each row and the view
carry tells (the view's is that of the SIM the address was typed under,
which Number's AfterStatus keeps; Number's AnotherPlan, its second
caller)); Sync's StateChanged moves the bubble's caption. Keys reach the
field while a conversation is open (Escape goes back, Ctrl+Enter sends),
a held key repeats through a timer since frames are on demand, and the
caret blinks on one. A text typed and not sent is its conversation's,
not the view's: leaving the conversation (Back, another one opened by a
notification or a link) keeps it by the conversation's key for the run,
and opening the conversation again takes it up (Edit's Drafts: an empty
field keeps nothing and drops nothing; the draft of a typed or linked
address follows imsd's status as the open conversation's key does —
Number's AfterStatus over the address and the plan kept with it — so one
left before the status brought the country code is found under the key
the address makes afterwards; and a second text kept under one key — two
keys that became one — goes after the first on a line of its own).
Tested: tests/Model, the address a text goes to (the typed or linked
one, the latest message's, none for an emptied conversation, none under
another SIM's plan than it was typed or written under — a national
number with or without a trunk prefix under another country's SIM, a
short code under another operator's too, though dialled under the same
operator, the own number read when it was typed or not; a national
number typed before the own number was read, none under another operator
— an international one under any — and a typed address judged by its own
plan, whatever the latest row's); tests/Edit (code points of one to four
bytes, the moves within a line, the edits that change nothing, the first
line shown as the caret moves down a long text; the drafts: kept and
taken up by key with the cursor, taken once, an empty field keeping and
dropping nothing, one per conversation, a second text under one key on a
line of its own; a typed address's following the status — moved when the
code comes, not while texts are stored under its key, not under another
SIM's status, a list conversation's left alone and the store not asked,
the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
}
// A kept typed address follows imsd's status as an open conversation's
// key does: typed before the country code was known, found after.
{
const SimPlan kpn { " 31 " , " 20408 " } ;
const auto nothing = [ ] ( std : : string_view ) { return true ; } ;
Drafts drafts ;
ComposeState typed ;
ComposeInsert ( typed , " typed before the status " ) ;
drafts . Keep ( " 0612345678 " , typed , " 0612345678 " , SimPlan { } ) ;
drafts . Status ( kpn , " 31 " , nothing ) ;
Check ( drafts . Take ( " 0612345678 " ) . value . empty ( ) & & drafts . Take ( " +31612345678 " ) . value = = " typed before the status " , " the status brings the code: a kept typed address moves to the key it makes now " ) ;
drafts . Keep ( " 0612345678 " , typed , " 0612345678 " , SimPlan { } ) ;
drafts . Status ( kpn , " 31 " , [ ] ( std : : string_view ) { return false ; } ) ;
Check ( drafts . Take ( " 0612345678 " ) . value = = " typed before the status " , " not while texts are stored under its key: the conversation stays on the key its rows carry " ) ;
drafts . Keep ( " 0612345678 " , typed , " 0612345678 " , SimPlan { " 32 " , " 20601 " } ) ;
drafts . Status ( kpn , " 31 " , nothing ) ;
Check ( drafts . Take ( " 0612345678 " ) . value = = " typed before the status " , " nor under another SIM's status " ) ;
std : : size_t asked = 0 ;
drafts . Keep ( " 0612345678 " , typed ) ;
drafts . Status ( kpn , " 31 " , [ & asked ] ( std : : string_view ) {
+ + asked ;
return true ;
} ) ;
Check ( asked = = 0 & & drafts . Take ( " 0612345678 " ) . value = = " typed before the status " , " nor a conversation opened from the list, which has no typed address: the store is not asked about it " ) ;
drafts . Keep ( " 0612345678 " , typed , " 0612345678 " , SimPlan { } ) ;
drafts . Status ( kpn , " 31 " , nothing ) ;
drafts . Status ( SimPlan { " 32 " , " 20601 " } , " 32 " , nothing ) ;
Check ( drafts . Take ( " +31612345678 " ) . value = = " typed before the status " , " a moved draft keeps the plan it learned: another SIM's status leaves it where it is " ) ;
ComposeState earlier ;
ComposeInsert ( earlier , " in the thread " ) ;
drafts . Keep ( " +31612345678 " , earlier ) ;
drafts . Keep ( " 0612345678 " , typed , " 0612345678 " , SimPlan { } ) ;
drafts . Status ( kpn , " 31 " , nothing ) ;
Check ( drafts . Size ( ) = = 1 & & drafts . Take ( " +31612345678 " ) . value = = " in the thread \n typed before the status " , " two keys that became one: both texts, each on its line " ) ;
}
return failures = = 0 ? 0 : 1 ;
}