Nostro/implementations/Nostro.Ui.Shell-Window.cpp

502 lines
18 KiB
C++
Raw Permalink Normal View History

feat(app): add the Nostro app, a window for phones and desktops Linux phones have no banking apps, and a command line is no answer on a phone. The app does everything the nostro command does and, like it, only talks to nostrod: it holds no key and no token. - Nostro.Ui, a toolkit whose screens are functions that fill a frame, ported from imsd-messages ca5cd72d; Nostro.App, the app's state, forms and screens; Nostro.Ui.Shell, which puts them on a Wayland window with Crafter.Graphics; nostro-app; and Nostro.DebugCommands for the --debug-api build. - Client: every method also in an asynchronous form for an sd-event loop, with DaemonMissing and OutcomeUnknown. - nostrod's Flatpak is net.catcrafts.Nostrod now and the app takes net.catcrafts.Nostro; install.sh moves the state. The app's Flatpak, both Flatpaks cross-built for aarch64, and the licence texts they carry. - nostro-fake-system, a made-up bus and bank with a real nostrod on them, to look at the app against. The README's screenshots are taken on it. - The nostro command: an API key's environment is the key's own to say, so --sandbox is for bunq-oauth alone, and a virtual card is listed as VIRTUAL. The published contract changes in three places, before any release (design rule 10): - Transactions' query takes `stored`: answered from what nostrod has stored, without asking the bank. The app searches with it; before, every search was a call to bunq. - AddBunq's `environment` no longer chooses over what the key says of itself: a key of the other environment is refused. - SetCardStatus refuses to freeze or unfreeze a virtual card. bunq reports one as DEACTIVATED however well it pays, and leaves it as it is when asked, without an error. The app is GPL-3.0-only, the library stays LGPL-3.0-only, and no code moved from one to the other (design rule 13). Transaction's schema is unchanged. Verified: the 17 tests pass with every line, function and region of what they link run, and the five lint runs are clean. Every screen was looked at on the made-up system, at a phone's and a desktop's sizes in the light and the dark look, on Plasma under Wayland. What is said of bunq's cards comes from its sandbox, with throwaway users, and from one real virtual card. Known to have been used against production: connecting, and reading accounts, payments and cards. Not known to have been tried: a payment from the app against bunq, OAuth against bunq, and anything on a phone. Building the app takes --graphics=, a Crafter.Graphics checkout on its branch claude/nostro-app, until that branch is merged and pinned here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 12:27:14 +01:00
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
module;
#include <string.h>
#include <xkbcommon/xkbcommon.h>
module Nostro.Ui.Shell:Window_impl;
import std;
import Crafter.Graphics;
import Crafter.Event;
import Nostro.Ui;
import :Window;
import :Loop;
import :Canvas;
using namespace Nostro::Ui;
using namespace Nostro::Ui::Shell;
namespace {
// The window library repeats a held key only while its own frames run; with frames drawn on demand a timer asks
// it to, this often while a key is down.
constexpr std::int64_t repeatMs = 30;
Key Letter(xkb_keysym_t symbol) noexcept {
switch(xkb_keysym_to_lower(symbol)) {
case XKB_KEY_a: return Key::A;
case XKB_KEY_c: return Key::C;
case XKB_KEY_f: return Key::F;
case XKB_KEY_r: return Key::R;
case XKB_KEY_v: return Key::V;
case XKB_KEY_x: return Key::X;
default: return Key::None;
}
}
// The key by what it types on the user's layout, so that Ctrl+A is the key marked A wherever that is.
Key Translate(Crafter::KeyCode code) noexcept {
xkb_state* const state = Crafter::Device::xkb_state;
if(state == nullptr) {
return Key::None;
}
// The window library's code is the kernel's; xkb's is that and 8.
const xkb_keycode_t keycode = code + 8;
const xkb_keysym_t symbol = xkb_state_key_get_one_sym(state, keycode);
switch(symbol) {
case XKB_KEY_Return:
case XKB_KEY_KP_Enter: return Key::Enter;
case XKB_KEY_Escape: return Key::Escape;
case XKB_KEY_Tab:
case XKB_KEY_ISO_Left_Tab: return Key::Tab;
case XKB_KEY_space: return Key::Space;
case XKB_KEY_BackSpace: return Key::Backspace;
case XKB_KEY_Delete:
case XKB_KEY_KP_Delete: return Key::Delete;
case XKB_KEY_Left:
case XKB_KEY_KP_Left: return Key::Left;
case XKB_KEY_Right:
case XKB_KEY_KP_Right: return Key::Right;
case XKB_KEY_Up:
case XKB_KEY_KP_Up: return Key::Up;
case XKB_KEY_Down:
case XKB_KEY_KP_Down: return Key::Down;
case XKB_KEY_Home:
case XKB_KEY_KP_Home: return Key::Home;
case XKB_KEY_End:
case XKB_KEY_KP_End: return Key::End;
case XKB_KEY_Page_Up:
case XKB_KEY_KP_Page_Up: return Key::PageUp;
case XKB_KEY_Page_Down:
case XKB_KEY_KP_Page_Down: return Key::PageDown;
case XKB_KEY_F5: return Key::F5;
default: break;
}
if(const Key letter = Letter(symbol); letter != Key::None) {
return letter;
}
// A layout without Latin letters (Greek, Cyrillic) has no key marked A: the shortcuts are then the keys of the
// first of the user's layouts that has them, as other toolkits have it.
xkb_keymap* const keymap = xkb_state_get_keymap(state);
for(xkb_layout_index_t layout = 0; layout < xkb_keymap_num_layouts_for_key(keymap, keycode); layout++) {
const xkb_keysym_t* symbols = nullptr;
if(xkb_keymap_key_get_syms_by_level(keymap, keycode, layout, 0, &symbols) == 1) {
if(const Key letter = Letter(symbols[0]); letter != Key::None) {
return letter;
}
}
}
return Key::None;
}
Modifiers HeldModifiers() noexcept {
xkb_state* const state = Crafter::Device::xkb_state;
if(state == nullptr) {
return {};
}
return {
.shift = xkb_state_mod_name_is_active(state, XKB_MOD_NAME_SHIFT, XKB_STATE_MODS_EFFECTIVE) > 0,
.control = xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) > 0,
};
}
// The text a key types as the keyboard stands, as the window library reports it: nothing for a key that types a
// control character.
std::string Typed(Crafter::KeyCode code) {
xkb_state* const state = Crafter::Device::xkb_state;
if(state == nullptr) {
return {};
}
std::array<char, 16> buffer{};
const std::int32_t length = xkb_state_key_get_utf8(state, code + 8, buffer.data(), buffer.size());
if(length <= 0 || static_cast<std::uint8_t>(buffer[0]) < 0x20 || buffer[0] == 0x7f) {
return {};
}
return std::string(buffer.data(), std::min<std::size_t>(static_cast<std::size_t>(length), buffer.size() - 1));
}
constexpr Crafter::TextInputPurpose Purpose(TextPurpose purpose) noexcept {
switch(purpose) {
case TextPurpose::Digits: return Crafter::TextInputPurpose::Digits;
case TextPurpose::Number: return Crafter::TextInputPurpose::Number;
case TextPurpose::Phone: return Crafter::TextInputPurpose::Phone;
case TextPurpose::Url: return Crafter::TextInputPurpose::Url;
case TextPurpose::Email: return Crafter::TextInputPurpose::Email;
case TextPurpose::Name: return Crafter::TextInputPurpose::Name;
case TextPurpose::Password: return Crafter::TextInputPurpose::Password;
default: return Crafter::TextInputPurpose::Normal;
}
}
}
Window::Window(Loop& loop, Context& context, Fonts& fonts, const CanvasOptions& options)
: loop(loop), context(context), canvas(fonts, options), source(loop, Crafter::Device::display), frames(loop, canvas.Native().surface),
wake(loop, [this] {
// What the compositor has already sent comes first: a release waiting to be read happened before this time,
// and the press it ends is not a long one.
source.Pump();
Before(NowMs());
}),
repeat(loop, [this] {
if(canvas.Native().heldKeys.empty()) {
return;
}
Crafter::Device::TickKeyRepeats();
repeat.After(repeatMs);
}),
paste(loop, [this] { Paste(); }) {
Crafter::Window& window = canvas.Native();
source.onLost = [this] { Fail("the connection to the compositor is gone"); };
frames.onFrame = [this] { DrawFrame(); };
// The listeners run inside libwayland's dispatch, which nothing may be thrown through.
const auto listen = [this](Crafter::Event<void>& event, std::function<void()> body) {
plain.emplace_back(&event, [this, body = std::move(body)] { this->loop.Guard("an event of the window", body); });
};
listen(window.onMouseLeftClick, [this] { Press(PointerPhase::Down); });
touchDown.emplace(&window.onTouchDown, [this](Crafter::TouchPoint point) {
// Before the library makes it the pointer: the first finger.
if(canvas.Native().primaryTouchId < 0) {
touch = point.id;
touchLifted = false;
resting.reset();
}
});
touchUp.emplace(&window.onTouchUp, [this](Crafter::TouchPoint point) {
if(touch && point.id == *touch) {
touchLifted = true;
}
});
listen(window.onMouseLeftRelease, [this] {
const bool cancelled = touch && !touchLifted;
touch.reset();
Press(cancelled ? PointerPhase::Cancel : PointerPhase::Up);
// What the pointer is over once the release has acted, which may be another screen.
Before(NowMs());
this->context.Hover(resting);
});
listen(window.onTouchCancel, [this] {
touch.reset();
if(down) {
Press(PointerPhase::Cancel);
}
});
listen(window.onMouseMove, [this] {
if(!touch) {
resting = Pointer();
}
if(down) {
Press(PointerPhase::Move);
} else {
Before(EventTime());
this->context.Hover(resting);
}
});
listen(window.onMouseLeave, [this] {
resting.reset();
Before(NowMs());
this->context.Hover(std::nullopt);
});
listen(window.onMouseRightClick, [this] {
Before(EventTime());
this->context.Secondary(Pointer());
});
scroll.emplace(&window.onMouseScroll, [this](std::uint32_t detents) {
this->loop.Guard("the wheel", [this, detents] {
Before(EventTime());
// Whole detents, signed, in an unsigned payload.
this->context.Wheel(Pointer(), static_cast<float>(static_cast<std::int32_t>(detents)));
});
});
keyDown.emplace(&window.onRawKeyDown, [this](Crafter::KeyCode code) {
this->loop.Guard("a key", [this, code] { OnKey(code); });
});
keyUp.emplace(&window.onRawKeyUp, [this](Crafter::KeyCode code) {
if(spent && spent->code == code) {
spent.reset();
}
});
text.emplace(&window.onTextInput, [this](const std::string_view utf8) {
this->loop.Guard("typed text", [this, utf8] { OnText(utf8); });
});
preedit.emplace(&window.onPreedit, [this](const std::string_view utf8) {
this->loop.Guard("the input method", [this, utf8] {
Before(NowMs());
this->context.Preedit(utf8);
});
});
textDelete.emplace(&window.onTextInputDelete, [this](Crafter::TextDelete range) {
this->loop.Guard("the input method", [this, range] {
Before(NowMs());
this->context.DeleteAround(range.beforeBytes, range.afterBytes);
});
});
listen(window.onResize, [this] {
if(failed) {
return;
}
// The screens at the new size at once, so that the next event finds them where they are. The frame is built
// again and not thrown away: a resize is no change of screen, and a menu that is open stays open. An on-screen
// keyboard resizes the window as it comes, which is when a field's own menu is up.
build(shell): name Crafter.Graphics at a commit of its master, and answer a compositor's resize with a frame The app was built against a checkout of Crafter.Graphics given with --graphics=, because the text-input purposes it asks the input method for were uncommitted work in one checkout. They are on Crafter.Graphics' master since a9ce1a0, so project.cpp names the library as a GitProject at that commit, as it names Crafter.Network and Crafter.DB. --graphics= is gone, and with it $NOSTRO_GRAPHICS in build-aarch64.sh and the workflow's step that cloned the branch claude/nostro-app, which the forge never had: neither job of the workflow could have built the app. That master also has 89111e0, which the window was not written against. A size the compositor configures is no longer taken in the configure's listener. The listener keeps it and fires onFrameOwed, and the next Render() makes the swapchain again, fires onResize from inside itself, and answers the configure with that frame's buffer. The window draws on demand, so: - Shell::Window asks for a frame from onFrameOwed. Without it nothing draws the frame that answers the configure, and the window keeps its old size until something else changes on it. - Canvas::Reconcile no longer turns the compositor's sizes into Resize(pixels). The library takes the size asked for last, whoever asked, so that call took the configured size's place, and with it came back the surface a dp larger than configured that 89111e0 had ended (Crafter.Graphics #201). It now sizes the window only where the library does not: the app's own size (--size, SetSize, --scale); the size that comes with a new window (#166), handed over in deferredLogicalWidth, where the library's listener keeps every later one; and a scale the display changes to by itself (#165), through RebuildSwapchain. The last two reach into the library's own state, and go once the library does them. The text-input API on master is the one the app was written against: nothing changed there. Looked at on 2026-11-20 on the made-up system, on a desktop (KWin at a scale of 1.85), with WAYLAND_DEBUG=1 on the app: - The accounts at 420x760: the start, and resize:600,800 from --poke, the app's own size. Each size reaches the surface once, with the first buffer drawn for it. - The same window given 760x532 by the compositor (a KWin script that sets its frameGeometry): the configure is kept, a frame is asked for, and set_destination(760, 532), the acknowledgement and the first buffer of 1406x985 go out together. A temporary probe had that frame's draw list reach 1406x985: it is laid out for the new size. - 421x761, whose pixels at 1.85 are no whole number: it opens as 422x762, since the app's own size goes through Resize in pixels. The notes say so. - --scale 2 --size 360x760, the cards and the pay form filled in from --poke, with resize:400,700: the compositor's sizes are passed over. - The --debug-api build driven with crafter-debug: Window_Resize, Ui_Tap, ui.texts and a screenshot. The two paths that are a phone's, a size in the first configure and a scale named after the first frames, were tried only with the values put in by hand in a temporary probe. Nothing was looked at on a phone, and what the input method is told was not read off the wire: the test window never had the keyboard. 17 tests pass and the four lint passes report nothing. The app, its --debug-api build, the fake system, the x86_64 Flatpak bundle and both aarch64 Flatpaks (build-aarch64.sh) build. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 06:00:54 +01:00
//
// A size the compositor asked for is taken by the frame that answers it, so for that resize this runs from
// inside the library's Render, before anything of the frame is recorded. The frame being drawn is the
// Context's, which Layout builds again where it is: what is drawn is the screens at the new size.
feat(app): add the Nostro app, a window for phones and desktops Linux phones have no banking apps, and a command line is no answer on a phone. The app does everything the nostro command does and, like it, only talks to nostrod: it holds no key and no token. - Nostro.Ui, a toolkit whose screens are functions that fill a frame, ported from imsd-messages ca5cd72d; Nostro.App, the app's state, forms and screens; Nostro.Ui.Shell, which puts them on a Wayland window with Crafter.Graphics; nostro-app; and Nostro.DebugCommands for the --debug-api build. - Client: every method also in an asynchronous form for an sd-event loop, with DaemonMissing and OutcomeUnknown. - nostrod's Flatpak is net.catcrafts.Nostrod now and the app takes net.catcrafts.Nostro; install.sh moves the state. The app's Flatpak, both Flatpaks cross-built for aarch64, and the licence texts they carry. - nostro-fake-system, a made-up bus and bank with a real nostrod on them, to look at the app against. The README's screenshots are taken on it. - The nostro command: an API key's environment is the key's own to say, so --sandbox is for bunq-oauth alone, and a virtual card is listed as VIRTUAL. The published contract changes in three places, before any release (design rule 10): - Transactions' query takes `stored`: answered from what nostrod has stored, without asking the bank. The app searches with it; before, every search was a call to bunq. - AddBunq's `environment` no longer chooses over what the key says of itself: a key of the other environment is refused. - SetCardStatus refuses to freeze or unfreeze a virtual card. bunq reports one as DEACTIVATED however well it pays, and leaves it as it is when asked, without an error. The app is GPL-3.0-only, the library stays LGPL-3.0-only, and no code moved from one to the other (design rule 13). Transaction's schema is unchanged. Verified: the 17 tests pass with every line, function and region of what they link run, and the five lint runs are clean. Every screen was looked at on the made-up system, at a phone's and a desktop's sizes in the light and the dark look, on Plasma under Wayland. What is said of bunq's cards comes from its sandbox, with throwaway users, and from one real virtual card. Known to have been used against production: connecting, and reading accounts, payments and cards. Not known to have been tried: a payment from the app against bunq, OAuth against bunq, and anything on a phone. Building the app takes --graphics=, a Crafter.Graphics checkout on its branch claude/nostro-app, until that branch is merged and pinned here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 12:27:14 +01:00
Layout();
atlasWait.Reset();
frames.RequestRedraw();
});
build(shell): name Crafter.Graphics at a commit of its master, and answer a compositor's resize with a frame The app was built against a checkout of Crafter.Graphics given with --graphics=, because the text-input purposes it asks the input method for were uncommitted work in one checkout. They are on Crafter.Graphics' master since a9ce1a0, so project.cpp names the library as a GitProject at that commit, as it names Crafter.Network and Crafter.DB. --graphics= is gone, and with it $NOSTRO_GRAPHICS in build-aarch64.sh and the workflow's step that cloned the branch claude/nostro-app, which the forge never had: neither job of the workflow could have built the app. That master also has 89111e0, which the window was not written against. A size the compositor configures is no longer taken in the configure's listener. The listener keeps it and fires onFrameOwed, and the next Render() makes the swapchain again, fires onResize from inside itself, and answers the configure with that frame's buffer. The window draws on demand, so: - Shell::Window asks for a frame from onFrameOwed. Without it nothing draws the frame that answers the configure, and the window keeps its old size until something else changes on it. - Canvas::Reconcile no longer turns the compositor's sizes into Resize(pixels). The library takes the size asked for last, whoever asked, so that call took the configured size's place, and with it came back the surface a dp larger than configured that 89111e0 had ended (Crafter.Graphics #201). It now sizes the window only where the library does not: the app's own size (--size, SetSize, --scale); the size that comes with a new window (#166), handed over in deferredLogicalWidth, where the library's listener keeps every later one; and a scale the display changes to by itself (#165), through RebuildSwapchain. The last two reach into the library's own state, and go once the library does them. The text-input API on master is the one the app was written against: nothing changed there. Looked at on 2026-11-20 on the made-up system, on a desktop (KWin at a scale of 1.85), with WAYLAND_DEBUG=1 on the app: - The accounts at 420x760: the start, and resize:600,800 from --poke, the app's own size. Each size reaches the surface once, with the first buffer drawn for it. - The same window given 760x532 by the compositor (a KWin script that sets its frameGeometry): the configure is kept, a frame is asked for, and set_destination(760, 532), the acknowledgement and the first buffer of 1406x985 go out together. A temporary probe had that frame's draw list reach 1406x985: it is laid out for the new size. - 421x761, whose pixels at 1.85 are no whole number: it opens as 422x762, since the app's own size goes through Resize in pixels. The notes say so. - --scale 2 --size 360x760, the cards and the pay form filled in from --poke, with resize:400,700: the compositor's sizes are passed over. - The --debug-api build driven with crafter-debug: Window_Resize, Ui_Tap, ui.texts and a screenshot. The two paths that are a phone's, a size in the first configure and a scale named after the first frames, were tried only with the values put in by hand in a temporary probe. Nothing was looked at on a phone, and what the input method is told was not read off the wire: the test window never had the keyboard. 17 tests pass and the four lint passes report nothing. The app, its --debug-api build, the fake system, the x86_64 Flatpak bundle and both aarch64 Flatpaks (build-aarch64.sh) build. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 06:00:54 +01:00
// The compositor asked for another size, or waits for a frame for another reason: the library has only kept what
// it asked, and answers with the next frame it draws. Frames are drawn here when asked for, so this one is.
// Without it the window keeps its old size until something else changes on it.
listen(window.onFrameOwed, [this] {
if(!failed) {
frames.RequestRedraw();
}
});
feat(app): add the Nostro app, a window for phones and desktops Linux phones have no banking apps, and a command line is no answer on a phone. The app does everything the nostro command does and, like it, only talks to nostrod: it holds no key and no token. - Nostro.Ui, a toolkit whose screens are functions that fill a frame, ported from imsd-messages ca5cd72d; Nostro.App, the app's state, forms and screens; Nostro.Ui.Shell, which puts them on a Wayland window with Crafter.Graphics; nostro-app; and Nostro.DebugCommands for the --debug-api build. - Client: every method also in an asynchronous form for an sd-event loop, with DaemonMissing and OutcomeUnknown. - nostrod's Flatpak is net.catcrafts.Nostrod now and the app takes net.catcrafts.Nostro; install.sh moves the state. The app's Flatpak, both Flatpaks cross-built for aarch64, and the licence texts they carry. - nostro-fake-system, a made-up bus and bank with a real nostrod on them, to look at the app against. The README's screenshots are taken on it. - The nostro command: an API key's environment is the key's own to say, so --sandbox is for bunq-oauth alone, and a virtual card is listed as VIRTUAL. The published contract changes in three places, before any release (design rule 10): - Transactions' query takes `stored`: answered from what nostrod has stored, without asking the bank. The app searches with it; before, every search was a call to bunq. - AddBunq's `environment` no longer chooses over what the key says of itself: a key of the other environment is refused. - SetCardStatus refuses to freeze or unfreeze a virtual card. bunq reports one as DEACTIVATED however well it pays, and leaves it as it is when asked, without an error. The app is GPL-3.0-only, the library stays LGPL-3.0-only, and no code moved from one to the other (design rule 13). Transaction's schema is unchanged. Verified: the 17 tests pass with every line, function and region of what they link run, and the five lint runs are clean. Every screen was looked at on the made-up system, at a phone's and a desktop's sizes in the light and the dark look, on Plasma under Wayland. What is said of bunq's cards comes from its sandbox, with throwaway users, and from one real virtual card. Known to have been used against production: connecting, and reading accounts, payments and cards. Not known to have been tried: a payment from the app against bunq, OAuth against bunq, and anything on a phone. Building the app takes --graphics=, a Crafter.Graphics checkout on its branch claude/nostro-app, until that branch is merged and pinned here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 12:27:14 +01:00
listen(window.onClose, [this] {
if(onClose) {
onClose();
}
});
}
Window::~Window() {
// The compositor's input method is told the field is gone, so that it carries no composition into whatever window
// comes next.
if(applied.active) {
canvas.Native().SetTextInput(false);
}
}
Canvas& Window::Surface() noexcept {
return canvas;
}
bool Window::Failed() const noexcept {
return failed;
}
void Window::Log(std::string_view line) const {
if(onLog) {
onLog(line);
}
}
void Window::Layout() {
Frame& frame = context.Begin(canvas.Bounds(), canvas.Scale(), NowMs());
if(onBuild) {
onBuild(frame);
}
context.End();
// What is under the pointer now, unless it is pressing something: a press stays on what it went down on.
if(!down) {
context.Hover(resting);
}
}
void Window::Before(std::int64_t atMs) {
context.Tick(atMs);
if(!context.Built()) {
Layout();
}
}
void Window::Prepare() {
Before(NowMs());
}
// The time the event being handled happened at, on the host's clock: the compositor's own stamp of it, which an event
// that waited in the queue keeps. By the host's clock at dispatch a backlog of a swipe would be a burst, read as a
// fling at many times the finger's speed, and a tap that waited out a stall would be a long press.
std::int64_t Window::EventTime() {
return clock.At(canvas.Native().lastInputTime, NowMs());
}
Point Window::Pointer() const noexcept {
const Crafter::Window& window = canvas.Native();
return {window.currentMousePos.x, window.currentMousePos.y};
}
void Window::Press(PointerPhase phase) {
const std::int64_t at = EventTime();
Before(at);
if(phase == PointerPhase::Down) {
down = true;
} else if(phase != PointerPhase::Move) {
down = false;
}
context.Pointer(phase, Pointer(), at);
}
void Window::OnKey(Crafter::KeyCode code) {
const Crafter::KeyRepeatState& repeating = Crafter::Device::keyRepeat;
// The library sends a held key down again and again; only its first is a press.
const bool repeated = repeating.active && repeating.key == code;
if(!repeated && spent && spent->code == code) {
spent.reset();
}
if(!repeat.Armed()) {
repeat.After(repeatMs);
}
const Key key = Translate(code);
if(key == Key::None) {
return;
}
Before(NowMs());
const std::string focus(context.Focused());
context.KeyDown(key, HeldModifiers(), repeated);
if(!repeated && (!context.Built() || context.Focused() != focus)) {
// The press changed the screen or moved the focus: what the key types, now and held down, was meant for
// neither the new screen nor the field that has the focus now. Space on a button is the case.
if(std::string typed = Typed(code); !typed.empty()) {
spent = Spent{code, std::move(typed)};
}
}
}
void Window::OnText(std::string_view utf8) {
if(spent && utf8 == spent->text && canvas.Native().heldKeys.contains(spent->code)) {
return;
}
Before(NowMs());
context.Text(utf8);
}
void Window::Start() {
Layout();
Apply(context.Take(), false);
canvas.Render(context.Shown().draw, context.theme.background);
AfterFrame();
// And one when the compositor first shows the window: its size and its scale may only be known by then.
frames.RequestRedraw();
}
void Window::Settle() {
if(failed) {
return;
}
build(shell): name Crafter.Graphics at a commit of its master, and answer a compositor's resize with a frame The app was built against a checkout of Crafter.Graphics given with --graphics=, because the text-input purposes it asks the input method for were uncommitted work in one checkout. They are on Crafter.Graphics' master since a9ce1a0, so project.cpp names the library as a GitProject at that commit, as it names Crafter.Network and Crafter.DB. --graphics= is gone, and with it $NOSTRO_GRAPHICS in build-aarch64.sh and the workflow's step that cloned the branch claude/nostro-app, which the forge never had: neither job of the workflow could have built the app. That master also has 89111e0, which the window was not written against. A size the compositor configures is no longer taken in the configure's listener. The listener keeps it and fires onFrameOwed, and the next Render() makes the swapchain again, fires onResize from inside itself, and answers the configure with that frame's buffer. The window draws on demand, so: - Shell::Window asks for a frame from onFrameOwed. Without it nothing draws the frame that answers the configure, and the window keeps its old size until something else changes on it. - Canvas::Reconcile no longer turns the compositor's sizes into Resize(pixels). The library takes the size asked for last, whoever asked, so that call took the configured size's place, and with it came back the surface a dp larger than configured that 89111e0 had ended (Crafter.Graphics #201). It now sizes the window only where the library does not: the app's own size (--size, SetSize, --scale); the size that comes with a new window (#166), handed over in deferredLogicalWidth, where the library's listener keeps every later one; and a scale the display changes to by itself (#165), through RebuildSwapchain. The last two reach into the library's own state, and go once the library does them. The text-input API on master is the one the app was written against: nothing changed there. Looked at on 2026-11-20 on the made-up system, on a desktop (KWin at a scale of 1.85), with WAYLAND_DEBUG=1 on the app: - The accounts at 420x760: the start, and resize:600,800 from --poke, the app's own size. Each size reaches the surface once, with the first buffer drawn for it. - The same window given 760x532 by the compositor (a KWin script that sets its frameGeometry): the configure is kept, a frame is asked for, and set_destination(760, 532), the acknowledgement and the first buffer of 1406x985 go out together. A temporary probe had that frame's draw list reach 1406x985: it is laid out for the new size. - 421x761, whose pixels at 1.85 are no whole number: it opens as 422x762, since the app's own size goes through Resize in pixels. The notes say so. - --scale 2 --size 360x760, the cards and the pay form filled in from --poke, with resize:400,700: the compositor's sizes are passed over. - The --debug-api build driven with crafter-debug: Window_Resize, Ui_Tap, ui.texts and a screenshot. The two paths that are a phone's, a size in the first configure and a scale named after the first frames, were tried only with the values put in by hand in a temporary probe. Nothing was looked at on a phone, and what the input method is told was not read off the wire: the test window never had the keyboard. 17 tests pass and the four lint passes report nothing. The app, its --debug-api build, the fake system, the x86_64 Flatpak bundle and both aarch64 Flatpaks (build-aarch64.sh) build. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 06:00:54 +01:00
// A size of the app's own that the window is still to take, or a scale the display changed to; the resize builds
// the frame anew by itself (onResize).
feat(app): add the Nostro app, a window for phones and desktops Linux phones have no banking apps, and a command line is no answer on a phone. The app does everything the nostro command does and, like it, only talks to nostrod: it holds no key and no token. - Nostro.Ui, a toolkit whose screens are functions that fill a frame, ported from imsd-messages ca5cd72d; Nostro.App, the app's state, forms and screens; Nostro.Ui.Shell, which puts them on a Wayland window with Crafter.Graphics; nostro-app; and Nostro.DebugCommands for the --debug-api build. - Client: every method also in an asynchronous form for an sd-event loop, with DaemonMissing and OutcomeUnknown. - nostrod's Flatpak is net.catcrafts.Nostrod now and the app takes net.catcrafts.Nostro; install.sh moves the state. The app's Flatpak, both Flatpaks cross-built for aarch64, and the licence texts they carry. - nostro-fake-system, a made-up bus and bank with a real nostrod on them, to look at the app against. The README's screenshots are taken on it. - The nostro command: an API key's environment is the key's own to say, so --sandbox is for bunq-oauth alone, and a virtual card is listed as VIRTUAL. The published contract changes in three places, before any release (design rule 10): - Transactions' query takes `stored`: answered from what nostrod has stored, without asking the bank. The app searches with it; before, every search was a call to bunq. - AddBunq's `environment` no longer chooses over what the key says of itself: a key of the other environment is refused. - SetCardStatus refuses to freeze or unfreeze a virtual card. bunq reports one as DEACTIVATED however well it pays, and leaves it as it is when asked, without an error. The app is GPL-3.0-only, the library stays LGPL-3.0-only, and no code moved from one to the other (design rule 13). Transaction's schema is unchanged. Verified: the 17 tests pass with every line, function and region of what they link run, and the five lint runs are clean. Every screen was looked at on the made-up system, at a phone's and a desktop's sizes in the light and the dark look, on Plasma under Wayland. What is said of bunq's cards comes from its sandbox, with throwaway users, and from one real virtual card. Known to have been used against production: connecting, and reading accounts, payments and cards. Not known to have been tried: a payment from the app against bunq, OAuth against bunq, and anything on a phone. Building the app takes --graphics=, a Crafter.Graphics checkout on its branch claude/nostro-app, until that branch is merged and pinned here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 12:27:14 +01:00
canvas.Reconcile();
// A frame the events left stale is built now: the next event acts on the screens as they are.
if(!context.Built()) {
Layout();
}
Apply(context.Take(), true);
}
void Window::Apply(const Context::Wants& wants, bool redraw) {
if(wants.copy) {
// Refused before the pointer or a finger has been in the window: the compositor takes a selection only from
// whoever it has just sent input.
if(!Crafter::Clipboard::SetText(*wants.copy)) {
Log("the clipboard did not take the copy");
}
}
if(wants.paste) {
pasteInto = std::string(context.Focused());
paste.Schedule();
}
ApplyTextInput(wants.textInput);
if(redraw && wants.redraw) {
// What is drawn may have changed, so the wait for the atlas starts over.
atlasWait.Reset();
frames.RequestRedraw();
}
if(wants.animating != frames.Animating()) {
frames.SetAnimating(wants.animating);
}
if(wants.wakeAtMs) {
wake.At(*wants.wakeAtMs);
} else {
wake.Cancel();
}
}
void Window::ApplyTextInput(const TextInputRequest& want) {
if(want == applied) {
return;
}
Crafter::Window& window = canvas.Native();
// Another field, or none: the input method drops what it was composing and starts afresh, which turning the input
// off does whatever the next field is. The Context took the composed word into its field before it asked.
if(applied.active && (!want.active || want.field != applied.field)) {
window.SetTextInput(false);
}
if(want.active) {
window.SetTextInput(true, 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), Purpose(want.purpose), want.hints);
}
applied = want;
}
void Window::DrawFrame() {
if(failed) {
return;
}
context.Tick(NowMs());
// Everything asked for so far but the frame, which this is.
Apply(context.Take(), false);
Layout();
try {
canvas.Render(context.Shown().draw, context.theme.background);
} catch(const std::exception& error) {
Fail(error.what());
return;
}
AfterFrame();
}
void Window::AfterFrame() {
const Canvas::Stats& stats = canvas.Last();
if(stats.overflowed && !overflowSaid) {
overflowSaid = true;
Log("a frame had more to draw than the window's buffers hold; part of it was left out");
}
// A glyph that found no cell in the font atlas drew blank and gets one when a later frame begins, and a frame
// comes only when asked for.
atlasWait.patience = Canvas::atlasPatience;
if(atlasWait.Again(stats.glyphsWaiting)) {
frames.RequestRedraw();
}
if(onFrame) {
onFrame();
}
}
void Window::Screenshot(const std::filesystem::path& png) {
context.Tick(NowMs());
Layout();
canvas.Capture(png);
canvas.Render(context.Shown().draw, context.theme.background);
AfterFrame();
}
// From the loop, never from inside a listener: the library waits for the clipboard's owner, for up to a second, and
// serves the compositor meanwhile, so its events run the listeners here from inside the read. Asked for from the loop
// that is all that happens; asked for from a listener they would run inside one another.
void Window::Paste() {
if(failed) {
return;
}
std::optional<std::string> clipboard = Crafter::Clipboard::GetText();
if(!clipboard) {
return;
}
// Not into another field than the one that asked, if the focus moved on while the clipboard was read.
if(!clipboard->empty() && context.Focused() == pasteInto) {
Before(NowMs());
context.Paste(*clipboard);
}
// It may have been a key for a bank.
explicit_bzero(clipboard->data(), clipboard->size());
}
void Window::Fail(std::string_view why) {
failed = true;
wake.Cancel();
repeat.Cancel();
frames.SetAnimating(false);
if(onFailed) {
onFailed(why);
}
}