Added lua parser.
Browse files
+153 −0 Cargo.lock
| @@ -38,6 +38,16 @@ dependencies = [ | |||
| 38 | "serde_core", | 38 | "serde_core", |
| 39 | ] | 39 | ] |
| 40 | 40 | ||
| 41 | +[[package]] | ||
| 42 | +name = "bstr" | ||
| 43 | +version = "1.12.1" | ||
| 44 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 45 | +checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab" | ||
| 46 | +dependencies = [ | ||
| 47 | + "memchr", | ||
| 48 | + "serde", | ||
| 49 | +] | ||
| 50 | + | ||
| 41 | [[package]] | 51 | [[package]] |
| 42 | name = "bumpalo" | 52 | name = "bumpalo" |
| 43 | version = "3.19.0" | 53 | version = "3.19.0" |
| @@ -100,6 +110,18 @@ dependencies = [ | |||
| 100 | "windows-sys 0.48.0", | 110 | "windows-sys 0.48.0", |
| 101 | ] | 111 | ] |
| 102 | 112 | ||
| 113 | +[[package]] | ||
| 114 | +name = "either" | ||
| 115 | +version = "1.15.0" | ||
| 116 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 117 | +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" | ||
| 118 | + | ||
| 119 | +[[package]] | ||
| 120 | +name = "env_home" | ||
| 121 | +version = "0.1.0" | ||
| 122 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 123 | +checksum = "c7f84e12ccf0a7ddc17a6c41c93326024c42920d7ee630d04950e6926645c0fe" | ||
| 124 | + | ||
| 103 | [[package]] | 125 | [[package]] |
| 104 | name = "errno" | 126 | name = "errno" |
| 105 | version = "0.3.14" | 127 | version = "0.3.14" |
| @@ -193,12 +215,74 @@ version = "0.11.0" | |||
| 193 | source = "registry+https://github.com/rust-lang/crates.io-index" | 215 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 194 | checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" | 216 | checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" |
| 195 | 217 | ||
| 218 | +[[package]] | ||
| 219 | +name = "lock_api" | ||
| 220 | +version = "0.4.14" | ||
| 221 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 222 | +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" | ||
| 223 | +dependencies = [ | ||
| 224 | + "scopeguard", | ||
| 225 | +] | ||
| 226 | + | ||
| 196 | [[package]] | 227 | [[package]] |
| 197 | name = "log" | 228 | name = "log" |
| 198 | version = "0.4.28" | 229 | version = "0.4.28" |
| 199 | source = "registry+https://github.com/rust-lang/crates.io-index" | 230 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 200 | checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" | 231 | checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" |
| 201 | 232 | ||
| 233 | +[[package]] | ||
| 234 | +name = "lua-src" | ||
| 235 | +version = "547.0.0" | ||
| 236 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 237 | +checksum = "1edaf29e3517b49b8b746701e5648ccb5785cde1c119062cbabbc5d5cd115e42" | ||
| 238 | +dependencies = [ | ||
| 239 | + "cc", | ||
| 240 | +] | ||
| 241 | + | ||
| 242 | +[[package]] | ||
| 243 | +name = "luajit-src" | ||
| 244 | +version = "210.5.12+a4f56a4" | ||
| 245 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 246 | +checksum = "b3a8e7962a5368d5f264d045a5a255e90f9aa3fc1941ae15a8d2940d42cac671" | ||
| 247 | +dependencies = [ | ||
| 248 | + "cc", | ||
| 249 | + "which", | ||
| 250 | +] | ||
| 251 | + | ||
| 252 | +[[package]] | ||
| 253 | +name = "memchr" | ||
| 254 | +version = "2.7.6" | ||
| 255 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 256 | +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" | ||
| 257 | + | ||
| 258 | +[[package]] | ||
| 259 | +name = "mlua" | ||
| 260 | +version = "0.10.5" | ||
| 261 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 262 | +checksum = "c1f5f8fbebc7db5f671671134b9321c4b9aa9adeafccfd9a8c020ae45c6a35d0" | ||
| 263 | +dependencies = [ | ||
| 264 | + "bstr", | ||
| 265 | + "either", | ||
| 266 | + "mlua-sys", | ||
| 267 | + "num-traits", | ||
| 268 | + "parking_lot", | ||
| 269 | + "rustc-hash", | ||
| 270 | + "rustversion", | ||
| 271 | +] | ||
| 272 | + | ||
| 273 | +[[package]] | ||
| 274 | +name = "mlua-sys" | ||
| 275 | +version = "0.6.8" | ||
| 276 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 277 | +checksum = "380c1f7e2099cafcf40e51d3a9f20a346977587aa4d012eae1f043149a728a93" | ||
| 278 | +dependencies = [ | ||
| 279 | + "cc", | ||
| 280 | + "cfg-if", | ||
| 281 | + "lua-src", | ||
| 282 | + "luajit-src", | ||
| 283 | + "pkg-config", | ||
| 284 | +] | ||
| 285 | + | ||
| 202 | [[package]] | 286 | [[package]] |
| 203 | name = "num-traits" | 287 | name = "num-traits" |
| 204 | version = "0.2.19" | 288 | version = "0.2.19" |
| @@ -227,12 +311,36 @@ dependencies = [ | |||
| 227 | "anyhow", | 311 | "anyhow", |
| 228 | "chrono", | 312 | "chrono", |
| 229 | "dirs", | 313 | "dirs", |
| 314 | + "mlua", | ||
| 230 | "ron", | 315 | "ron", |
| 231 | "serde", | 316 | "serde", |
| 232 | "x11", | 317 | "x11", |
| 233 | "x11rb", | 318 | "x11rb", |
| 234 | ] | 319 | ] |
| 235 | 320 | ||
| 321 | +[[package]] | ||
| 322 | +name = "parking_lot" | ||
| 323 | +version = "0.12.5" | ||
| 324 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 325 | +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" | ||
| 326 | +dependencies = [ | ||
| 327 | + "lock_api", | ||
| 328 | + "parking_lot_core", | ||
| 329 | +] | ||
| 330 | + | ||
| 331 | +[[package]] | ||
| 332 | +name = "parking_lot_core" | ||
| 333 | +version = "0.9.12" | ||
| 334 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 335 | +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" | ||
| 336 | +dependencies = [ | ||
| 337 | + "cfg-if", | ||
| 338 | + "libc", | ||
| 339 | + "redox_syscall", | ||
| 340 | + "smallvec", | ||
| 341 | + "windows-link", | ||
| 342 | +] | ||
| 343 | + | ||
| 236 | [[package]] | 344 | [[package]] |
| 237 | name = "pkg-config" | 345 | name = "pkg-config" |
| 238 | version = "0.3.32" | 346 | version = "0.3.32" |
| @@ -257,6 +365,15 @@ dependencies = [ | |||
| 257 | "proc-macro2", | 365 | "proc-macro2", |
| 258 | ] | 366 | ] |
| 259 | 367 | ||
| 368 | +[[package]] | ||
| 369 | +name = "redox_syscall" | ||
| 370 | +version = "0.5.18" | ||
| 371 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 372 | +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" | ||
| 373 | +dependencies = [ | ||
| 374 | + "bitflags", | ||
| 375 | +] | ||
| 376 | + | ||
| 260 | [[package]] | 377 | [[package]] |
| 261 | name = "redox_users" | 378 | name = "redox_users" |
| 262 | version = "0.4.6" | 379 | version = "0.4.6" |
| @@ -280,6 +397,12 @@ dependencies = [ | |||
| 280 | "serde_derive", | 397 | "serde_derive", |
| 281 | ] | 398 | ] |
| 282 | 399 | ||
| 400 | +[[package]] | ||
| 401 | +name = "rustc-hash" | ||
| 402 | +version = "2.1.1" | ||
| 403 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 404 | +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" | ||
| 405 | + | ||
| 283 | [[package]] | 406 | [[package]] |
| 284 | name = "rustix" | 407 | name = "rustix" |
| 285 | version = "1.1.2" | 408 | version = "1.1.2" |
| @@ -299,6 +422,12 @@ version = "1.0.22" | |||
| 299 | source = "registry+https://github.com/rust-lang/crates.io-index" | 422 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 300 | checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" | 423 | checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" |
| 301 | 424 | ||
| 425 | +[[package]] | ||
| 426 | +name = "scopeguard" | ||
| 427 | +version = "1.2.0" | ||
| 428 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 429 | +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" | ||
| 430 | + | ||
| 302 | [[package]] | 431 | [[package]] |
| 303 | name = "serde" | 432 | name = "serde" |
| 304 | version = "1.0.228" | 433 | version = "1.0.228" |
| @@ -335,6 +464,12 @@ version = "1.3.0" | |||
| 335 | source = "registry+https://github.com/rust-lang/crates.io-index" | 464 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 336 | checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" | 465 | checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" |
| 337 | 466 | ||
| 467 | +[[package]] | ||
| 468 | +name = "smallvec" | ||
| 469 | +version = "1.15.1" | ||
| 470 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 471 | +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" | ||
| 472 | + | ||
| 338 | [[package]] | 473 | [[package]] |
| 339 | name = "syn" | 474 | name = "syn" |
| 340 | version = "2.0.107" | 475 | version = "2.0.107" |
| @@ -437,6 +572,18 @@ dependencies = [ | |||
| 437 | "unicode-ident", | 572 | "unicode-ident", |
| 438 | ] | 573 | ] |
| 439 | 574 | ||
| 575 | +[[package]] | ||
| 576 | +name = "which" | ||
| 577 | +version = "7.0.3" | ||
| 578 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 579 | +checksum = "24d643ce3fd3e5b54854602a080f34fb10ab75e0b813ee32d00ca2b44fa74762" | ||
| 580 | +dependencies = [ | ||
| 581 | + "either", | ||
| 582 | + "env_home", | ||
| 583 | + "rustix", | ||
| 584 | + "winsafe", | ||
| 585 | +] | ||
| 586 | + | ||
| 440 | [[package]] | 587 | [[package]] |
| 441 | name = "windows-core" | 588 | name = "windows-core" |
| 442 | version = "0.62.2" | 589 | version = "0.62.2" |
| @@ -571,6 +718,12 @@ version = "0.48.5" | |||
| 571 | source = "registry+https://github.com/rust-lang/crates.io-index" | 718 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 572 | checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" | 719 | checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" |
| 573 | 720 | ||
| 721 | +[[package]] | ||
| 722 | +name = "winsafe" | ||
| 723 | +version = "0.0.19" | ||
| 724 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 725 | +checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" | ||
| 726 | + | ||
| 574 | [[package]] | 727 | [[package]] |
| 575 | name = "x11" | 728 | name = "x11" |
| 576 | version = "2.21.0" | 729 | version = "2.21.0" |
+1 −0 Cargo.toml
| @@ -19,3 +19,4 @@ chrono = "0.4" | |||
| 19 | dirs = "5.0" | 19 | dirs = "5.0" |
| 20 | serde = { version = "1.0", features = ["derive"] } | 20 | serde = { version = "1.0", features = ["derive"] } |
| 21 | ron = "0.8" | 21 | ron = "0.8" |
| 22 | +mlua = { version = "0.10", features = ["lua54", "vendored"] } | ||
+407 −0 UPDATES.md new file mode 100644
| @@ -0,0 +1,407 @@ | |||
| 1 | +# OXWM Recent Updates | ||
| 2 | + | ||
| 3 | +## Lua Configuration Support (Latest) | ||
| 4 | + | ||
| 5 | +OXWM now supports **Lua-based configuration** as an alternative to the compiled Rust configuration. This is a major update that makes the window manager much more user-friendly and easier to customize. | ||
| 6 | + | ||
| 7 | +### Key Features | ||
| 8 | + | ||
| 9 | +#### 1. **Dynamic Configuration - No Compilation Required** | ||
| 10 | +- Edit your config file and reload with `Mod+Shift+R` - changes apply instantly | ||
| 11 | +- No need to recompile the entire window manager for config changes | ||
| 12 | +- Configuration file located at `~/.config/oxwm/config.lua` | ||
| 13 | + | ||
| 14 | +#### 2. **Full Feature Parity** | ||
| 15 | +The Lua configuration supports all features previously available in Rust config: | ||
| 16 | +- Window appearance (borders, gaps, fonts) | ||
| 17 | +- Keybindings (single keys and keychords) | ||
| 18 | +- Layout management and custom symbols | ||
| 19 | +- Status bar configuration | ||
| 20 | +- Workspace tags | ||
| 21 | +- Autostart commands | ||
| 22 | +- Color schemes | ||
| 23 | + | ||
| 24 | +#### 3. **LSP Support & Autocomplete** | ||
| 25 | +Config files include comprehensive type annotations for Lua language servers: | ||
| 26 | +- Full autocomplete for all configuration options | ||
| 27 | +- Type checking to catch errors before runtime | ||
| 28 | +- Hover documentation for all fields | ||
| 29 | +- IntelliSense support in modern editors (VS Code, Neovim, etc.) | ||
| 30 | + | ||
| 31 | +### Configuration Structure | ||
| 32 | + | ||
| 33 | +```lua | ||
| 34 | +---@type Config | ||
| 35 | +config = { | ||
| 36 | + -- Appearance | ||
| 37 | + border_width = 2, | ||
| 38 | + border_focused = 0x6dade3, | ||
| 39 | + border_unfocused = 0xbbbbbb, | ||
| 40 | + font = "monospace:style=Bold:size=10", | ||
| 41 | + | ||
| 42 | + -- Window gaps | ||
| 43 | + gaps_enabled = true, | ||
| 44 | + gap_inner_horizontal = 5, | ||
| 45 | + gap_inner_vertical = 5, | ||
| 46 | + gap_outer_horizontal = 5, | ||
| 47 | + gap_outer_vertical = 5, | ||
| 48 | + | ||
| 49 | + -- Basics | ||
| 50 | + modkey = "Mod4", | ||
| 51 | + terminal = "st", | ||
| 52 | + | ||
| 53 | + -- Workspace tags | ||
| 54 | + tags = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}, | ||
| 55 | + | ||
| 56 | + -- Keybindings (see below for details) | ||
| 57 | + keybindings = { ... }, | ||
| 58 | + | ||
| 59 | + -- Status bar blocks (see below for details) | ||
| 60 | + status_blocks = { ... }, | ||
| 61 | + | ||
| 62 | + -- Color schemes | ||
| 63 | + scheme_normal = { ... }, | ||
| 64 | + scheme_occupied = { ... }, | ||
| 65 | + scheme_selected = { ... }, | ||
| 66 | + | ||
| 67 | + -- Autostart commands | ||
| 68 | + autostart = { | ||
| 69 | + "picom -b", | ||
| 70 | + "nitrogen --restore &", | ||
| 71 | + }, | ||
| 72 | +} | ||
| 73 | +``` | ||
| 74 | + | ||
| 75 | +### Keybindings | ||
| 76 | + | ||
| 77 | +#### Single Key Bindings | ||
| 78 | +```lua | ||
| 79 | +{ | ||
| 80 | + modifiers = {"Mod", "Shift"}, | ||
| 81 | + key = "Return", | ||
| 82 | + action = "Spawn", | ||
| 83 | + arg = "alacritty" | ||
| 84 | +} | ||
| 85 | +``` | ||
| 86 | + | ||
| 87 | +#### Keychords (Multi-key Sequences) | ||
| 88 | +```lua | ||
| 89 | +{ | ||
| 90 | + keys = { | ||
| 91 | + {modifiers = {"Mod4"}, key = "Space"}, | ||
| 92 | + {modifiers = {}, key = "T"} | ||
| 93 | + }, | ||
| 94 | + action = "Spawn", | ||
| 95 | + arg = "st" | ||
| 96 | +} | ||
| 97 | +``` | ||
| 98 | + | ||
| 99 | +Press Escape to cancel any in-progress keychord. | ||
| 100 | + | ||
| 101 | +#### Available Modifiers | ||
| 102 | +- `"Mod"` - Replaced with your configured modkey | ||
| 103 | +- `"Mod1"` - Alt key | ||
| 104 | +- `"Mod4"` - Super/Windows key | ||
| 105 | +- `"Shift"` - Shift key | ||
| 106 | +- `"Control"` - Control key | ||
| 107 | +- `"Mod2"`, `"Mod3"`, `"Mod5"` - Additional modifiers | ||
| 108 | + | ||
| 109 | +#### Available Actions | ||
| 110 | +- `"Spawn"` - Launch a program (arg: string or string[]) | ||
| 111 | +- `"KillClient"` - Close focused window | ||
| 112 | +- `"FocusStack"` - Focus next/prev in stack (arg: 1 or -1) | ||
| 113 | +- `"FocusDirection"` - Focus by direction (arg: 0=up, 1=down, 2=left, 3=right) | ||
| 114 | +- `"SwapDirection"` - Swap window by direction (arg: 0=up, 1=down, 2=left, 3=right) | ||
| 115 | +- `"Quit"` - Exit window manager | ||
| 116 | +- `"Restart"` - Restart and reload config | ||
| 117 | +- `"Recompile"` - Recompile and restart (for Rust config) | ||
| 118 | +- `"ViewTag"` - Switch to tag (arg: tag index) | ||
| 119 | +- `"MoveToTag"` - Move window to tag (arg: tag index) | ||
| 120 | +- `"ToggleGaps"` - Toggle gaps on/off | ||
| 121 | +- `"ToggleFullScreen"` - Toggle fullscreen mode | ||
| 122 | +- `"ToggleFloating"` - Toggle floating mode | ||
| 123 | +- `"ChangeLayout"` - Switch to specific layout (arg: layout name) | ||
| 124 | +- `"CycleLayout"` - Cycle through layouts | ||
| 125 | +- `"FocusMonitor"` - Focus monitor (arg: 1 or -1) | ||
| 126 | +- `"SmartMoveWin"` - Smart window movement | ||
| 127 | +- `"ExchangeClient"` - Exchange window positions | ||
| 128 | + | ||
| 129 | +### Status Bar Configuration | ||
| 130 | + | ||
| 131 | +Status blocks support various command types for displaying system information: | ||
| 132 | + | ||
| 133 | +```lua | ||
| 134 | +status_blocks = { | ||
| 135 | + -- RAM usage | ||
| 136 | + { | ||
| 137 | + format = "Ram: {used}/{total} GB", | ||
| 138 | + command = "Ram", | ||
| 139 | + interval_secs = 5, | ||
| 140 | + color = 0x7aa2f7, | ||
| 141 | + underline = true | ||
| 142 | + }, | ||
| 143 | + | ||
| 144 | + -- Date/Time with custom format | ||
| 145 | + { | ||
| 146 | + format = "{}", | ||
| 147 | + command = "DateTime", | ||
| 148 | + command_arg = "%a, %b %d - %-I:%M %P", | ||
| 149 | + interval_secs = 1, | ||
| 150 | + color = 0x0db9d7, | ||
| 151 | + underline = true | ||
| 152 | + }, | ||
| 153 | + | ||
| 154 | + -- Custom shell command | ||
| 155 | + { | ||
| 156 | + format = "Kernel: {}", | ||
| 157 | + command = "Shell", | ||
| 158 | + command_arg = "uname -r", | ||
| 159 | + interval_secs = 999999999, | ||
| 160 | + color = 0xf7768e, | ||
| 161 | + underline = true | ||
| 162 | + }, | ||
| 163 | + | ||
| 164 | + -- Static text (separator) | ||
| 165 | + { | ||
| 166 | + format = " │ ", | ||
| 167 | + command = "Static", | ||
| 168 | + interval_secs = 999999999, | ||
| 169 | + color = 0xa9b1d6, | ||
| 170 | + underline = false | ||
| 171 | + }, | ||
| 172 | + | ||
| 173 | + -- Battery status | ||
| 174 | + { | ||
| 175 | + format = "{}", | ||
| 176 | + command = "Battery", | ||
| 177 | + interval_secs = 30, | ||
| 178 | + color = 0x9ece6a, | ||
| 179 | + underline = true, | ||
| 180 | + battery_formats = { | ||
| 181 | + charging = "⚡ {}%", | ||
| 182 | + discharging = "🔋 {}%", | ||
| 183 | + full = "✓ {}%" | ||
| 184 | + } | ||
| 185 | + }, | ||
| 186 | +} | ||
| 187 | +``` | ||
| 188 | + | ||
| 189 | +#### Available Status Block Commands | ||
| 190 | +- `"Ram"` - Shows RAM usage (no command_arg needed) | ||
| 191 | +- `"DateTime"` - Shows date/time with strftime format in command_arg | ||
| 192 | +- `"Shell"` - Runs shell command from command_arg | ||
| 193 | +- `"Static"` - Static text (format field determines what's shown) | ||
| 194 | +- `"Battery"` - Shows battery status (requires battery_formats table) | ||
| 195 | + | ||
| 196 | +### Layout Symbols | ||
| 197 | + | ||
| 198 | +Customize how layouts appear in the status bar: | ||
| 199 | + | ||
| 200 | +```lua | ||
| 201 | +layout_symbols = { | ||
| 202 | + {name = "tiling", symbol = "[T]"}, | ||
| 203 | + {name = "normie", symbol = "[F]"}, | ||
| 204 | +} | ||
| 205 | +``` | ||
| 206 | + | ||
| 207 | +### Color Schemes | ||
| 208 | + | ||
| 209 | +Define color schemes for tag indicators in the status bar: | ||
| 210 | + | ||
| 211 | +```lua | ||
| 212 | +scheme_normal = { | ||
| 213 | + foreground = 0xbbbbbb, | ||
| 214 | + background = 0x1a1b26, | ||
| 215 | + underline = 0x444444 | ||
| 216 | +}, | ||
| 217 | +scheme_occupied = { | ||
| 218 | + foreground = 0x0db9d7, | ||
| 219 | + background = 0x1a1b26, | ||
| 220 | + underline = 0x0db9d7 | ||
| 221 | +}, | ||
| 222 | +scheme_selected = { | ||
| 223 | + foreground = 0x0db9d7, | ||
| 224 | + background = 0x1a1b26, | ||
| 225 | + underline = 0xad8ee6 | ||
| 226 | +} | ||
| 227 | +``` | ||
| 228 | + | ||
| 229 | +### Autostart Commands | ||
| 230 | + | ||
| 231 | +Commands to run when the window manager starts: | ||
| 232 | + | ||
| 233 | +```lua | ||
| 234 | +autostart = { | ||
| 235 | + "picom -b", | ||
| 236 | + "nitrogen --restore &", | ||
| 237 | + "dunst &", | ||
| 238 | +} | ||
| 239 | +``` | ||
| 240 | + | ||
| 241 | +### Advanced Usage | ||
| 242 | + | ||
| 243 | +You can use Lua's full programming capabilities for dynamic configuration: | ||
| 244 | + | ||
| 245 | +```lua | ||
| 246 | +-- Generate keybindings programmatically | ||
| 247 | +for i = 1, 9 do | ||
| 248 | + table.insert(config.keybindings, { | ||
| 249 | + modifiers = {"Mod"}, | ||
| 250 | + key = tostring(i), | ||
| 251 | + action = "ViewTag", | ||
| 252 | + arg = i - 1 | ||
| 253 | + }) | ||
| 254 | +end | ||
| 255 | + | ||
| 256 | +-- Create helper functions | ||
| 257 | +local function create_spawn_binding(mods, key, cmd) | ||
| 258 | + return {modifiers = mods, key = key, action = "Spawn", arg = cmd} | ||
| 259 | +end | ||
| 260 | + | ||
| 261 | +table.insert(config.keybindings, | ||
| 262 | + create_spawn_binding({"Mod"}, "Return", terminal)) | ||
| 263 | +``` | ||
| 264 | + | ||
| 265 | +### Migration from Rust Config | ||
| 266 | + | ||
| 267 | +For existing users with Rust-based configurations: | ||
| 268 | +1. Your old Rust config still works - no breaking changes | ||
| 269 | +2. To migrate to Lua, run OXWM and it will generate `~/.config/oxwm/config.lua` | ||
| 270 | +3. Customize the generated file to match your preferences | ||
| 271 | +4. Reload with `Mod+Shift+R` to apply changes | ||
| 272 | + | ||
| 273 | +### Technical Implementation | ||
| 274 | + | ||
| 275 | +- Configuration parsing via `mlua` (Lua 5.4) | ||
| 276 | +- Full deserialization into Rust types with `serde` | ||
| 277 | +- Hot-reloading on `Restart` action | ||
| 278 | +- Comprehensive error reporting for config issues | ||
| 279 | +- Type-safe validation of all configuration values | ||
| 280 | + | ||
| 281 | +### Files | ||
| 282 | + | ||
| 283 | +- Template: `templates/config.lua` - Default configuration template | ||
| 284 | +- User config: `~/.config/oxwm/config.lua` - User's configuration file | ||
| 285 | +- Test config: `resources/test-config.lua` - Configuration for Xephyr testing | ||
| 286 | + | ||
| 287 | +--- | ||
| 288 | + | ||
| 289 | +## Documentation Suggestions | ||
| 290 | + | ||
| 291 | +### New Pages to Create | ||
| 292 | + | ||
| 293 | +1. **"Lua Configuration Guide"** - Complete guide to Lua config | ||
| 294 | + - Getting started | ||
| 295 | + - Configuration structure | ||
| 296 | + - Examples for common use cases | ||
| 297 | + - Tips and best practices | ||
| 298 | + | ||
| 299 | +2. **"Keybindings Reference"** - Detailed keybinding documentation | ||
| 300 | + - How to define single key bindings | ||
| 301 | + - How to create keychords | ||
| 302 | + - List of all available actions with examples | ||
| 303 | + - Modifier key reference | ||
| 304 | + | ||
| 305 | +3. **"Status Bar Configuration"** - Status bar setup guide | ||
| 306 | + - Available command types | ||
| 307 | + - Format string syntax | ||
| 308 | + - Custom shell commands | ||
| 309 | + - Battery configuration | ||
| 310 | + - Creating custom blocks | ||
| 311 | + | ||
| 312 | +### Pages to Update | ||
| 313 | + | ||
| 314 | +1. **Installation/Quickstart** | ||
| 315 | + - Mention Lua configuration as the recommended approach | ||
| 316 | + - Add note that no recompilation needed for config changes | ||
| 317 | + - Update first-run instructions | ||
| 318 | + | ||
| 319 | +2. **Configuration Page** (if exists) | ||
| 320 | + - Add prominent notice about Lua support | ||
| 321 | + - Deprecation notice for Rust config (if planned) | ||
| 322 | + - Link to new Lua configuration guide | ||
| 323 | + | ||
| 324 | +3. **Keybindings Page** (if exists) | ||
| 325 | + - Update with Lua syntax | ||
| 326 | + - Add keychord examples | ||
| 327 | + - Update modifier key documentation | ||
| 328 | + | ||
| 329 | +### Highlights for Documentation | ||
| 330 | + | ||
| 331 | +**Key Selling Points:** | ||
| 332 | +- "Edit and reload instantly - no compilation required" | ||
| 333 | +- "LSP-powered autocomplete for config editing" | ||
| 334 | +- "Full Lua programming support for dynamic configs" | ||
| 335 | +- "Keychord support for complex key combinations" | ||
| 336 | + | ||
| 337 | +**Common Questions to Address:** | ||
| 338 | +- How do I reload my config? (`Mod+Shift+R`) | ||
| 339 | +- Where is my config file? (`~/.config/oxwm/config.lua`) | ||
| 340 | +- Can I still use the Rust config? (Yes, for now) | ||
| 341 | +- How do I see config errors? (Check terminal output when starting OXWM) | ||
| 342 | + | ||
| 343 | +### Example Snippets for Docs | ||
| 344 | + | ||
| 345 | +#### Quick Config Example | ||
| 346 | +```lua | ||
| 347 | +-- Minimal working config | ||
| 348 | +config = { | ||
| 349 | + modkey = "Mod4", | ||
| 350 | + terminal = "alacritty", | ||
| 351 | + tags = {"web", "code", "term"}, | ||
| 352 | + border_width = 2, | ||
| 353 | + border_focused = 0x89b4fa, | ||
| 354 | + border_unfocused = 0x45475a, | ||
| 355 | + keybindings = { | ||
| 356 | + {modifiers = {"Mod"}, key = "Return", action = "Spawn", arg = "alacritty"}, | ||
| 357 | + {modifiers = {"Mod"}, key = "Q", action = "KillClient"}, | ||
| 358 | + {modifiers = {"Mod", "Shift"}, key = "Q", action = "Quit"}, | ||
| 359 | + } | ||
| 360 | +} | ||
| 361 | +``` | ||
| 362 | + | ||
| 363 | +#### Advanced Keychord Example | ||
| 364 | +```lua | ||
| 365 | +-- Open application menu with Mod+Space, then choose app | ||
| 366 | +keybindings = { | ||
| 367 | + -- Mod+Space, then B -> browser | ||
| 368 | + { | ||
| 369 | + keys = { | ||
| 370 | + {modifiers = {"Mod4"}, key = "Space"}, | ||
| 371 | + {modifiers = {}, key = "B"} | ||
| 372 | + }, | ||
| 373 | + action = "Spawn", | ||
| 374 | + arg = "firefox" | ||
| 375 | + }, | ||
| 376 | + -- Mod+Space, then T -> terminal | ||
| 377 | + { | ||
| 378 | + keys = { | ||
| 379 | + {modifiers = {"Mod4"}, key = "Space"}, | ||
| 380 | + {modifiers = {}, key = "T"} | ||
| 381 | + }, | ||
| 382 | + action = "Spawn", | ||
| 383 | + arg = "alacritty" | ||
| 384 | + }, | ||
| 385 | +} | ||
| 386 | +``` | ||
| 387 | + | ||
| 388 | +--- | ||
| 389 | + | ||
| 390 | +## Other Recent Updates | ||
| 391 | + | ||
| 392 | +### Autostart Support | ||
| 393 | +- Added `autostart` field to configuration | ||
| 394 | +- Commands run when window manager starts | ||
| 395 | +- Useful for launching compositors, wallpaper setters, notification daemons, etc. | ||
| 396 | + | ||
| 397 | +### Fullscreen Fixes | ||
| 398 | +- Fixed issue where fullscreen windows weren't properly applying geometries | ||
| 399 | +- Border handling corrected for fullscreen mode | ||
| 400 | + | ||
| 401 | +### Layout Updates | ||
| 402 | +- Improved layout switching behavior | ||
| 403 | +- Better handling of layout symbols in status bar | ||
| 404 | + | ||
| 405 | +--- | ||
| 406 | + | ||
| 407 | +**Last Updated:** 2025-11-07 | ||
+5 −5 justfile
| @@ -10,7 +10,7 @@ install: build | |||
| 10 | uninstall: | 10 | uninstall: |
| 11 | rm -f /usr/bin/oxwm | 11 | rm -f /usr/bin/oxwm |
| 12 | @echo "✓ oxwm uninstalled" | 12 | @echo "✓ oxwm uninstalled" |
| 13 | - @echo " Your config at ~/.config/oxwm/config.ron is preserved" | 13 | + @echo " Your config at ~/.config/oxwm/ is preserved" |
| 14 | 14 | ||
| 15 | clean: | 15 | clean: |
| 16 | cargo clean | 16 | cargo clean |
| @@ -19,23 +19,23 @@ test-clean: | |||
| 19 | pkill Xephyr || true | 19 | pkill Xephyr || true |
| 20 | rm -rf ~/.config/oxwm | 20 | rm -rf ~/.config/oxwm |
| 21 | Xephyr -screen 1280x800 :1 & sleep 1 | 21 | Xephyr -screen 1280x800 :1 & sleep 1 |
| 22 | - DISPLAY=:1 cargo run --release -- --config resources/test-config.ron | 22 | + DISPLAY=:1 cargo run --release -- --config resources/test-config.lua |
| 23 | 23 | ||
| 24 | test: | 24 | test: |
| 25 | pkill Xephyr || true | 25 | pkill Xephyr || true |
| 26 | Xephyr -screen 1280x800 :1 & sleep 1 | 26 | Xephyr -screen 1280x800 :1 & sleep 1 |
| 27 | - DISPLAY=:1 cargo run --release -- --config resources/test-config.ron | 27 | + DISPLAY=:1 cargo run --release -- --config resources/test-config.lua |
| 28 | 28 | ||
| 29 | test-multimon: | 29 | test-multimon: |
| 30 | pkill Xephyr || true | 30 | pkill Xephyr || true |
| 31 | Xephyr +xinerama -screen 640x480 -screen 640x480 :1 & sleep 1 | 31 | Xephyr +xinerama -screen 640x480 -screen 640x480 :1 & sleep 1 |
| 32 | - DISPLAY=:1 cargo run --release -- --config resources/test-config.ron | 32 | + DISPLAY=:1 cargo run --release -- --config resources/test-config.lua |
| 33 | 33 | ||
| 34 | init: | 34 | init: |
| 35 | cargo run --release -- --init | 35 | cargo run --release -- --init |
| 36 | 36 | ||
| 37 | edit: | 37 | edit: |
| 38 | - $EDITOR ~/.config/oxwm/config.ron | 38 | + $EDITOR ~/.config/oxwm/config.lua |
| 39 | 39 | ||
| 40 | check: | 40 | check: |
| 41 | cargo clippy -- -W clippy::all | 41 | cargo clippy -- -W clippy::all |
+260 −0 resources/test-config.lua new file mode 100644
| @@ -0,0 +1,260 @@ | |||
| 1 | +-- OXWM Test Configuration File (Lua) | ||
| 2 | +-- This config uses Mod1 (Alt) as the modkey for testing in Xephyr | ||
| 3 | + | ||
| 4 | +---@class LayoutSymbol | ||
| 5 | +---@field name string The internal layout name (e.g., "tiling", "normie") | ||
| 6 | +---@field symbol string The display symbol for the layout (e.g., "[T]", "[F]") | ||
| 7 | + | ||
| 8 | +---@class KeyBinding | ||
| 9 | +---@field modifiers string[] List of modifiers: "Mod", "Mod1"-"Mod5", "Shift", "Control" | ||
| 10 | +---@field key string The key name (e.g., "Return", "Q", "1", "Space") | ||
| 11 | +---@field action string Action to perform (see below for list) | ||
| 12 | +---@field arg? string|number|string[] Optional argument for the action | ||
| 13 | + | ||
| 14 | +---@class KeyChord | ||
| 15 | +---@field keys {modifiers: string[], key: string}[] Sequence of keys to press | ||
| 16 | +---@field action string Action to perform when chord completes | ||
| 17 | +---@field arg? string|number|string[] Optional argument for the action | ||
| 18 | + | ||
| 19 | +---@class StatusBlock | ||
| 20 | +---@field format string Display format with {} placeholders | ||
| 21 | +---@field command string Command type: "Ram", "DateTime", "Shell", "Static", "Battery" | ||
| 22 | +---@field command_arg? string Argument for command (shell command, date format, etc.) | ||
| 23 | +---@field interval_secs number Update interval in seconds | ||
| 24 | +---@field color number Color as hex number (e.g., 0xff0000 for red) | ||
| 25 | +---@field underline boolean Whether to show underline | ||
| 26 | +---@field battery_formats? {charging: string, discharging: string, full: string} Battery format strings | ||
| 27 | + | ||
| 28 | +---@class ColorScheme | ||
| 29 | +---@field foreground number Foreground color (hex) | ||
| 30 | +---@field background number Background color (hex) | ||
| 31 | +---@field underline number Underline color (hex) | ||
| 32 | + | ||
| 33 | +---@class Config | ||
| 34 | +---@field border_width number Width of window borders in pixels | ||
| 35 | +---@field border_focused number Color for focused window border (hex) | ||
| 36 | +---@field border_unfocused number Color for unfocused window border (hex) | ||
| 37 | +---@field font string Font specification (e.g., "monospace:style=Bold:size=10") | ||
| 38 | +---@field gaps_enabled boolean Whether gaps are enabled | ||
| 39 | +---@field gap_inner_horizontal number Inner horizontal gap size | ||
| 40 | +---@field gap_inner_vertical number Inner vertical gap size | ||
| 41 | +---@field gap_outer_horizontal number Outer horizontal gap size | ||
| 42 | +---@field gap_outer_vertical number Outer vertical gap size | ||
| 43 | +---@field modkey string Main modifier key (e.g., "Mod4" for Super) | ||
| 44 | +---@field terminal string Terminal emulator command | ||
| 45 | +---@field tags string[] List of workspace tag names | ||
| 46 | +---@field layout_symbols LayoutSymbol[] Custom layout symbols | ||
| 47 | +---@field keybindings (KeyBinding|KeyChord)[] List of keybindings | ||
| 48 | +---@field status_blocks StatusBlock[] Status bar configuration blocks | ||
| 49 | +---@field scheme_normal ColorScheme Color scheme for normal tags | ||
| 50 | +---@field scheme_occupied ColorScheme Color scheme for occupied tags | ||
| 51 | +---@field scheme_selected ColorScheme Color scheme for selected tag | ||
| 52 | +---@field autostart string[] Commands to run on startup | ||
| 53 | + | ||
| 54 | +-- Available Actions: | ||
| 55 | +-- "Spawn" - Launch a program (arg: string or string[]) | ||
| 56 | +-- "KillClient" - Close focused window | ||
| 57 | +-- "FocusStack" - Focus next/prev in stack (arg: 1 or -1) | ||
| 58 | +-- "FocusDirection" - Focus by direction (arg: 0=up, 1=down, 2=left, 3=right) | ||
| 59 | +-- "SwapDirection" - Swap window by direction (arg: 0=up, 1=down, 2=left, 3=right) | ||
| 60 | +-- "Quit" - Exit window manager | ||
| 61 | +-- "Restart" - Restart and reload config | ||
| 62 | +-- "Recompile" - Recompile and restart | ||
| 63 | +-- "ViewTag" - Switch to tag (arg: tag index) | ||
| 64 | +-- "MoveToTag" - Move window to tag (arg: tag index) | ||
| 65 | +-- "ToggleGaps" - Toggle gaps on/off | ||
| 66 | +-- "ToggleFullScreen" - Toggle fullscreen mode | ||
| 67 | +-- "ToggleFloating" - Toggle floating mode | ||
| 68 | +-- "ChangeLayout" - Switch to specific layout (arg: layout name) | ||
| 69 | +-- "CycleLayout" - Cycle through layouts | ||
| 70 | +-- "FocusMonitor" - Focus monitor (arg: 1 or -1) | ||
| 71 | +-- "SmartMoveWin" - Smart window movement | ||
| 72 | +-- "ExchangeClient" - Exchange window positions | ||
| 73 | + | ||
| 74 | +-- Available Modifiers: | ||
| 75 | +-- "Mod" - Replaced with configured modkey | ||
| 76 | +-- "Mod1" - Alt key | ||
| 77 | +-- "Mod4" - Super/Windows key | ||
| 78 | +-- "Shift" - Shift key | ||
| 79 | +-- "Control" - Control key | ||
| 80 | +-- "Mod2", "Mod3", "Mod5" - Additional modifiers | ||
| 81 | + | ||
| 82 | +-- Define variables for easy customization | ||
| 83 | +local terminal = "st" | ||
| 84 | +local modkey = "Mod1" -- Alt key for Xephyr testing | ||
| 85 | +local secondary_modkey = "Control" | ||
| 86 | + | ||
| 87 | +-- Color palette (Tokyo Night theme) | ||
| 88 | +local colors = { | ||
| 89 | + blue = 0x6dade3, | ||
| 90 | + grey = 0xbbbbbb, | ||
| 91 | + green = 0x9ece6a, | ||
| 92 | + red = 0xf7768e, | ||
| 93 | + cyan = 0x0db9d7, | ||
| 94 | + purple = 0xad8ee6, | ||
| 95 | + lavender = 0xa9b1d6, | ||
| 96 | + bg = 0x1a1b26, | ||
| 97 | + fg = 0xbbbbbb, | ||
| 98 | + light_blue = 0x7aa2f7, | ||
| 99 | +} | ||
| 100 | + | ||
| 101 | +-- Main configuration table | ||
| 102 | +---@type Config | ||
| 103 | +config = { | ||
| 104 | + -- Appearance | ||
| 105 | + border_width = 2, | ||
| 106 | + border_focused = colors.blue, | ||
| 107 | + border_unfocused = colors.grey, | ||
| 108 | + font = "monospace:style=Bold:size=10", | ||
| 109 | + | ||
| 110 | + -- Window gaps | ||
| 111 | + gaps_enabled = true, | ||
| 112 | + gap_inner_horizontal = 5, | ||
| 113 | + gap_inner_vertical = 5, | ||
| 114 | + gap_outer_horizontal = 5, | ||
| 115 | + gap_outer_vertical = 5, | ||
| 116 | + | ||
| 117 | + -- Basics | ||
| 118 | + modkey = modkey, | ||
| 119 | + terminal = terminal, | ||
| 120 | + | ||
| 121 | + -- Workspace tags | ||
| 122 | + tags = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}, | ||
| 123 | + | ||
| 124 | + -- Layout symbol overrides | ||
| 125 | + layout_symbols = { | ||
| 126 | + {name = "tiling", symbol = "[T]"}, | ||
| 127 | + {name = "normie", symbol = "[F]"}, | ||
| 128 | + }, | ||
| 129 | + | ||
| 130 | + -- Keybindings | ||
| 131 | + -- Using Mod1 (Alt) for Xephyr testing so it doesn't conflict with host WM | ||
| 132 | + keybindings = { | ||
| 133 | + -- Basic window management | ||
| 134 | + {modifiers = {"Mod"}, key = "Return", action = "Spawn", arg = terminal}, | ||
| 135 | + {modifiers = {"Mod"}, key = "D", action = "Spawn", arg = {"sh", "-c", "dmenu_run -l 10"}}, | ||
| 136 | + {modifiers = {"Mod"}, key = "S", action = "Spawn", arg = {"sh", "-c", "maim -s | xclip -selection clipboard -t image/png"}}, | ||
| 137 | + {modifiers = {"Mod"}, key = "Q", action = "KillClient"}, | ||
| 138 | + {modifiers = {"Mod", "Shift"}, key = "F", action = "ToggleFullScreen"}, | ||
| 139 | + {modifiers = {"Mod", "Shift"}, key = "Space", action = "ToggleFloating"}, | ||
| 140 | + | ||
| 141 | + -- Layout management | ||
| 142 | + {modifiers = {"Mod"}, key = "F", action = "ChangeLayout", arg = "normie"}, | ||
| 143 | + {modifiers = {"Mod"}, key = "C", action = "ChangeLayout", arg = "tiling"}, | ||
| 144 | + {modifiers = {secondary_modkey}, key = "N", action = "CycleLayout"}, | ||
| 145 | + {modifiers = {"Mod"}, key = "A", action = "ToggleGaps"}, | ||
| 146 | + | ||
| 147 | + -- WM control | ||
| 148 | + {modifiers = {"Mod", "Shift"}, key = "Q", action = "Quit"}, | ||
| 149 | + {modifiers = {"Mod", "Shift"}, key = "R", action = "Restart"}, | ||
| 150 | + | ||
| 151 | + -- Focus movement (vim-style hjkl) | ||
| 152 | + {modifiers = {"Mod"}, key = "H", action = "FocusDirection", arg = 2}, -- left | ||
| 153 | + {modifiers = {"Mod"}, key = "J", action = "FocusDirection", arg = 1}, -- down | ||
| 154 | + {modifiers = {"Mod"}, key = "K", action = "FocusDirection", arg = 0}, -- up | ||
| 155 | + {modifiers = {"Mod"}, key = "L", action = "FocusDirection", arg = 3}, -- right | ||
| 156 | + | ||
| 157 | + -- Window swapping (vim-style hjkl) | ||
| 158 | + {modifiers = {"Mod", "Shift"}, key = "H", action = "SwapDirection", arg = 2}, -- left | ||
| 159 | + {modifiers = {"Mod", "Shift"}, key = "J", action = "SwapDirection", arg = 1}, -- down | ||
| 160 | + {modifiers = {"Mod", "Shift"}, key = "K", action = "SwapDirection", arg = 0}, -- up | ||
| 161 | + {modifiers = {"Mod", "Shift"}, key = "L", action = "SwapDirection", arg = 3}, -- right | ||
| 162 | + | ||
| 163 | + -- Monitor focus | ||
| 164 | + {modifiers = {"Mod"}, key = "Comma", action = "FocusMonitor", arg = -1}, | ||
| 165 | + {modifiers = {"Mod"}, key = "Period", action = "FocusMonitor", arg = 1}, | ||
| 166 | + | ||
| 167 | + -- View tags | ||
| 168 | + {modifiers = {"Mod"}, key = "1", action = "ViewTag", arg = 0}, | ||
| 169 | + {modifiers = {"Mod"}, key = "2", action = "ViewTag", arg = 1}, | ||
| 170 | + {modifiers = {"Mod"}, key = "3", action = "ViewTag", arg = 2}, | ||
| 171 | + {modifiers = {"Mod"}, key = "4", action = "ViewTag", arg = 3}, | ||
| 172 | + {modifiers = {"Mod"}, key = "5", action = "ViewTag", arg = 4}, | ||
| 173 | + {modifiers = {"Mod"}, key = "6", action = "ViewTag", arg = 5}, | ||
| 174 | + {modifiers = {"Mod"}, key = "7", action = "ViewTag", arg = 6}, | ||
| 175 | + {modifiers = {"Mod"}, key = "8", action = "ViewTag", arg = 7}, | ||
| 176 | + {modifiers = {"Mod"}, key = "9", action = "ViewTag", arg = 8}, | ||
| 177 | + | ||
| 178 | + -- Move window to tag | ||
| 179 | + {modifiers = {"Mod", "Shift"}, key = "1", action = "MoveToTag", arg = 0}, | ||
| 180 | + {modifiers = {"Mod", "Shift"}, key = "2", action = "MoveToTag", arg = 1}, | ||
| 181 | + {modifiers = {"Mod", "Shift"}, key = "3", action = "MoveToTag", arg = 2}, | ||
| 182 | + {modifiers = {"Mod", "Shift"}, key = "4", action = "MoveToTag", arg = 3}, | ||
| 183 | + {modifiers = {"Mod", "Shift"}, key = "5", action = "MoveToTag", arg = 4}, | ||
| 184 | + {modifiers = {"Mod", "Shift"}, key = "6", action = "MoveToTag", arg = 5}, | ||
| 185 | + {modifiers = {"Mod", "Shift"}, key = "7", action = "MoveToTag", arg = 6}, | ||
| 186 | + {modifiers = {"Mod", "Shift"}, key = "8", action = "MoveToTag", arg = 7}, | ||
| 187 | + {modifiers = {"Mod", "Shift"}, key = "9", action = "MoveToTag", arg = 8}, | ||
| 188 | + | ||
| 189 | + -- Example keychord: Alt+Space, then T to spawn terminal | ||
| 190 | + { | ||
| 191 | + keys = { | ||
| 192 | + {modifiers = {"Mod1"}, key = "Space"}, | ||
| 193 | + {modifiers = {}, key = "T"} | ||
| 194 | + }, | ||
| 195 | + action = "Spawn", | ||
| 196 | + arg = terminal | ||
| 197 | + }, | ||
| 198 | + }, | ||
| 199 | + | ||
| 200 | + -- Status bar blocks | ||
| 201 | + status_blocks = { | ||
| 202 | + { | ||
| 203 | + format = "Ram: {used}/{total} GB", | ||
| 204 | + command = "Ram", | ||
| 205 | + interval_secs = 5, | ||
| 206 | + color = colors.light_blue, | ||
| 207 | + underline = true | ||
| 208 | + }, | ||
| 209 | + { | ||
| 210 | + format = " │ ", | ||
| 211 | + command = "Static", | ||
| 212 | + interval_secs = 999999999, -- Very large number for static blocks | ||
| 213 | + color = colors.lavender, | ||
| 214 | + underline = false | ||
| 215 | + }, | ||
| 216 | + { | ||
| 217 | + format = "Kernel: {}", | ||
| 218 | + command = "Shell", | ||
| 219 | + command_arg = "uname -r", | ||
| 220 | + interval_secs = 999999999, | ||
| 221 | + color = colors.red, | ||
| 222 | + underline = true | ||
| 223 | + }, | ||
| 224 | + { | ||
| 225 | + format = " │ ", | ||
| 226 | + command = "Static", | ||
| 227 | + interval_secs = 999999999, | ||
| 228 | + color = colors.lavender, | ||
| 229 | + underline = false | ||
| 230 | + }, | ||
| 231 | + { | ||
| 232 | + format = "{}", | ||
| 233 | + command = "DateTime", | ||
| 234 | + command_arg = "%a, %b %d - %-I:%M %P", | ||
| 235 | + interval_secs = 1, | ||
| 236 | + color = colors.cyan, | ||
| 237 | + underline = true | ||
| 238 | + }, | ||
| 239 | + }, | ||
| 240 | + | ||
| 241 | + -- Color schemes for bar | ||
| 242 | + scheme_normal = { | ||
| 243 | + foreground = colors.fg, | ||
| 244 | + background = colors.bg, | ||
| 245 | + underline = 0x444444 | ||
| 246 | + }, | ||
| 247 | + scheme_occupied = { | ||
| 248 | + foreground = colors.cyan, | ||
| 249 | + background = colors.bg, | ||
| 250 | + underline = colors.cyan | ||
| 251 | + }, | ||
| 252 | + scheme_selected = { | ||
| 253 | + foreground = colors.cyan, | ||
| 254 | + background = colors.bg, | ||
| 255 | + underline = colors.purple | ||
| 256 | + }, | ||
| 257 | + | ||
| 258 | + -- Autostart commands | ||
| 259 | + autostart = {}, | ||
| 260 | +} | ||
+30 −11 src/bin/main.rs
| @@ -50,27 +50,46 @@ fn load_config(custom_path: Option<PathBuf>) -> Result<oxwm::Config> { | |||
| 50 | let config_path = if let Some(path) = custom_path { | 50 | let config_path = if let Some(path) = custom_path { |
| 51 | path | 51 | path |
| 52 | } else { | 52 | } else { |
| 53 | - let default_path = get_config_path().join("config.ron"); | 53 | + // Try to find config.lua first, then config.ron |
| 54 | - if !default_path.exists() { | 54 | + let config_dir = get_config_path(); |
| 55 | - println!("No config found at {:?}", default_path); | 55 | + let lua_path = config_dir.join("config.lua"); |
| 56 | - println!("Creating default config..."); | 56 | + let ron_path = config_dir.join("config.ron"); |
| 57 | + | ||
| 58 | + if lua_path.exists() { | ||
| 59 | + lua_path | ||
| 60 | + } else if ron_path.exists() { | ||
| 61 | + ron_path | ||
| 62 | + } else { | ||
| 63 | + println!("No config found at {:?}", config_dir); | ||
| 64 | + println!("Creating default Lua config..."); | ||
| 57 | init_config()?; | 65 | init_config()?; |
| 66 | + config_dir.join("config.lua") | ||
| 58 | } | 67 | } |
| 59 | - default_path | ||
| 60 | }; | 68 | }; |
| 61 | 69 | ||
| 62 | let config_str = | 70 | let config_str = |
| 63 | std::fs::read_to_string(&config_path).with_context(|| "Failed to read config file")?; | 71 | std::fs::read_to_string(&config_path).with_context(|| "Failed to read config file")?; |
| 64 | 72 | ||
| 65 | - oxwm::config::parse_config(&config_str).with_context(|| "Failed to parse config") | 73 | + // Determine config format based on file extension |
| 74 | + let is_lua = config_path | ||
| 75 | + .extension() | ||
| 76 | + .and_then(|s| s.to_str()) | ||
| 77 | + .map(|s| s == "lua") | ||
| 78 | + .unwrap_or(false); | ||
| 79 | + | ||
| 80 | + if is_lua { | ||
| 81 | + oxwm::config::parse_lua_config(&config_str).with_context(|| "Failed to parse Lua config") | ||
| 82 | + } else { | ||
| 83 | + oxwm::config::parse_config(&config_str).with_context(|| "Failed to parse RON config") | ||
| 84 | + } | ||
| 66 | } | 85 | } |
| 67 | 86 | ||
| 68 | fn init_config() -> Result<()> { | 87 | fn init_config() -> Result<()> { |
| 69 | let config_dir = get_config_path(); | 88 | let config_dir = get_config_path(); |
| 70 | std::fs::create_dir_all(&config_dir)?; | 89 | std::fs::create_dir_all(&config_dir)?; |
| 71 | 90 | ||
| 72 | - let config_template = include_str!("../../templates/config.ron"); | 91 | + let config_template = include_str!("../../templates/config.lua"); |
| 73 | - let config_path = config_dir.join("config.ron"); | 92 | + let config_path = config_dir.join("config.lua"); |
| 74 | 93 | ||
| 75 | std::fs::write(&config_path, config_template)?; | 94 | std::fs::write(&config_path, config_template)?; |
| 76 | 95 | ||
| @@ -92,12 +111,12 @@ fn print_help() { | |||
| 92 | println!("USAGE:"); | 111 | println!("USAGE:"); |
| 93 | println!(" oxwm [OPTIONS]\n"); | 112 | println!(" oxwm [OPTIONS]\n"); |
| 94 | println!("OPTIONS:"); | 113 | println!("OPTIONS:"); |
| 95 | - println!(" --init Create default config in ~/.config/oxwm/config.ron"); | 114 | + println!(" --init Create default config in ~/.config/oxwm/config.lua"); |
| 96 | - println!(" --config <PATH> Use custom config file"); | 115 | + println!(" --config <PATH> Use custom config file (.lua or .ron)"); |
| 97 | println!(" --version Print version information"); | 116 | println!(" --version Print version information"); |
| 98 | println!(" --help Print this help message\n"); | 117 | println!(" --help Print this help message\n"); |
| 99 | println!("CONFIG:"); | 118 | println!("CONFIG:"); |
| 100 | - println!(" Location: ~/.config/oxwm/config.ron"); | 119 | + println!(" Location: ~/.config/oxwm/config.lua (or config.ron for legacy)"); |
| 101 | println!(" Edit the config file and use Mod+Shift+R to reload"); | 120 | println!(" Edit the config file and use Mod+Shift+R to reload"); |
| 102 | println!(" No compilation needed - instant hot-reload!\n"); | 121 | println!(" No compilation needed - instant hot-reload!\n"); |
| 103 | println!("FIRST RUN:"); | 122 | println!("FIRST RUN:"); |
+574 −0 src/config/lua.rs new file mode 100644 Large diff collapsed, click to expand
| @@ -0,0 +1,574 @@ | |||
| 1 | +use crate::bar::{BlockCommand, BlockConfig}; | ||
| 2 | +use crate::errors::ConfigError; | ||
| 3 | +use crate::keyboard::handlers::{KeyBinding, KeyPress}; | ||
| 4 | +use crate::keyboard::keysyms::{self, Keysym}; | ||
| 5 | +use crate::keyboard::{Arg, KeyAction}; | ||
| 6 | +use crate::{ColorScheme, LayoutSymbolOverride}; | ||
| 7 | +use mlua::{Lua, Table, Value}; | ||
| 8 | +use x11rb::protocol::xproto::KeyButMask; | ||
| 9 | + | ||
| 10 | +pub fn parse_lua_config(input: &str) -> Result<crate::Config, ConfigError> { | ||
| 11 | + let lua = Lua::new(); | ||
| 12 | + | ||
| 13 | + // Execute the config file | ||
| 14 | + lua.load(input) | ||
| 15 | + .exec() | ||
| 16 | + .map_err(|e| ConfigError::LuaError(format!("Failed to execute Lua config: {}", e)))?; | ||
| 17 | + | ||
| 18 | + // Get the config table from global scope | ||
| 19 | + let globals = lua.globals(); | ||
| 20 | + let config: Table = globals | ||
| 21 | + .get("config") | ||
| 22 | + .map_err(|e| ConfigError::LuaError(format!("Config table not found: {}", e)))?; | ||
| 23 | + | ||
| 24 | + // Parse each config section | ||
| 25 | + let border_width: u32 = get_table_field(&config, "border_width")?; | ||
| 26 | + let border_focused: u32 = parse_color(&config, "border_focused")?; | ||
| 27 | + let border_unfocused: u32 = parse_color(&config, "border_unfocused")?; | ||
| 28 | + let font: String = get_table_field(&config, "font")?; | ||
| 29 | + | ||
| 30 | + let gaps_enabled: bool = get_table_field(&config, "gaps_enabled")?; | ||
| 31 | + let gap_inner_horizontal: u32 = get_table_field(&config, "gap_inner_horizontal")?; | ||
| 32 | + let gap_inner_vertical: u32 = get_table_field(&config, "gap_inner_vertical")?; | ||
| 33 | + let gap_outer_horizontal: u32 = get_table_field(&config, "gap_outer_horizontal")?; | ||
| 34 | + let gap_outer_vertical: u32 = get_table_field(&config, "gap_outer_vertical")?; | ||
| 35 | + | ||
| 36 | + let terminal: String = get_table_field(&config, "terminal")?; | ||
| 37 | + let modkey = parse_modkey(&config)?; | ||
| 38 | + | ||
| 39 | + let tags = parse_tags(&config)?; | ||
| 40 | + let layout_symbols = parse_layout_symbols(&config)?; | ||
| 41 | + let keybindings = parse_keybindings(&config, modkey)?; | ||
| 42 | + let status_blocks = parse_status_blocks(&config)?; | ||
| 43 | + | ||
| 44 | + let scheme_normal = parse_color_scheme(&config, "scheme_normal")?; | ||
| 45 | + let scheme_occupied = parse_color_scheme(&config, "scheme_occupied")?; | ||
| 46 | + let scheme_selected = parse_color_scheme(&config, "scheme_selected")?; | ||
| 47 | + | ||
| 48 | + let autostart = parse_autostart(&config)?; | ||
| 49 | + | ||
| 50 | + Ok(crate::Config { | ||
| 51 | + border_width, | ||
| 52 | + border_focused, | ||
| 53 | + border_unfocused, | ||
| 54 | + font, | ||
| 55 | + gaps_enabled, | ||
| 56 | + gap_inner_horizontal, | ||
| 57 | + gap_inner_vertical, | ||
| 58 | + gap_outer_horizontal, | ||
| 59 | + gap_outer_vertical, | ||
| 60 | + terminal, | ||
| 61 | + modkey, | ||
| 62 | + tags, | ||
| 63 | + layout_symbols, | ||
| 64 | + keybindings, | ||
| 65 | + status_blocks, | ||
| 66 | + scheme_normal, | ||
| 67 | + scheme_occupied, | ||
| 68 | + scheme_selected, | ||
| 69 | + autostart, | ||
| 70 | + }) | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +fn get_table_field<T>(table: &Table, field: &str) -> Result<T, ConfigError> | ||
| 74 | +where | ||
| 75 | + T: mlua::FromLua, | ||
| 76 | +{ | ||
| 77 | + table | ||
| 78 | + .get::<T>(field) | ||
| 79 | + .map_err(|e| ConfigError::LuaError(format!("Failed to get field '{}': {}", field, e))) | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +fn parse_color(table: &Table, field: &str) -> Result<u32, ConfigError> { | ||
| 83 | + let value: Value = table | ||
| 84 | + .get(field) | ||
| 85 | + .map_err(|e| ConfigError::LuaError(format!("Failed to get color field '{}': {}", field, e)))?; | ||
| 86 | + | ||
| 87 | + match value { | ||
| 88 | + Value::String(s) => { | ||
| 89 | + let s = s.to_str().map_err(|e| { | ||
| 90 | + ConfigError::LuaError(format!("Invalid UTF-8 in color string: {}", e)) | ||
| 91 | + })?; | ||
| 92 | + parse_color_string(&s) | ||
| 93 | + } | ||
| 94 | + Value::Integer(i) => Ok(i as u32), | ||
| 95 | + Value::Number(n) => Ok(n as u32), | ||
| 96 | + _ => Err(ConfigError::LuaError(format!( | ||
| 97 | + "Color field '{}' must be a string or number", | ||
| 98 | + field | ||
| 99 | + ))), | ||
| 100 | + } | ||
| 101 | +} | ||
| 102 | + | ||
| 103 | +fn parse_color_string(s: &str) -> Result<u32, ConfigError> { | ||
| 104 | + let s = s.trim(); | ||
| 105 | + if s.starts_with('#') { | ||
| 106 | + u32::from_str_radix(&s[1..], 16) | ||
| 107 | + .map_err(|e| ConfigError::LuaError(format!("Invalid hex color '{}': {}", s, e))) | ||
| 108 | + } else if s.starts_with("0x") { | ||
| 109 | + u32::from_str_radix(&s[2..], 16) | ||
| 110 | + .map_err(|e| ConfigError::LuaError(format!("Invalid hex color '{}': {}", s, e))) | ||
| 111 | + } else { | ||
| 112 | + s.parse::<u32>() | ||
| 113 | + .map_err(|e| ConfigError::LuaError(format!("Invalid color '{}': {}", s, e))) | ||
| 114 | + } | ||
| 115 | +} | ||
| 116 | + | ||
| 117 | +fn parse_modkey(config: &Table) -> Result<KeyButMask, ConfigError> { | ||
| 118 | + let modkey_str: String = get_table_field(config, "modkey")?; | ||
| 119 | + parse_modkey_string(&modkey_str) | ||
| 120 | +} | ||
| 121 | + | ||
| 122 | +fn parse_modkey_string(s: &str) -> Result<KeyButMask, ConfigError> { | ||
| 123 | + match s { | ||
| 124 | + "Mod1" => Ok(KeyButMask::MOD1), | ||
| 125 | + "Mod2" => Ok(KeyButMask::MOD2), | ||
| 126 | + "Mod3" => Ok(KeyButMask::MOD3), | ||
| 127 | + "Mod4" => Ok(KeyButMask::MOD4), | ||
| 128 | + "Mod5" => Ok(KeyButMask::MOD5), | ||
| 129 | + "Shift" => Ok(KeyButMask::SHIFT), | ||
| 130 | + "Control" => Ok(KeyButMask::CONTROL), | ||
| 131 | + _ => Err(ConfigError::InvalidModkey(s.to_string())), | ||
| 132 | + } | ||
| 133 | +} | ||
| 134 | + | ||
| 135 | +fn parse_tags(config: &Table) -> Result<Vec<String>, ConfigError> { | ||
| 136 | + let tags_table: Table = get_table_field(config, "tags")?; | ||
| 137 | + let mut tags = Vec::new(); | ||
| 138 | + | ||
| 139 | + for i in 1..=tags_table.len().map_err(|e| { | ||
| 140 | + ConfigError::LuaError(format!("Failed to get tags length: {}", e)) | ||
| 141 | + })? { | ||
| 142 | + let tag: String = tags_table.get(i).map_err(|e| { | ||
| 143 | + ConfigError::LuaError(format!("Failed to get tag at index {}: {}", i, e)) | ||
| 144 | + })?; | ||
| 145 | + tags.push(tag); | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + Ok(tags) | ||
| 149 | +} | ||
| 150 | + | ||
| 151 | +fn parse_layout_symbols(config: &Table) -> Result<Vec<LayoutSymbolOverride>, ConfigError> { | ||
| 152 | + let layout_symbols_result: Result<Table, _> = config.get("layout_symbols"); | ||
| 153 | + | ||
| 154 | + match layout_symbols_result { | ||
| 155 | + Ok(layout_symbols_table) => { | ||
| 156 | + let mut layout_symbols = Vec::new(); | ||
| 157 | + | ||
| 158 | + for i in 1..=layout_symbols_table.len().map_err(|e| { | ||
| 159 | + ConfigError::LuaError(format!("Failed to get layout_symbols length: {}", e)) | ||
| 160 | + })? { | ||
| 161 | + let entry: Table = layout_symbols_table.get(i).map_err(|e| { | ||
| 162 | + ConfigError::LuaError(format!("Failed to get layout_symbol at index {}: {}", i, e)) | ||
| 163 | + })?; | ||
| 164 | + | ||
| 165 | + let name: String = get_table_field(&entry, "name")?; | ||
| 166 | + let symbol: String = get_table_field(&entry, "symbol")?; | ||
| 167 | + | ||
| 168 | + layout_symbols.push(LayoutSymbolOverride { name, symbol }); | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + Ok(layout_symbols) | ||
| 172 | + } | ||
| 173 | + Err(_) => Ok(Vec::new()), // layout_symbols is optional | ||
| 174 | + } | ||
| 175 | +} | ||
| 176 | + | ||
| 177 | +fn parse_keybindings( | ||
| 178 | + config: &Table, | ||
| 179 | + modkey: KeyButMask, | ||
| 180 | +) -> Result<Vec<KeyBinding>, ConfigError> { | ||
| 181 | + let keybindings_table: Table = get_table_field(config, "keybindings")?; | ||
| 182 | + let mut keybindings = Vec::new(); | ||
| 183 | + | ||
| 184 | + for i in 1..=keybindings_table.len().map_err(|e| { | ||
| 185 | + ConfigError::LuaError(format!("Failed to get keybindings length: {}", e)) | ||
| 186 | + })? { | ||
| 187 | + let kb_table: Table = keybindings_table.get(i).map_err(|e| { | ||
| 188 | + ConfigError::LuaError(format!("Failed to get keybinding at index {}: {}", i, e)) | ||
| 189 | + })?; | ||
| 190 | + | ||
| 191 | + let keys = parse_keypress_list(&kb_table, modkey)?; | ||
| 192 | + let action = parse_key_action(&kb_table)?; | ||
| 193 | + let arg = parse_arg(&kb_table)?; | ||
| 194 | + | ||
| 195 | + keybindings.push(KeyBinding::new(keys, action, arg)); | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + Ok(keybindings) | ||
| 199 | +} | ||
| 200 | + | ||
| 201 | +fn parse_keypress_list( | ||
| 202 | + kb_table: &Table, | ||
| 203 | + modkey: KeyButMask, | ||
| 204 | +) -> Result<Vec<KeyPress>, ConfigError> { | ||
| 205 | + // Check if 'keys' field exists (for keychords) | ||
| 206 | + let keys_result: Result<Table, _> = kb_table.get("keys"); | ||
| 207 | + | ||
| 208 | + if let Ok(keys_table) = keys_result { | ||
| 209 | + // Parse keychord | ||
| 210 | + let mut keys = Vec::new(); | ||
| 211 | + for i in 1..=keys_table.len().map_err(|e| { | ||
| 212 | + ConfigError::LuaError(format!("Failed to get keys length: {}", e)) | ||
| 213 | + })? { | ||
| 214 | + let key_entry: Table = keys_table.get(i).map_err(|e| { | ||
| 215 | + ConfigError::LuaError(format!("Failed to get key at index {}: {}", i, e)) | ||
| 216 | + })?; | ||
| 217 | + | ||
| 218 | + let modifiers = parse_modifiers(&key_entry, "modifiers", modkey)?; | ||
| 219 | + let keysym = parse_keysym(&key_entry, "key")?; | ||
| 220 | + | ||
| 221 | + keys.push(KeyPress { modifiers, keysym }); | ||
| 222 | + } | ||
| 223 | + Ok(keys) | ||
| 224 | + } else { | ||
| 225 | + // Parse single key (old format) | ||
| 226 | + let modifiers = parse_modifiers(kb_table, "modifiers", modkey)?; | ||
| 227 | + let keysym = parse_keysym(kb_table, "key")?; | ||
| 228 | + | ||
| 229 | + Ok(vec![KeyPress { modifiers, keysym }]) | ||
| 230 | + } | ||
| 231 | +} | ||
| 232 | + | ||
| 233 | +fn parse_modifiers( | ||
| 234 | + table: &Table, | ||
| 235 | + field: &str, | ||
| 236 | + modkey: KeyButMask, | ||
| 237 | +) -> Result<Vec<KeyButMask>, ConfigError> { | ||
| 238 | + let mods_table: Table = get_table_field(table, field)?; | ||
| 239 | + let mut modifiers = Vec::new(); | ||
| 240 | + | ||
| 241 | + for i in 1..=mods_table.len().map_err(|e| { | ||
| 242 | + ConfigError::LuaError(format!("Failed to get modifiers length: {}", e)) | ||
| 243 | + })? { | ||
| 244 | + let mod_str: String = mods_table.get(i).map_err(|e| { | ||
| 245 | + ConfigError::LuaError(format!("Failed to get modifier at index {}: {}", i, e)) | ||
| 246 | + })?; | ||
| 247 | + | ||
| 248 | + let modifier = if mod_str == "Mod" { | ||
| 249 | + modkey | ||
| 250 | + } else { | ||
| 251 | + parse_modkey_string(&mod_str)? | ||
| 252 | + }; | ||
| 253 | + | ||
| 254 | + modifiers.push(modifier); | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + Ok(modifiers) | ||
| 258 | +} | ||
| 259 | + | ||
| 260 | +fn parse_keysym(table: &Table, field: &str) -> Result<Keysym, ConfigError> { | ||
| 261 | + let key_str: String = get_table_field(table, field)?; | ||
| 262 | + string_to_keysym(&key_str) | ||
| 263 | +} | ||
| 264 | + | ||
| 265 | +fn string_to_keysym(s: &str) -> Result<Keysym, ConfigError> { | ||
| 266 | + let keysym = match s { | ||
| 267 | + "Return" => keysyms::XK_RETURN, | ||
| 268 | + "Q" => keysyms::XK_Q, | ||
| 269 | + "Escape" => keysyms::XK_ESCAPE, | ||
| 270 | + "Space" => keysyms::XK_SPACE, | ||
| 271 | + "Tab" => keysyms::XK_TAB, | ||
| 272 | + "Backspace" => keysyms::XK_BACKSPACE, | ||
| 273 | + "Delete" => keysyms::XK_DELETE, | ||
| 274 | + "F1" => keysyms::XK_F1, | ||
| 275 | + "F2" => keysyms::XK_F2, | ||
| 276 | + "F3" => keysyms::XK_F3, | ||
| 277 | + "F4" => keysyms::XK_F4, | ||
| 278 | + "F5" => keysyms::XK_F5, | ||
| 279 | + "F6" => keysyms::XK_F6, | ||
| 280 | + "F7" => keysyms::XK_F7, | ||
| 281 | + "F8" => keysyms::XK_F8, | ||
| 282 | + "F9" => keysyms::XK_F9, | ||
| 283 | + "F10" => keysyms::XK_F10, | ||
| 284 | + "F11" => keysyms::XK_F11, | ||
| 285 | + "F12" => keysyms::XK_F12, | ||
| 286 | + "A" => keysyms::XK_A, | ||
| 287 | + "B" => keysyms::XK_B, | ||
| 288 | + "C" => keysyms::XK_C, | ||
| 289 | + "D" => keysyms::XK_D, | ||
| 290 | + "E" => keysyms::XK_E, | ||
| 291 | + "F" => keysyms::XK_F, | ||
| 292 | + "G" => keysyms::XK_G, | ||
| 293 | + "H" => keysyms::XK_H, | ||
| 294 | + "I" => keysyms::XK_I, | ||
| 295 | + "J" => keysyms::XK_J, | ||
| 296 | + "K" => keysyms::XK_K, | ||
| 297 | + "L" => keysyms::XK_L, | ||
| 298 | + "M" => keysyms::XK_M, | ||
| 299 | + "N" => keysyms::XK_N, | ||
| 300 | + "O" => keysyms::XK_O, | ||
| 301 | + "P" => keysyms::XK_P, | ||
| 302 | + "R" => keysyms::XK_R, | ||
| 303 | + "S" => keysyms::XK_S, | ||
| 304 | + "T" => keysyms::XK_T, | ||
| 305 | + "U" => keysyms::XK_U, | ||
| 306 | + "V" => keysyms::XK_V, | ||
| 307 | + "W" => keysyms::XK_W, | ||
| 308 | + "X" => keysyms::XK_X, | ||
| 309 | + "Y" => keysyms::XK_Y, | ||
| 310 | + "Z" => keysyms::XK_Z, | ||
| 311 | + "0" => keysyms::XK_0, | ||
| 312 | + "1" => keysyms::XK_1, | ||
| 313 | + "2" => keysyms::XK_2, | ||
| 314 | + "3" => keysyms::XK_3, | ||
| 315 | + "4" => keysyms::XK_4, | ||
| 316 | + "5" => keysyms::XK_5, | ||
| 317 | + "6" => keysyms::XK_6, | ||
| 318 | + "7" => keysyms::XK_7, | ||
| 319 | + "8" => keysyms::XK_8, | ||
| 320 | + "9" => keysyms::XK_9, | ||
| 321 | + "Left" => keysyms::XK_LEFT, | ||
| 322 | + "Right" => keysyms::XK_RIGHT, | ||
| 323 | + "Up" => keysyms::XK_UP, | ||
| 324 | + "Down" => keysyms::XK_DOWN, | ||
| 325 | + "Home" => keysyms::XK_HOME, | ||
| 326 | + "End" => keysyms::XK_END, | ||
| 327 | + "PageUp" => keysyms::XK_PAGE_UP, | ||
| 328 | + "PageDown" => keysyms::XK_PAGE_DOWN, | ||
| 329 | + "Insert" => keysyms::XK_INSERT, | ||
| 330 | + "Minus" => keysyms::XK_MINUS, | ||
| 331 | + "Equal" => keysyms::XK_EQUAL, | ||
| 332 | + "BracketLeft" => keysyms::XK_LEFT_BRACKET, | ||
| 333 | + "BracketRight" => keysyms::XK_RIGHT_BRACKET, | ||
| 334 | + "Semicolon" => keysyms::XK_SEMICOLON, | ||
| 335 | + "Apostrophe" => keysyms::XK_APOSTROPHE, | ||
| 336 | + "Grave" => keysyms::XK_GRAVE, | ||
| 337 | + "Backslash" => keysyms::XK_BACKSLASH, | ||
| 338 | + "Comma" => keysyms::XK_COMMA, | ||
| 339 | + "Period" => keysyms::XK_PERIOD, | ||
| 340 | + "Slash" => keysyms::XK_SLASH, | ||
| 341 | + "AudioRaiseVolume" => keysyms::XF86_AUDIO_RAISE_VOLUME, | ||
| 342 | + "AudioLowerVolume" => keysyms::XF86_AUDIO_LOWER_VOLUME, | ||
| 343 | + "AudioMute" => keysyms::XF86_AUDIO_MUTE, | ||
| 344 | + "MonBrightnessUp" => keysyms::XF86_MON_BRIGHTNESS_UP, | ||
| 345 | + "MonBrightnessDown" => keysyms::XF86_MON_BRIGHTNESS_DOWN, | ||
| 346 | + _ => return Err(ConfigError::UnknownKey(s.to_string())), | ||
| 347 | + }; | ||
| 348 | + | ||
| 349 | + Ok(keysym) | ||
| 350 | +} | ||
| 351 | + | ||
| 352 | +fn parse_key_action(kb_table: &Table) -> Result<KeyAction, ConfigError> { | ||
| 353 | + let action_str: String = get_table_field(kb_table, "action")?; | ||
| 354 | + string_to_key_action(&action_str) | ||
| 355 | +} | ||
| 356 | + | ||
| 357 | +fn string_to_key_action(s: &str) -> Result<KeyAction, ConfigError> { | ||
| 358 | + let action = match s { | ||
| 359 | + "Spawn" => KeyAction::Spawn, | ||
| 360 | + "KillClient" => KeyAction::KillClient, | ||
| 361 | + "FocusStack" => KeyAction::FocusStack, | ||
| 362 | + "FocusDirection" => KeyAction::FocusDirection, | ||
| 363 | + "SwapDirection" => KeyAction::SwapDirection, | ||
| 364 | + "Quit" => KeyAction::Quit, | ||
| 365 | + "Restart" => KeyAction::Restart, | ||
| 366 | + "Recompile" => KeyAction::Recompile, | ||
| 367 | + "ViewTag" => KeyAction::ViewTag, | ||
| 368 | + "ToggleGaps" => KeyAction::ToggleGaps, | ||
| 369 | + "ToggleFullScreen" => KeyAction::ToggleFullScreen, | ||
| 370 | + "ToggleFloating" => KeyAction::ToggleFloating, | ||
| 371 | + "ChangeLayout" => KeyAction::ChangeLayout, | ||
| 372 | + "CycleLayout" => KeyAction::CycleLayout, | ||
| 373 | + "MoveToTag" => KeyAction::MoveToTag, | ||
| 374 | + "FocusMonitor" => KeyAction::FocusMonitor, | ||
| 375 | + "SmartMoveWin" => KeyAction::SmartMoveWin, | ||
| 376 | + "ExchangeClient" => KeyAction::ExchangeClient, | ||
| 377 | + "None" => KeyAction::None, | ||
| 378 | + _ => return Err(ConfigError::UnknownAction(s.to_string())), | ||
| 379 | + }; | ||
| 380 | + | ||
| 381 | + Ok(action) | ||
| 382 | +} | ||
| 383 | + | ||
| 384 | +fn parse_arg(kb_table: &Table) -> Result<Arg, ConfigError> { | ||
| 385 | + let arg_result: Result<Value, _> = kb_table.get("arg"); | ||
| 386 | + | ||
| 387 | + match arg_result { | ||
| 388 | + Ok(Value::Nil) | Err(_) => Ok(Arg::None), | ||
| 389 | + Ok(Value::String(s)) => { | ||
| 390 | + let s = s | ||
| 391 | + .to_str() | ||
| 392 | + .map_err(|e| ConfigError::LuaError(format!("Invalid UTF-8 in arg: {}", e)))?; | ||
| 393 | + Ok(Arg::Str(s.to_string())) | ||
| 394 | + } | ||
| 395 | + Ok(Value::Integer(i)) => Ok(Arg::Int(i as i32)), | ||
| 396 | + Ok(Value::Number(n)) => Ok(Arg::Int(n as i32)), | ||
| 397 | + Ok(Value::Table(t)) => { | ||
| 398 | + let mut arr = Vec::new(); | ||
| 399 | + for i in 1..=t | ||
| 400 | + .len() | ||
| 401 | + .map_err(|e| ConfigError::LuaError(format!("Failed to get arg array length: {}", e)))? | ||
| 402 | + { | ||
| 403 | + let item: String = t.get(i).map_err(|e| { | ||
| 404 | + ConfigError::LuaError(format!("Failed to get arg array item at index {}: {}", i, e)) | ||
| 405 | + })?; | ||
| 406 | + arr.push(item); | ||
| 407 | + } | ||
| 408 | + Ok(Arg::Array(arr)) | ||
| 409 | + } | ||
| 410 | + Ok(_) => Err(ConfigError::LuaError( | ||
| 411 | + "Arg must be nil, string, number, or array".to_string(), | ||
| 412 | + )), | ||
| 413 | + } | ||
| 414 | +} | ||
| 415 | + | ||
| 416 | +fn parse_status_blocks(config: &Table) -> Result<Vec<BlockConfig>, ConfigError> { | ||
| 417 | + let blocks_table: Table = get_table_field(config, "status_blocks")?; | ||
| 418 | + let mut blocks = Vec::new(); | ||
| 419 | + | ||
| 420 | + for i in 1..=blocks_table.len().map_err(|e| { | ||
| 421 | + ConfigError::LuaError(format!("Failed to get status_blocks length: {}", e)) | ||
| 422 | + })? { | ||
| 423 | + let block_table: Table = blocks_table.get(i).map_err(|e| { | ||
| 424 | + ConfigError::LuaError(format!("Failed to get status_block at index {}: {}", i, e)) | ||
| 425 | + })?; | ||
| 426 | + | ||
| 427 | + let format: String = get_table_field(&block_table, "format")?; | ||
| 428 | + let command_str: String = get_table_field(&block_table, "command")?; | ||
| 429 | + | ||
| 430 | + // Parse interval_secs - handle both integer and number types | ||
| 431 | + let interval_secs: u64 = { | ||
| 432 | + let value: Value = block_table.get("interval_secs").map_err(|e| { | ||
| 433 | + ConfigError::LuaError(format!("Failed to get interval_secs: {}", e)) | ||
| 434 | + })?; | ||
| 435 | + match value { | ||
| 436 | + Value::Integer(i) => i as u64, | ||
| 437 | + Value::Number(n) => n as u64, | ||
| 438 | + _ => return Err(ConfigError::LuaError("interval_secs must be a number".to_string())), | ||
| 439 | + } | ||
| 440 | + }; | ||
| 441 | + | ||
| 442 | + let color: u32 = parse_color(&block_table, "color")?; | ||
| 443 | + let underline: bool = get_table_field(&block_table, "underline")?; | ||
| 444 | + | ||
| 445 | + let command = match command_str.as_str() { | ||
| 446 | + "DateTime" => { | ||
| 447 | + let fmt: String = get_table_field(&block_table, "command_arg")?; | ||
| 448 | + BlockCommand::DateTime(fmt) | ||
| 449 | + } | ||
| 450 | + "Shell" => { | ||
| 451 | + let cmd: String = get_table_field(&block_table, "command_arg")?; | ||
| 452 | + BlockCommand::Shell(cmd) | ||
| 453 | + } | ||
| 454 | + "Ram" => BlockCommand::Ram, | ||
| 455 | + "Static" => { | ||
| 456 | + let text_result: Result<String, _> = block_table.get("command_arg"); | ||
| 457 | + let text = text_result.unwrap_or_default(); | ||
| 458 | + BlockCommand::Static(text) | ||
| 459 | + } | ||
| 460 | + "Battery" => { | ||
| 461 | + let formats_table: Table = get_table_field(&block_table, "battery_formats")?; | ||
| 462 | + let format_charging: String = get_table_field(&formats_table, "charging")?; | ||
| 463 | + let format_discharging: String = get_table_field(&formats_table, "discharging")?; | ||
| 464 | + let format_full: String = get_table_field(&formats_table, "full")?; | ||
| 465 | + | ||
| 466 | + BlockCommand::Battery { | ||
| 467 | + format_charging, | ||
| 468 | + format_discharging, | ||
| 469 | + format_full, | ||
| 470 | + } | ||
| 471 | + } | ||
| 472 | + _ => return Err(ConfigError::UnknownBlockCommand(command_str)), | ||
| 473 | + }; | ||
| 474 | + | ||
| 475 | + blocks.push(BlockConfig { | ||
| 476 | + format, | ||
| 477 | + command, | ||
| 478 | + interval_secs, | ||
| 479 | + color, | ||
| 480 | + underline, | ||
| 481 | + }); | ||
| 482 | + } | ||
| 483 | + | ||
| 484 | + Ok(blocks) | ||
| 485 | +} | ||
| 486 | + | ||
| 487 | +fn parse_color_scheme(config: &Table, field: &str) -> Result<ColorScheme, ConfigError> { | ||
| 488 | + let scheme_table: Table = get_table_field(config, field)?; | ||
| 489 | + | ||
| 490 | + let foreground = parse_color(&scheme_table, "foreground")?; | ||
| 491 | + let background = parse_color(&scheme_table, "background")?; | ||
| 492 | + let underline = parse_color(&scheme_table, "underline")?; | ||
| 493 | + | ||
| 494 | + Ok(ColorScheme { | ||
| 495 | + foreground, | ||
| 496 | + background, | ||
| 497 | + underline, | ||
| 498 | + }) | ||
| 499 | +} | ||
| 500 | + | ||
| 501 | +fn parse_autostart(config: &Table) -> Result<Vec<String>, ConfigError> { | ||
| 502 | + let autostart_result: Result<Table, _> = config.get("autostart"); | ||
| 503 | + | ||
| 504 | + match autostart_result { | ||
| 505 | + Ok(autostart_table) => { | ||
| 506 | + let mut autostart = Vec::new(); | ||
| 507 | + | ||
| 508 | + for i in 1..=autostart_table.len().map_err(|e| { | ||
| 509 | + ConfigError::LuaError(format!("Failed to get autostart length: {}", e)) | ||
| 510 | + })? { | ||
| 511 | + let cmd: String = autostart_table.get(i).map_err(|e| { | ||
| 512 | + ConfigError::LuaError(format!("Failed to get autostart command at index {}: {}", i, e)) | ||
| 513 | + })?; | ||
| 514 | + autostart.push(cmd); | ||
| 515 | + } | ||
| 516 | + | ||
| 517 | + Ok(autostart) | ||
| 518 | + } | ||
| 519 | + Err(_) => Ok(Vec::new()), // autostart is optional | ||
| 520 | + } | ||
| 521 | +} | ||
| 522 | + | ||
| 523 | +#[cfg(test)] | ||
| 524 | +mod tests { | ||
| 525 | + use super::*; | ||
| 526 | + | ||
| 527 | + #[test] | ||
| 528 | + fn test_parse_minimal_lua_config() { | ||
| 529 | + let config_str = r#" | ||
| 530 | +config = { | ||
| 531 | + border_width = 2, | ||
| 532 | + border_focused = 0x6dade3, | ||
| 533 | + border_unfocused = 0xbbbbbb, | ||
| 534 | + font = "monospace:style=Bold:size=10", | ||
| 535 | + | ||
| 536 | + gaps_enabled = true, | ||
| 537 | + gap_inner_horizontal = 5, | ||
| 538 | + gap_inner_vertical = 5, | ||
| 539 | + gap_outer_horizontal = 5, | ||
| 540 | + gap_outer_vertical = 5, | ||
| 541 | + | ||
| 542 | + modkey = "Mod4", | ||
| 543 | + terminal = "st", | ||
| 544 | + | ||
| 545 | + tags = {"1", "2", "3"}, | ||
| 546 | + | ||
| 547 | + keybindings = { | ||
| 548 | + {modifiers = {"Mod4"}, key = "Return", action = "Spawn", arg = "st"}, | ||
| 549 | + {modifiers = {"Mod4"}, key = "Q", action = "KillClient"}, | ||
| 550 | + }, | ||
| 551 | + | ||
| 552 | + status_blocks = { | ||
| 553 | + {format = "{}", command = "DateTime", command_arg = "%H:%M", interval_secs = 1, color = 0xffffff, underline = true}, | ||
| 554 | + }, | ||
| 555 | + | ||
| 556 | + scheme_normal = {foreground = 0xffffff, background = 0x000000, underline = 0x444444}, | ||
| 557 | + scheme_occupied = {foreground = 0xffffff, background = 0x000000, underline = 0x444444}, | ||
| 558 | + scheme_selected = {foreground = 0xffffff, background = 0x000000, underline = 0x444444}, | ||
| 559 | + | ||
| 560 | + autostart = {}, | ||
| 561 | +} | ||
| 562 | +"#; | ||
| 563 | + | ||
| 564 | + let config = parse_lua_config(config_str).expect("Failed to parse config"); | ||
| 565 | + | ||
| 566 | + assert_eq!(config.border_width, 2); | ||
| 567 | + assert_eq!(config.border_focused, 0x6dade3); | ||
| 568 | + assert_eq!(config.terminal, "st"); | ||
| 569 | + assert_eq!(config.tags.len(), 3); | ||
| 570 | + assert_eq!(config.keybindings.len(), 2); | ||
| 571 | + assert_eq!(config.status_blocks.len(), 1); | ||
| 572 | + assert!(config.gaps_enabled); | ||
| 573 | + } | ||
| 574 | +} | ||
+4 −0 src/config/mod.rs
| @@ -1,3 +1,5 @@ | |||
| 1 | +mod lua; | ||
| 2 | + | ||
| 1 | use crate::bar::{BlockCommand, BlockConfig}; | 3 | use crate::bar::{BlockCommand, BlockConfig}; |
| 2 | use crate::errors::ConfigError; | 4 | use crate::errors::ConfigError; |
| 3 | use crate::keyboard::handlers::{KeyBinding, KeyPress}; | 5 | use crate::keyboard::handlers::{KeyBinding, KeyPress}; |
| @@ -8,6 +10,8 @@ use serde::Deserialize; | |||
| 8 | use std::collections::HashMap; | 10 | use std::collections::HashMap; |
| 9 | use x11rb::protocol::xproto::KeyButMask; | 11 | use x11rb::protocol::xproto::KeyButMask; |
| 10 | 12 | ||
| 13 | +pub use lua::parse_lua_config; | ||
| 14 | + | ||
| 11 | #[derive(Debug, Deserialize)] | 15 | #[derive(Debug, Deserialize)] |
| 12 | pub enum ModKey { | 16 | pub enum ModKey { |
| 13 | Mod, | 17 | Mod, |
+2 −0 src/errors.rs
| @@ -23,6 +23,7 @@ pub enum X11Error { | |||
| 23 | #[derive(Debug)] | 23 | #[derive(Debug)] |
| 24 | pub enum ConfigError { | 24 | pub enum ConfigError { |
| 25 | ParseError(ron::error::SpannedError), | 25 | ParseError(ron::error::SpannedError), |
| 26 | + LuaError(String), | ||
| 26 | InvalidModkey(String), | 27 | InvalidModkey(String), |
| 27 | UnknownKey(String), | 28 | UnknownKey(String), |
| 28 | UnknownAction(String), | 29 | UnknownAction(String), |
| @@ -68,6 +69,7 @@ impl std::fmt::Display for ConfigError { | |||
| 68 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 69 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 69 | match self { | 70 | match self { |
| 70 | Self::ParseError(err) => write!(f, "Failed to parse RON config: {}", err), | 71 | Self::ParseError(err) => write!(f, "Failed to parse RON config: {}", err), |
| 72 | + Self::LuaError(msg) => write!(f, "Lua config error: {}", msg), | ||
| 71 | Self::InvalidModkey(key) => write!(f, "Invalid modkey: {}", key), | 73 | Self::InvalidModkey(key) => write!(f, "Invalid modkey: {}", key), |
| 72 | Self::UnknownKey(key) => write!(f, "Unknown key: {}", key), | 74 | Self::UnknownKey(key) => write!(f, "Unknown key: {}", key), |
| 73 | Self::UnknownAction(action) => write!(f, "Unknown action: {}", action), | 75 | Self::UnknownAction(action) => write!(f, "Unknown action: {}", action), |
+309 −0 templates/config.lua new file mode 100644
| @@ -0,0 +1,309 @@ | |||
| 1 | +-- OXWM Configuration File (Lua) | ||
| 2 | +-- Edit this file and reload with Mod+Shift+R (no compilation needed!) | ||
| 3 | + | ||
| 4 | +---@class LayoutSymbol | ||
| 5 | +---@field name string The internal layout name (e.g., "tiling", "normie") | ||
| 6 | +---@field symbol string The display symbol for the layout (e.g., "[T]", "[F]") | ||
| 7 | + | ||
| 8 | +---@class KeyBinding | ||
| 9 | +---@field modifiers string[] List of modifiers: "Mod", "Mod1"-"Mod5", "Shift", "Control" | ||
| 10 | +---@field key string The key name (e.g., "Return", "Q", "1", "Space") | ||
| 11 | +---@field action string Action to perform (see below for list) | ||
| 12 | +---@field arg? string|number|string[] Optional argument for the action | ||
| 13 | + | ||
| 14 | +---@class KeyChord | ||
| 15 | +---@field keys {modifiers: string[], key: string}[] Sequence of keys to press | ||
| 16 | +---@field action string Action to perform when chord completes | ||
| 17 | +---@field arg? string|number|string[] Optional argument for the action | ||
| 18 | + | ||
| 19 | +---@class StatusBlock | ||
| 20 | +---@field format string Display format with {} placeholders | ||
| 21 | +---@field command string Command type: "Ram", "DateTime", "Shell", "Static", "Battery" | ||
| 22 | +---@field command_arg? string Argument for command (shell command, date format, etc.) | ||
| 23 | +---@field interval_secs number Update interval in seconds | ||
| 24 | +---@field color number Color as hex number (e.g., 0xff0000 for red) | ||
| 25 | +---@field underline boolean Whether to show underline | ||
| 26 | +---@field battery_formats? {charging: string, discharging: string, full: string} Battery format strings | ||
| 27 | + | ||
| 28 | +---@class ColorScheme | ||
| 29 | +---@field foreground number Foreground color (hex) | ||
| 30 | +---@field background number Background color (hex) | ||
| 31 | +---@field underline number Underline color (hex) | ||
| 32 | + | ||
| 33 | +---@class Config | ||
| 34 | +---@field border_width number Width of window borders in pixels | ||
| 35 | +---@field border_focused number Color for focused window border (hex) | ||
| 36 | +---@field border_unfocused number Color for unfocused window border (hex) | ||
| 37 | +---@field font string Font specification (e.g., "monospace:style=Bold:size=10") | ||
| 38 | +---@field gaps_enabled boolean Whether gaps are enabled | ||
| 39 | +---@field gap_inner_horizontal number Inner horizontal gap size | ||
| 40 | +---@field gap_inner_vertical number Inner vertical gap size | ||
| 41 | +---@field gap_outer_horizontal number Outer horizontal gap size | ||
| 42 | +---@field gap_outer_vertical number Outer vertical gap size | ||
| 43 | +---@field modkey string Main modifier key (e.g., "Mod4" for Super) | ||
| 44 | +---@field terminal string Terminal emulator command | ||
| 45 | +---@field tags string[] List of workspace tag names | ||
| 46 | +---@field layout_symbols LayoutSymbol[] Custom layout symbols | ||
| 47 | +---@field keybindings (KeyBinding|KeyChord)[] List of keybindings | ||
| 48 | +---@field status_blocks StatusBlock[] Status bar configuration blocks | ||
| 49 | +---@field scheme_normal ColorScheme Color scheme for normal tags | ||
| 50 | +---@field scheme_occupied ColorScheme Color scheme for occupied tags | ||
| 51 | +---@field scheme_selected ColorScheme Color scheme for selected tag | ||
| 52 | +---@field autostart string[] Commands to run on startup | ||
| 53 | + | ||
| 54 | +-- Available Actions: | ||
| 55 | +-- "Spawn" - Launch a program (arg: string or string[]) | ||
| 56 | +-- "KillClient" - Close focused window | ||
| 57 | +-- "FocusStack" - Focus next/prev in stack (arg: 1 or -1) | ||
| 58 | +-- "FocusDirection" - Focus by direction (arg: 0=up, 1=down, 2=left, 3=right) | ||
| 59 | +-- "SwapDirection" - Swap window by direction (arg: 0=up, 1=down, 2=left, 3=right) | ||
| 60 | +-- "Quit" - Exit window manager | ||
| 61 | +-- "Restart" - Restart and reload config | ||
| 62 | +-- "Recompile" - Recompile and restart | ||
| 63 | +-- "ViewTag" - Switch to tag (arg: tag index) | ||
| 64 | +-- "MoveToTag" - Move window to tag (arg: tag index) | ||
| 65 | +-- "ToggleGaps" - Toggle gaps on/off | ||
| 66 | +-- "ToggleFullScreen" - Toggle fullscreen mode | ||
| 67 | +-- "ToggleFloating" - Toggle floating mode | ||
| 68 | +-- "ChangeLayout" - Switch to specific layout (arg: layout name) | ||
| 69 | +-- "CycleLayout" - Cycle through layouts | ||
| 70 | +-- "FocusMonitor" - Focus monitor (arg: 1 or -1) | ||
| 71 | +-- "SmartMoveWin" - Smart window movement | ||
| 72 | +-- "ExchangeClient" - Exchange window positions | ||
| 73 | + | ||
| 74 | +-- Available Modifiers: | ||
| 75 | +-- "Mod" - Replaced with configured modkey | ||
| 76 | +-- "Mod1" - Alt key | ||
| 77 | +-- "Mod4" - Super/Windows key | ||
| 78 | +-- "Shift" - Shift key | ||
| 79 | +-- "Control" - Control key | ||
| 80 | +-- "Mod2", "Mod3", "Mod5" - Additional modifiers | ||
| 81 | + | ||
| 82 | +-- Define variables for easy customization | ||
| 83 | +local terminal = "st" | ||
| 84 | +local modkey = "Mod4" | ||
| 85 | +local secondary_modkey = "Mod1" | ||
| 86 | + | ||
| 87 | +-- Color palette (Tokyo Night theme) | ||
| 88 | +local colors = { | ||
| 89 | + blue = 0x6dade3, | ||
| 90 | + grey = 0xbbbbbb, | ||
| 91 | + green = 0x9ece6a, | ||
| 92 | + red = 0xf7768e, | ||
| 93 | + cyan = 0x0db9d7, | ||
| 94 | + purple = 0xad8ee6, | ||
| 95 | + lavender = 0xa9b1d6, | ||
| 96 | + bg = 0x1a1b26, | ||
| 97 | + fg = 0xbbbbbb, | ||
| 98 | + light_blue = 0x7aa2f7, | ||
| 99 | +} | ||
| 100 | + | ||
| 101 | +-- Main configuration table | ||
| 102 | +---@type Config | ||
| 103 | +config = { | ||
| 104 | + -- Appearance | ||
| 105 | + border_width = 2, | ||
| 106 | + border_focused = colors.blue, | ||
| 107 | + border_unfocused = colors.grey, | ||
| 108 | + font = "monospace:style=Bold:size=10", | ||
| 109 | + | ||
| 110 | + -- Window gaps | ||
| 111 | + gaps_enabled = true, | ||
| 112 | + gap_inner_horizontal = 5, | ||
| 113 | + gap_inner_vertical = 5, | ||
| 114 | + gap_outer_horizontal = 5, | ||
| 115 | + gap_outer_vertical = 5, | ||
| 116 | + | ||
| 117 | + -- Basics | ||
| 118 | + modkey = modkey, | ||
| 119 | + terminal = terminal, | ||
| 120 | + | ||
| 121 | + -- Workspace tags | ||
| 122 | + tags = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}, | ||
| 123 | + | ||
| 124 | + -- Layout symbol overrides | ||
| 125 | + layout_symbols = { | ||
| 126 | + {name = "tiling", symbol = "[T]"}, | ||
| 127 | + {name = "normie", symbol = "[F]"}, | ||
| 128 | + }, | ||
| 129 | + | ||
| 130 | + -- Keybindings | ||
| 131 | + -- | ||
| 132 | + -- Format: | ||
| 133 | + -- Single key: {modifiers = {...}, key = "X", action = "...", arg = ...} | ||
| 134 | + -- Keychord: {keys = {{modifiers = {...}, key = "X"}, {modifiers = {...}, key = "Y"}}, action = "...", arg = ...} | ||
| 135 | + -- | ||
| 136 | + -- Available modifiers: "Mod", "Mod1", "Mod2", "Mod3", "Mod4", "Mod5", "Shift", "Control" | ||
| 137 | + -- "Mod" will be replaced with the configured modkey | ||
| 138 | + -- | ||
| 139 | + -- Available actions: | ||
| 140 | + -- "Spawn", "KillClient", "FocusStack", "FocusDirection", "SwapDirection", | ||
| 141 | + -- "Quit", "Restart", "Recompile", "ViewTag", "ToggleGaps", "ToggleFullScreen", | ||
| 142 | + -- "ToggleFloating", "ChangeLayout", "CycleLayout", "MoveToTag", "FocusMonitor", | ||
| 143 | + -- "SmartMoveWin", "ExchangeClient" | ||
| 144 | + -- | ||
| 145 | + -- arg can be: string, number, array of strings, or omitted (nil) | ||
| 146 | + -- | ||
| 147 | + -- You can cancel any in-progress keychord by pressing Escape. | ||
| 148 | + keybindings = { | ||
| 149 | + -- Basic window management | ||
| 150 | + {modifiers = {"Mod"}, key = "Return", action = "Spawn", arg = terminal}, | ||
| 151 | + {modifiers = {"Mod"}, key = "D", action = "Spawn", arg = {"sh", "-c", "dmenu_run -l 10"}}, | ||
| 152 | + {modifiers = {"Mod"}, key = "S", action = "Spawn", arg = {"sh", "-c", "maim -s | xclip -selection clipboard -t image/png"}}, | ||
| 153 | + {modifiers = {"Mod"}, key = "Q", action = "KillClient"}, | ||
| 154 | + {modifiers = {"Mod", "Shift"}, key = "F", action = "ToggleFullScreen"}, | ||
| 155 | + {modifiers = {"Mod", "Shift"}, key = "Space", action = "ToggleFloating"}, | ||
| 156 | + | ||
| 157 | + -- Layout management | ||
| 158 | + {modifiers = {"Mod"}, key = "F", action = "ChangeLayout", arg = "normie"}, | ||
| 159 | + {modifiers = {"Mod"}, key = "C", action = "ChangeLayout", arg = "tiling"}, | ||
| 160 | + {modifiers = {secondary_modkey}, key = "N", action = "CycleLayout"}, | ||
| 161 | + {modifiers = {"Mod"}, key = "A", action = "ToggleGaps"}, | ||
| 162 | + | ||
| 163 | + -- WM control | ||
| 164 | + {modifiers = {"Mod", "Shift"}, key = "Q", action = "Quit"}, | ||
| 165 | + {modifiers = {"Mod", "Shift"}, key = "R", action = "Restart"}, | ||
| 166 | + | ||
| 167 | + -- Focus movement (vim-style hjkl) | ||
| 168 | + {modifiers = {"Mod"}, key = "H", action = "FocusDirection", arg = 2}, -- left | ||
| 169 | + {modifiers = {"Mod"}, key = "J", action = "FocusDirection", arg = 1}, -- down | ||
| 170 | + {modifiers = {"Mod"}, key = "K", action = "FocusDirection", arg = 0}, -- up | ||
| 171 | + {modifiers = {"Mod"}, key = "L", action = "FocusDirection", arg = 3}, -- right | ||
| 172 | + | ||
| 173 | + -- Window swapping (vim-style hjkl) | ||
| 174 | + {modifiers = {"Mod", "Shift"}, key = "H", action = "SwapDirection", arg = 2}, -- left | ||
| 175 | + {modifiers = {"Mod", "Shift"}, key = "J", action = "SwapDirection", arg = 1}, -- down | ||
| 176 | + {modifiers = {"Mod", "Shift"}, key = "K", action = "SwapDirection", arg = 0}, -- up | ||
| 177 | + {modifiers = {"Mod", "Shift"}, key = "L", action = "SwapDirection", arg = 3}, -- right | ||
| 178 | + | ||
| 179 | + -- Monitor focus | ||
| 180 | + {modifiers = {"Mod"}, key = "Comma", action = "FocusMonitor", arg = -1}, | ||
| 181 | + {modifiers = {"Mod"}, key = "Period", action = "FocusMonitor", arg = 1}, | ||
| 182 | + | ||
| 183 | + -- View tags | ||
| 184 | + {modifiers = {"Mod"}, key = "1", action = "ViewTag", arg = 0}, | ||
| 185 | + {modifiers = {"Mod"}, key = "2", action = "ViewTag", arg = 1}, | ||
| 186 | + {modifiers = {"Mod"}, key = "3", action = "ViewTag", arg = 2}, | ||
| 187 | + {modifiers = {"Mod"}, key = "4", action = "ViewTag", arg = 3}, | ||
| 188 | + {modifiers = {"Mod"}, key = "5", action = "ViewTag", arg = 4}, | ||
| 189 | + {modifiers = {"Mod"}, key = "6", action = "ViewTag", arg = 5}, | ||
| 190 | + {modifiers = {"Mod"}, key = "7", action = "ViewTag", arg = 6}, | ||
| 191 | + {modifiers = {"Mod"}, key = "8", action = "ViewTag", arg = 7}, | ||
| 192 | + {modifiers = {"Mod"}, key = "9", action = "ViewTag", arg = 8}, | ||
| 193 | + | ||
| 194 | + -- Move window to tag | ||
| 195 | + {modifiers = {"Mod", "Shift"}, key = "1", action = "MoveToTag", arg = 0}, | ||
| 196 | + {modifiers = {"Mod", "Shift"}, key = "2", action = "MoveToTag", arg = 1}, | ||
| 197 | + {modifiers = {"Mod", "Shift"}, key = "3", action = "MoveToTag", arg = 2}, | ||
| 198 | + {modifiers = {"Mod", "Shift"}, key = "4", action = "MoveToTag", arg = 3}, | ||
| 199 | + {modifiers = {"Mod", "Shift"}, key = "5", action = "MoveToTag", arg = 4}, | ||
| 200 | + {modifiers = {"Mod", "Shift"}, key = "6", action = "MoveToTag", arg = 5}, | ||
| 201 | + {modifiers = {"Mod", "Shift"}, key = "7", action = "MoveToTag", arg = 6}, | ||
| 202 | + {modifiers = {"Mod", "Shift"}, key = "8", action = "MoveToTag", arg = 7}, | ||
| 203 | + {modifiers = {"Mod", "Shift"}, key = "9", action = "MoveToTag", arg = 8}, | ||
| 204 | + | ||
| 205 | + -- Example keychord: Mod+Space, then T to spawn terminal | ||
| 206 | + { | ||
| 207 | + keys = { | ||
| 208 | + {modifiers = {"Mod4"}, key = "Space"}, | ||
| 209 | + {modifiers = {}, key = "T"} | ||
| 210 | + }, | ||
| 211 | + action = "Spawn", | ||
| 212 | + arg = terminal | ||
| 213 | + }, | ||
| 214 | + }, | ||
| 215 | + | ||
| 216 | + -- Status bar blocks | ||
| 217 | + -- | ||
| 218 | + -- Available commands: | ||
| 219 | + -- "Ram" - Shows RAM usage (no command_arg needed) | ||
| 220 | + -- "DateTime" - Shows date/time with strftime format in command_arg | ||
| 221 | + -- "Shell" - Runs shell command from command_arg | ||
| 222 | + -- "Static" - Static text from command_arg | ||
| 223 | + -- "Battery" - Shows battery status (requires battery_formats table) | ||
| 224 | + -- | ||
| 225 | + -- Battery formats example: | ||
| 226 | + -- battery_formats = { | ||
| 227 | + -- charging = "⚡ {}%", | ||
| 228 | + -- discharging = "🔋 {}%", | ||
| 229 | + -- full = "✓ {}%" | ||
| 230 | + -- } | ||
| 231 | + status_blocks = { | ||
| 232 | + { | ||
| 233 | + format = "Ram: {used}/{total} GB", | ||
| 234 | + command = "Ram", | ||
| 235 | + interval_secs = 5, | ||
| 236 | + color = colors.light_blue, | ||
| 237 | + underline = true | ||
| 238 | + }, | ||
| 239 | + { | ||
| 240 | + format = " │ ", | ||
| 241 | + command = "Static", | ||
| 242 | + interval_secs = 999999999, -- Very large number for static blocks (never update) | ||
| 243 | + color = colors.lavender, | ||
| 244 | + underline = false | ||
| 245 | + }, | ||
| 246 | + { | ||
| 247 | + format = "Kernel: {}", | ||
| 248 | + command = "Shell", | ||
| 249 | + command_arg = "uname -r", | ||
| 250 | + interval_secs = 999999999, | ||
| 251 | + color = colors.red, | ||
| 252 | + underline = true | ||
| 253 | + }, | ||
| 254 | + { | ||
| 255 | + format = " │ ", | ||
| 256 | + command = "Static", | ||
| 257 | + interval_secs = 999999999, | ||
| 258 | + color = colors.lavender, | ||
| 259 | + underline = false | ||
| 260 | + }, | ||
| 261 | + { | ||
| 262 | + format = "{}", | ||
| 263 | + command = "DateTime", | ||
| 264 | + command_arg = "%a, %b %d - %-I:%M %P", | ||
| 265 | + interval_secs = 1, | ||
| 266 | + color = colors.cyan, | ||
| 267 | + underline = true | ||
| 268 | + }, | ||
| 269 | + }, | ||
| 270 | + | ||
| 271 | + -- Color schemes for bar | ||
| 272 | + scheme_normal = { | ||
| 273 | + foreground = colors.fg, | ||
| 274 | + background = colors.bg, | ||
| 275 | + underline = 0x444444 | ||
| 276 | + }, | ||
| 277 | + scheme_occupied = { | ||
| 278 | + foreground = colors.cyan, | ||
| 279 | + background = colors.bg, | ||
| 280 | + underline = colors.cyan | ||
| 281 | + }, | ||
| 282 | + scheme_selected = { | ||
| 283 | + foreground = colors.cyan, | ||
| 284 | + background = colors.bg, | ||
| 285 | + underline = colors.purple | ||
| 286 | + }, | ||
| 287 | + | ||
| 288 | + -- Autostart commands | ||
| 289 | + -- These are executed when the window manager starts | ||
| 290 | + -- Add your startup applications here | ||
| 291 | + autostart = { | ||
| 292 | + -- Uncomment and add your autostart commands: | ||
| 293 | + -- "picom -b", | ||
| 294 | + -- "nitrogen --restore &", | ||
| 295 | + -- "dunst &", | ||
| 296 | + }, | ||
| 297 | +} | ||
| 298 | + | ||
| 299 | +-- You can also add helper functions for more complex configs: | ||
| 300 | +-- | ||
| 301 | +-- Example: Generate keybindings programmatically | ||
| 302 | +-- for i = 1, 9 do | ||
| 303 | +-- table.insert(config.keybindings, { | ||
| 304 | +-- modifiers = {"Mod"}, | ||
| 305 | +-- key = tostring(i), | ||
| 306 | +-- action = "ViewTag", | ||
| 307 | +-- arg = i - 1 | ||
| 308 | +-- }) | ||
| 309 | +-- end | ||