![]() |
The Widkit ports: X11, SDL and Qtwk | ![]() |
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.
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.
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.
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.
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.
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.
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.
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.
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.
sdl_gui.cpp
); snapshot name saves the backing store of the target window in the directory TEXMACS_SDL_SNAPSHOT.
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.
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).
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.
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.
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).