Stage 1 tasks
Stage 1 is the demo: examples/demo.tcl opens a window on Linux, with grid, labels, buttons, and an entry, with bind, with a CSS stylesheet, and with a GPU renderer at 60 frames in each second. The same demo also draws directly on the display of a Linux device with no display server: with Vulkan on the display, or on the CPU to the framebuffer. The plan has the design.
Do the tasks in order. One task is one commit, or a few commits when the task says so. Do not start a task before the tests of the task before it pass.
| # | Task | Needs | ztcl event loop |
|---|---|---|---|
| 01 | Project skeleton | ||
| 02 | App, widget tree, frame, destroy, winfo |
01 | |
| 03 | Options: configure and cget |
02 | |
| 04 | The event loop adapter | 02 | yes |
| 05 | The backend interface and the headless backend | 04 | |
| 06 | The scene, the CPU renderer, and golden images | 01 | |
| 07 | Text: the built-in font engine | 06 | |
| 08 | The CSS parser | 01 | |
| 09 | Selectors, the cascade, and ztk::style |
03, 07, 08 | |
| 10 | grid |
03 | |
| 11 | The frame pipeline, ., frame, label, and wm |
05, 07, 09, 10 | |
| 12 | Events, bind, and event generate |
11 | uses 04 |
| 13 | Focus | 12 | |
| 14 | button |
13 | |
| 15 | entry |
14 | uses 04 |
| 16 | The Vulkan renderer | 07 | |
| 17 | The Wayland backend and the ztk program |
15, 16 | |
| 17b | The render thread | 17 | |
| 18 | Frame pacing, transitions, statistics, and memory | 17 | uses 04 |
| 19 | The demo, the scene checks, and the end-to-end tests | 18 | |
| 20 | The direct backend | 19 | |
| 21 | The Stage 1 report | 20 |
Tasks 06, 07, 08, and 16 need no widget code. They can go before their place in the order when another task is blocked. The framebuffer output of task 20 does not need tasks 16 and 17.
Tasks 06, 07, 12, 18, 19, and 20 use what the Printdeck project learned with its own UI framework on a small touch screen. The lessons has the facts. The implementer reads that page and does not open the Printdeck source, because Printdeck has the AGPL.
The ztcl event loop
The event loop of ztcl (after, vwait, update, fileevent) is not on the main branch of ztcl at commit 125392f. Stage 1 does not wait for it.
- Task 04 makes
src/loop.zig. It has the timers and the idle list of ztk, and it registersafter,update,vwait, andtkwait. - All other code calls only the functions of
src/loop.zig. No other file registers a timer command. - When the loop of ztcl is on
mainand it has the event source of request 2 in the plan, a later task changes the inside ofsrc/loop.zig. The tests of task 04 stay and must still pass. - When the loop of ztcl is on
mainwithout that event source, keep the loop of ztk. Do not turn on theeventcapability of ztcl, because then two sets of timers exist. - Before task 04, check the pinned ztcl:
it.findCommand("after")in a test. If the pinned ztcl hasafterwith no capability, stop and report. That is a change of ztcl that this plan does not cover.
Rules for each task
- Use Zig 0.16.0. Check with
zig version. - Run each build, test, and benchmark under the memory cap:
The commands in the task files do not show the cap. Add it to each one.systemd-run --user --scope -q -p MemoryMax=4G -p MemorySwapMax=0 -- <command> - Stop only your own processes, by PID. Do not use
pkill -f. - Work only in the ztk repository. Read ztcl through the pinned package. Do not change the local ztcl folder, and do not read the zslice source or the Printdeck source.
- Read WRITING.md before the first comment and the first commit.
- Start each source file with a
//!comment that explains what the file does and how, and an SPDX line:// SPDX-License-Identifier: BSD-2-Clause(inside the//!block, as ztcl does). - Add no dependency that the plan does not list. Stage 1 links only the Wayland client library,
libxkbcommon, and libc for the Wayland backend, and opens the Vulkan loader at run time. The core, the text code, the headless backend, and the direct backend link no library. - ztk keeps its state in the allocator of the
App. It keeps noztcl.Valueand no slice of the ztcl arena after a command returns. Copy what must stay. - Each error message that Tk also has is the same text as in
wish8.6.16. Runwishto get the text. Do not guess it. - Each behavior comes from the manual page or from a run of
wish. Copy no code from Tk. Add an entry indocs/references/for each new source. - A test that needs something the machine does not have (a GPU, a Wayland compositor,
wish) skips with a message that names the missing thing. It does not pass silently, and the report counts it as skipped. - Do not change a golden file to make a test pass, unless the task changes that output on purpose. Say so in the commit message.
- Run
zig build testbefore each commit. All tests pass. - A commit message passes
WRITING.md. It names no AI model and no vendor, and has no attribution line. - When a step of a task is not possible, stop and write the reason in
docs/tasks/BLOCKED.md: the task, the step, what you tried, and the exact error. Then go to the next task that does not need the blocked one. - When a task file and the manual page of Tk disagree, the manual page and
wishwin. Note the difference in the commit message.
Facts about the build that were checked
These were checked on the development machine on 2026-11-23 with a scratch program.
- A Zig 0.16.0 program that links the system libc fails in the linker of Zig:
unhandled relocation type R_X86_64_PC64incrt1.o, section.sframe. Setuse_llvm = trueanduse_lld = trueon each executable and each test that links libc. Then it links and runs. @cImportworks forwayland-client.h,xkbcommon/xkbcommon.h, andvulkan/vulkan.h.Module.linkSystemLibrary(name, .{})findswayland-clientandxkbcommonthroughpkg-config.- The machine has no Vulkan headers in
/usr/include. The build must get them from a package (task 16). std.DynLib.open("libvulkan.so.1")opens the Vulkan loader at run time, andvkGetInstanceProcAddrfrom it gives the other functions. The program then has no link to the loader.vkCreateInstanceworks and reports two physical devices. The machine has no software Vulkan driver.- The loader lists the instance extensions
VK_KHR_display,VK_KHR_wayland_surface, andVK_EXT_headless_surface. - A program with ztcl and no libc builds as a static executable (
fileprintsstatically linked) and runs. The same program builds with-Dtarget=aarch64-linux. The ARM program was not run. - Python has the package
fontTools4.67.0, andttxis on the path.hb-shapeis not on the machine. glslc,wayland-scanner,weston,sway,Xvfb,xvfb-run,wish8.6.16, andtclsh8.6are on the path.wayland-protocols1.49 is in/usr/share/wayland-protocols.std.compress.flatehasCompress.zigandDecompress.zig.std.Build.TestOptionshas the fieldsfilters,use_llvm, anduse_lld.examples/demo.tclof task 19 runs inwish8.6.16 as written in that task.
The ztcl interface
The signatures are from ztcl commit 125392f. Check them in the pinned package before use.
const ztcl = @import("ztcl");
// ztcl.Interp, ztcl.Value, ztcl.Error
// ztcl.interp.NativeFn = *const fn (it: *Interp, argv: []const Value, cmd: ?*Cmd) Error!Value
// ztcl.interp.Command { name, impl, ctx: ?*anyopaque, traces }
it.init(gpa) // the Interp must not move after init
it.register(name, native_fn) // then: it.findCommand(name).?.ctx = ptr
it.findCommand(name) ?*Command
it.eval(text) Error!Value // copies and parses the text at each call
it.compile(text) Error!*Script // text must stay valid as long as the script
it.evalTop(script) Error!Value
it.callWords(argv) Error!Value
it.str(v) / it.list(v) / it.int(v)
it.setVar(name, v) / it.getVarOpt(name)
it.fail(fmt, args) Error // sets the result, returns error.TclError
it.wrongArgs(usage) Error
it.alloc() // the arena of the interpreter
it.result // the message after error.TclError
it.frame, it.global, it.ns // set frame = &global and ns = "" for a callback
argv[0] of a native command is the command name.
Names used in all tasks
| Name | File | Meaning |
|---|---|---|
App |
src/app.zig |
One ztk instance on one interpreter |
Widget |
src/widget.zig |
One node of the widget tree |
Class |
src/widget.zig |
The table of a widget class |
Loop |
src/loop.zig |
Timers, idle work, and the wait |
Platform, Window |
src/platform/platform.zig |
The backend interface |
Event |
src/event.zig |
One input event |
Scene, Quad |
src/scene.zig |
What a frame draws |
Renderer |
src/render/renderer.zig |
The interface of the CPU and Vulkan renderers |
Style |
src/style.zig |
The computed style of a widget |
Harness |
src/testing.zig |
An interpreter, an App, and a headless backend for a test |