App
An App represents one connection to an X server and is the factory for
windows and pixmaps.
createClient([options], [callback]) → Promise<App>
import { createClient } from 'ntk';
const app = await createClient(); // uses $DISPLAY
const app2 = await createClient({ display: ':1' });
optionsis passed through tox11.createClient(e.g.{ display: ':1' }). ntk additionally understands:fontSource— pluggable system-font lookup forapp.fonts(see fonts.md);glxVisual— visual idgetContext('opengl')should use instead of querying the server for one (see context-opengl.md);onXError— called with X protocol errors that no request callback claimed (races like a request landing after its window was destroyed). Defaults to aconsole.warn; without any listener node-x11's error emit would throw inside its packet parser and wedge the connection.
- The XRender extension is preloaded (required for the 2d context). GLX is
preloaded when available;
app.display.GLXisnullwhen the server has no GLX support. - Keyboard mapping is fetched up front and kept up to date on
MappingNotify, sokeydownevents carrycodepoint. - A big-endian (MSBFirst) connection is rejected with an error. node-x11 declares the host byte order in its connection hello but encodes every request LSBFirst regardless, so such a connection is already inconsistent before ntk sees it; failing here beats decoding byte-swapped properties into plausible-looking nonsense.
- The legacy node-style
callbackis also supported.
Properties
app.display— the node-x11 display object (screen,Render,GLX, …)app.X— the raw node-x11 client, for direct protocol requestsapp.fonts— lazy FontManager: font matching/loading, shapingapp.clipboard— lazy Clipboard: selection/clipboard text transfer (write()/read())
Methods
app.createWindow(args) → Window— see window.mdapp.rootWindow() → Window— wrapper for the first screen's root windowapp.createPixmap(args) → Pixmap— see pixmap.mdapp.createColormap(visual, screen = 0) → id— allocate a colormap for a visual (alloc None). Windows created with an explicitvisualget one automatically, so this is only needed to share one between windowsapp.chooseGLXConfig(spec) → Promise<config>— pick a GLX-capable visual by querying the server;config.visual/config.depthfeedcreateWindowand the whole object feedsgetContext('opengl', config). See context-opengl.mdapp.close() → Promise— flush pending requests, then close the connection
Resource management
App implements both Symbol.asyncDispose (flush + close, prefer this) and
Symbol.dispose (immediate terminate):
await using app = await createClient();
// connection closed automatically at end of scope