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:
parent
99119e6d5e
commit
f93144ae2f
7 changed files with 325 additions and 66 deletions
|
|
@ -18,9 +18,19 @@ export namespace ImsdMessages {
|
|||
struct ComposeState {
|
||||
std::string value;
|
||||
std::size_t cursor = 0; // a byte offset on a code point boundary
|
||||
bool focused = true;
|
||||
std::string preedit; // the input method's composing text: shown at the cursor, not yet in the value
|
||||
bool focused = false;
|
||||
};
|
||||
|
||||
// The text as shown: the value with the composing text at the cursor.
|
||||
std::string ComposeShown(const ComposeState& s) {
|
||||
std::string shown = s.value;
|
||||
shown.insert(s.cursor, s.preedit);
|
||||
return shown;
|
||||
}
|
||||
|
||||
std::size_t ShownCursor(const ComposeState& s) { return s.cursor + s.preedit.size(); }
|
||||
|
||||
// The byte offset of the code point before `at`.
|
||||
std::size_t PreviousCodepoint(std::string_view s, std::size_t at) {
|
||||
if (at == 0) return 0;
|
||||
|
|
@ -41,6 +51,18 @@ export namespace ImsdMessages {
|
|||
c.cursor += utf8.size();
|
||||
}
|
||||
|
||||
// The input method's deletion: so many bytes before and after the cursor,
|
||||
// rounded out to code points. The composing text stays; the input method
|
||||
// replaces it when it changes.
|
||||
void ComposeDeleteAround(ComposeState& c, std::size_t beforeBytes, std::size_t afterBytes) {
|
||||
std::size_t from = c.cursor;
|
||||
while (from > 0 && c.cursor - from < beforeBytes) from = PreviousCodepoint(c.value, from);
|
||||
std::size_t to = c.cursor;
|
||||
while (to < c.value.size() && to - c.cursor < afterBytes) to = NextCodepoint(c.value, to);
|
||||
c.value.erase(from, to - from);
|
||||
c.cursor = from;
|
||||
}
|
||||
|
||||
enum class EditKey : std::uint8_t { Backspace, Delete, Left, Right, Home, End, Newline };
|
||||
|
||||
// Applies one key. False when Backspace or Delete has nothing to delete;
|
||||
|
|
@ -103,6 +125,15 @@ export namespace ImsdMessages {
|
|||
return caretLine + 1 > shown ? caretLine + 1 - shown : 0;
|
||||
}
|
||||
|
||||
// Takes the composing text into the value at the cursor, as the input
|
||||
// method would commit it: what Send and Start read is what the field shows.
|
||||
void ComposeCommitPreedit(ComposeState& c) {
|
||||
if (c.preedit.empty()) return;
|
||||
const std::string preedit = std::move(c.preedit);
|
||||
c.preedit.clear();
|
||||
ComposeInsert(c, preedit);
|
||||
}
|
||||
|
||||
// What was typed in the conversations that were left, and not sent, by
|
||||
// conversation key, for this run. A draft is its conversation's, not
|
||||
// the view's: leaving the conversation keeps it, opening it again
|
||||
|
|
@ -110,15 +141,17 @@ export namespace ImsdMessages {
|
|||
// deleted.
|
||||
class Drafts {
|
||||
public:
|
||||
// A conversation is left: what its field holds is kept and comes
|
||||
// back as a field is opened; an empty field keeps nothing and drops
|
||||
// nothing. `dialled` and `plan` are the view's: the address as typed
|
||||
// or linked — "" for a conversation opened from the list, whose
|
||||
// draft Status leaves where it is — and the plan of the SIM it was
|
||||
// opened under. A second text kept under one key (two keys that
|
||||
// became one: Status, and the open conversation's own move) goes
|
||||
// after the first on a line of its own, so nothing typed is dropped.
|
||||
// A conversation is left: what its field holds is kept — a word
|
||||
// still being composed as text — and comes back as a field is
|
||||
// opened; an empty field keeps nothing and drops nothing. `dialled`
|
||||
// and `plan` are the view's: the address as typed or linked — ""
|
||||
// for a conversation opened from the list, whose draft Status
|
||||
// leaves where it is — and the plan of the SIM it was opened
|
||||
// under. A second text kept under one key (two keys that became
|
||||
// one: Status, and the open conversation's own move) goes after
|
||||
// the first on a line of its own, so nothing typed is dropped.
|
||||
void Keep(std::string_view key, ComposeState field, std::string_view dialled = {}, SimPlan plan = {}) {
|
||||
ComposeCommitPreedit(field);
|
||||
if (field.value.empty()) return;
|
||||
field.focused = ComposeState{}.focused;
|
||||
const auto kept = byKey.find(key);
|
||||
|
|
|
|||
Loading…
Reference in a new issue