NanoWM

Systems Engineer · 2026 · 40 Minutes · 1 person · 3 min read

A high-performance, ultra-minimalist C-based window manager for X11 that implements manual tiling, multi-monitor support via Xinerama, and a macro-driven configuration system.

Overview

Developed NanoWM, a functional window manager from scratch using the Xlib library. The project focuses on extreme resource efficiency and a 'key-driven' workflow. It handles window mapping, focus management, and integrates with system-level utilities like Rofi and Redshift to provide a complete desktop environment experience within a tiny memory footprint.

Problem

Modern desktop environments and popular tiling window managers have become bloated with complex configuration languages (DSLs) and heavy dependencies. I needed a 'code-as-config' solution that allowed for instantaneous response times and direct control over window placement across multiple monitors without the overhead of a large codebase.

Constraints

  • Codebase must remain under 150 lines of C for maintainability
  • Requires native multi-monitor support via Xinerama
  • Must intercept all window mapping requests via SubstructureRedirectMask
  • System calls must be handled asynchronously to prevent UI hangs

Approach

Utilized Xlib's event-driven architecture to create an infinite loop that listens for ConfigureRequest and MapRequest events. I implemented a unique macro-based 'Table' system (TBL) to map keys to functions and system commands efficiently. For monitor management, I integrated Xinerama to track screen boundaries and pointer warping for seamless focus transitions.

Key Decisions

X-Macro Dispatcher System

Reasoning:

To keep the binary small and the config readable, I used X-Macros (the TBL macro). This allows the same list of definitions to both grab keys from the X server and map those keys to actions in the event loop, ensuring the registration and logic never diverge.

Alternatives considered:
  • External Config Parser (Adds significant LOC and overhead)
  • Hardcoded Switch/Case (Difficult to maintain and update keybindings)

Monocle Tiling Logic

Reasoning:

I opted for a simplified 'monocle' style where every new window is automatically resized to the dimensions of the active monitor. This maximizes screen real estate and simplifies the window management logic significantly.

Alternatives considered:
  • Dynamic Tiling (Requires complex tree data structures and auto-layout algorithms)
  • Floating Mode (Harder to manage via keyboard alone)

Tech Stack

  • C (GCC)
  • Xlib
  • Xinerama
  • POSIX System API

Result & Impact

  • < 2MB RAM usage
    Memory Footprint
  • 98 Lines of Code
    Codebase Size
  • Near-zero (Hardware limited)
    Input Latency

The project successfully created a distraction-free environment. By shifting all window management to a few key chords, I removed the need for a mouse in 90% of daily operations. The integration with Xinerama provided a more fluid multi-monitor experience than many mainstream desktop environments.

Learnings

  • Low-level X11 programming reveals how much modern DEs do 'under the hood' to manage window focus and stacking order.
  • Manual memory management for Xinerama structures is vital to prevent leaks in a process that runs for days or weeks.
  • Compile-time configuration via macros is an incredibly powerful pattern for minimalist software.

Additional Context

The most critical part of the project was the Xinerama Monitor Switching logic. Handling multiple displays in X11 requires querying the screen information and manually calculating offsets (). By using XWarpPointer, I ensured that when a user switches focus to a different monitor via Alt+i, the mouse follows the focus, preventing the “lost cursor” syndrome common in multi-head setups.

The implementation of the SubstructureRedirectMask was a “make or break” moment. Without it, the window manager cannot intercept requests from applications to resize or map themselves. By capturing these, the WM becomes the “source of truth,” forcing every application—whether it’s vivaldi or st—to conform to the dimensions of the current active monitor provided by the Xinerama screen info.

[ repository ]