nx_x11_connect.nx
buildroot/runtime/nx_x11_connect.nx
about
nx_x11_connect.nx -- bits-up X11 wire-protocol connection setup.
Opens an AF_UNIX socket to the local X server (typically WSLg's
/tmp/.X11-unix/X0 on Windows/WSL2, or an X11/Xorg server on
Linux), sends the connection-setup request, and reads the
server's reply. Returns the connected fd + parsed server info.
X11 protocol reference: X Window System Protocol ยง8 (Connection
Setup), public wire spec (X11 Release 11.0+). Same flavor of
bits-up work as TLS/HTTP: we read the spec, write the bytes,
no third-party client library.
Setup request bytes (12 + auth-name + auth-data, padded to 4):
byte 0: byte-order ('l' = 0x6c = little-endian, 'B' = big)
byte 1: pad (0)
bytes 2-3: major version (11) [u16 LE]
bytes 4-5: minor version (0) [u16 LE]
bytes 6-7: auth_proto_name_len [u16 LE]
bytes 8-9: auth_proto_data_len [u16 LE]
bytes 10-11: pad
auth_proto_name (padded to 4)
auth_proto_data (padded to 4)
Server reply byte 0:
1 = success (info follows)
0 = failed (reason string follows)
2 = authenticate (more auth needed)
For local WSLg, anonymous auth (zero-length name/data) is accepted
when the connecting uid matches the server's owner. If WSLg
rejects this, we'll add MIT-MAGIC-COOKIE-1 via ~/.Xauthority parse.
Public API:
nx_x11_connect_local(display_num)
Connects to /tmp/.X11-unix/X<display_num>, performs setup
handshake. Returns negative verdict or positive fd.
Sealed verdict (negative on failure):
NX_X11_OK positive fd returned
NX_X11_SOCKET_FAIL socket()/connect() failed
dependencies 2 imports · 16 importers
diagram shows first 10 each side; +0 more imports, +6 more importers in the complete lists below.
imports: nx_syscalls.nxnx_unix_socket.nx
imported by: nx_browser.nxnx_browser_demo_test.nxnx_render_wiki_styled_window.nxnx_render_wiki_window.nxnx_x11_connect_real_test.nxnx_x11_font_test.nxnx_x11_get_image.nxnx_x11_keyboard.nxnx_x11_paint.nxnx_x11_paint_text_5x7.nxnx_x11_pixmap.nxnx_x11_pixmap_kat_test.nxnx_x11_put_image.nxnx_x11_screenshot.nxnx_x11_window.nxnx_x11_window_real_test.nx
structs
| 64 | struct X11Conn |
consts
| 52 | const NX_X11_OK: i64 = 1 |
| 53 | const NX_X11_SOCKET_FAIL: i64 = 2 |
| 54 | const NX_X11_WRITE_FAIL: i64 = 3 |
| 55 | const NX_X11_READ_FAIL: i64 = 4 |
| 56 | const NX_X11_REJECTED: i64 = 5 |
| 57 | const NX_X11_VERDICT_N: i64 = 6 |
| 77 | const NX_X11_CONN_BYTES: i64 = 80 |
functions
| 80 | func _x11_rd_u16(buf: *u8, off: i64) -> i64 called by 1: nx_x11_connect_local |
| 85 | func _x11_rd_u32(buf: *u8, off: i64) -> i64 |
| 93 | func nx_x11_alloc_id(c: *X11Conn) -> i64 |
| 100 | func _x11_build_path(out: *u8, display_num: i64) -> i64 called by 1: nx_x11_connect_local |
| 118 | func _x11_write_n(fd: i64, buf: *u8, n: i64) -> i64 |
| 129 | func _x11_read_n(fd: i64, buf: *u8, n: i64) -> i64 |
| 142 | func nx_x11_connect_local(display_num: i64) -> i64 called by 9: mainmaindg_setupmainmainmain+3 calls 8: sys_mmap_x11_build_pathnx_unix_connect_x11_write_nsys_close_x11_read_n+2 |
| 256 | func main() -> i64 |