GNU TeXmacsUser manualReferenceAboutEnglish
The Widkit ports: X11, SDL and Qtwk

1.Widkit

Three ports draw all their widgets with

Plugins/Widkit

, a complete widget toolkit whose widgets are drawn with the TeXmacs renderer and communicate by events. They only differ by the layer below, which provides the windows, the events, the clipboards and the renderer: X11 (

Plugins/X11

), SDL3 (

Plugins/SDL

) or Qt (

Plugins/Qtwk

). The design of Widkit is described in the graphical user interface (historical Widkit toolkit), and the mapping of the abstract constructors to it is in

Widkit/Basic/widkit_wrapper.cpp

.

The wrapper defines all constructors of the abstract interface, but some are placeholders (see the overview): printer_widget is a bare “Cancel” button, tree_view_widget shows “Not implemented”, the responsive tabs are plain tabs and the tooltip windows are popup windows. File choosers, color pickers and the other dialogs are Widkit widgets. The main window (

Widkit/Misc/texmacs_widget.cpp

) has side panels for the tools, 300 points wide and hidden until tools are shown on that side. After a window is shown or resized the whole window must be invalidated, as the Expose events of X11 do: Widkit relies on them.

2.The X11 port

The X11 port is the original port of TeXmacs. It is still updated when the abstract interface changes, but lacks the features which the Scheme code only offers when qt-gui? or vue-gui? holds.

The event loop.
x_gui_rep::event_loop (
X11/x_loop.cpp

) is a polling loop which runs while there are windows or remote clients. In each iteration it processes at most one pending X event (after XFilterEvent, for input methods); when no event arrived, it sleeps with select for a delay which starts at 10 ms and grows to 1 s after two minutes of inactivity (MIN_DELAY, MAX_DELAY, SLEEP_AFTER). It then calls the interpose handler, shows pending help balloons, and redraws invalid windows when no events are pending, with an interruption deadline so that typing remains responsive. Repaints are skipped while the window is being resized or exposed.

Keyboard and input methods.
When an input method could be opened at startup, each window gets an input context created with the style XIMPreeditNothing | XIMStatusNothing (
x_window.cpp

), that is, without on-the-spot or over-the-spot preedit. Key presses are decoded with Xutf8LookupString (

x_loop.cpp

); a decoded Unicode character is converted to Cork and used directly, and otherwise the key symbol is looked up in the tables lower_key and upper_key built in

x_init.cpp

. Without an input method, XLookupString is used.

Selections.
The clipboard "primary" is the X selection CLIPBOARD and "mouse" is PRIMARY. For the format default, the global set_selection (
x_gui.cpp

) publishes the verbatim version sv of the selection, so that other programs receive plain text; since the port offers a single string, another TeXmacs instance receives that plain text too, and a copy between two instances loses its structure. When TeXmacs owns a selection, it answers requests for TARGETS and STRING only (SelectionRequest in

x_loop.cpp

). To paste from another program, x_gui_rep::get_selection requests STRING and polls for the SelectionNotify event, giving up after a fixed number of polls.

Printing.
Since use-print-dialog? is false, printing always goes through the printing command.
Headless mode.
With -headless the windows are made but never mapped (x_window_rep::set_visibility in
x_window.cpp

). The port still needs a display: without one, x_gui_rep (

x_init.cpp

) stops with a message which suggests xvfb-run or a virtual DISPLAY.

3.The SDL port

Plugins/SDL

is an experimental port which uses SDL3 for the windows and the events, Widkit for the widgets, and the MuPDF renderer for the drawing (configure --with-gui=sdl --with-mupdf=… --with-sdl3, or CMake TEXMACS_GUI=SDL). Its

README.md

describes it.

