tony / oxwm

Branch: e9ab027
Switch branches/tags
master
tonybtw Updated readme. e9ab027 2025-10-05
294 lines · 12.7 KB Rendered Raw Blame History
1 #+AUTHOR: Tony
2 #+STARTUP: overview
3
4 * Table of Contents :toc:
5 - [[#oxwm--dwm-but-better-and-oxidized][OXWM — DWM but Better (and oxidized)]]
6 - [[#project-structure][Project Structure]]
7 - [[#event-flow][Event Flow]]
8 - [[#key-bindings][Key Bindings]]
9 - [[#-installation--running-with-nix-flakes][⚙ Installation — Running with Nix Flakes]]
10 - [[#testing-xephyr-with-justfile][Testing Xephyr with Justfile]]
11 - [[#current-status][Current Status]]
12 - [[#working-features][Working Features]]
13 - [[#immediate-next-steps][Immediate Next Steps]]
14 - [[#long-term-roadmap][Long Term Roadmap]]
15 - [[#oxwm-development-todo][OXWM Development Todo]]
16 - [[#core-window-management-22][Core Window Management]]
17 - [[#tag-system-33][Tag System]]
18 - [[#status-bar-22][Status Bar]]
19 - [[#bar-enhancements-33][Bar Enhancements]]
20 - [[#key-system-improvements-22][Key System Improvements]]
21 - [[#layout-system-05][Layout System]]
22 - [[#advanced-features-04][Advanced Features]]
23 - [[#polish--features][Polish & Features]]
24 - [[#architecture-notes][Architecture Notes]]
25 - [[#tag-system][Tag System]]
26 - [[#bar-design][Bar Design]]
27 - [[#configuration-philosophy][Configuration Philosophy]]
28 - [[#license][License]]
29
30 * OXWM — DWM but Better (and oxidized)
31 A dynamic window manager written in Rust, inspired by dwm but designed to evolve
32 on its own. Configuration is done in Rust source code, keeping with the suckless
33 philosophy of *"edit + recompile."*
34
35 * Project Structure
36
37 #+begin_src sh
38 src/
39 ├── main.rs
40 │ └── main()
41 │ └── Creates WindowManager and calls .run()
42 │
43 ├── window_manager.rs [CORE - X11 event handling]
44 │ ├── struct WindowManager
45 │ │ ├── connection: RustConnection [X11 connection]
46 │ │ ├── windows: Vec<Window> [All managed windows]
47 │ │ ├── focused_window: Option<Window>
48 │ │ ├── layout: Box<dyn Layout>
49 │ │ ├── window_tags: HashMap<Window, TagMask>
50 │ │ ├── selected_tags: TagMask
51 │ │ └── bar: Bar [Status bar]
52 │ │
53 │ ├── new() [Initialize WM, grab root, restore tags, scan windows]
54 │ ├── run() [Main event loop with block updates]
55 │ ├── handle_event() [Route X11 events]
56 │ │ ├── MapRequest → add window, apply layout, update bar, save tag
57 │ │ ├── UnmapNotify → remove window, update bar
58 │ │ ├── DestroyNotify → remove window, update bar
59 │ │ ├── KeyPress → get action, handle it (includes Restart)
60 │ │ ├── ButtonPress → handle bar clicks
61 │ │ └── Expose → redraw bar
62 │ ├── handle_key_action() [Execute keyboard actions]
63 │ ├── get_saved_selected_tags() [Restore selected tags from _NET_CURRENT_DESKTOP]
64 │ ├── save_selected_tags() [Persist selected tags to root window]
65 │ ├── get_saved_tag() [Restore window tag from _NET_CLIENT_INFO]
66 │ ├── save_client_tag() [Persist window tag to window property]
67 │ ├── scan_existing_windows() [Manage windows on startup]
68 │ ├── remove_window() [Remove from Vec, reapply layout]
69 │ ├── set_focus() [Focus window, update visuals]
70 │ ├── cycle_focus() [Move focus to next/prev window]
71 │ ├── view_tag() [Switch to tag/workspace, update visibility]
72 │ ├── move_to_tag() [Move window to tag]
73 │ ├── update_bar() [Calculate occupied tags, redraw bar]
74 │ ├── update_focus_visuals() [Set border colors]
75 │ ├── update_window_visibility() [Map/unmap windows based on tags]
76 │ └── apply_layout() [Position all windows below bar]
77 │
78 ├── config.rs [CONFIGURATION - all settings here]
79 │ ├── BORDER_WIDTH, BORDER_FOCUSED, BORDER_UNFOCUSED
80 │ ├── FONT [XFT font string]
81 │ ├── TAG_COUNT, TAGS [Workspace configuration]
82 │ ├── TERMINAL, MODKEY
83 │ ├── ColorScheme [Foreground, background, border colors]
84 │ ├── SCHEME_NORMAL, SCHEME_OCCUPIED, SCHEME_SELECTED
85 │ ├── KEYBINDINGS [All keybinds as const array]
86 │ └── STATUS_BLOCKS [Block configurations with format, command, interval]
87 │
88 ├── bar/
89 │ ├── mod.rs [Re-exports: Bar, BlockCommand, BlockConfig]
90 │ ├── bar.rs
91 │ │ ├── struct Bar [Status bar window with XFT support]
92 │ │ ├── new() [Create bar X11 window, load font, init blocks]
93 │ │ ├── draw() [Render tags + blocks with underlines]
94 │ │ ├── update_blocks() [Update block content based on intervals]
95 │ │ ├── handle_click() [Detect which tag was clicked]
96 │ │ └── invalidate() [Mark bar as needing redraw]
97 │ ├── font.rs
98 │ │ ├── struct Font [XFT font wrapper]
99 │ │ ├── struct FontDraw [XFT drawing context]
100 │ │ └── draw_text() [Render text with color]
101 │ └── blocks/
102 │ ├── mod.rs [Block trait, BlockConfig, BlockCommand enum]
103 │ ├── battery.rs [Battery status block]
104 │ ├── datetime.rs [Date/time formatting block]
105 │ └── shell.rs [Shell command execution block]
106 │
107 ├── keyboard/
108 │ ├── mod.rs [Re-exports]
109 │ ├── keycodes.rs [Key constants: Q, J, RETURN, etc]
110 │ └── handlers.rs
111 │ ├── enum KeyAction [Spawn, KillClient, FocusStack, ViewTag, Restart, etc]
112 │ ├── enum Arg [None, Int, Str, Array]
113 │ ├── struct Key [Keybinding definition]
114 │ ├── setup_keybinds() [Register keys with X11]
115 │ └── handle_key_press() [Parse KeyPressEvent → KeyAction]
116 │
117 └── layout/
118 ├── mod.rs [Layout trait definition]
119 └── tiling.rs
120 └── TilingLayout::arrange() [Calculate window positions]
121 #+end_src
122
123 * Event Flow
124
125 1. X11 event arrives → run() receives it
126 2. handle_event() matches event type
127 3. For KeyPress:
128 - keyboard::handle_key_press() → KeyAction
129 - handle_key_action() executes action
130 - update_bar() if tags/windows changed
131 4. For Map/Unmap:
132 - Modify windows Vec and window_tags HashMap
133 - apply_layout() repositions everything (accounting for bar)
134 - update_bar() shows occupied tags
135 - update_focus_visuals() redraws borders
136 5. For ButtonPress on bar:
137 - bar.handle_click() determines clicked tag
138 - view_tag() switches workspace
139
140 * Key Bindings
141
142 | Binding | Action |
143 |-----------------+-------------------------|
144 | Alt+Return | Spawn terminal |
145 | Alt+J/K | Cycle focus down/up |
146 | Alt+Q | Kill focused window |
147 | Alt+Shift+Q | Quit WM |
148 | Alt+Shift+R | Hot reload WM |
149 | Alt+1-9 | View tag 1-9 |
150 | Alt+Shift+1-9 | Move window to tag 1-9 |
151 | Alt+S | Screenshot (maim) |
152 | Alt+D | Application launcher |
153
154 * ⚙ Installation — Running with Nix Flakes
155 You can set up a reproducible development environment with Rust, Cargo, Xephyr, xterm, and
156 just by using the flake.
157
158 #+begin_src sh
159 git clone https://github.com/tonybanters/oxwm
160 cd oxwm
161
162 # enter the dev shell
163 nix develop
164
165 # build normally
166 cargo build
167 #+end_src
168
169 * Testing Xephyr with Justfile
170 The =justfile= includes a =test= recipe that starts Xephyr on =:1=, launches
171 test clients (xterm, xclock), and runs oxwm in the foreground.
172
173 #+begin_src sh
174 # inside nix develop
175 just test
176 #+end_src
177
178 This should open a new Xephyr window. oxwm will attach to it and log X11
179 events in your host terminal. Clients like xterm/xclock will appear inside Xephyr.
180
181 * Current Status
182 ** Working Features
183 - ✓ X11 event handling and window management
184 - ✓ Tag system (9 workspaces) with keyboard switching
185 - ✓ Window focus cycling (Alt+J/K)
186 - ✓ Tiling layout with border indicators
187 - ✓ Status bar showing tags
188 - Visual indicators: selected (white), occupied (gray line), empty (dim)
189 - Click-to-switch tags
190 - Performance-optimized redrawing
191 - ✓ Basic keybindings (spawn, kill, focus, tags)
192 - ✓ Configuration via Rust constants in config.rs
193 - ✓ Hot reload functionality (Alt+Shift+R)
194 - ✓ Persistent window tags across restarts
195 - ✓ Status bar blocks system
196 - DateTime, Battery, Shell command blocks
197 - Configurable colors and update intervals
198 - Underline indicators for blocks
199 - Proper spacing between blocks
200 - Hackable block system for custom widgets
201 - ✓ dmenu integration (Alt+D)
202
203 ** Immediate Next Steps
204 - [ ] Mouse hover to focus windows
205 - [ ] Configurable gaps between windows (vanitygaps-style)
206 - [ ] Decide on reload behavior (should it auto-rebuild?)
207
208 ** Long Term Roadmap
209 - [ ] Multi-monitor support
210 - [ ] Additional layouts (monocle, floating, etc.)
211 - [ ] Per-window floating behavior
212 - [ ] Per-program rules (auto-tag assignment, floating rules)
213 - [ ] Master area resizing
214 - [ ] Window swapping in layout
215 - [ ] External bar support (polybar, lemonbar, etc.)
216
217 * OXWM Development Todo
218 ** DONE Core Window Management [2/2]
219 - [X] Fix layout after program is closed (handle UnmapNotify events)
220 - [X] Add UnmapNotify to event handling
221 - [X] Remove closed windows from windows vector
222 - [X] Re-apply layout after window removal
223 - [X] Add keybind to swap focus between windows
224 - [X] Track focused window in WindowManager struct
225 - [X] Implement focus cycling logic
226 - [X] Add visual focus indication (borders/colors)
227
228 ** DONE Tag System [3/3]
229 - [X] Implement tag/workspace system (9 tags)
230 - [X] Keybinds to switch tags (Alt+1-9)
231 - [X] Keybinds to move windows to tags (Alt+Shift+1-9)
232
233 ** DONE Status Bar [2/2]
234 - [X] Create basic bar window at screen top
235 - [X] Display tag indicators with state (selected/occupied/empty)
236
237 ** DONE Bar Enhancements [3/3]
238 - [X] Add status text area (right side of bar)
239 - [X] Implement clock widget
240 - [X] Add system information widgets
241
242 ** DONE Key System Improvements [2/2]
243 - [X] dmenu integration for application launching
244 - [X] More spawn commands in config (screenshot, volume, etc.)
245
246 ** TODO Layout System [0/5]
247 - [ ] Mouse hover to focus windows
248 - [ ] Configurable gaps between windows (vanitygaps-style)
249 - [ ] Add monocle layout
250 - [ ] Add floating layout mode
251 - [ ] Handle window resize requests properly
252
253 ** TODO Advanced Features [0/4]
254 - [ ] Decide on reload behavior (auto-rebuild vs manual)
255 - [ ] Multi-monitor support
256 - [ ] Per-window rules (floating, tag assignment)
257 - [ ] Master area resizing keybinds
258
259 ** Polish & Features
260 - [ ] Clean window destruction/cleanup
261 - [ ] Handle edge cases (empty window list, invalid windows)
262 - [ ] Better error messages and logging
263 - [ ] Proper font rendering in bar (currently using basic X11 text)
264
265 * Architecture Notes
266 ** Tag System
267 Tags are implemented as bitmasks (TagMask = u32), allowing windows to belong to
268 multiple tags simultaneously (though current UI only supports single tags).
269 Each window has an associated TagMask in window_tags HashMap. Tags persist across
270 WM restarts using X11 properties (_NET_CURRENT_DESKTOP for selected tags,
271 _NET_CLIENT_INFO for per-window tags).
272
273 ** Bar Design
274 The bar uses a performance-optimized approach with a modular block system:
275 - Only redraws when invalidate() is called
276 - Pre-calculates tag widths on creation
277 - Uses X11 graphics context for efficient drawing
278 - Click handling uses O(n) tag width lookup
279 - Blocks are updated independently based on their interval
280 - Each block can have custom colors and optional underline indicators
281 - Blocks are defined in config.rs and can be:
282 - DateTime: Display formatted date/time
283 - Battery: Show battery status with custom formats
284 - Shell: Execute shell commands and display output
285 - Static: Display fixed text
286 - Blocks are easily hackable - add new block types in src/bar/blocks/
287
288 ** Configuration Philosophy
289 Following dwm's approach: all configuration is in Rust source code. No runtime
290 config files. Edit config.rs and recompile. This ensures type safety and
291 compile-time validation of all settings.
292
293 * License
294 [[https://www.gnu.org/licenses/gpl-3.0.en.html][GPL]]