![]() |
The native Cocoa port | ![]() |
Plugins/NS
is a native macOS port written in Objective-C++ on AppKit. It maps every abstract widget to native views, as the Qt port maps them to Qt widgets, and its widget layer was completed on the model of Qt, so that it offers the same features: menus in the menu bar, icon bars, side and bottom tools, dialogs made with tm-widget, tooltips, the file panels, the color picker, printing, the clipboard, drag and drop, trackpad gestures and input methods. The macro is AQUATEXMACS, gui_version () returns "ns" (ns-gui? in Scheme), and qt-gui? holds, so that the Scheme code uses the same native dialogs and shortcuts as with Qt; x-gui? does not hold, so that, as with Qt, the save panel of macOS asks before overwriting a file instead of Scheme. It replaces the older Plugins/Cocoa port (with its nib files), which has been removed.
The status of the port, its test aids and its packaging are described in
src/docs/ns-port.md
; this page summarizes it.
configure --with-gui=cocoa (or aqua) compiles
Plugins/NS
together with
Plugins/MacOS
(the macOS extensions are required) and links with the Cocoa and PDFKit frameworks; CMake cannot build it. MuPDF is refused: the port has pictures of its own. The PDF is written by TeXmacs itself with PDFHummus (
Plugins/Pdf
), which configure enables when it finds libpng; without it the port has no PDF writer. The dependencies of the headers are followed by the make build, also those of the headers of
Plugins/NS
which the editor includes.
packages/macos/build-ns-app.sh
configures, builds and makes the application bundle (and with --dmg the disk image), copies the libraries which do not come with macOS into the bundle and signs it.
build-deps.sh
builds these libraries statically for an older macOS and either architecture,
merge-universal.sh
merges two applications into a universal one, and
check-app.sh
checks the signature, that only system libraries and those of the bundle are used, and, for an application made for an older macOS, that the main program is linked against an SDK newer than its minimal version. The continuous integration workflow .github/workflows/upsilon-macos.yml does all this on the branch upsilon_ci, for the Cocoa and the Vue ports and both architectures, and publishes the two disk images as the pre-release upsilon-latest; a state of upsilon_texmacs is built by moving upsilon_ci to it (git push -f origin upsilon_texmacs:upsilon_ci). The older workflow macos-ns.yml, for the branch ns_ci, has been removed from this branch (it is kept on wip_other_guis).
ns_widget.mm
The widget constructors, the base, window, popup and view widgets.
ns_tm_widget.mm
The main window: menu bar, icon bars, canvas, side and bottom tools, footer (which can be interactive), full screen.
ns_ui_element.mm,
ns_menu.mm
Menu items (for the menus and the icon bars) and the views of the dialogs, laid out with NSStackView and NSGridView; the menu classes and the popup menus.
ns_dialogues.mm
File chooser, questions and input dialogs, line inputs, the embedded editor, the color picker and the printer.
ns_simple_widget.mm,
TMView.mm
The canvas of the editor: a document view in a scroll view, and the canvas which follows its visible part, with a backing store of that size.
ns_renderer.mm,
ns_picture.mm
The Core Graphics renderer and the pictures.
ns_gui.mm
The application, the event loop, the clipboard and the test aids.
ns_gui_rep::event_loop calls [NSApp finishLaunching], installs the test timers and then [NSApp run]. As in
qt_gui.cpp
, the keyboard, mouse, resize and command events are queued and handled by ns_gui_rep::update, which processes a bounded number of them, runs the interpose handler and repaints the canvases (ns_simple_widget_rep::repaint_all); an NSTimer (also active in modal panels) schedules the next update. Only the canvases of a visible window are repainted. The delayed commands are also run by exec_pending_commands, needed by a server in the same process.
TMView passes the key events to interpretKeyEvents: and implements the NSTextInputClient protocol (insertText:, setMarkedText:, …), so that an input method gets all the keys while it composes, and its marked text is shown as a pre-edit. The keys are named as in Qt (space, S-tab, enter, the Cork names of the other characters); command is M-, option A- and control C-. Option with a letter gives A-letter when that key is bound and the composed character otherwise; this is decided when the key is pressed, where Qt lets the kernel decide. Only the canvas which is the first responder of the key window has the focus. The text fields of the dialogs get the usual editing shortcuts (command-C, -X, -V, -A, -Z) through a local event monitor.
Each main window has its own menu bar, installed when the window becomes main (not while a menu is open), and its menus are computed each time they are shown, as in Qt. The menus show the shortcuts as native key equivalents, but the keys go to the editor, which handles them as in Qt. The icon bars are flat rows of buttons and input fields (the focus bar), with a small triangle on the icons which have a pull-down menu. The icons are drawn from the SVG files of the light or dark variant of the icon set, and follow a change of the appearance of the system.
ns_dialogues.mm
), without Ghostscript; PostScript is only printed through Ghostscript.
ns_gui.mm
), the windows are made but never ordered front (
ns_widget.mm
), and the wait window is not shown. The option is read in immediate_options of
texmacs.cpp
, as for the Qt and Vue interfaces, and TeXmacs quits after the commands given with -x or -c; -X keeps it running, for instance for a script with delayed actions or a server, until (quit-TeXmacs). The modal dialogs (file choosers, questions, lists of fields, the color picker, the print panel) are answered as cancelled, since nobody could answer them.
ns_renderer_rep draws with Core Graphics. Its clipping follows QPainter::setClipRect, patterns are cached as in Qt, and shadows draw in the context of their master. The glyphs of the fonts with a file (TrueType, OpenType, Type 1) are drawn from their outlines (tt_glyph_outline), filled with the antialiasing of Core Graphics into images cached per glyph, size and color, at the place of the bitmaps to the pixel; the other glyphs use the bitmaps made by shrink. The backing store of a canvas wraps around in both directions, so that a scroll only repaints the uncovered strips.
Other programs may not capture or drive the windows of TeXmacs, so the port reads environment variables (see
src/docs/ns-port.md
and
ns_gui.mm
). With them, TeXmacs becomes the active application.
| Variable | Effect |
| TEXMACS_NS_SNAPSHOT | directory in which the windows are saved as PNG every 3 s |
| TEXMACS_NS_TYPE | text typed into the canvas after 2 s |
| TEXMACS_NS_CLICK | a click, move or drag on the canvas before typing |
| TEXMACS_NS_PRESS | steps pressing buttons, tabs and segments by their label, filling fields, closing modal panels |
| TEXMACS_NS_WINDOW_TEST | steps on the windows, the menu bar, the lists and the combo boxes |
| TEXMACS_NS_MENUS | print the menu bar to the given depth |
| TEXMACS_NS_SCROLL, TEXMACS_NS_SCROLL_STEP | scroll the document in steps |
| TEXMACS_NS_DROP | drop a file on the canvas |
| TEXMACS_NS_BENCH, TEXMACS_NS_BENCH_SIZE | time repaints, scrolls and zooms of the front window, print a table and quit |
| TEXMACS_NS_THEME | light or dark, instead of the preference gui theme |
| TEXMACS_NS_GLYPHS | bitmap: all glyphs from the bitmaps of shrink |
| TEXMACS_NS_DEBUG_RED, TEXMACS_NS_DEBUG_DRAW | show the parts of the backing store which are not kept, print the redrawn rectangles |
As in Qt: no ink widget, no empty widget, no wait widget (the wait indicator works), no mouse pointer shapes (set_mouse_pointer is empty), no proposals in the color picker. The responsive tabs are plain tabs, and tree views ignore their roles.
The bottom and extra tools have no handle and a fixed height.
Not tested with real hardware: printing on a printer, a real input method, gestures other than scrolling, help balloons triggered by hovering.