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.
This commit is contained in:
Jorijn van der Graaf 2026-11-01 18:11:40 +01:00
commit 20e687452f
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
10 changed files with 358 additions and 38 deletions

View file

@ -50,8 +50,10 @@ struct Options {
std::optional<double> quitAfter; // seconds
std::optional<double> hideAfter; // seconds: the bench's close
std::optional<double> hideEvery; // seconds: the bench's repeated close
std::optional<std::string> prefill; // typed into the opened conversation's field
std::optional<std::string> prefill; // typed into the open screen's field
bool sendDraft = false; // and sent, as if the button were tapped
bool openNew = false; // the bench opens the new-conversation screen
std::optional<std::string> benchSheet; // "conversation" or "message": the bench's long press
std::string country;
std::string error;
};
@ -61,7 +63,7 @@ struct Options {
// a running instance, whose window is not this one. What configures a
// process (its store, its country code) is not among them: beside a
// running instance that instance's own stands.
bool WindowFlags(const Options& o) { return o.screenshot || o.prefill || o.sendDraft || o.hideAfter || o.hideEvery; }
bool WindowFlags(const Options& o) { return o.screenshot || o.prefill || o.sendDraft || o.hideAfter || o.hideEvery || o.openNew || o.benchSheet; }
// A bench clock's seconds, which its timer takes as a guint of
// milliseconds: what is not such a number is the error.
@ -94,6 +96,8 @@ Options Parse(std::span<const char* const> args) {
else if (a == "--hide-every" && i + 1 < args.size()) o.hideEvery = Seconds(a, args[++i], o.error);
else if (a == "--prefill" && i + 1 < args.size()) o.prefill = args[++i];
else if (a == "--send-draft") o.sendDraft = true;
else if (a == "--new") o.openNew = true;
else if (a == "--bench-sheet" && i + 1 < args.size()) o.benchSheet = args[++i];
else if (a == "--country" && i + 1 < args.size()) o.country = args[++i];
else if (IsSmsUri(a)) o.uri = std::string(a);
else o.error = std::format("unknown argument: {}", a);
@ -111,6 +115,7 @@ Options Parse(std::span<const char* const> args) {
// completed key is made of it as it is, and read by that rule.
if (!o.country.empty() && (o.country.front() == '0' || CountryCodeOf(std::format("+{}0000000", o.country)) != o.country)) o.error = "--country: not a country code (one to three digits, without its +)";
if (o.hideEvery && *o.hideEvery * 1000 < 1) o.error = "--hide-every: a millisecond at least";
if (o.benchSheet && *o.benchSheet != "conversation" && *o.benchSheet != "message") o.error = "--bench-sheet: conversation or message";
if (o.send && o.quit) o.error = "--send and --quit do not go together";
if (o.send && o.uri) o.error = "--send and an sms: link do not go together";
if (o.send && WindowFlags(o)) o.error = "--send and a window do not go together";
@ -186,7 +191,7 @@ public:
void OnImported(const Message& m) override {
if (verbose) Log(std::format("received {} from {}: {} ({} byte(s), segments {})", m.imsdId, m.conversation, m.read ? "read" : "unread", m.text.size(), m.segments));
if (!m.read) notifier.Notify(m);
if (app) app->Changed();
if (app) app->Imported(m);
}
void OnMessageChanged(const Message& m) override {
@ -276,7 +281,7 @@ int main(int argc, char** argv) {
return 0;
}
if (o.help) {
std::println("imsd-messages [--daemon|--headless] [--send NUMBER TEXT] [--quit] [--session] [--data-dir DIR] [--country CC] [--screenshot FILE.png] [--screenshot-after SECONDS] [--quit-after SECONDS] [--hide-after SECONDS] [--hide-every SECONDS] [--prefill TEXT] [--send-draft] [sms:NUMBER] [--version]");
std::println("imsd-messages [--daemon|--headless] [--send NUMBER TEXT] [--quit] [--session] [--data-dir DIR] [--country CC] [--screenshot FILE.png] [--screenshot-after SECONDS] [--quit-after SECONDS] [--hide-after SECONDS] [--hide-every SECONDS] [--prefill TEXT] [--send-draft] [--new] [--bench-sheet conversation|message] [sms:NUMBER] [--version]");
return 0;
}
@ -392,6 +397,7 @@ int main(int argc, char** argv) {
app->sync = &sync;
app->onQuit = [loop] { g_main_loop_quit(loop); };
app->onConversationOpened = [&notifier](const std::string& conversation) { notifier.Close(conversation); };
app->onConversationDeleted = [&notifier](const std::string& conversation) { notifier.Close(conversation); };
app->onLog = Log;
// The compositor's connection broke, and the process cannot connect its
// display again: it ends (the store flushed, the name freed), so the next
@ -417,6 +423,10 @@ int main(int argc, char** argv) {
} else if (!o.daemon) {
app->Show();
}
if (o.openNew) {
app->NewConversation();
if (o.prefill) app->Prefill(*o.prefill);
}
// A start that asked for the window and has none (Ui's log said why)
// ends with exit 1, as one without its database does; a resident
// instance runs on without a window, and the next Activate or Open
@ -427,6 +437,20 @@ int main(int argc, char** argv) {
g_main_loop_unref(loop);
return 1;
}
struct SheetJob {
Ui::App* app;
std::string which;
};
std::optional<SheetJob> sheetJob;
if (o.benchSheet) {
sheetJob.emplace(&*app, *o.benchSheet);
g_timeout_add(2000, [](gpointer data) -> gboolean {
SheetJob& job = *static_cast<SheetJob*>(data);
job.app->Show();
job.app->BenchSheet(job.which);
return G_SOURCE_REMOVE;
}, &*sheetJob);
}
// The bench's tap on Send, 1.5 s after start.
if (o.sendDraft) g_timeout_add(1500, [](gpointer data) -> gboolean {
static_cast<Ui::App*>(data)->SendDraft();