![]() |
The Vue port | ![]() |
Plugins/Vue
is an experimental port built on three libraries: SDL3 for the windows, the events, the clipboard and the file dialogs (
vue_gui.cpp
); Clay, an immediate mode layout library (the single header
clay.h
, compiled once in
clay.c
), for the layout of the widgets (
vue_widget.cpp
); and the TeXmacs renderer of
Plugins/MuPDF
, or the GPU renderer of
vue_gpu.cpp
, for the drawing. The texts of the interface are typeset with TeXmacs fonts. It implements all the widget constructors of the abstract interface (see the overview) and runs on macOS, Linux and, with limitations, Windows.
The design notes are in
docs/vue-graphics-stack.md
(windows, event loop, input, renderers),
docs/vue-widgets.md
and
docs/vue-testing.md
, and the state of the port is kept in
Plugins/Vue/TODO
. This page summarizes them.
configure --with-gui=vue --with-mupdf=prefix --with-sdl3 defines VUETEXMACS and compiles the port with -std=c++20; MuPDF is required. With --with-thorvg=prefix (ThorVG built by
misc/thorvg/build-thorvg.sh
) the GPU renderer is compiled in (USE_THORVG). CMake builds the port with TEXMACS_GUI=Vue (SDL3, SDL3_ttf and MuPDF required), with the GPU renderer when THORVG_DIR names the prefix of a ThorVG build and with MuPDF only otherwise, see selecting and building a port.
clay.h
is upstream Clay, taken verbatim;
clay_renderer_SDL3.c
is the example renderer of the library and is not compiled.
vue_window_rep (
vue_gui.hpp
) is the abstract window. vue_sdl_base_window_rep holds what is SDL (creation, visibility, pixel density, size limits), vue_sdl_mupdf_window_rep adds the MuPDF drawing and vue_sdl_gpu_window_rep the OpenGL one; a variant drawing through the renderer of SDL (with SDL3_ttf) is kept but unused. Each window has its own Clay context and its own input state (vue_input_state); with_window makes them current, together with the retina_factor of the display the window is on.
Popup windows (menus, balloons, tooltips) are borderless windows on top, sized to their contents and clamped to the screen; while one is visible it grabs the pointer, since
edit_mouse.cpp
relies on the grab semantics of X11. A new window is shown once its contents fit, and dialogs are sized to their contents. The close button sends SLOT_DESTROY, which runs the quit command of the window.
gui_start_loop runs loop_iteration, whose steps are: one SDL event is translated into the input state of its window (the motion and wheel events queued behind it are merged); every window is laid out, which is also where the input is dispatched, since in immediate mode a widget reads the input state while it lays itself out; the commands which the widgets queued during the layout are run (a widget never runs TeXmacs code while it is laid out); the interpose handler runs (Scheme delayed commands, socket notifiers); the windows are laid out again if a widget was replaced; the editors repaint their backing stores (skipped while events are waiting, for at most 16 ms); and the render commands of every window are replayed. Between iterations the loop sleeps in SDL_WaitEventTimeout for a pause which grows from 10 ms to 1 s, capped at 40 ms while socket notifiers are registered. The loop keeps running without windows as long as there are servers. A resize is handled inside the event pump of SDL, in an event watch which runs a whole frame for that window, so that the window never shows stale contents while it is dragged. In the browser, the iteration is called once per animation frame (emscripten_set_main_loop), and in headless mode headless_loop replaces the loop.
Clay works in device pixels, y downwards; widgets which need input or measurement name their elements with ids derived from the serial number of the widget. Sizes which Clay cannot express (the rows of aligned_widget, the largest page of a tab widget, …) are measured on the bounding boxes of the previous pass, and a widget without them asks for another pass (layout_again), so that the first frame shown is already correct. render_clay_commands replays the render commands on a TeXmacs renderer; the editors and other custom elements draw themselves through render callbacks. Every colour of the interface is a field of vue_theme: a light and a dark theme ship, chosen by the preference gui theme (default follows the system). The icons are the SVG sets of
TeXmacs/misc/pixmaps/light
and
dark
, drawn by MuPDF at the resolution of the window. Button highlights, tool panels and zooms are animated (transitions of Clay, smooth zoom of the editor).
The main window draws its menu bar and icon bars itself (there is no native menu bar); contents which do not fit in a bar or a menu are clipped and marked rather than given a scroll bar. Pulldown menus are popup windows, chained through current_popup. The icon bars can be placed in columns at the left of the editor (preference icon bars).
Each window starts the text input of SDL (SDL_StartTextInput). A key which produces a character is not delivered as a key: the text which the system composes with the dead keys and the input method comes as SDL_EVENT_TEXT_INPUT, and that is what the editor receives; every other key (return, arrows, C-, M-, A- combinations) is delivered as a key named by lookup_key after the TeXmacs conventions. A text event which follows a key with a modifier within 30 ms belongs to the same keystroke and is dropped. With a command modifier, a key of a non Latin layout is named by its US key. A composition (SDL_EVENT_TEXT_EDITING) is shown as a pre-edit: the editor receives "pre-edit:pos:text" as in Qt, and the text inputs of the dialogs show it too. The focused editor tells SDL where its cursor is (SDL_SetTextInputArea), so that candidate windows are placed next to it. The keyboard focus is kept per window (set_kbd_focus).
The mouse follows the Qt port (on macOS, control and option emulate the right and middle buttons). A trackpad swipe drags the view, a wheel notch is travelled over a few frames, and control (command on macOS) with the wheel zooms. Files and texts dropped on a window reach the widget under the pointer as a "drop" mouse event.
Plugins/MuPDF/mupdf_renderer.cpp
) draws through a PDF run processor on a pixmap. Each editor keeps an opaque backing store which is repainted incrementally; a scroll shifts its pixels and repaints the exposed strips; plain fills and 1:1 blits write the pixels directly. The window is a pixmap copied to the SDL window surface.
| Variable | Effect |
| TEXMACS_VUE_GPU | 0 draws with MuPDF in a build with ThorVG |
| TEXMACS_VUE_GPU_SYNC | wait for the GPU at the end of a repaint (profiling) |
| TEXMACS_VUE_SLUG | glyphs drawn from their outlines on the GPU |
| TEXMACS_VUE_SINGLE_WINDOW | single window mode on the desktop |
| TEXMACS_VUE_SCRIPT | replay a test script |
| TEXMACS_VUE_SNAPSHOT | directory in which every redraw of a window is saved as PNG |
| TEXMACS_VUE_THEME | light or dark, instead of the preference |
| TEXMACS_VUE_DENSITY | pixel density used instead of that of the display |
| TEXMACS_VUE_SCALE | interface scaling used instead of the preference gui scaling. As with QT_SCALE_FACTOR, a point of TeXmacs takes the density of the display, rounded, times this scaling in device pixels, and the windows grow with it. The window is drawn at the nearest integer factor and presented scaled when the two differ: vue_scaling. A change of the preference is followed while TeXmacs runs (vue_follow_interface_scale) |
| TEXMACS_VUE_TAB_MODE | presentation of the responsive tabs: top, side, mobile or grid |
| TEXMACS_VUE_BARS | icon bars at the top or on the left |
| TEXMACS_VUE_RADIUS | rounding of the corners of the theme (0: square) |
| TEXMACS_VUE_PROFILE | print timings every so many frames |
| TEXMACS_VUE_DUMP | print every render command of Clay |
| TEXMACS_VUE_CLAY_DEBUG | F1 opens the debug view of Clay (also with -debug-qt) |
Since other programs may not capture or drive the windows of TeXmacs on macOS, the port has its own test driver: with TEXMACS_VUE_SCRIPT=file, the loop executes one command of the file per iteration, by pushing synthetic SDL events (wait, window, move, click, wheel, key, text, compose, commit, drop, resize, scheme, snapshot, close, …; see script_step in
vue_gui.cpp
). The directory
tests/Plugins/Vue
holds about 57 scripts, most with a Scheme file which builds the widget they drive, and
run.sh
, which runs one of them in a copy of the home directory (a test must never change the preferences of the user) and checks what the callbacks print. The catalogue of the tests is in
docs/vue-testing.md
.
TeXmacs also runs in a web page: a WebAssembly build of this port with Emscripten, on Scheme S7 (the collector of Guile scans the C stack, which WebAssembly does not expose). It lives in this tree (it was developed on the branch wip_wasm_vue until it was merged into upsilon_texmacs). The design notes, measurements and the state of the port are in
docs/wasm/README.md
(with
tikzjax.md
and
asymptote.md
for two of the plug-ins); what the user sees is described in the help page
texmacs-vue.en.tm
(Help\(\rightarrow\)TeXmacs in the browser, in the browser only), whose recent changes list every feature and fix of the browser version.
The build uses neither configure nor CMake: everything is in
misc/wasm
, run from src:
. misc/wasm/emenv.sh build-wasm # the Emscripten environment sh misc/wasm/build-mupdf.sh # the slim MuPDF, once make -C build-wasm -f ../misc/wasm/Makefile -j8 web # the page make -C build-wasm -f ../misc/wasm/Makefile -j8 node # node, headless node misc/wasm/serve.mjs # http://localhost:8080/texmacs.html
Makefile
compiles the sources listed in
sources.txt
(those of a desktop Vue+S7 build without the Objective-C; written again by
list-sources.sh
) with
config.h
and
tm_configure.hpp
in place of what configure writes. SDL3 is the port of Emscripten (-sUSE_SDL=3); MuPDF is a slim build without fonts of its own, patched (
build-mupdf.sh
,
mupdf-subset-cff.patch
); SDL3_ttf is not linked; Hunspell is compiled in for the spelling (
get-hunspell.sh
). The exceptions and setjmp/longjmp are those of WebAssembly (-fwasm-exceptions), as in MuPDF, which rules out ASYNCIFY: the loop cannot block, and gives control back to the browser every frame. The files of the directory TeXmacs are written as packages with a manifest by
package.py
, the files read at startup (
boot-files.txt
) in the boot package.
What the code of the port compiles under __EMSCRIPTEN__ (mostly in
vue_gui.cpp
) does: single window mode always on, the windows of the editors being tabs of the page; the loop driven by emscripten_set_main_loop, one loop_iteration per frame, the keys queued in a frame all handled in it (web_more_events); file dialogs through the page; the Fira fonts for the interface; WebGL2 in the GPU renderer; the tabs sent to the frame of the page (frame_sync, vue_web_move_tab), the input methods (vue_web_compose), the clipboard and printing through the page. Headless mode, which opens no display, makes the build testable under node.
The page is
shell.html
and a series of scripts given to Emscripten as --pre-js, each with a header which explains it:
progress.js
The progress of the loading, until TeXmacs runs.
packages.js
The tree /texmacs: every file a placeholder, filled by the boot package before the start, by the other packages in the background, or by a range of its package when it is read first; the fonts fetched one by one; all kept in the Cache Storage of the browser.
web-pre.js
The home directory /home/web, kept in IndexedDB and written back a moment after each change, by the one tab which holds a Web Lock.
files.js
The Files panel: uploads, downloads, folders and zips, the files of TeXmacs.
frame.js
The frame: a column at the left of the canvas with a TeXmacs menu and the tabs of the windows.
clipboard.js
The clipboard: TeXmacs reads it synchronously, the browser gives it to a paste event only, so the page keeps what it knows of it.
ime.js
Dead keys and input methods, which SDL does not have on the web.
print.js
Print and preview: the PDF of MuPDF opens in a tab of the browser.
javascript.js
The global TeXmacs of the page (Scheme from JavaScript).
wallet.js
The wallet, encrypted by WebCrypto instead of GnuPG.
workers.js
The plug-ins which are Web Workers (below).
The node build has
node-pre.js
instead, which passes the environment of node to TeXmacs.
A page has no processes: posix_spawnp fails and the plug-ins which run a program are not offered. A plug-in may instead say (:worker "url") in its plugin-configure, the url being its script relative to the page: the link (
worker_link.cpp
) sends the input of a session to that worker and reads back what it posts, in the usual protocol of the plug-ins, as through pipes;
workers.js
describes the messages. The scripts are in the web directory of their plug-ins: Python on Pyodide (
tm-python.mjs
), R on webR (
tm-r.mjs
), TikZ on TikZJax (
tm-tikz.js
), Asymptote on Asymptote-web (
tm-asy.mjs
), and JavaScript, which runs in the page itself ((:worker "page:file"),
tm-javascript.js
). The web target of the makefile copies them and their engines into the page.
Under node, which sees the files of the host, the node build converts documents as the desktop does:
TEXMACS_PATH=$PWD/TeXmacs TEXMACS_HOME_PATH=/tmp/tmhome HOME=/tmp/tmhome \ node build-wasm/out/node/texmacs.js -headless -c in.tm out.pdf -q
In a browser,
browser-run.mjs
loads the page in a headless Firefox (with puppeteer-core in build-wasm/tools), prints the console and replays a script of clicks, keys and screenshots;
serve.mjs
serves the page, possibly as over a slow network. The tests of
misc/wasm/test
check the home directory with several tabs (home-tabs.mjs, also in Safari and Chrome) and the frames drawn while the page is resized (resize-flicker.mjs, resize-jitter.mjs).
The workflow .github/workflows/wasm.yml runs on the branch wasm_ci only: work on upsilon_texmacs triggers nothing, and a state is built, tested (the node build turns the Welcome document into a PDF) and published on GitHub Pages by moving wasm_ci to it,
git push origin upsilon_texmacs:wasm_ci
The page of the run is also kept as an artifact (texmacs-wasm-web), to be served with node misc/wasm/serve.mjs dir.
From
TODO
and the design notes:
the color picker offers named colours only (the color menus route on qt-gui? and use the Scheme picker instead);
no image preview in the file chooser;
on Windows, perform_select and the pipes are stubs: no plug-ins and no client/server; printing uses CUPS commands;
on Linux, no PRIMARY selection, and the interface is drawn in the TeX fonts rather than a desktop font;
a few colours are still literals and stay light in the dark theme;
popup windows (menus) cannot be animated, being separate SDL windows;
on the GPU, draw_spacial and transformed glyphs are untested.