tony / oxwm

Branch: 251382c
Switch branches/tags
master
tonybtw Added bar. 2mb! 8347143 2025-10-03
225 lines · 8.7 KB Rendered Raw Blame History
1 #+AUTHOR: Tony
2 #+STARTUP: overview
3
4 * OXWM — DWM but Better (and oxidized)
5 A dynamic window manager written in Rust, inspired by dwm but designed to evolve
6 on its own. Configuration is done in Rust source code, keeping with the suckless
7 philosophy of *"edit + recompile."*
8
9 * Project Structure
10
11 #+begin_src sh
12 src/
13 ├── main.rs
14 │ └── main()
15 │ └── Creates WindowManager and calls .run()
16 │
17 ├── window_manager.rs [CORE - X11 event handling]
18 │ ├── struct WindowManager
19 │ │ ├── connection: RustConnection [X11 connection]
20 │ │ ├── windows: Vec<Window> [All managed windows]
21 │ │ ├── focused_window: Option<Window>
22 │ │ ├── layout: Box<dyn Layout>
23 │ │ ├── window_tags: HashMap<Window, TagMask>
24 │ │ ├── selected_tags: TagMask
25 │ │ └── bar: Bar [Status bar]
26 │ │
27 │ ├── new() [Initialize WM, grab root, create bar]
28 │ ├── run() [Main event loop]
29 │ ├── handle_event() [Route X11 events]
30 │ │ ├── MapRequest → add window, apply layout, update bar
31 │ │ ├── UnmapNotify → remove window, update bar
32 │ │ ├── DestroyNotify → remove window, update bar
33 │ │ ├── KeyPress → get action, handle it
34 │ │ ├── ButtonPress → handle bar clicks
35 │ │ └── Expose → redraw bar
36 │ ├── handle_key_action() [Execute keyboard actions]
37 │ ├── remove_window() [Remove from Vec, reapply layout]
38 │ ├── set_focus() [Focus window, update visuals]
39 │ ├── cycle_focus() [Move focus to next/prev window]
40 │ ├── view_tag() [Switch to tag/workspace]
41 │ ├── move_to_tag() [Move window to tag]
42 │ ├── update_bar() [Calculate occupied tags, redraw bar]
43 │ ├── update_focus_visuals() [Set border colors]
44 │ └── apply_layout() [Position all windows below bar]
45 │
46 ├── config.rs [CONFIGURATION - all settings here]
47 │ ├── BORDER_WIDTH, BORDER_FOCUSED, BORDER_UNFOCUSED
48 │ ├── TAG_COUNT, TAGS [Workspace configuration]
49 │ ├── TERMINAL, MODKEY
50 │ └── KEYBINDINGS [All keybinds as const array]
51 │
52 ├── bar/
53 │ ├── mod.rs [Re-exports, constants]
54 │ └── bar.rs
55 │ ├── struct Bar [Status bar window]
56 │ ├── new() [Create bar X11 window]
57 │ ├── draw() [Render tags with state indicators]
58 │ ├── handle_click() [Detect which tag was clicked]
59 │ └── invalidate() [Mark bar as needing redraw]
60 │
61 ├── keyboard/
62 │ ├── mod.rs [Re-exports]
63 │ ├── keycodes.rs [Key constants: Q, J, RETURN, etc]
64 │ └── handlers.rs
65 │ ├── enum KeyAction [Spawn, KillClient, FocusStack, ViewTag, etc]
66 │ ├── enum Arg [None, Int, Str, Array]
67 │ ├── setup_keybinds() [Register keys with X11]
68 │ └── handle_key_press() [Parse KeyPressEvent → KeyAction]
69 │
70 └── layout/
71 ├── mod.rs [Layout trait definition]
72 └── tiling.rs
73 └── TilingLayout::arrange() [Calculate window positions]
74 #+end_src
75
76 * Event Flow
77
78 1. X11 event arrives → run() receives it
79 2. handle_event() matches event type
80 3. For KeyPress:
81 - keyboard::handle_key_press() → KeyAction
82 - handle_key_action() executes action
83 - update_bar() if tags/windows changed
84 4. For Map/Unmap:
85 - Modify windows Vec and window_tags HashMap
86 - apply_layout() repositions everything (accounting for bar)
87 - update_bar() shows occupied tags
88 - update_focus_visuals() redraws borders
89 5. For ButtonPress on bar:
90 - bar.handle_click() determines clicked tag
91 - view_tag() switches workspace
92
93 * Key Bindings
94
95 | Binding | Action |
96 |-----------------+-------------------------|
97 | Alt+Return | Spawn terminal |
98 | Alt+J/K | Cycle focus down/up |
99 | Alt+Q | Kill focused window |
100 | Alt+Shift+Q | Quit WM |
101 | Alt+1-9 | View tag 1-9 |
102 | Alt+Shift+1-9 | Move window to tag 1-9 |
103 | Alt+S | Screenshot (maim) |
104
105 * ⚙ Installation — Running with Nix Flakes
106 You can set up a reproducible development environment with Rust, Cargo, Xephyr, xterm, and
107 just by using the flake.
108
109 #+begin_src sh
110 git clone https://github.com/tonybanters/oxwm
111 cd oxwm
112
113 # enter the dev shell
114 nix develop
115
116 # build normally
117 cargo build
118 #+end_src
119
120 * Testing Xephyr with Justfile
121 The =justfile= includes a =test= recipe that starts Xephyr on =:1=, launches
122 test clients (xterm, xclock), and runs oxwm in the foreground.
123
124 #+begin_src sh
125 # inside nix develop
126 just test
127 #+end_src
128
129 This should open a new Xephyr window. oxwm will attach to it and log X11
130 events in your host terminal. Clients like xterm/xclock will appear inside Xephyr.
131
132 * Current Status
133 ** Working Features
134 - ✓ X11 event handling and window management
135 - ✓ Tag system (9 workspaces) with keyboard switching
136 - ✓ Window focus cycling (Alt+J/K)
137 - ✓ Tiling layout with border indicators
138 - ✓ Status bar showing tags
139 - Visual indicators: selected (white), occupied (gray line), empty (dim)
140 - Click-to-switch tags
141 - Performance-optimized redrawing
142 - ✓ Basic keybindings (spawn, kill, focus, tags)
143 - ✓ Configuration via Rust constants in config.rs
144
145 ** Immediate Next Steps
146 - [ ] Status text in bar (date, time, system info)
147 - [ ] dmenu integration for application launcher
148 - [ ] Additional widgets (clock, battery, etc.)
149
150 ** Long Term Roadmap
151 - [ ] Multi-monitor support
152 - [ ] Additional layouts (monocle, floating, etc.)
153 - [ ] Per-window floating behavior
154 - [ ] Per-program rules (auto-tag assignment, floating rules)
155 - [ ] Master area resizing
156 - [ ] Window swapping in layout
157 - [ ] Configurable gaps between windows
158 - [ ] External bar support (polybar, lemonbar, etc.)
159
160 * OXWM Development Todo
161 ** DONE Core Window Management [2/2]
162 - [X] Fix layout after program is closed (handle UnmapNotify events)
163 - [X] Add UnmapNotify to event handling
164 - [X] Remove closed windows from windows vector
165 - [X] Re-apply layout after window removal
166 - [X] Add keybind to swap focus between windows
167 - [X] Track focused window in WindowManager struct
168 - [X] Implement focus cycling logic
169 - [X] Add visual focus indication (borders/colors)
170
171 ** DONE Tag System [3/3]
172 - [X] Implement tag/workspace system (9 tags)
173 - [X] Keybinds to switch tags (Alt+1-9)
174 - [X] Keybinds to move windows to tags (Alt+Shift+1-9)
175
176 ** DONE Status Bar [2/2]
177 - [X] Create basic bar window at screen top
178 - [X] Display tag indicators with state (selected/occupied/empty)
179
180 ** IN PROGRESS Bar Enhancements [0/3]
181 - [ ] Add status text area (right side of bar)
182 - [ ] Implement clock widget
183 - [ ] Add system information widgets
184
185 ** TODO Key System Improvements [0/2]
186 - [ ] dmenu integration for application launching
187 - [ ] More spawn commands in config (screenshot, volume, etc.)
188
189 ** TODO Layout System [0/4]
190 - [ ] Add monocle layout
191 - [ ] Add floating layout mode
192 - [ ] Handle window resize requests properly
193 - [ ] Add configurable gaps between windows
194
195 ** TODO Advanced Features [0/3]
196 - [ ] Multi-monitor support
197 - [ ] Per-window rules (floating, tag assignment)
198 - [ ] Master area resizing keybinds
199
200 ** Polish & Features
201 - [ ] Clean window destruction/cleanup
202 - [ ] Handle edge cases (empty window list, invalid windows)
203 - [ ] Better error messages and logging
204 - [ ] Proper font rendering in bar (currently using basic X11 text)
205
206 * Architecture Notes
207 ** Tag System
208 Tags are implemented as bitmasks (TagMask = u32), allowing windows to belong to
209 multiple tags simultaneously (though current UI only supports single tags).
210 Each window has an associated TagMask in window_tags HashMap.
211
212 ** Bar Design
213 The bar uses a performance-optimized approach:
214 - Only redraws when invalidate() is called
215 - Pre-calculates tag widths on creation
216 - Uses X11 graphics context for efficient drawing
217 - Click handling uses O(n) tag width lookup
218
219 ** Configuration Philosophy
220 Following dwm's approach: all configuration is in Rust source code. No runtime
221 config files. Edit config.rs and recompile. This ensures type safety and
222 compile-time validation of all settings.
223
224 * License
225 [[https://www.gnu.org/licenses/gpl-3.0.en.html][GPL]]