Windows and drawing.
Each window has a backing store, an opaque MuPDF pixmap of the size of the window in device pixels, in which the widgets draw with mupdf_renderer_rep. A repaint records the rectangles it changed, and only these are copied to the surface of the window (SDL_ConvertPixels, then SDL_UpdateWindowSurfaceRects); a scroll shifts the pixels of the backing store in place. There is no SDL_Renderer. The renderers draw at retina_factor pixels per point, the pixel density of the primary display (TEXMACS_SDL_DENSITY overrides it).
The event loop.
sdl_gui_rep::event_loop (
sdl_gui.cpp

) runs while there are windows or servers. It sleeps in SDL_WaitEventTimeout, handles the waiting events in a burst (a mouse motion superseded by the next one is dropped), lets the editors apply their changes, and repaints when the queue is empty, or at least every 50 ms. While a window is resized by its border, an event watch lays it out and repaints it from inside the event pump of SDL, but only while the loop is waiting.

Keyboard and input methods.
Each window calls SDL_StartTextInput (
sdl_window.cpp

). A keystroke which types text is delivered by its text event, which carries what the input method or a dead key composed; the others are delivered as keys (C-x, M-s, return, …). The composition of an input method is sent as pre-edit:cursor:text, as in Qt.

Clipboards.
The system clipboard holds the selection "primary", under the types application/x-texmacs-clipboard, text/html (when there is an HTML version) and plain text, the latter being sv for the format default. The other selections are kept internally; SDL has no X11 PRIMARY selection.
Testing.
TEXMACS_SDL_SCRIPT=file replays the commands of the file (wait, window, click, key, text, snapshot, …, see the comment in
sdl_gui.cpp

); snapshot name saves the backing store of the target window in the directory TEXMACS_SDL_SNAPSHOT.

Headless mode.
With -headless, the constructor of sdl_gui_rep (
sdl_gui.cpp

) selects the dummy video driver of SDL, which opens no display, and sdl_window_rep::set_visibility (

sdl_window.cpp

) shows no window; the windows are still drawn in their backing stores.

Limits.
No file dialogs of the system and no drag and drop, no custom cursors (except the invisible one), and the positions of popups may be off on a display whose density differs from retina_factor. Printing goes through the printing command, as in X11.

4.The Qtwk port

Plugins/Qtwk

(configure --with-gui=qtwk, macros QTWKTEXMACS and QTTEXMACS) uses Qt as a platform layer under Widkit: a QTWKApplication (a QApplication, or a QTWKCoreApplication in headless mode), one QTWKWindow (a QWidget) per TeXmacs window, painted with the Qt renderer qt_renderer_rep of Plugins/Qt, and fonts, pictures, pipes, sockets and HTTP taken from Plugins/Qt (see selecting and building a port).

The event loop.
As in the Qt port, Qt runs the loop (qApp->exec () in
qtwk_gui.cpp

), and the events of the windows (key presses, mouse, resizes, socket notifications, commands) are queued as qp_type events and handled by the update cycle of qtwk_gui_rep.

Keyboard and input methods.
QTWKWindow::keyPressEvent and QTWKWindow::inputMethodEvent (
QTWKWindow.cpp

) follow the Qt port; committed text is replayed as one synthetic key press per character, a surrogate pair (a character outside the basic multilingual plane) being kept together, as in Qt.

Clipboards.
qtwk_gui_rep::set_selection and get_selection are those of the Qt port: the same QMimeData with application/x-texmacs-clipboard and application/x-texmacs-pid, "primary" on the system clipboard and "mouse" on the X11 selection. As in Qt, a null QClipboard::mimeData (an empty clipboard on some platforms) is checked for.
Scheme.
gui-version is "qt5" or "qt6", but qt-gui? does not hold and x-gui? does (
Kernel/Abstractions/basic.cpp

), although QTTEXMACS is defined: the widgets are those of Widkit, so the Scheme code treats the port as X11. In particular use-print-dialog? is false and printing goes through the printing command. In C++, on the other hand, code which tests QTTEXMACS applies to Qtwk too (see pitfalls).

Headless mode.
A QTWKCoreApplication replaces the application, but the windows do not test is_headless.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".