Develop on Linux
This page is the loop of a developer on Linux: run a script, choose the renderer, find a bug, test the window, and make an app with a desktop entry.
Run a script
ztk app.tcl
The program runs until the last window closes or the script calls exit. After you change the script, close the window and run the command again.
| Output | Where it goes |
|---|---|
puts |
The terminal. |
An error in a binding or a -command |
The terminal. The window stays open. |
| An error in the main script | The terminal. The program ends with the status 1. |
Quick start has a first script with a style sheet, and The ztk program has each flag.
The display and the renderer
ztk chooses the display from the environment:
| Session | What ztk uses |
|---|---|
WAYLAND_DISPLAY is set |
The Wayland client, with Vulkan or the CPU renderer. |
Only DISPLAY is set |
The X11 client, with the CPU renderer. |
No display, or --headless |
The headless backend: no window, the CPU renderer. |
On Wayland, ztk draws with Vulkan when the GPU and the compositor share buffers (zwp_linux_dmabuf_v1 version 3 with linear XBGR8888). Else it draws with the CPU renderer, and it writes the cause to the terminal once:
ztk: the CPU renderer: the compositor has no zwp_linux_dmabuf_v1 version 3
These variables change the choice:
| Variable | What it does |
|---|---|
ZTK_RENDERER=cpu (or the flag --cpu) |
Uses the CPU renderer on Wayland. |
ZTK_RENDERER=vulkan |
Uses Vulkan, and stops the program when Vulkan does not work. |
ZTK_WAYLAND_DEBUG=1 |
Prints each Wayland event to the terminal. |
ZTK_WAYLAND_CSD=1 |
Draws the title bar of ztk also on a compositor that draws the frames of the windows (The title bar on GNOME and weston). |
ZTK_NO_ANIMATION=1 |
Turns the animations off. |
Find a bug
ztk::debug tells you why a widget looks or acts as it does: the source of each option, the geometry chain of its size, and what ran for a click.
ztk::debug sources on
ttk::button .ok -text Save
pack .ok
.ok configure -state disabled
puts [ztk::debug why .ok -state]
The output names the line that set the option. Debugging has each tool. ztk --mcp app.tcl gives the same tools to an agent.
Test the window
--headless runs a script with no display. A test drives the window with ztk::inject and reads it with ztk::tree, so it runs in CI with no display server. For agents has a test that clicks a button and checks the count. --screenshot writes the last frame to a PNG file:
ztk --headless --scale 2 --exit-after-frames 2 --screenshot app.png app.tcl
On Linux a headless picture has the look of a window, because ztk draws each window itself. The picture has no frame of the compositor.
Make an app
ztk bundle writes one program file, a copy of the ztk program with the scripts in it. With --desktop it also writes a desktop entry and an icon, so the app shows in the menu of the desktop:
ztk bundle -o notes --desktop --name "My Notes" --icon notes.png \
notes.tcl lib/ images/
The command writes three files:
| File | What it is |
|---|---|
notes |
The program, with the scripts and the files inside it. |
notes.desktop |
The desktop entry, with Exec=notes. |
notes.png |
The icon, 256 pixels or less. |
Install the three files for your user:
install -D notes ~/.local/bin/notes
install -D -m 644 notes.desktop ~/.local/share/applications/notes.desktop
install -D -m 644 notes.png ~/.local/share/icons/hicolor/256x256/apps/notes.png
The program gives its file name as the app id of its Wayland window, so the desktop finds the entry and its icon. A program with another name needs an entry of that name.
The program reads no flag: each word of its command line goes to $argv. --allow of ztk bundle sets its capabilities, and the default is file,channels.
ZTK_HEADLESS=1 ./notes runs it with no window. ztk bundle --strip makes a smaller program with only the parts that the scripts use (A smaller app).
A program for another platform comes from the same command with --target, such as --target x86_64-windows or --target aarch64-macos. Install has the rules of the files of an app.
The next page, Widgets, shows how the widgets look and act on Linux.