tony / oxwm

Updated hot reload, xmonad style Browse files
tonybtw committed 2025-10-10 parent 7c10ebe commit 0fc3d435e6bbf7ff432b203536c5d9a8a0d63ccc
Showing 12 changed files with 922 additions and 92 deletions. UnifiedSplit
+162 −10 Cargo.lock
@@ -70,6 +70,27 @@ version = "0.8.7"
70 source = "registry+https://github.com/rust-lang/crates.io-index" 70 source = "registry+https://github.com/rust-lang/crates.io-index"
71 checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" 71 checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
72 72
73 +[[package]]
74 +name = "dirs"
75 +version = "5.0.1"
76 +source = "registry+https://github.com/rust-lang/crates.io-index"
77 +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
78 +dependencies = [
79 + "dirs-sys",
80 +]
81 +
82 +[[package]]
83 +name = "dirs-sys"
84 +version = "0.4.1"
85 +source = "registry+https://github.com/rust-lang/crates.io-index"
86 +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
87 +dependencies = [
88 + "libc",
89 + "option-ext",
90 + "redox_users",
91 + "windows-sys 0.48.0",
92 +]
93 +
73 [[package]] 94 [[package]]
74 name = "errno" 95 name = "errno"
75 version = "0.3.14" 96 version = "0.3.14"
@@ -77,7 +98,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
77 checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" 98 checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
78 dependencies = [ 99 dependencies = [
79 "libc", 100 "libc",
80 - "windows-sys", 101 + "windows-sys 0.61.0",
81 ] 102 ]
82 103
83 [[package]] 104 [[package]]
@@ -93,7 +114,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
93 checksum = "fc257fdb4038301ce4b9cd1b3b51704509692bb3ff716a410cbd07925d9dae55" 114 checksum = "fc257fdb4038301ce4b9cd1b3b51704509692bb3ff716a410cbd07925d9dae55"
94 dependencies = [ 115 dependencies = [
95 "rustix", 116 "rustix",
96 - "windows-targets", 117 + "windows-targets 0.52.6",
118 +]
119 +
120 +[[package]]
121 +name = "getrandom"
122 +version = "0.2.16"
123 +source = "registry+https://github.com/rust-lang/crates.io-index"
124 +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
125 +dependencies = [
126 + "cfg-if",
127 + "libc",
128 + "wasi",
97 ] 129 ]
98 130
99 [[package]] 131 [[package]]
@@ -136,6 +168,16 @@ version = "0.2.175"
136 source = "registry+https://github.com/rust-lang/crates.io-index" 168 source = "registry+https://github.com/rust-lang/crates.io-index"
137 checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" 169 checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543"
138 170
171 +[[package]]
172 +name = "libredox"
173 +version = "0.1.10"
174 +source = "registry+https://github.com/rust-lang/crates.io-index"
175 +checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb"
176 +dependencies = [
177 + "bitflags",
178 + "libc",
179 +]
180 +
139 [[package]] 181 [[package]]
140 name = "linux-raw-sys" 182 name = "linux-raw-sys"
141 version = "0.11.0" 183 version = "0.11.0"
@@ -163,12 +205,19 @@ version = "1.21.3"
163 source = "registry+https://github.com/rust-lang/crates.io-index" 205 source = "registry+https://github.com/rust-lang/crates.io-index"
164 checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" 206 checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
165 207
208 +[[package]]
209 +name = "option-ext"
210 +version = "0.2.0"
211 +source = "registry+https://github.com/rust-lang/crates.io-index"
212 +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
213 +
166 [[package]] 214 [[package]]
167 name = "oxwm" 215 name = "oxwm"
168 version = "0.1.0" 216 version = "0.1.0"
169 dependencies = [ 217 dependencies = [
170 "anyhow", 218 "anyhow",
171 "chrono", 219 "chrono",
220 + "dirs",
172 "x11", 221 "x11",
173 "x11rb", 222 "x11rb",
174 ] 223 ]
@@ -197,6 +246,17 @@ dependencies = [
197 "proc-macro2", 246 "proc-macro2",
198 ] 247 ]
199 248
249 +[[package]]
250 +name = "redox_users"
251 +version = "0.4.6"
252 +source = "registry+https://github.com/rust-lang/crates.io-index"
253 +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
254 +dependencies = [
255 + "getrandom",
256 + "libredox",
257 + "thiserror",
258 +]
259 +
200 [[package]] 260 [[package]]
201 name = "rustix" 261 name = "rustix"
202 version = "1.1.2" 262 version = "1.1.2"
@@ -207,7 +267,7 @@ dependencies = [
207 "errno", 267 "errno",
208 "libc", 268 "libc",
209 "linux-raw-sys", 269 "linux-raw-sys",
210 - "windows-sys", 270 + "windows-sys 0.61.0",
211 ] 271 ]
212 272
213 [[package]] 273 [[package]]
@@ -233,12 +293,38 @@ dependencies = [
233 "unicode-ident", 293 "unicode-ident",
234 ] 294 ]
235 295
296 +[[package]]
297 +name = "thiserror"
298 +version = "1.0.69"
299 +source = "registry+https://github.com/rust-lang/crates.io-index"
300 +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
301 +dependencies = [
302 + "thiserror-impl",
303 +]
304 +
305 +[[package]]
306 +name = "thiserror-impl"
307 +version = "1.0.69"
308 +source = "registry+https://github.com/rust-lang/crates.io-index"
309 +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
310 +dependencies = [
311 + "proc-macro2",
312 + "quote",
313 + "syn",
314 +]
315 +
236 [[package]] 316 [[package]]
237 name = "unicode-ident" 317 name = "unicode-ident"
238 version = "1.0.19" 318 version = "1.0.19"
239 source = "registry+https://github.com/rust-lang/crates.io-index" 319 source = "registry+https://github.com/rust-lang/crates.io-index"
240 checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" 320 checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
241 321
322 +[[package]]
323 +name = "wasi"
324 +version = "0.11.1+wasi-snapshot-preview1"
325 +source = "registry+https://github.com/rust-lang/crates.io-index"
326 +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
327 +
242 [[package]] 328 [[package]]
243 name = "wasm-bindgen" 329 name = "wasm-bindgen"
244 version = "0.2.104" 330 version = "0.2.104"
@@ -357,6 +443,15 @@ dependencies = [
357 "windows-link", 443 "windows-link",
358 ] 444 ]
359 445
446 +[[package]]
447 +name = "windows-sys"
448 +version = "0.48.0"
449 +source = "registry+https://github.com/rust-lang/crates.io-index"
450 +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
451 +dependencies = [
452 + "windows-targets 0.48.5",
453 +]
454 +
360 [[package]] 455 [[package]]
361 name = "windows-sys" 456 name = "windows-sys"
362 version = "0.61.0" 457 version = "0.61.0"
@@ -366,34 +461,67 @@ dependencies = [
366 "windows-link", 461 "windows-link",
367 ] 462 ]
368 463
464 +[[package]]
465 +name = "windows-targets"
466 +version = "0.48.5"
467 +source = "registry+https://github.com/rust-lang/crates.io-index"
468 +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
469 +dependencies = [
470 + "windows_aarch64_gnullvm 0.48.5",
471 + "windows_aarch64_msvc 0.48.5",
472 + "windows_i686_gnu 0.48.5",
473 + "windows_i686_msvc 0.48.5",
474 + "windows_x86_64_gnu 0.48.5",
475 + "windows_x86_64_gnullvm 0.48.5",
476 + "windows_x86_64_msvc 0.48.5",
477 +]
478 +
369 [[package]] 479 [[package]]
370 name = "windows-targets" 480 name = "windows-targets"
371 version = "0.52.6" 481 version = "0.52.6"
372 source = "registry+https://github.com/rust-lang/crates.io-index" 482 source = "registry+https://github.com/rust-lang/crates.io-index"
373 checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 483 checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
374 dependencies = [ 484 dependencies = [
375 - "windows_aarch64_gnullvm", 485 + "windows_aarch64_gnullvm 0.52.6",
376 - "windows_aarch64_msvc", 486 + "windows_aarch64_msvc 0.52.6",
377 - "windows_i686_gnu", 487 + "windows_i686_gnu 0.52.6",
378 "windows_i686_gnullvm", 488 "windows_i686_gnullvm",
379 - "windows_i686_msvc", 489 + "windows_i686_msvc 0.52.6",
380 - "windows_x86_64_gnu", 490 + "windows_x86_64_gnu 0.52.6",
381 - "windows_x86_64_gnullvm", 491 + "windows_x86_64_gnullvm 0.52.6",
382 - "windows_x86_64_msvc", 492 + "windows_x86_64_msvc 0.52.6",
383 ] 493 ]
384 494
495 +[[package]]
496 +name = "windows_aarch64_gnullvm"
497 +version = "0.48.5"
498 +source = "registry+https://github.com/rust-lang/crates.io-index"
499 +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
500 +
385 [[package]] 501 [[package]]
386 name = "windows_aarch64_gnullvm" 502 name = "windows_aarch64_gnullvm"
387 version = "0.52.6" 503 version = "0.52.6"
388 source = "registry+https://github.com/rust-lang/crates.io-index" 504 source = "registry+https://github.com/rust-lang/crates.io-index"
389 checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 505 checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
390 506
507 +[[package]]
508 +name = "windows_aarch64_msvc"
509 +version = "0.48.5"
510 +source = "registry+https://github.com/rust-lang/crates.io-index"
511 +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
512 +
391 [[package]] 513 [[package]]
392 name = "windows_aarch64_msvc" 514 name = "windows_aarch64_msvc"
393 version = "0.52.6" 515 version = "0.52.6"
394 source = "registry+https://github.com/rust-lang/crates.io-index" 516 source = "registry+https://github.com/rust-lang/crates.io-index"
395 checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 517 checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
396 518
519 +[[package]]
520 +name = "windows_i686_gnu"
521 +version = "0.48.5"
522 +source = "registry+https://github.com/rust-lang/crates.io-index"
523 +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
524 +
397 [[package]] 525 [[package]]
398 name = "windows_i686_gnu" 526 name = "windows_i686_gnu"
399 version = "0.52.6" 527 version = "0.52.6"
@@ -406,24 +534,48 @@ version = "0.52.6"
406 source = "registry+https://github.com/rust-lang/crates.io-index" 534 source = "registry+https://github.com/rust-lang/crates.io-index"
407 checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 535 checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
408 536
537 +[[package]]
538 +name = "windows_i686_msvc"
539 +version = "0.48.5"
540 +source = "registry+https://github.com/rust-lang/crates.io-index"
541 +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
542 +
409 [[package]] 543 [[package]]
410 name = "windows_i686_msvc" 544 name = "windows_i686_msvc"
411 version = "0.52.6" 545 version = "0.52.6"
412 source = "registry+https://github.com/rust-lang/crates.io-index" 546 source = "registry+https://github.com/rust-lang/crates.io-index"
413 checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 547 checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
414 548
549 +[[package]]
550 +name = "windows_x86_64_gnu"
551 +version = "0.48.5"
552 +source = "registry+https://github.com/rust-lang/crates.io-index"
553 +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
554 +
415 [[package]] 555 [[package]]
416 name = "windows_x86_64_gnu" 556 name = "windows_x86_64_gnu"
417 version = "0.52.6" 557 version = "0.52.6"
418 source = "registry+https://github.com/rust-lang/crates.io-index" 558 source = "registry+https://github.com/rust-lang/crates.io-index"
419 checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 559 checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
420 560
561 +[[package]]
562 +name = "windows_x86_64_gnullvm"
563 +version = "0.48.5"
564 +source = "registry+https://github.com/rust-lang/crates.io-index"
565 +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
566 +
421 [[package]] 567 [[package]]
422 name = "windows_x86_64_gnullvm" 568 name = "windows_x86_64_gnullvm"
423 version = "0.52.6" 569 version = "0.52.6"
424 source = "registry+https://github.com/rust-lang/crates.io-index" 570 source = "registry+https://github.com/rust-lang/crates.io-index"
425 checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 571 checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
426 572
573 +[[package]]
574 +name = "windows_x86_64_msvc"
575 +version = "0.48.5"
576 +source = "registry+https://github.com/rust-lang/crates.io-index"
577 +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
578 +
427 [[package]] 579 [[package]]
428 name = "windows_x86_64_msvc" 580 name = "windows_x86_64_msvc"
429 version = "0.52.6" 581 version = "0.52.6"
+9 −0 Cargo.toml
@@ -3,8 +3,17 @@ name = "oxwm"
3 version = "0.1.0" 3 version = "0.1.0"
4 edition = "2024" 4 edition = "2024"
5 5
6 +[lib]
7 +name = "oxwm"
8 +path = "src/lib.rs"
9 +
10 +[[bin]]
11 +name = "oxwm"
12 +path = "src/bin/main.rs"
13 +
6 [dependencies] 14 [dependencies]
7 x11 = { version = "2.21", features = ["xlib", "xft"] } 15 x11 = { version = "2.21", features = ["xlib", "xft"] }
8 x11rb = "0.13" 16 x11rb = "0.13"
9 anyhow = "1" 17 anyhow = "1"
10 chrono = "0.4" 18 chrono = "0.4"
19 +dirs = "5.0"
+27 −14 justfile
@@ -1,28 +1,41 @@
1 -ensure-config: 1 +build:
2 - @if [ ! -f src/config.rs ]; then \
3 - echo "Creating config.rs from default_config.rs..."; \
4 - cp src/default_config.rs src/config.rs; \
5 - echo "✓ Edit src/config.rs to customize your setup"; \
6 - fi
7 -
8 -build: ensure-config
9 cargo build --release 2 cargo build --release
10 3
11 install: build 4 install: build
12 sudo cp target/release/oxwm /usr/local/bin/oxwm 5 sudo cp target/release/oxwm /usr/local/bin/oxwm
13 - @echo "✓ oxwm installed. Restart X or hit Mod+Shift+R (when implemented)" 6 + @echo "✓ oxwm installed to /usr/local/bin/oxwm"
7 + @echo " Run 'oxwm --init' to set up your config"
14 8
15 uninstall: 9 uninstall:
16 sudo rm -f /usr/local/bin/oxwm 10 sudo rm -f /usr/local/bin/oxwm
11 + @echo "✓ oxwm uninstalled"
12 + @echo " Your config at ~/.config/oxwm is preserved"
17 13
18 clean: 14 clean:
19 cargo clean 15 cargo clean
20 16
21 -test: ensure-config 17 +test:
22 pkill Xephyr || true 18 pkill Xephyr || true
23 Xephyr -screen 1280x800 :1 & sleep 1 19 Xephyr -screen 1280x800 :1 & sleep 1
24 - DISPLAY=:1 cargo run 20 + DISPLAY=:1 cargo run -- --init
21 + DISPLAY=:1 ~/.cache/oxwm/oxwm-binary
22 +
23 +init:
24 + cargo run -- --init
25 +
26 +recompile:
27 + cargo run -- --recompile
28 +
29 +edit:
30 + $EDITOR ~/.config/oxwm/config.rs
31 +
32 +check:
33 + cargo clippy -- -W clippy::all
34 + cargo fmt -- --check
35 +
36 +fmt:
37 + cargo fmt
38 +
39 +pre-commit: fmt check build
40 + @echo "✓ All checks passed!"
25 41
26 -reset-config:
27 - cp src/default_config.rs src/config.rs
28 - @echo "✓ Config reset to default"
+35 −18 src/bar/bar.rs
@@ -1,6 +1,6 @@
1 use super::blocks::Block; 1 use super::blocks::Block;
2 use super::font::{Font, FontDraw}; 2 use super::font::{Font, FontDraw};
3 -use crate::config::{FONT, SCHEME_NORMAL, SCHEME_OCCUPIED, SCHEME_SELECTED, STATUS_BLOCKS, TAGS}; 3 +use crate::Config;
4 use anyhow::Result; 4 use anyhow::Result;
5 use std::time::Instant; 5 use std::time::Instant;
6 use x11rb::COPY_DEPTH_FROM_PARENT; 6 use x11rb::COPY_DEPTH_FROM_PARENT;
@@ -25,10 +25,20 @@ pub struct Bar {
25 block_last_updates: Vec<Instant>, 25 block_last_updates: Vec<Instant>,
26 block_underlines: Vec<bool>, 26 block_underlines: Vec<bool>,
27 status_text: String, 27 status_text: String,
28 +
29 + tags: Vec<String>,
30 + scheme_normal: crate::ColorScheme,
31 + scheme_occupied: crate::ColorScheme,
32 + scheme_selected: crate::ColorScheme,
28 } 33 }
29 34
30 impl Bar { 35 impl Bar {
31 - pub fn new(connection: &RustConnection, screen: &Screen, screen_num: usize) -> Result<Self> { 36 + pub fn new(
37 + connection: &RustConnection,
38 + screen: &Screen,
39 + screen_num: usize,
40 + config: &Config,
41 + ) -> Result<Self> {
32 let window = connection.generate_id()?; 42 let window = connection.generate_id()?;
33 let graphics_context = connection.generate_id()?; 43 let graphics_context = connection.generate_id()?;
34 44
@@ -38,7 +48,7 @@ impl Bar {
38 if display.is_null() { 48 if display.is_null() {
39 anyhow::bail!("Failed to open X11 display for XFT"); 49 anyhow::bail!("Failed to open X11 display for XFT");
40 } 50 }
41 - let font = Font::new(display, screen_num as i32, FONT)?; 51 + let font = Font::new(display, screen_num as i32, &config.font)?;
42 52
43 let height = (font.height() as f32 * 1.4) as u16; 53 let height = (font.height() as f32 * 1.4) as u16;
44 54
@@ -54,7 +64,7 @@ impl Bar {
54 WindowClass::INPUT_OUTPUT, 64 WindowClass::INPUT_OUTPUT,
55 screen.root_visual, 65 screen.root_visual,
56 &CreateWindowAux::new() 66 &CreateWindowAux::new()
57 - .background_pixel(SCHEME_NORMAL.background) 67 + .background_pixel(config.scheme_normal.background)
58 .event_mask(EventMask::EXPOSURE | EventMask::BUTTON_PRESS) 68 .event_mask(EventMask::EXPOSURE | EventMask::BUTTON_PRESS)
59 .override_redirect(1), 69 .override_redirect(1),
60 )?; 70 )?;
@@ -63,8 +73,8 @@ impl Bar {
63 graphics_context, 73 graphics_context,
64 window, 74 window,
65 &CreateGCAux::new() 75 &CreateGCAux::new()
66 - .foreground(SCHEME_NORMAL.foreground) 76 + .foreground(config.scheme_normal.foreground)
67 - .background(SCHEME_NORMAL.background), 77 + .background(config.scheme_normal.background),
68 )?; 78 )?;
69 79
70 connection.map_window(window)?; 80 connection.map_window(window)?;
@@ -77,7 +87,8 @@ impl Bar {
77 87
78 let horizontal_padding = (font.height() as f32 * 0.4) as u16; 88 let horizontal_padding = (font.height() as f32 * 0.4) as u16;
79 89
80 - let tag_widths = TAGS 90 + let tag_widths = config
91 + .tags
81 .iter() 92 .iter()
82 .map(|tag| { 93 .map(|tag| {
83 let text_width = font.text_width(tag); 94 let text_width = font.text_width(tag);
@@ -85,14 +96,16 @@ impl Bar {
85 }) 96 })
86 .collect(); 97 .collect();
87 98
88 - let blocks: Vec<Box<dyn Block>> = STATUS_BLOCKS 99 + let blocks: Vec<Box<dyn Block>> = config
100 + .status_blocks
89 .iter() 101 .iter()
90 - .map(|config| config.to_block()) 102 + .map(|block_config| block_config.to_block())
91 .collect(); 103 .collect();
92 104
93 - let block_underlines: Vec<bool> = STATUS_BLOCKS 105 + let block_underlines: Vec<bool> = config
106 + .status_blocks
94 .iter() 107 .iter()
95 - .map(|config| config.underline) 108 + .map(|block_config| block_config.underline)
96 .collect(); 109 .collect();
97 110
98 let block_last_updates = vec![Instant::now(); blocks.len()]; 111 let block_last_updates = vec![Instant::now(); blocks.len()];
@@ -111,6 +124,10 @@ impl Bar {
111 block_last_updates, 124 block_last_updates,
112 block_underlines, 125 block_underlines,
113 status_text: String::new(), 126 status_text: String::new(),
127 + tags: config.tags.clone(),
128 + scheme_normal: config.scheme_normal,
129 + scheme_occupied: config.scheme_occupied,
130 + scheme_selected: config.scheme_selected,
114 }) 131 })
115 } 132 }
116 133
@@ -134,7 +151,7 @@ impl Bar {
134 let elapsed = now.duration_since(self.block_last_updates[i]); 151 let elapsed = now.duration_since(self.block_last_updates[i]);
135 152
136 if elapsed >= block.interval() { 153 if elapsed >= block.interval() {
137 - if let Ok(_) = block.content() { 154 + if block.content().is_ok() {
138 self.block_last_updates[i] = now; 155 self.block_last_updates[i] = now;
139 changed = true; 156 changed = true;
140 } 157 }
@@ -167,7 +184,7 @@ impl Bar {
167 184
168 connection.change_gc( 185 connection.change_gc(
169 self.graphics_context, 186 self.graphics_context,
170 - &ChangeGCAux::new().foreground(SCHEME_NORMAL.background), 187 + &ChangeGCAux::new().foreground(self.scheme_normal.background),
171 )?; 188 )?;
172 connection.poly_fill_rectangle( 189 connection.poly_fill_rectangle(
173 self.window, 190 self.window,
@@ -182,7 +199,7 @@ impl Bar {
182 199
183 let mut x_position: i16 = 0; 200 let mut x_position: i16 = 0;
184 201
185 - for (tag_index, tag) in TAGS.iter().enumerate() { 202 + for (tag_index, tag) in self.tags.iter().enumerate() {
186 let tag_mask = 1 << tag_index; 203 let tag_mask = 1 << tag_index;
187 let is_selected = (current_tags & tag_mask) != 0; 204 let is_selected = (current_tags & tag_mask) != 0;
188 let is_occupied = (occupied_tags & tag_mask) != 0; 205 let is_occupied = (occupied_tags & tag_mask) != 0;
@@ -190,11 +207,11 @@ impl Bar {
190 let tag_width = self.tag_widths[tag_index]; 207 let tag_width = self.tag_widths[tag_index];
191 208
192 let scheme = if is_selected { 209 let scheme = if is_selected {
193 - &SCHEME_SELECTED 210 + &self.scheme_selected
194 } else if is_occupied { 211 } else if is_occupied {
195 - &SCHEME_OCCUPIED 212 + &self.scheme_occupied
196 } else { 213 } else {
197 - &SCHEME_NORMAL 214 + &self.scheme_normal
198 }; 215 };
199 216
200 let text_width = self.font.text_width(tag); 217 let text_width = self.font.text_width(tag);
@@ -297,7 +314,7 @@ impl Bar {
297 } 314 }
298 current_x_position += tag_width as i16; 315 current_x_position += tag_width as i16;
299 } 316 }
300 - return None; 317 + None
301 } 318 }
302 319
303 pub fn needs_redraw(&self) -> bool { 320 pub fn needs_redraw(&self) -> bool {
+2 −0 src/bar/blocks/mod.rs
@@ -17,6 +17,7 @@ pub trait Block {
17 fn color(&self) -> u32; 17 fn color(&self) -> u32;
18 } 18 }
19 19
20 +#[derive(Clone)]
20 pub struct BlockConfig { 21 pub struct BlockConfig {
21 pub format: &'static str, 22 pub format: &'static str,
22 pub command: BlockCommand, 23 pub command: BlockCommand,
@@ -25,6 +26,7 @@ pub struct BlockConfig {
25 pub underline: bool, 26 pub underline: bool,
26 } 27 }
27 28
29 +#[derive(Clone)]
28 pub enum BlockCommand { 30 pub enum BlockCommand {
29 Shell(&'static str), 31 Shell(&'static str),
30 DateTime(&'static str), 32 DateTime(&'static str),
+0 −2 src/bar/blocks/ram.rs
@@ -40,8 +40,6 @@ impl Ram {
40 } 40 }
41 41
42 let used = total.saturating_sub(available); 42 let used = total.saturating_sub(available);
43 - let used_gb = used as f32 / 1024.0 / 1024.0;
44 - let total_gb = total as f32 / 1024.0 / 1024.0;
45 let percentage = if total > 0 { 43 let percentage = if total > 0 {
46 (used as f32 / total as f32) * 100.0 44 (used as f32 / total as f32) * 100.0
47 } else { 45 } else {
+195 −0 src/bin/main.rs new file mode 100644
@@ -0,0 +1,195 @@
1 +use anyhow::Result;
2 +use std::path::PathBuf;
3 +use std::process::Command;
4 +
5 +fn main() -> Result<()> {
6 + let args: Vec<String> = std::env::args().collect();
7 +
8 + match args.get(1).map(|s| s.as_str()) {
9 + Some("--init") => return init_config(),
10 + Some("--recompile") => return recompile_config(),
11 + Some("--version") => {
12 + println!("oxwm {}", env!("CARGO_PKG_VERSION"));
13 + return Ok(());
14 + }
15 + Some("--help") => {
16 + print_help();
17 + return Ok(());
18 + }
19 + _ => {}
20 + }
21 +
22 + let cache_binary = get_cache_binary_path();
23 +
24 + if cache_binary.exists() {
25 + let config_path = get_config_path().join("config.rs");
26 + if should_recompile(&config_path, &cache_binary)? {
27 + println!("Config changed, recompiling...");
28 + recompile_config()?;
29 + }
30 +
31 + use std::os::unix::process::CommandExt;
32 + let err = Command::new(&cache_binary).args(&args[1..]).exec();
33 + anyhow::bail!("Failed to exec user binary: {}", err);
34 + } else {
35 + eprintln!("No configuration found.");
36 + eprintln!("Run: oxwm --init");
37 + eprintln!("Then add 'exec oxwm' to your ~/.xinitrc");
38 + std::process::exit(1);
39 + }
40 +}
41 +
42 +fn init_config() -> Result<()> {
43 + let config_dir = get_config_path();
44 + std::fs::create_dir_all(&config_dir)?;
45 +
46 + if config_dir.join("config.rs").exists() {
47 + eprintln!("Config already exists at ~/.config/oxwm/config.rs");
48 + eprintln!("Remove it first if you want to reinitialize.");
49 + return Ok(());
50 + }
51 +
52 + let config_template = include_str!("../../templates/config.rs");
53 + std::fs::write(config_dir.join("config.rs"), config_template)?;
54 +
55 + let main_template = include_str!("../../templates/main.rs");
56 + std::fs::write(config_dir.join("main.rs"), main_template)?;
57 +
58 + let manifest_dir = env!("CARGO_MANIFEST_DIR");
59 + let cargo_toml = format!(
60 + r#"[package]
61 +name = "oxwm-user"
62 +version = "0.1.0"
63 +edition = "2024"
64 +
65 +[dependencies]
66 +oxwm = {{ path = "{}" }}
67 +anyhow = "1"
68 +
69 +[[bin]]
70 +name = "oxwm-user"
71 +path = "main.rs"
72 +"#,
73 + manifest_dir
74 + );
75 + std::fs::write(config_dir.join("Cargo.toml"), cargo_toml)?;
76 +
77 + std::fs::write(config_dir.join(".gitignore"), "target/\nCargo.lock\n")?;
78 +
79 + println!("✓ Created ~/.config/oxwm/config.rs");
80 + println!("✓ Created ~/.config/oxwm/main.rs");
81 + println!("✓ Edit ~/.config/oxwm/config.rs to customize your setup");
82 +
83 + println!("\nCompiling initial configuration...");
84 + recompile_config()?;
85 +
86 + println!("\n✓ Setup complete!");
87 + println!(" Add 'exec oxwm' to your ~/.xinitrc");
88 + println!(" Reload config anytime with Mod+Shift+R");
89 +
90 + Ok(())
91 +}
92 +
93 +fn recompile_config() -> Result<()> {
94 + let config_dir = get_config_path();
95 +
96 + if !config_dir.join("config.rs").exists() {
97 + anyhow::bail!("No config found. Run: oxwm --init");
98 + }
99 +
100 + println!("Compiling oxwm configuration...");
101 +
102 + let output = Command::new("cargo")
103 + .args(&["build", "--release"])
104 + .current_dir(&config_dir)
105 + .output()?;
106 +
107 + if !output.status.success() {
108 + let stderr = String::from_utf8_lossy(&output.stderr);
109 + eprintln!("\n❌ Compilation failed:\n{}", stderr);
110 +
111 + let _ = Command::new("notify-send")
112 + .args(&[
113 + "-u",
114 + "critical",
115 + "OXWM Compile Error",
116 + "Check terminal for details",
117 + ])
118 + .spawn();
119 +
120 + anyhow::bail!("Failed to compile configuration");
121 + }
122 +
123 + let source = config_dir.join("target/release/oxwm-user");
124 + let dest = get_cache_binary_path();
125 +
126 + std::fs::create_dir_all(dest.parent().unwrap())?;
127 + std::fs::copy(&source, &dest)?;
128 +
129 + println!("✓ Compiled successfully");
130 +
131 + let _ = Command::new("notify-send")
132 + .args(&[
133 + "OXWM",
134 + "Configuration recompiled! Hit Mod+Shift+R to restart.",
135 + ])
136 + .spawn();
137 +
138 + Ok(())
139 +}
140 +
141 +fn should_recompile(config: &PathBuf, binary: &PathBuf) -> Result<bool> {
142 + if !config.exists() {
143 + return Ok(false);
144 + }
145 +
146 + let config_dir = get_config_path();
147 + let binary_time = std::fs::metadata(binary)?.modified()?;
148 +
149 + let watch_files = ["config.rs", "main.rs", "Cargo.toml"];
150 +
151 + for filename in &watch_files {
152 + let path = config_dir.join(filename);
153 + if !path.exists() {
154 + continue;
155 + }
156 +
157 + let file_time = std::fs::metadata(&path)?.modified()?;
158 + if file_time > binary_time {
159 + return Ok(true);
160 + }
161 + }
162 +
163 + Ok(false)
164 +}
165 +
166 +fn get_config_path() -> PathBuf {
167 + dirs::config_dir()
168 + .expect("Could not find config directory")
169 + .join("oxwm")
170 +}
171 +
172 +fn get_cache_binary_path() -> PathBuf {
173 + dirs::cache_dir()
174 + .expect("Could not find cache directory")
175 + .join("oxwm/oxwm-binary")
176 +}
177 +
178 +fn print_help() {
179 + println!("OXWM - A dynamic window manager written in Rust\n");
180 + println!("USAGE:");
181 + println!(" oxwm [OPTIONS]\n");
182 + println!("OPTIONS:");
183 + println!(" --init Initialize user configuration in ~/.config/oxwm");
184 + println!(" --recompile Recompile user configuration");
185 + println!(" --version Print version information");
186 + println!(" --help Print this help message\n");
187 + println!("SETUP:");
188 + println!(" 1. Run 'oxwm --init' to create your config");
189 + println!(" 2. Edit ~/.config/oxwm/config.rs");
190 + println!(" 3. Add 'exec oxwm' to your ~/.xinitrc");
191 + println!(" 4. Start X with 'startx'\n");
192 + println!("CONFIGURATION:");
193 + println!(" Config location: ~/.config/oxwm/config.rs");
194 + println!(" Reload hotkey: Mod+Shift+R (auto-recompiles if needed)");
195 +}
+19 −8 src/keyboard/handlers.rs
@@ -1,4 +1,3 @@
1 -use crate::config::KEYBINDINGS;
2 use anyhow::Result; 1 use anyhow::Result;
3 use x11rb::connection::Connection; 2 use x11rb::connection::Connection;
4 use x11rb::protocol::xproto::*; 3 use x11rb::protocol::xproto::*;
@@ -10,6 +9,7 @@ pub enum KeyAction {
10 FocusStack, 9 FocusStack,
11 Quit, 10 Quit,
12 Restart, 11 Restart,
12 + Recompile,
13 ViewTag, 13 ViewTag,
14 ToggleGaps, 14 ToggleGaps,
15 ToggleFullScreen, 15 ToggleFullScreen,
@@ -17,7 +17,7 @@ pub enum KeyAction {
17 None, 17 None,
18 } 18 }
19 19
20 -#[derive(Debug)] 20 +#[derive(Debug, Clone)]
21 pub enum Arg { 21 pub enum Arg {
22 None, 22 None,
23 Int(i32), 23 Int(i32),
@@ -25,6 +25,13 @@ pub enum Arg {
25 Array(&'static [&'static str]), 25 Array(&'static [&'static str]),
26 } 26 }
27 27
28 +impl Arg {
29 + pub const fn none() -> Self {
30 + Arg::None
31 + }
32 +}
33 +
34 +#[derive(Clone)]
28 pub struct Key { 35 pub struct Key {
29 pub(crate) modifiers: &'static [KeyButMask], 36 pub(crate) modifiers: &'static [KeyButMask],
30 pub(crate) key: Keycode, 37 pub(crate) key: Keycode,
@@ -54,8 +61,12 @@ fn modifiers_to_mask(modifiers: &[KeyButMask]) -> u16 {
54 .fold(0u16, |acc, &modifier| acc | u16::from(modifier)) 61 .fold(0u16, |acc, &modifier| acc | u16::from(modifier))
55 } 62 }
56 63
57 -pub fn setup_keybinds(connection: &impl Connection, root: Window) -> Result<()> { 64 +pub fn setup_keybinds(
58 - for keybinding in KEYBINDINGS { 65 + connection: &impl Connection,
66 + root: Window,
67 + keybindings: &[Key],
68 +) -> Result<()> {
69 + for keybinding in keybindings {
59 let modifier_mask = modifiers_to_mask(keybinding.modifiers); 70 let modifier_mask = modifiers_to_mask(keybinding.modifiers);
60 71
61 connection.grab_key( 72 connection.grab_key(
@@ -70,14 +81,14 @@ pub fn setup_keybinds(connection: &impl Connection, root: Window) -> Result<()>
70 Ok(()) 81 Ok(())
71 } 82 }
72 83
73 -pub fn handle_key_press(event: KeyPressEvent) -> Result<(KeyAction, &'static Arg)> { 84 +pub fn handle_key_press(event: KeyPressEvent, keybindings: &[Key]) -> Result<(KeyAction, Arg)> {
74 - for keybinding in KEYBINDINGS { 85 + for keybinding in keybindings {
75 let modifier_mask = modifiers_to_mask(keybinding.modifiers); 86 let modifier_mask = modifiers_to_mask(keybinding.modifiers);
76 87
77 if event.detail == keybinding.key && event.state == modifier_mask.into() { 88 if event.detail == keybinding.key && event.state == modifier_mask.into() {
78 - return Ok((keybinding.func, &keybinding.arg)); 89 + return Ok((keybinding.func, keybinding.arg.clone()));
79 } 90 }
80 } 91 }
81 92
82 - Ok((KeyAction::None, &Arg::None)) 93 + Ok((KeyAction::None, Arg::None))
83 } 94 }
+91 −0 src/lib.rs new file mode 100644
@@ -0,0 +1,91 @@
1 +pub mod bar;
2 +pub mod keyboard;
3 +pub mod layout;
4 +pub mod window_manager;
5 +
6 +pub mod prelude {
7 + pub use crate::ColorScheme;
8 + pub use crate::bar::{BlockCommand, BlockConfig};
9 + pub use crate::keyboard::{Arg, KeyAction, handlers::Key, keycodes};
10 + pub use x11rb::protocol::xproto::KeyButMask;
11 +}
12 +
13 +#[derive(Clone)]
14 +pub struct Config {
15 + // Appearance
16 + pub border_width: u32,
17 + pub border_focused: u32,
18 + pub border_unfocused: u32,
19 + pub font: String,
20 +
21 + // Gaps
22 + pub gaps_enabled: bool,
23 + pub gap_inner_horizontal: u32,
24 + pub gap_inner_vertical: u32,
25 + pub gap_outer_horizontal: u32,
26 + pub gap_outer_vertical: u32,
27 +
28 + // Basics
29 + pub terminal: String,
30 + pub modkey: x11rb::protocol::xproto::KeyButMask,
31 +
32 + // Tags
33 + pub tags: Vec<String>,
34 +
35 + // Keybindings
36 + pub keybindings: Vec<crate::keyboard::handlers::Key>,
37 +
38 + // Status bar
39 + pub status_blocks: Vec<crate::bar::BlockConfig>,
40 +
41 + // Bar color schemes
42 + pub scheme_normal: ColorScheme,
43 + pub scheme_occupied: ColorScheme,
44 + pub scheme_selected: ColorScheme,
45 +}
46 +
47 +#[derive(Clone, Copy)]
48 +pub struct ColorScheme {
49 + pub foreground: u32,
50 + pub background: u32,
51 + pub underline: u32,
52 +}
53 +
54 +impl Default for Config {
55 + fn default() -> Self {
56 + Self {
57 + border_width: 2,
58 + border_focused: 0x6dade3,
59 + border_unfocused: 0xbbbbbb,
60 + font: "monospace:size=12".to_string(),
61 + gaps_enabled: false,
62 + gap_inner_horizontal: 0,
63 + gap_inner_vertical: 0,
64 + gap_outer_horizontal: 0,
65 + gap_outer_vertical: 0,
66 + terminal: "xterm".to_string(),
67 + modkey: x11rb::protocol::xproto::KeyButMask::MOD4,
68 + tags: vec!["1", "2", "3", "4", "5", "6", "7", "8", "9"]
69 + .into_iter()
70 + .map(String::from)
71 + .collect(),
72 + keybindings: Vec::new(),
73 + status_blocks: Vec::new(),
74 + scheme_normal: ColorScheme {
75 + foreground: 0xbbbbbb,
76 + background: 0x1a1b26,
77 + underline: 0x444444,
78 + },
79 + scheme_occupied: ColorScheme {
80 + foreground: 0x0db9d7,
81 + background: 0x1a1b26,
82 + underline: 0x0db9d7,
83 + },
84 + scheme_selected: ColorScheme {
85 + foreground: 0x0db9d7,
86 + background: 0x1a1b26,
87 + underline: 0xad8ee6,
88 + },
89 + }
90 + }
91 +}
+149 −40 src/window_manager.rs
@@ -1,14 +1,13 @@
1 +use crate::Config;
1 use crate::bar::Bar; 2 use crate::bar::Bar;
2 -use crate::config::{
3 - BORDER_FOCUSED, BORDER_UNFOCUSED, BORDER_WIDTH, GAP_INNER_HORIZONTAL, GAP_INNER_VERTICAL,
4 - GAP_OUTER_HORIZONTAL, GAP_OUTER_VERTICAL, GAPS_ENABLED, MODKEY, TAG_COUNT,
5 -};
6 use crate::keyboard::{self, Arg, KeyAction}; 3 use crate::keyboard::{self, Arg, KeyAction};
7 use crate::layout::GapConfig; 4 use crate::layout::GapConfig;
8 use crate::layout::Layout; 5 use crate::layout::Layout;
9 use crate::layout::tiling::TilingLayout; 6 use crate::layout::tiling::TilingLayout;
7 +
10 use anyhow::Result; 8 use anyhow::Result;
11 use std::collections::HashSet; 9 use std::collections::HashSet;
10 +use std::path::PathBuf;
12 11
13 use x11rb::connection::Connection; 12 use x11rb::connection::Connection;
14 use x11rb::protocol::Event; 13 use x11rb::protocol::Event;
@@ -21,6 +20,7 @@ pub fn tag_mask(tag: usize) -> TagMask {
21 } 20 }
22 21
23 pub struct WindowManager { 22 pub struct WindowManager {
23 + config: Config,
24 connection: RustConnection, 24 connection: RustConnection,
25 screen_number: usize, 25 screen_number: usize,
26 root: Window, 26 root: Window,
@@ -37,7 +37,7 @@ pub struct WindowManager {
37 } 37 }
38 38
39 impl WindowManager { 39 impl WindowManager {
40 - pub fn new() -> Result<Self> { 40 + pub fn new(config: Config) -> Result<Self> {
41 let (connection, screen_number) = x11rb::connect(None)?; 41 let (connection, screen_number) = x11rb::connect(None)?;
42 let root = connection.setup().roots[screen_number].root; 42 let root = connection.setup().roots[screen_number].root;
43 let screen = connection.setup().roots[screen_number].clone(); 43 let screen = connection.setup().roots[screen_number].clone();
@@ -64,7 +64,7 @@ impl WindowManager {
64 x11rb::NONE, 64 x11rb::NONE,
65 x11rb::NONE, 65 x11rb::NONE,
66 ButtonIndex::M1, 66 ButtonIndex::M1,
67 - u16::from(MODKEY).into(), 67 + u16::from(config.modkey).into(),
68 )?; 68 )?;
69 69
70 connection.grab_button( 70 connection.grab_button(
@@ -76,15 +76,16 @@ impl WindowManager {
76 x11rb::NONE, 76 x11rb::NONE,
77 x11rb::NONE, 77 x11rb::NONE,
78 ButtonIndex::M3, 78 ButtonIndex::M3,
79 - u16::from(MODKEY).into(), 79 + u16::from(config.modkey).into(),
80 )?; 80 )?;
81 81
82 - let bar = Bar::new(&connection, &screen, screen_number)?; 82 + let bar = Bar::new(&connection, &screen, screen_number, &config)?;
83 83
84 - let selected_tags = Self::get_saved_selected_tags(&connection, root)?; 84 + let selected_tags = Self::get_saved_selected_tags(&connection, root, config.tags.len())?;
85 - let gaps_enabled = GAPS_ENABLED; 85 + let gaps_enabled = config.gaps_enabled;
86 86
87 - let mut window_manger = Self { 87 + let mut window_manager = Self {
88 + config,
88 connection, 89 connection,
89 screen_number, 90 screen_number,
90 root, 91 root,
@@ -100,13 +101,17 @@ impl WindowManager {
100 bar, 101 bar,
101 }; 102 };
102 103
103 - window_manger.scan_existing_windows()?; 104 + window_manager.scan_existing_windows()?;
104 - window_manger.update_bar()?; 105 + window_manager.update_bar()?;
105 106
106 - Ok(window_manger) 107 + Ok(window_manager)
107 } 108 }
108 109
109 - fn get_saved_selected_tags(connection: &RustConnection, root: Window) -> Result<TagMask> { 110 + fn get_saved_selected_tags(
111 + connection: &RustConnection,
112 + root: Window,
113 + tag_count: usize,
114 + ) -> Result<TagMask> {
110 let net_current_desktop = connection 115 let net_current_desktop = connection
111 .intern_atom(false, b"_NET_CURRENT_DESKTOP")? 116 .intern_atom(false, b"_NET_CURRENT_DESKTOP")?
112 .reply()? 117 .reply()?
@@ -123,7 +128,7 @@ impl WindowManager {
123 prop.value[2], 128 prop.value[2],
124 prop.value[3], 129 prop.value[3],
125 ]); 130 ]);
126 - if desktop < TAG_COUNT as u32 { 131 + if desktop < tag_count as u32 {
127 let mask = tag_mask(desktop as usize); 132 let mask = tag_mask(desktop as usize);
128 return Ok(mask); 133 return Ok(mask);
129 } 134 }
@@ -224,7 +229,7 @@ impl WindowManager {
224 prop.value[3], 229 prop.value[3],
225 ]); 230 ]);
226 231
227 - if tags != 0 && tags < (1 << crate::config::TAG_COUNT) { 232 + if tags != 0 && tags < (1 << self.config.tags.len()) {
228 return Ok(tags); 233 return Ok(tags);
229 } 234 }
230 } 235 }
@@ -284,10 +289,81 @@ impl WindowManager {
284 Ok(()) 289 Ok(())
285 } 290 }
286 291
292 + fn handle_restart(&self) -> Result<bool> {
293 + if !can_recompile() {
294 + eprintln!("Error: cargo not found. Install rust toolchain.");
295 + notify_error("OXWM", "Cannot recompile: cargo not installed");
296 + return Ok(false);
297 + }
298 +
299 + if self.needs_recompile()? {
300 + println!("Config changed, recompiling...");
301 + self.recompile()?;
302 + }
303 +
304 + Ok(true)
305 + }
306 +
307 + fn needs_recompile(&self) -> Result<bool> {
308 + let config_dir = get_config_path();
309 + let binary_path = get_cache_binary_path();
310 +
311 + if !binary_path.exists() {
312 + return Ok(true);
313 + }
314 +
315 + let binary_time = std::fs::metadata(&binary_path)?.modified()?;
316 +
317 + let watch_files = ["config.rs", "main.rs", "Cargo.toml"];
318 +
319 + for filename in &watch_files {
320 + let path = config_dir.join(filename);
321 + if !path.exists() {
322 + continue;
323 + }
324 +
325 + let file_time = std::fs::metadata(&path)?.modified()?;
326 + if file_time > binary_time {
327 + println!("✓ Change detected: {}", filename);
328 + return Ok(true);
329 + }
330 + }
331 +
332 + Ok(false)
333 + }
334 +
335 + fn recompile(&self) -> Result<()> {
336 + let config_dir = get_config_path();
337 +
338 + notify("OXWM", "Recompiling configuration...");
339 +
340 + let output = std::process::Command::new("cargo")
341 + .args(&["build", "--release"])
342 + .current_dir(&config_dir)
343 + .output()?;
344 +
345 + if !output.status.success() {
346 + let stderr = String::from_utf8_lossy(&output.stderr);
347 + notify_error("OXWM Compile Error", &stderr);
348 + eprintln!("Compilation failed:\n{}", stderr);
349 + anyhow::bail!("Failed to compile configuration");
350 + }
351 +
352 + let source = config_dir.join("target/release/oxwm-user");
353 + let dest = get_cache_binary_path();
354 +
355 + std::fs::create_dir_all(dest.parent().unwrap())?;
356 + std::fs::copy(&source, &dest)?;
357 +
358 + notify("OXWM", "Recompiled successfully! Restarting...");
359 +
360 + Ok(())
361 + }
362 +
287 pub fn run(&mut self) -> Result<bool> { 363 pub fn run(&mut self) -> Result<bool> {
288 println!("oxwm started on display {}", self.screen_number); 364 println!("oxwm started on display {}", self.screen_number);
289 365
290 - keyboard::setup_keybinds(&self.connection, self.root)?; 366 + keyboard::setup_keybinds(&self.connection, self.root, &self.config.keybindings)?;
291 self.update_bar()?; 367 self.update_bar()?;
292 368
293 loop { 369 loop {
@@ -387,7 +463,12 @@ impl WindowManager {
387 } 463 }
388 } 464 }
389 KeyAction::Quit | KeyAction::Restart => { 465 KeyAction::Quit | KeyAction::Restart => {
390 - //no-op 466 + // Handled in handle_event
467 + }
468 + KeyAction::Recompile => {
469 + if let Err(e) = self.recompile() {
470 + eprintln!("Recompile failed: {}", e);
471 + }
391 } 472 }
392 KeyAction::ViewTag => { 473 KeyAction::ViewTag => {
393 if let Arg::Int(tag_index) = arg { 474 if let Arg::Int(tag_index) = arg {
@@ -403,9 +484,7 @@ impl WindowManager {
403 self.gaps_enabled = !self.gaps_enabled; 484 self.gaps_enabled = !self.gaps_enabled;
404 self.apply_layout()?; 485 self.apply_layout()?;
405 } 486 }
406 - KeyAction::None => { 487 + KeyAction::None => {}
407 - //no-op
408 - }
409 } 488 }
410 Ok(()) 489 Ok(())
411 } 490 }
@@ -439,7 +518,7 @@ impl WindowManager {
439 } 518 }
440 519
441 pub fn view_tag(&mut self, tag_index: usize) -> Result<()> { 520 pub fn view_tag(&mut self, tag_index: usize) -> Result<()> {
442 - if tag_index >= TAG_COUNT { 521 + if tag_index >= self.config.tags.len() {
443 return Ok(()); 522 return Ok(());
444 } 523 }
445 524
@@ -487,7 +566,7 @@ impl WindowManager {
487 } 566 }
488 567
489 pub fn move_to_tag(&mut self, tag_index: usize) -> Result<()> { 568 pub fn move_to_tag(&mut self, tag_index: usize) -> Result<()> {
490 - if tag_index >= TAG_COUNT { 569 + if tag_index >= self.config.tags.len() {
491 return Ok(()); 570 return Ok(());
492 } 571 }
493 572
@@ -547,9 +626,9 @@ impl WindowManager {
547 fn update_focus_visuals(&self) -> Result<()> { 626 fn update_focus_visuals(&self) -> Result<()> {
548 for &window in &self.windows { 627 for &window in &self.windows {
549 let (border_color, border_width) = if self.focused_window == Some(window) { 628 let (border_color, border_width) = if self.focused_window == Some(window) {
550 - (BORDER_FOCUSED, BORDER_WIDTH) 629 + (self.config.border_focused, self.config.border_width)
551 } else { 630 } else {
552 - (BORDER_UNFOCUSED, BORDER_WIDTH) 631 + (self.config.border_unfocused, self.config.border_width)
553 }; 632 };
554 633
555 self.connection.configure_window( 634 self.connection.configure_window(
@@ -585,7 +664,7 @@ impl WindowManager {
585 .reply()?; 664 .reply()?;
586 665
587 let pointer = self.connection.query_pointer(self.root)?.reply()?; 666 let pointer = self.connection.query_pointer(self.root)?.reply()?;
588 - let (original_x_value, original_y_value) = (pointer.root_x, pointer.root_y); 667 + let (start_x, start_y) = (pointer.root_x, pointer.root_y);
589 668
590 self.connection.configure_window( 669 self.connection.configure_window(
591 window, 670 window,
@@ -596,13 +675,11 @@ impl WindowManager {
596 let event = self.connection.wait_for_event()?; 675 let event = self.connection.wait_for_event()?;
597 match event { 676 match event {
598 Event::MotionNotify(e) => { 677 Event::MotionNotify(e) => {
599 - let new_x_value = geometry.x + (e.root_x - original_x_value); 678 + let new_x = geometry.x + (e.root_x - start_x);
600 - let new_y_value = geometry.y + (e.root_y - original_y_value); 679 + let new_y = geometry.y + (e.root_y - start_y);
601 self.connection.configure_window( 680 self.connection.configure_window(
602 window, 681 window,
603 - &ConfigureWindowAux::new() 682 + &ConfigureWindowAux::new().x(new_x as i32).y(new_y as i32),
604 - .x(new_x_value as i32)
605 - .y(new_y_value as i32),
606 )?; 683 )?;
607 self.connection.flush()?; 684 self.connection.flush()?;
608 } 685 }
@@ -735,11 +812,11 @@ impl WindowManager {
735 } 812 }
736 } 813 }
737 Event::KeyPress(event) => { 814 Event::KeyPress(event) => {
738 - let (action, arg) = keyboard::handle_key_press(event)?; 815 + let (action, arg) = keyboard::handle_key_press(event, &self.config.keybindings)?;
739 match action { 816 match action {
740 KeyAction::Quit => return Ok(Some(false)), 817 KeyAction::Quit => return Ok(Some(false)),
741 - KeyAction::Restart => return Ok(Some(true)), 818 + KeyAction::Restart => return Ok(Some(self.handle_restart()?)),
742 - _ => self.handle_key_action(action, arg)?, 819 + _ => self.handle_key_action(action, &arg)?,
743 } 820 }
744 } 821 }
745 Event::ButtonPress(event) => { 822 Event::ButtonPress(event) => {
@@ -774,17 +851,17 @@ impl WindowManager {
774 } 851 }
775 let screen_width = self.screen.width_in_pixels as u32; 852 let screen_width = self.screen.width_in_pixels as u32;
776 let screen_height = self.screen.height_in_pixels as u32; 853 let screen_height = self.screen.height_in_pixels as u32;
777 - let border_width = BORDER_WIDTH; 854 + let border_width = self.config.border_width;
778 855
779 let bar_height = self.bar.height() as u32; 856 let bar_height = self.bar.height() as u32;
780 let usable_height = screen_height.saturating_sub(bar_height); 857 let usable_height = screen_height.saturating_sub(bar_height);
781 858
782 let gaps = if self.gaps_enabled { 859 let gaps = if self.gaps_enabled {
783 GapConfig { 860 GapConfig {
784 - inner_horizontal: GAP_INNER_HORIZONTAL, 861 + inner_horizontal: self.config.gap_inner_horizontal,
785 - inner_vertical: GAP_INNER_VERTICAL, 862 + inner_vertical: self.config.gap_inner_vertical,
786 - outer_horizontal: GAP_OUTER_HORIZONTAL, 863 + outer_horizontal: self.config.gap_outer_horizontal,
787 - outer_vertical: GAP_OUTER_VERTICAL, 864 + outer_vertical: self.config.gap_outer_vertical,
788 } 865 }
789 } else { 866 } else {
790 GapConfig { 867 GapConfig {
@@ -851,3 +928,35 @@ impl WindowManager {
851 Ok(()) 928 Ok(())
852 } 929 }
853 } 930 }
931 +
932 +fn get_config_path() -> PathBuf {
933 + dirs::config_dir()
934 + .expect("Could not find config directory")
935 + .join("oxwm")
936 +}
937 +
938 +fn get_cache_binary_path() -> PathBuf {
939 + dirs::cache_dir()
940 + .expect("Could not find cache directory")
941 + .join("oxwm/oxwm-binary")
942 +}
943 +
944 +fn can_recompile() -> bool {
945 + std::process::Command::new("cargo")
946 + .arg("--version")
947 + .output()
948 + .map(|o| o.status.success())
949 + .unwrap_or(false)
950 +}
951 +
952 +fn notify(title: &str, body: &str) {
953 + let _ = std::process::Command::new("notify-send")
954 + .args(&[title, body])
955 + .spawn();
956 +}
957 +
958 +fn notify_error(title: &str, body: &str) {
959 + let _ = std::process::Command::new("notify-send")
960 + .args(&["-u", "critical", title, body])
961 + .spawn();
962 +}
+212 −0 templates/config.rs new file mode 100644
@@ -0,0 +1,212 @@
1 +use oxwm::ColorScheme;
2 +use oxwm::prelude::*;
3 +
4 +// ========================================
5 +// APPEARANCE
6 +// ========================================
7 +pub const BORDER_WIDTH: u32 = 2;
8 +pub const BORDER_FOCUSED: u32 = 0x6dade3;
9 +pub const BORDER_UNFOCUSED: u32 = 0xbbbbbb;
10 +pub const FONT: &str = "JetBrainsMono Nerd Font:style=Bold:size=12";
11 +
12 +// ========================================
13 +// GAPS (Vanity Gaps)
14 +// ========================================
15 +pub const GAPS_ENABLED: bool = false;
16 +pub const GAP_INNER_HORIZONTAL: u32 = 3;
17 +pub const GAP_INNER_VERTICAL: u32 = 3;
18 +pub const GAP_OUTER_HORIZONTAL: u32 = 3;
19 +pub const GAP_OUTER_VERTICAL: u32 = 3;
20 +
21 +// ========================================
22 +// DEFAULTS
23 +// ========================================
24 +pub const TERMINAL: &str = "st";
25 +pub const MODKEY: KeyButMask = KeyButMask::MOD4;
26 +
27 +// ========================================
28 +// TAGS (Workspaces)
29 +// ========================================
30 +pub const TAG_COUNT: usize = 9;
31 +pub const TAGS: [&str; TAG_COUNT] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"];
32 +
33 +// Alternative tag styles you can use:
34 +// pub const TAGS: [&str; TAG_COUNT] = ["", "󰊯", "", "", "󰙯", "󱇤", "", "󱘶", "󰧮"];
35 +// pub const TAGS: [&str; TAG_COUNT] = ["DEV", "WWW", "SYS", "DOC", "VBOX", "CHAT", "MUS", "VID", "MISC"];
36 +
37 +// ========================================
38 +// BAR COLORS
39 +// ========================================
40 +const GRAY_DARK: u32 = 0x1a1b26;
41 +const GRAY_SEP: u32 = 0xa9b1d6;
42 +const GRAY_MID: u32 = 0x444444;
43 +const GRAY_LIGHT: u32 = 0xbbbbbb;
44 +const CYAN: u32 = 0x0db9d7;
45 +const MAGENTA: u32 = 0xad8ee6;
46 +const RED: u32 = 0xf7768e;
47 +const GREEN: u32 = 0x9ece6a;
48 +const BLUE: u32 = 0x7aa2f7;
49 +const YELLOW: u32 = 0xe0af68;
50 +
51 +pub const SCHEME_NORMAL: ColorScheme = ColorScheme {
52 + foreground: GRAY_LIGHT,
53 + background: GRAY_DARK,
54 + underline: GRAY_MID,
55 +};
56 +
57 +pub const SCHEME_OCCUPIED: ColorScheme = ColorScheme {
58 + foreground: CYAN,
59 + background: GRAY_DARK,
60 + underline: CYAN,
61 +};
62 +
63 +pub const SCHEME_SELECTED: ColorScheme = ColorScheme {
64 + foreground: CYAN,
65 + background: GRAY_DARK,
66 + underline: MAGENTA,
67 +};
68 +
69 +// ========================================
70 +// COMMANDS
71 +// ========================================
72 +const SCREENSHOT_CMD: &[&str] = &[
73 + "sh",
74 + "-c",
75 + "maim -s | xclip -selection clipboard -t image/png",
76 +];
77 +
78 +const DMENU_CMD: &[&str] = &["sh", "-c", "dmenu_run -l 10"];
79 +
80 +// ========================================
81 +// KEYBINDINGS
82 +// ========================================
83 +const SHIFT: KeyButMask = KeyButMask::SHIFT;
84 +
85 +#[rustfmt::skip]
86 +pub const KEYBINDINGS: &[Key] = &[
87 + // Launch applications
88 + Key::new(&[MODKEY], keycodes::RETURN, KeyAction::Spawn, Arg::Str(TERMINAL)),
89 + Key::new(&[MODKEY], keycodes::F, KeyAction::Spawn, Arg::Str("xclock")),
90 + Key::new(&[MODKEY], keycodes::S, KeyAction::Spawn, Arg::Array(SCREENSHOT_CMD)),
91 + Key::new(&[MODKEY], keycodes::D, KeyAction::Spawn, Arg::Array(DMENU_CMD)),
92 +
93 + // Window management
94 + Key::new(&[MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None),
95 + Key::new(&[MODKEY, SHIFT], keycodes::F, KeyAction::ToggleFullScreen, Arg::None),
96 + Key::new(&[MODKEY], keycodes::A, KeyAction::ToggleGaps, Arg::None),
97 +
98 + // WM controls
99 + Key::new(&[MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None),
100 + Key::new(&[MODKEY, SHIFT], keycodes::R, KeyAction::Restart, Arg::None),
101 + Key::new(&[MODKEY, SHIFT], keycodes::C, KeyAction::Recompile, Arg::None),
102 +
103 + // Focus
104 + Key::new(&[MODKEY], keycodes::J, KeyAction::FocusStack, Arg::Int(-1)),
105 + Key::new(&[MODKEY], keycodes::K, KeyAction::FocusStack, Arg::Int(1)),
106 +
107 + // View tags (workspaces)
108 + Key::new(&[MODKEY], keycodes::KEY_1, KeyAction::ViewTag, Arg::Int(0)),
109 + Key::new(&[MODKEY], keycodes::KEY_2, KeyAction::ViewTag, Arg::Int(1)),
110 + Key::new(&[MODKEY], keycodes::KEY_3, KeyAction::ViewTag, Arg::Int(2)),
111 + Key::new(&[MODKEY], keycodes::KEY_4, KeyAction::ViewTag, Arg::Int(3)),
112 + Key::new(&[MODKEY], keycodes::KEY_5, KeyAction::ViewTag, Arg::Int(4)),
113 + Key::new(&[MODKEY], keycodes::KEY_6, KeyAction::ViewTag, Arg::Int(5)),
114 + Key::new(&[MODKEY], keycodes::KEY_7, KeyAction::ViewTag, Arg::Int(6)),
115 + Key::new(&[MODKEY], keycodes::KEY_8, KeyAction::ViewTag, Arg::Int(7)),
116 + Key::new(&[MODKEY], keycodes::KEY_9, KeyAction::ViewTag, Arg::Int(8)),
117 +
118 + // Move windows to tags
119 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_1, KeyAction::MoveToTag, Arg::Int(0)),
120 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_2, KeyAction::MoveToTag, Arg::Int(1)),
121 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_3, KeyAction::MoveToTag, Arg::Int(2)),
122 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_4, KeyAction::MoveToTag, Arg::Int(3)),
123 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_5, KeyAction::MoveToTag, Arg::Int(4)),
124 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_6, KeyAction::MoveToTag, Arg::Int(5)),
125 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_7, KeyAction::MoveToTag, Arg::Int(6)),
126 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_8, KeyAction::MoveToTag, Arg::Int(7)),
127 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_9, KeyAction::MoveToTag, Arg::Int(8)),
128 +];
129 +
130 +// ========================================
131 +// STATUS BAR BLOCKS
132 +// ========================================
133 +pub const STATUS_BLOCKS: &[BlockConfig] = &[
134 + BlockConfig {
135 + format: "",
136 + command: BlockCommand::Battery {
137 + format_charging: "󰂄 Bat: {}%",
138 + format_discharging: "󰁹 Bat:{}%",
139 + format_full: "󰁹 Bat: {}%",
140 + },
141 + interval_secs: 30,
142 + color: GREEN,
143 + underline: true,
144 + },
145 + BlockConfig {
146 + format: " │ ",
147 + command: BlockCommand::Static(""),
148 + interval_secs: u64::MAX,
149 + color: GRAY_SEP,
150 + underline: false,
151 + },
152 + BlockConfig {
153 + format: "󰍛 {used}/{total} GB",
154 + command: BlockCommand::Ram,
155 + interval_secs: 5,
156 + color: BLUE,
157 + underline: true,
158 + },
159 + BlockConfig {
160 + format: " │ ",
161 + command: BlockCommand::Static(""),
162 + interval_secs: u64::MAX,
163 + color: GRAY_SEP,
164 + underline: false,
165 + },
166 + BlockConfig {
167 + format: " {}",
168 + command: BlockCommand::Shell("uname -r"),
169 + interval_secs: u64::MAX,
170 + color: RED,
171 + underline: true,
172 + },
173 + BlockConfig {
174 + format: " │ ",
175 + command: BlockCommand::Static(""),
176 + interval_secs: u64::MAX,
177 + color: GRAY_SEP,
178 + underline: false,
179 + },
180 + BlockConfig {
181 + format: "󰸘 {}",
182 + command: BlockCommand::DateTime("%a, %b %d - %-I:%M %P"),
183 + interval_secs: 1,
184 + color: CYAN,
185 + underline: true,
186 + },
187 +];
188 +
189 +// ========================================
190 +// BUILD CONFIG FROM CONSTANTS
191 +// ========================================
192 +pub fn build_config() -> oxwm::Config {
193 + oxwm::Config {
194 + border_width: BORDER_WIDTH,
195 + border_focused: BORDER_FOCUSED,
196 + border_unfocused: BORDER_UNFOCUSED,
197 + font: FONT.to_string(),
198 + gaps_enabled: GAPS_ENABLED,
199 + gap_inner_horizontal: GAP_INNER_HORIZONTAL,
200 + gap_inner_vertical: GAP_INNER_VERTICAL,
201 + gap_outer_horizontal: GAP_OUTER_HORIZONTAL,
202 + gap_outer_vertical: GAP_OUTER_VERTICAL,
203 + terminal: TERMINAL.to_string(),
204 + modkey: MODKEY,
205 + tags: TAGS.iter().map(|s| s.to_string()).collect(),
206 + keybindings: KEYBINDINGS.to_vec(),
207 + status_blocks: STATUS_BLOCKS.to_vec(),
208 + scheme_normal: SCHEME_NORMAL,
209 + scheme_occupied: SCHEME_OCCUPIED,
210 + scheme_selected: SCHEME_SELECTED,
211 + }
212 +}
+21 −0 templates/main.rs new file mode 100644
@@ -0,0 +1,21 @@
1 +mod config;
2 +
3 +use anyhow::Result;
4 +
5 +fn main() -> Result<()> {
6 + let cfg = config::build_config();
7 +
8 + let args: Vec<String> = std::env::args().collect();
9 + let mut wm = oxwm::window_manager::WindowManager::new(cfg)?;
10 + let should_restart = wm.run()?;
11 +
12 + drop(wm);
13 +
14 + if should_restart {
15 + use std::os::unix::process::CommandExt;
16 + let err = std::process::Command::new(&args[0]).args(&args[1..]).exec();
17 + eprintln!("Failed to restart: {}", err);
18 + }
19 +
20 + Ok(())
21 +}