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

344 lines
15 KiB
C++
Raw 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 "vulkan/vulkan.h"
module Nostro.Ui.Shell:Canvas_impl;
import std;
import Crafter.Graphics;
import Crafter.Event;
import Nostro.Ui;
import :Canvas;
using namespace Nostro::Ui;
using namespace Nostro::Ui::Shell;
namespace fs = std::filesystem;
namespace {
// A font's file, or the error that names it: the window library reads a file that is not there as an empty font.
fs::path Existing(fs::path file) {
std::error_code ignored;
if(!fs::is_regular_file(file, ignored)) {
throw std::runtime_error(std::format("the font {} is missing", file.string()));
}
return file;
}
constexpr Crafter::TextAlign Align(TextAlign align) noexcept {
switch(align) {
case TextAlign::Center: return Crafter::TextAlign::Center;
case TextAlign::Right: return Crafter::TextAlign::Right;
default: return Crafter::TextAlign::Left;
}
}
}
Fonts::Fonts(const fs::path& directory) : regular(Existing(directory / "NotoSans-Regular.ttf")), medium(Existing(directory / "NotoSans-Medium.ttf")) {
}
Crafter::Font& Fonts::Face(FontFace face) noexcept {
// There is no font of symbols yet: what asks for one is set in the text font, which has the few marks in use.
return face == FontFace::Medium ? medium : regular;
}
TextMeasure Fonts::Measure() {
return {
.advance = [this](FontFace face, std::uint32_t codepoint, float px) {
Crafter::Font& font = Face(face);
return static_cast<float>(font.AdvanceUnits(codepoint)) * font.ScaleForSize(px);
},
.ascent = [this](FontFace face, float px) { return Face(face).AscentPx(px); },
.lineHeight = [this](FontFace face, float px) { return Face(face).LineHeight(px); },
};
}
Canvas::Parts::Parts(std::uint32_t width, std::uint32_t height, std::string_view title) : window(width, height, title) {
}
Canvas::Canvas(Fonts& fonts, const CanvasOptions& options) : fonts(fonts), logicalWidth(static_cast<std::int32_t>(options.widthDp)), logicalHeight(static_cast<std::int32_t>(options.heightDp)), pretend(options.scale) {
// The device is the process's own and is set up once, whatever number of windows the process makes.
static bool deviceReady = false;
if(!deviceReady) {
std::error_code ignored;
fs::create_directories(options.cache, ignored);
Crafter::Device::pipelineCachePath = options.cache / "pipeline_cache.bin";
Crafter::Device::Initialize();
deviceReady = true;
}
// In pixels at a scale of 1; the display's scale is known only once the window is there.
parts.emplace(options.widthDp, options.heightDp, options.title);
try {
Crafter::Window& window = parts->window;
window.SetAppId(options.appId);
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 size the compositor gave with the new window, the whole screen on a phone, which the library passes over
// (Crafter.Graphics #166). It is handed to the library as its own listener keeps every later one, and taken
// at once: as the surface's size, unchanged, with the pixels that come to at the display's scale. Sized in
// pixels instead, the surface would be what those come back to, a dp more than the screen at a scale such as
// 2.85. Nothing is listening yet, and nothing has been made for the window's size.
if(!pretend && window.pendingLogicalWidth > 0 && window.pendingLogicalHeight > 0) {
window.deferredLogicalWidth = window.pendingLogicalWidth;
window.deferredLogicalHeight = window.pendingLogicalHeight;
window.RebuildIfDeferred();
wanted = false;
}
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
Reconcile();
const VkCommandBuffer init = window.StartInit();
// A slot for every buffer of the pool, and a few to spare; the renderer's own images and its sampler.
constexpr std::uint16_t bufferSlots = (smallPairs + largePairs) * 2 * Crafter::Window::numFrames + 16;
parts->heap.Initialize(16, bufferSlots, 4);
window.descriptorHeap = &parts->heap;
parts->atlas.Initialize(init);
parts->renderer.fontAtlas = &parts->atlas;
// By their full paths: the library looks for its shaders in the working directory, which is the user's.
parts->renderer.Initialize(window, parts->heap, init, options.assets / "ui-quads.comp.spv", options.assets / "ui-circles.comp.spv", options.assets / "ui-images.comp.spv", options.assets / "ui-text.comp.spv", options.assets / "ui-fused.comp.spv");
window.passes.push_back(&parts->renderer);
for(FrameSet& set : parts->pool) {
MakePairs(set.small, smallPairs, smallBoxes, smallGlyphs);
MakePairs(set.large, largePairs, largeBoxes, largeGlyphs);
}
parts->build.emplace(&parts->renderer.onBuild, [this](Crafter::UIBuildArgs args) { Build(args.cmd, args.frameIdx); });
window.FinishInit();
} catch(...) {
Release();
throw;
}
}
Canvas::~Canvas() {
Release();
}
void Canvas::Release() noexcept {
if(!parts) {
return;
}
// The frames still on the GPU read the pool's buffers as they run.
vkDeviceWaitIdle(Crafter::Device::device);
parts.reset();
// What the parts held is queued for a later frame to free, and none comes.
Crafter::Device::DrainDeletions();
}
void Canvas::MakePairs(std::vector<Pair>& pairs, std::uint32_t count, std::uint32_t boxCap, std::uint32_t glyphCap) {
constexpr VkBufferUsageFlags2 usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
pairs.reserve(count);
for(std::uint32_t i = 0; i < count; i++) {
Pair& pair = pairs.emplace_back();
// Memory the host writes, on the device too where there is such a kind: a GPU with memory of its own need not
// have one.
pair.boxes.Create(usage, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, boxCap, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
pair.glyphs.Create(usage, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, glyphCap, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
pair.boxSlot.emplace(parts->renderer.RegisterBuffer(pair.boxes));
pair.glyphSlot.emplace(parts->renderer.RegisterBuffer(pair.glyphs));
pair.boxCap = boxCap;
pair.glyphCap = glyphCap;
}
}
Crafter::Window& Canvas::Native() noexcept {
return parts->window;
}
const Crafter::Window& Canvas::Native() const noexcept {
return parts->window;
}
float Canvas::Scale() const noexcept {
const float scale = pretend.value_or(parts->window.scale);
return scale > 0 ? scale : 1.0f;
}
Box Canvas::Bounds() const noexcept {
return {0, 0, static_cast<float>(parts->window.width), static_cast<float>(parts->window.height)};
}
bool Canvas::Reconcile() {
Crafter::Window& window = parts->window;
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 frame being recorded draws at the size it began with. What the app asked for waits for the next look.
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
if(window.recording) {
return false;
}
// In pixels by the library's own sum, so that a size the library did apply is found applied.
const float scale = Scale();
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
const auto pixels = [scale](std::int32_t length) { return static_cast<std::uint32_t>(std::ceil(static_cast<float>(length) * scale)); };
const std::uint32_t ownWidth = pixels(logicalWidth);
const std::uint32_t ownHeight = pixels(logicalHeight);
const std::uint32_t widthBefore = window.width;
const std::uint32_t heightBefore = window.height;
if(pretend || wanted) {
// The app's own size. The library takes the size asked for last, whoever asked, so this also takes the place
// of one the compositor asked for that still waits for its frame: at a scale that is not the display's the
// compositor's sizes mean something else, and every one of them is passed over this way.
wanted = false;
window.Resize(ownWidth, ownHeight);
} else if(window.deferredLogicalWidth == 0) {
// Nothing asked for is waiting, so the window has its size, and what can be off is its pixels: the display's
// scale changed since they were worked out, which the library leaves until it next makes the window's images
// (Crafter.Graphics #165). (While a size the compositor asked for waits for the frame that answers it, the
// library takes it there with the scale of that moment, and a size asked for here would take its place.)
if(window.logicalConfigured) {
// The compositor's size, which the surface keeps: the images are made again, and the library works the
// pixels out for them.
if(pixels(window.logicalWidth) != window.width || pixels(window.logicalHeight) != window.height) {
window.RebuildSwapchain();
}
} else if(ownWidth != 0 && ownHeight != 0 && (ownWidth != window.width || ownHeight != window.height)) {
// The app's size, which is these pixels.
window.Resize(ownWidth, ownHeight);
}
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
}
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
return window.width != widthBefore || window.height != heightBefore;
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
}
void Canvas::SetSize(std::uint32_t widthDp, std::uint32_t heightDp) noexcept {
logicalWidth = static_cast<std::int32_t>(widthDp);
logicalHeight = static_cast<std::int32_t>(heightDp);
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
wanted = true;
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
}
void Canvas::Render(const DrawList& list, Color ground) {
drawing = &list;
background = ground;
try {
parts->window.Update();
} catch(...) {
drawing = nullptr;
throw;
}
drawing = nullptr;
frames++;
}
void Canvas::Capture(const fs::path& png) {
parts->window.CaptureNextFrame(png);
}
const Canvas::Stats& Canvas::Last() const noexcept {
return stats;
}
std::uint64_t Canvas::Frames() const noexcept {
return frames;
}
std::string Canvas::Device() const {
// The name is a C array of the driver's.
const std::string_view name(Crafter::Device::deviceProperties.deviceName);
return std::format("{} ({})", name, Crafter::Device::descriptorHeapSupported ? "descriptor heap" : "descriptor sets");
}
void Canvas::Build(VkCommandBuffer commands, std::uint32_t frameIndex) {
FrameSet& set = parts->pool[frameIndex];
set.smallUsed = 0;
set.largeUsed = 0;
stats = {};
// Nothing clears the window's image, so the ground is the first thing drawn: under the first batch where that
// covers the whole window, which saves a pass over it, and by itself otherwise.
const RectItem ground{.box = Bounds(), .color = background};
bool grounded = false;
if(drawing != nullptr) {
for(std::size_t layer = 0; layer < layerCount; layer++) {
for(const Batch& batch : drawing->Batches(static_cast<Layer>(layer))) {
if(!grounded && batch.clip) {
Submit(commands, set, Batch(), &ground);
}
Submit(commands, set, batch, grounded ? nullptr : &ground);
grounded = true;
}
}
}
if(!grounded) {
Submit(commands, set, Batch(), &ground);
}
}
Canvas::Pair* Canvas::Take(FrameSet& set, std::size_t boxes, std::size_t glyphs) noexcept {
if(boxes <= smallBoxes && glyphs <= smallGlyphs && set.smallUsed < set.small.size()) {
return &set.small[set.smallUsed++];
}
if(set.largeUsed < set.large.size()) {
return &set.large[set.largeUsed++];
}
// No large pair left for a batch that wants one: a small one shows the start of it.
if(set.smallUsed < set.small.size()) {
return &set.small[set.smallUsed++];
}
return nullptr;
}
void Canvas::Submit(VkCommandBuffer commands, FrameSet& set, const Batch& batch, const RectItem* under) {
// A glyph per code point at most: enough to choose the buffers by.
std::size_t glyphsNeeded = 0;
for(const TextItem& text : batch.texts) {
glyphsNeeded += CountCodepoints(text.text);
}
const std::size_t boxesNeeded = batch.rects.size() + batch.circles.size() + (under != nullptr ? 1 : 0);
if(boxesNeeded == 0 && glyphsNeeded == 0) {
return;
}
Pair* const pair = Take(set, boxesNeeded, glyphsNeeded);
if(pair == nullptr) {
stats.overflowed = true;
return;
}
std::uint32_t boxes = 0;
const auto box = [this, pair, &boxes](Box at, Color color, Corners corners, float outline, Color outlineColor) {
if(boxes >= pair->boxCap) {
stats.overflowed = true;
return;
}
// On whole pixels, edge by edge: boxes that share an edge still do, and a hairline is one row of pixels, not
// two half-lit ones.
const float left = std::round(at.x);
const float top = std::round(at.y);
const float right = std::round(at.Right());
const float bottom = std::round(at.Bottom());
pair->boxes.value[boxes] = Crafter::QuadItem{left, top, right - left, bottom - top, color.r, color.g, color.b, color.a, corners.topLeft, corners.topRight, corners.bottomRight, corners.bottomLeft, outline, outlineColor.r, outlineColor.g, outlineColor.b};
boxes++;
};
if(under != nullptr) {
box(under->box, under->color, under->corners, under->outline, under->outlineColor);
}
for(const RectItem& rect : batch.rects) {
box(rect.box, rect.color, rect.corners, rect.outline, rect.outlineColor);
}
// A circle is a square with its corners rounded all the way, which leaves the batch one kind of shape and one
// buffer for it.
for(const CircleItem& circle : batch.circles) {
box({circle.center.x - circle.radius, circle.center.y - circle.radius, circle.radius * 2, circle.radius * 2}, circle.color, Corners::All(circle.radius), circle.outline, circle.outlineColor);
}
std::uint32_t glyphs = 0;
for(const TextItem& text : batch.texts) {
Crafter::Font& font = fonts.Face(text.face);
// The baseline on a whole pixel, so that a line of text looks the same wherever it is.
glyphs += parts->renderer.ShapeText(font, text.px, text.x, std::round(text.baseline), text.text, {text.color.r, text.color.g, text.color.b, text.color.a}, pair->glyphs.value + glyphs, pair->glyphCap - glyphs, nullptr, Align(text.align));
// A glyph with ink that found no cell in the atlas drew blank, and gets one when a later frame begins: counted,
// so that the frame is asked for.
for(std::size_t i = 0; i < text.text.size();) {
const std::uint32_t codepoint = DecodeUtf8(text.text, i);
if(const Crafter::Glyph* glyph = parts->atlas.Lookup(font, codepoint); glyph != nullptr && glyph->w > 0 && !glyph->Resident()) {
stats.glyphsWaiting++;
}
}
}
if(glyphsNeeded > pair->glyphCap) {
stats.overflowed = true;
}
if(boxes == 0 && glyphs == 0) {
return;
}
if(boxes > 0) {
pair->boxes.FlushDevice(commands, VK_ACCESS_SHADER_READ_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
}
if(glyphs > 0) {
pair->glyphs.FlushDevice(commands, VK_ACCESS_SHADER_READ_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
}
const std::array<float, 4> clip = batch.clip ? std::array<float, 4>{batch.clip->x, batch.clip->y, batch.clip->w, batch.clip->h} : std::array<float, 4>{0.0f, 0.0f, 1e9f, 1e9f};
parts->renderer.DispatchFused(commands, {*pair->boxSlot, boxes, clip}, {}, {}, {*pair->glyphSlot, glyphs, clip});
stats.batches++;
stats.boxes += boxes;
stats.glyphs += glyphs;
}