Ui: the window on Crafter.Graphics, driven from the GLib main loop
The window library. Loop makes the Wayland display a GSource (libwayland's prepare_read protocol) so D-Bus and the window are served from one thread without the library's StartSync, which runs a loop of its own that serves no GMainContext and would starve the bus; the app owns its frame callback too — a redraw is a frame request and a bare commit, the compositor's done runs one Window::Update, and nothing re-arms unless something is dirty or animating — or the day changes: the captions name the day and an idle window draws no frame by itself, so a timer on the wall clock, which wakes at the next local midnight and whenever that clock is set, asks for one when the local date is another one (DayWatch); when the compositor's connection breaks the source stops and says so (App's onDisplayLost), since the process cannot connect its display again. Canvas initialises the device once per process and holds the window, the font with a word wrapper and a text width over its unrounded advances, as DrawText draws them, and four compositing layers (background, the clipped scrolling content, the chrome, an overlay): within one fused dispatch all quads composite before all text, so the layers are separate dispatches in that order. The layers' buffer slots hand their numbers back to the descriptor heap when they go, so the heap is declared before them and outlives them. Screens draw the conversation list (avatars, previews, time captions, unread badges, the new-conversation button, with room under the last row to scroll clear of it) and one conversation (day separators, wrapped bubbles, clock and state captions — only what is in view, the layer's glyph budget being finite) and record the regions a tap can hit. App wires them to the store and Sync: mouse events become gestures (the detector's slop and fling threshold set from the window's scale, the positions being buffer pixels), a tap is resolved against the last frame's regions (which name the conversation or message they drew, not a position a reload may shift), scrolling is by wheel, drag or fling (a press stops a fling; a screen change stops a fling and cancels the press under it, so the scroll left behind keeps no velocity for a return to revive and a release after a link's or a notification's Open is no tap on the new screen), the window is created on the first Show (when the library cannot and says so — no display, a compositor without wl_shm, wl_compositor or xdg_wm_base, no Vulkan driver — Show logs why, Open opens nothing, and the app runs on without one; a later Show fails at once, the device's set-up running only once) and torn down in order on Shutdown. ScreenshotThenQuit renders one frame outside the compositor's pacing and saves it; a window it creates first waits 600 ms for the compositor's configure, which sizes it (to the screen, on a phone). A capture with no window to render it — none could be made, or it went before the frame — is logged and sets App's exitCode to 1. project.cpp gains Crafter.Graphics (--local takes the branch worktree with the Wayland input work until it is merged), the imsd-messages-ui library, and libevdev from the prefix of packaging/build-libevdev.sh on the library's include path and the executable's library path (a sysroot build looks for it in the sysroot instead).
This commit is contained in:
parent
f360a746c2
commit
6eea7228d0
8 changed files with 1132 additions and 3 deletions
48
project.cpp
48
project.cpp
|
|
@ -77,6 +77,11 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
Configuration* db = local
|
||||
? LocalProject({ .projectFile = "../Crafter/Crafter.DB/project.cpp", .args = depArgs })
|
||||
: GitProject({ .source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.DB.git" }, .args = depArgs });
|
||||
// The window library. --local takes the branch worktree with the Wayland
|
||||
// input work until it is merged.
|
||||
Configuration* graphics = local
|
||||
? LocalProject({ .projectFile = "../Crafter/Crafter.Graphics-imsd-messages/project.cpp", .args = depArgs })
|
||||
: GitProject({ .source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.Graphics.git" }, .args = depArgs });
|
||||
|
||||
// imsd-messages-core — numbers, time, the model, word wrap, gestures,
|
||||
// the store and the sync logic: std + Crafter.DB, no GLib, so every
|
||||
|
|
@ -127,6 +132,28 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
const GioFlags gio = ComputeGioFlags(*Bus);
|
||||
ApplyGioFlags(*Bus, gio);
|
||||
|
||||
// imsd-messages-ui — the window: Crafter.Graphics driven from the GLib
|
||||
// main loop.
|
||||
static auto Ui = std::make_unique<Configuration>();
|
||||
Ui->path = "./";
|
||||
Ui->name = "imsd-messages-ui";
|
||||
Ui->outputName = "imsd-messages-ui";
|
||||
ApplyStandardArgs(*Ui, args);
|
||||
Ui->type = ConfigurationType::LibraryStatic;
|
||||
Ui->dependencies = { Core.get(), graphics };
|
||||
{
|
||||
std::array<fs::path, 5> ifaces = {
|
||||
"interfaces/ImsdMessages.Ui",
|
||||
"interfaces/ImsdMessages.Ui-Loop",
|
||||
"interfaces/ImsdMessages.Ui-Canvas",
|
||||
"interfaces/ImsdMessages.Ui-Screens",
|
||||
"interfaces/ImsdMessages.Ui-App",
|
||||
};
|
||||
std::array<fs::path, 0> impls = {};
|
||||
Ui->GetInterfacesAndImplementations(ifaces, impls);
|
||||
}
|
||||
ApplyGioFlags(*Ui, gio);
|
||||
|
||||
// imsd-messages — the executable: the command line, the window and the
|
||||
// wiring between the bus layer and the UI.
|
||||
Configuration cfg;
|
||||
|
|
@ -135,13 +162,32 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
cfg.outputName = "imsd-messages";
|
||||
ApplyStandardArgs(cfg, args);
|
||||
cfg.type = ConfigurationType::Executable;
|
||||
cfg.dependencies = { Core.get(), Bus.get(), db };
|
||||
cfg.dependencies = { Core.get(), Bus.get(), Ui.get(), db };
|
||||
{
|
||||
std::array<fs::path, 0> ifaces = {};
|
||||
std::array<fs::path, 1> impls = { "implementations/main" };
|
||||
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
||||
}
|
||||
ApplyGioFlags(cfg, gio);
|
||||
cfg.files.push_back("assets/NotoSans-Regular.ttf");
|
||||
|
||||
// libevdev, for Crafter.Graphics's gamepad backend: the crafter-build
|
||||
// Flatpak's SDK has none, so a sysroot build looks for it in the
|
||||
// sysroot and a native build in the prefix of
|
||||
// packaging/build-libevdev.sh. Crafter.Graphics itself names
|
||||
// the host's directory, which is an ignored, absent path in the sandbox.
|
||||
if (!cfg.sysroot.empty()) {
|
||||
graphics->compileFlags.push_back("-I=/usr/include/libevdev-1.0");
|
||||
} else {
|
||||
const std::string arch = cfg.target.substr(0, cfg.target.find('-'));
|
||||
const char* env = std::getenv("IMSD_MESSAGES_LIBEVDEV");
|
||||
const char* home = std::getenv("HOME");
|
||||
const fs::path prefix = env ? fs::path(env) : fs::path(home ? home : ".") / ".cache" / "imsd-messages" / std::format("libevdev-{}", arch);
|
||||
if (!fs::exists(prefix / "include" / "libevdev-1.0")) std::println(std::cerr, "imsd-messages: no libevdev at {} — run packaging/build-libevdev.sh first", prefix.string());
|
||||
graphics->compileFlags.push_back(std::format("-I{}", (prefix / "include" / "libevdev-1.0").string()));
|
||||
cfg.linkFlags.push_back(std::format("-L{}", (prefix / "lib").string()));
|
||||
cfg.linkFlags.push_back(std::format("-Wl,-rpath,{}", (prefix / "lib").string()));
|
||||
}
|
||||
|
||||
cfg.AddTest("Number").Dependencies({ Core.get() });
|
||||
cfg.AddTest("Time").Dependencies({ Core.get() });
|
||||
|
|
|
|||
Loading…
Reference in a new issue