Opening Windows in Linux with sockets, bare hands and 200 lines of C
Title and terminology
- Several commenters note the title is confusing: “Windows” suggests Microsoft Windows rather than “X windows”; they argue for lowercase “windows” and fixing “a Windows” → “a window” in the article text.
- Some call the title clickbaity, though they generally like the technical content.
What X11 Does and System Comparisons
- X11 is described as a network‑transparent display protocol / windowing system: apps connect to a display server over a socket, send drawing commands, and receive input events.
- It centralizes access to graphics and input, manages windows, focus, clipboard, drag‑and‑drop, and inter‑app coordination.
- Compared to Windows and macOS:
- Windows equivalents are split across Win32, WDDM, DWM, RDP.
- macOS uses a WindowServer that talks to apps via Mach ports, largely undocumented below AppKit/CoreGraphics.
- X11’s defining difference is being a protocol rather than just a local API, making remote GUIs first‑class.
Remote GUI, X Forwarding, VNC/RDP, and Performance
- Classic use case: run GUI apps on remote/headless servers and display them locally via
ssh -Xor direct TCP. - Experiences vary:
- Some report good performance, especially on LAN, with tuned SSH or plain TCP; even browsers and video can work.
- Others find X over SSH sluggish, especially with complex toolkits or high latency links.
- Debate on whether the X protocol is “too chatty”:
- One side says many round trips and modern client‑side rendering make it behave like poor VNC.
- Others counter that X is highly asynchronous and that bad libraries/toolkits and lack of compression are the real culprits.
- Alternatives:
- VNC/Xvnc praised for session persistence and robustness on unstable links.
- X2Go and Xpra are cited as smarter remoting layers, sometimes using video codecs (H.264/265) for better performance.
Rendering Model and Graphics Capabilities
- Early X leveraged server‑side drawing primitives (lines, text, rectangles) for a “smart terminal” model.
- Critics argue this is now limited (no modern antialiasing/blending, mostly CPU‑bound).
- Others point to the XRender extension and hardware acceleration, and note toolkits like Cairo can use it efficiently.
- There’s disagreement on how much modern software still uses native X drawing commands vs client‑side bitmaps/OpenGL.
- Some lament the loss of “do everything over the wire” graphics with the move toward client‑side composited systems.
Xlib, XCB, and Other Client Libraries
- Many commenters find the raw X11 protocol conceptually simpler than Xlib, which adds queues, sync APIs, and extra utilities.
- Xlib is criticized for encouraging synchronous patterns that hurt remote performance.
- XCB and other language‑native bindings (e.g., in Lisp, Go, Ruby) are praised for being closer to the protocol and more pleasant to use.
- Some have implemented window managers and tools directly on X protocol bindings rather than Xlib.
Wayland vs X11 “From Scratch”
- Multiple people request a similar “bare hands” tutorial for Wayland; some links are provided.
- Wayland is viewed as:
- Protocol‑wise comparable (Unix domain socket, messages), but with more to do client‑side: fonts, input methods, hotplug, decorations, cursor themes.
- Defined via XML protocol specs with code generators (“scanners”), which adds up‑front tooling complexity.
- Limitations noted:
- Many features that were server‑side in X (decorations, cursor shape, XRender‑like primitives) are absent or moved to optional protocols/toolkits.
- EGL for Wayland typically requires linking against libwayland types, making “pure from‑scratch” harder.
- Opinions differ on whether this is a clean modern design or an ecosystem burden.
C Implementation Style: Arrays vs Structs
- The article’s choice to build X messages with byte arrays is debated.
- Critique: C structs with packing attributes could simplify code.
- Counterpoints:
- Struct layout has portability issues (padding, alignment, endianness); attributes like
__attribute__((packed))andalignedare compiler‑specific. - For production, explicit byte‑level serialization is often safer and more portable, especially across ABIs.
- For educational purposes, manual packing can mirror the protocol spec more clearly, despite being “product‑code‑ugly.”
- Struct layout has portability issues (padding, alignment, endianness); attributes like
Protocol Debugging and Human‑Readability
- X11 is contrasted with ASCII protocols like HTTP/SMTP: binary format trades debuggability for performance.
- Tools like x11trace and Wireshark parsers are mentioned as ways to inspect and understand X protocol traffic.