gardesk/gar / 1ae2b84

Browse files

Add CLAUDE.md project guide

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
1ae2b8491ea831139d5e30efe42b5c4f16bac1b5
Parents
a4f9469
Tree
d0b7b7a

1 changed file

StatusFile+-
A CLAUDE.md 122 0
CLAUDE.mdadded
@@ -0,0 +1,122 @@
1
+# CLAUDE.md
2
+
3
+This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+## Project Overview
6
+
7
+**gar** is a Rust X11 tiling window manager with smart BSP (binary space partitioning) tree layout, i3-compatible IPC, and Lua scripting for configuration.
8
+
9
+Workspace structure:
10
+- `gar/` - Main window manager crate (~6,300 lines)
11
+- `garctl/` - CLI control tool for managing gar via IPC
12
+
13
+## Build Commands
14
+
15
+```bash
16
+# Development build
17
+cargo build
18
+
19
+# Release build (required for start-gar.sh)
20
+cargo build --release
21
+
22
+# Build specific package
23
+cargo build -p gar
24
+cargo build -p garctl
25
+
26
+# Lint and format
27
+cargo clippy
28
+cargo fmt
29
+```
30
+
31
+Requires X11 development headers. On NixOS/Nix, use:
32
+```bash
33
+nix-shell --run 'cargo build --release'
34
+```
35
+
36
+## Running and Testing
37
+
38
+**From TTY (recommended for real X session):**
39
+```bash
40
+./start-gar.sh
41
+```
42
+
43
+**Nested X session (safe testing without switching sessions):**
44
+```bash
45
+Xephyr -br -ac -noreset -screen 1280x720 :1 &
46
+DISPLAY=:1 cargo run
47
+```
48
+
49
+**Panic exit:** `Super+Shift+Escape`
50
+
51
+**Logs:** `/tmp/gar.log` and stdout. Control with `RUST_LOG` or `GAR_LOG` environment variables.
52
+
53
+## Architecture
54
+
55
+### Event-Driven Design
56
+
57
+```
58
+X11 Event Loop (x11/events.rs)
59
+    ↓
60
+handle_event() dispatch
61
+    ├→ MapRequest       → manage_window()
62
+    ├→ KeyPress         → keybind lookup → action
63
+    ├→ ButtonPress      → drag/focus handling
64
+    ├→ UnmapNotify      → unmanage_window()
65
+    ├→ RandR events     → refresh_monitors()
66
+    └→ ClientMessage    → EWMH requests
67
+    ↓
68
+apply_layout() → X11 configure calls → flush
69
+```
70
+
71
+### Core Modules
72
+
73
+| Module | Purpose |
74
+|--------|---------|
75
+| `core/mod.rs` | WindowManager struct - central state and event orchestration |
76
+| `core/tree.rs` | BSP tree for smart tiling layout |
77
+| `core/workspace.rs` | Workspace management (10 workspaces, i3-style) |
78
+| `x11/events.rs` | Event loop and X11 event handlers |
79
+| `x11/connection.rs` | X11 connection, atoms, EWMH/ICCCM |
80
+| `config/lua.rs` | Lua API setup and config integration |
81
+| `ipc/server.rs` | Custom IPC (Unix socket, JSON protocol) |
82
+| `ipc/i3_server.rs` | i3-compatible IPC for polybar integration |
83
+
84
+### Window States
85
+
86
+- **Tiled** - Managed by BSP tree
87
+- **Floating** - Separate list, rendered above tiled windows
88
+- **Fullscreen** - Covers entire monitor, restores previous state on toggle
89
+
90
+### IPC
91
+
92
+Two socket servers run simultaneously:
93
+- Custom protocol at `$XDG_RUNTIME_DIR/gar.sock` (or `/tmp/gar.sock`)
94
+- i3-compatible protocol for polybar at separate socket
95
+
96
+Control via `garctl`:
97
+```bash
98
+garctl focus left
99
+garctl workspace 3
100
+garctl get-workspaces
101
+```
102
+
103
+## Configuration
104
+
105
+Lua config at `~/.config/gar/init.lua`. Default config with keybinds: `gar/config/default.lua`
106
+
107
+Key Lua API functions:
108
+- `gar.bind(key, action)` - Bind key to action
109
+- `gar.set(option, value)` - Set config option
110
+- `gar.exec(cmd)` / `gar.exec_once(cmd)` - Execute commands
111
+- `gar.focus(dir)`, `gar.swap(dir)`, `gar.resize(dir, amount)` - Window operations
112
+- `gar.workspace(n)`, `gar.move_to_workspace(n)` - Workspace operations
113
+- `gar.reload`, `gar.exit` - WM control
114
+
115
+Mod key: Use `"mod"` (Super) for real sessions, `"alt"` for nested Xephyr testing.
116
+
117
+## Key Entry Points
118
+
119
+1. `main.rs` - Logging setup, X connection, WM initialization
120
+2. `WindowManager::new()` in `core/mod.rs` - State initialization, monitor detection, IPC server startup
121
+3. `WindowManager::run()` - Main event loop
122
+4. `handle_event()` in `x11/events.rs` - Event dispatch to specific handlers