refactored to allow ron file, and not have to deal with compiling or initting. added ron parser
Browse files
+54 −1 Cargo.lock
| @@ -23,11 +23,20 @@ version = "1.5.0" | ||
| 23 | 23 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 24 | 24 | checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" |
| 25 | 25 | |
| 26 | +[[package]] | |
| 27 | +name = "base64" | |
| 28 | +version = "0.21.7" | |
| 29 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 30 | +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" | |
| 31 | + | |
| 26 | 32 | [[package]] |
| 27 | 33 | name = "bitflags" |
| 28 | 34 | version = "2.9.4" |
| 29 | 35 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 30 | 36 | checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" |
| 37 | +dependencies = [ | |
| 38 | + "serde", | |
| 39 | +] | |
| 31 | 40 | |
| 32 | 41 | [[package]] |
| 33 | 42 | name = "bumpalo" |
| @@ -213,11 +222,13 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" | ||
| 213 | 222 | |
| 214 | 223 | [[package]] |
| 215 | 224 | name = "oxwm" |
| 216 | -version = "0.1.11" | |
| 225 | +version = "0.1.12" | |
| 217 | 226 | dependencies = [ |
| 218 | 227 | "anyhow", |
| 219 | 228 | "chrono", |
| 220 | 229 | "dirs", |
| 230 | + "ron", | |
| 231 | + "serde", | |
| 221 | 232 | "x11", |
| 222 | 233 | "x11rb", |
| 223 | 234 | ] |
| @@ -257,6 +268,18 @@ dependencies = [ | ||
| 257 | 268 | "thiserror", |
| 258 | 269 | ] |
| 259 | 270 | |
| 271 | +[[package]] | |
| 272 | +name = "ron" | |
| 273 | +version = "0.8.1" | |
| 274 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 275 | +checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" | |
| 276 | +dependencies = [ | |
| 277 | + "base64", | |
| 278 | + "bitflags", | |
| 279 | + "serde", | |
| 280 | + "serde_derive", | |
| 281 | +] | |
| 282 | + | |
| 260 | 283 | [[package]] |
| 261 | 284 | name = "rustix" |
| 262 | 285 | version = "1.1.2" |
| @@ -276,6 +299,36 @@ version = "1.0.22" | ||
| 276 | 299 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 277 | 300 | checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" |
| 278 | 301 | |
| 302 | +[[package]] | |
| 303 | +name = "serde" | |
| 304 | +version = "1.0.228" | |
| 305 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 306 | +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" | |
| 307 | +dependencies = [ | |
| 308 | + "serde_core", | |
| 309 | + "serde_derive", | |
| 310 | +] | |
| 311 | + | |
| 312 | +[[package]] | |
| 313 | +name = "serde_core" | |
| 314 | +version = "1.0.228" | |
| 315 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 316 | +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" | |
| 317 | +dependencies = [ | |
| 318 | + "serde_derive", | |
| 319 | +] | |
| 320 | + | |
| 321 | +[[package]] | |
| 322 | +name = "serde_derive" | |
| 323 | +version = "1.0.228" | |
| 324 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 325 | +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" | |
| 326 | +dependencies = [ | |
| 327 | + "proc-macro2", | |
| 328 | + "quote", | |
| 329 | + "syn", | |
| 330 | +] | |
| 331 | + | |
| 279 | 332 | [[package]] |
| 280 | 333 | name = "shlex" |
| 281 | 334 | version = "1.3.0" |
+3 −2 Cargo.toml
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | [package] |
| 2 | 2 | name = "oxwm" |
| 3 | -version = "0.1.11" | |
| 3 | +version = "0.1.12" | |
| 4 | 4 | edition = "2024" |
| 5 | 5 | |
| 6 | 6 | [lib] |
| @@ -17,4 +17,5 @@ x11rb = { version = "0.13", features = ["cursor"] } | ||
| 17 | 17 | anyhow = "1" |
| 18 | 18 | chrono = "0.4" |
| 19 | 19 | dirs = "5.0" |
| 20 | -# xcursor-rs = "0.1" | |
| 20 | +serde = { version = "1.0", features = ["derive"] } | |
| 21 | +ron = "0.8" |
+4 −14 justfile
| @@ -5,12 +5,12 @@ install: build | ||
| 5 | 5 | cp target/release/oxwm ~/.local/bin/oxwm |
| 6 | 6 | chmod +x ~/.local/bin/oxwm |
| 7 | 7 | @echo "✓ oxwm installed to ~/.local/bin/oxwm" |
| 8 | - @echo " Run 'oxwm --init' to set up your config" | |
| 8 | + @echo " Run 'oxwm --init' to create your config" | |
| 9 | 9 | |
| 10 | 10 | uninstall: |
| 11 | 11 | rm -f ~/.local/bin/oxwm |
| 12 | 12 | @echo "✓ oxwm uninstalled" |
| 13 | - @echo " Your config at ~/.config/oxwm is preserved" | |
| 13 | + @echo " Your config at ~/.config/oxwm/config.ron is preserved" | |
| 14 | 14 | |
| 15 | 15 | clean: |
| 16 | 16 | cargo clean |
| @@ -23,24 +23,14 @@ test-clean: | ||
| 23 | 23 | |
| 24 | 24 | test: |
| 25 | 25 | pkill Xephyr || true |
| 26 | - rm -f ~/.config/oxwm/oxwm-user | |
| 27 | 26 | Xephyr -screen 1280x800 :1 & sleep 1 |
| 28 | 27 | DISPLAY=:1 cargo run --release |
| 29 | 28 | |
| 30 | -test-user: | |
| 31 | - pkill Xephyr || true | |
| 32 | - cargo run --release -- --recompile | |
| 33 | - Xephyr -screen 1280x800 :1 & sleep 1 | |
| 34 | - DISPLAY=:1 ~/.config/oxwm/oxwm-user | |
| 35 | - | |
| 36 | 29 | init: |
| 37 | - cargo run -- --init | |
| 38 | - | |
| 39 | -recompile: | |
| 40 | - cargo run -- --recompile | |
| 30 | + cargo run --release -- --init | |
| 41 | 31 | |
| 42 | 32 | edit: |
| 43 | - $EDITOR ~/.config/oxwm/config.rs | |
| 33 | + $EDITOR ~/.config/oxwm/config.ron | |
| 44 | 34 | |
| 45 | 35 | check: |
| 46 | 36 | cargo clippy -- -W clippy::all |
+25 −162 src/bin/main.rs
| @@ -15,36 +15,13 @@ fn main() -> Result<()> { | ||
| 15 | 15 | } |
| 16 | 16 | Some("--init") => { |
| 17 | 17 | init_config()?; |
| 18 | - println!("✓ Config created at ~/.config/oxwm/config.rs"); | |
| 19 | - println!(" Edit and reload with Mod+Shift+R"); | |
| 20 | - return Ok(()); | |
| 21 | - } | |
| 22 | - Some("--recompile") => { | |
| 23 | - recompile_config()?; | |
| 24 | 18 | return Ok(()); |
| 25 | 19 | } |
| 26 | 20 | _ => {} |
| 27 | 21 | } |
| 28 | 22 | |
| 29 | - let config_dir = get_config_path(); | |
| 30 | - let user_bin = config_dir.join("target/release/oxwm-user"); | |
| 31 | - | |
| 32 | - if user_bin.exists() { | |
| 33 | - use std::os::unix::process::CommandExt; | |
| 34 | - let err = std::process::Command::new(&user_bin) | |
| 35 | - .args(&args[1..]) | |
| 36 | - .exec(); | |
| 37 | - eprintln!("Failed to exec user binary: {}", err); | |
| 38 | - std::process::exit(1); | |
| 39 | - } | |
| 23 | + let config = load_config()?; | |
| 40 | 24 | |
| 41 | - let config = oxwm::Config::default(); | |
| 42 | - run_wm_with_config(config, &args)?; | |
| 43 | - | |
| 44 | - Ok(()) | |
| 45 | -} | |
| 46 | - | |
| 47 | -fn run_wm_with_config(config: oxwm::Config, args: &[String]) -> Result<()> { | |
| 48 | 25 | let mut wm = oxwm::window_manager::WindowManager::new(config)?; |
| 49 | 26 | let should_restart = wm.run()?; |
| 50 | 27 | |
| @@ -59,171 +36,57 @@ fn run_wm_with_config(config: oxwm::Config, args: &[String]) -> Result<()> { | ||
| 59 | 36 | Ok(()) |
| 60 | 37 | } |
| 61 | 38 | |
| 62 | -fn should_recompile(config: &PathBuf, binary: &PathBuf) -> Result<bool> { | |
| 63 | - let config_dir = get_config_path(); | |
| 64 | - let binary_time = std::fs::metadata(binary)?.modified()?; | |
| 65 | - | |
| 66 | - let watch_files = ["config.rs", "Cargo.toml"]; | |
| 67 | - | |
| 68 | - for filename in &watch_files { | |
| 69 | - let path = config_dir.join(filename); | |
| 70 | - if !path.exists() { | |
| 71 | - continue; | |
| 72 | - } | |
| 39 | +fn load_config() -> Result<oxwm::Config> { | |
| 40 | + let config_path = get_config_path().join("config.ron"); | |
| 73 | 41 | |
| 74 | - let file_time = std::fs::metadata(&path)?.modified()?; | |
| 75 | - if file_time > binary_time { | |
| 76 | - return Ok(true); | |
| 77 | - } | |
| 42 | + if !config_path.exists() { | |
| 43 | + println!("No config found at {:?}", config_path); | |
| 44 | + println!("Creating default config..."); | |
| 45 | + init_config()?; | |
| 78 | 46 | } |
| 79 | 47 | |
| 80 | - Ok(false) | |
| 48 | + let config_str = std::fs::read_to_string(&config_path) | |
| 49 | + .map_err(|e| anyhow::anyhow!("Failed to read config file: {}", e))?; | |
| 50 | + | |
| 51 | + oxwm::config::parse_config(&config_str) | |
| 52 | + .map_err(|e| anyhow::anyhow!("Failed to parse config: {}", e)) | |
| 81 | 53 | } |
| 82 | 54 | |
| 83 | 55 | fn init_config() -> Result<()> { |
| 84 | 56 | let config_dir = get_config_path(); |
| 85 | 57 | std::fs::create_dir_all(&config_dir)?; |
| 86 | 58 | |
| 87 | - let config_template = include_str!("../../templates/config.rs"); | |
| 88 | - std::fs::write(config_dir.join("config.rs"), config_template)?; | |
| 89 | - | |
| 90 | - let main_template = include_str!("../../templates/main.rs"); | |
| 91 | - std::fs::write(config_dir.join("main.rs"), main_template)?; | |
| 92 | - | |
| 93 | - let cargo_toml = r#"[package] | |
| 94 | -name = "oxwm-user" | |
| 95 | -version = "0.1.0" | |
| 96 | -edition = "2024" | |
| 97 | - | |
| 98 | -[dependencies] | |
| 99 | -oxwm = { git = "https://github.com/tonybanters/oxwm" } | |
| 100 | -anyhow = "1" | |
| 101 | - | |
| 102 | -[[bin]] | |
| 103 | -name = "oxwm-user" | |
| 104 | -path = "main.rs" | |
| 105 | -"#; | |
| 106 | - | |
| 107 | - std::fs::write(config_dir.join("Cargo.toml"), cargo_toml)?; | |
| 108 | - std::fs::write(config_dir.join(".gitignore"), "target/\nCargo.lock\n")?; | |
| 109 | - | |
| 110 | - if is_nixos() { | |
| 111 | - let shell_nix = r#"{ pkgs ? import <nixpkgs> {} }: | |
| 112 | -pkgs.mkShell { | |
| 113 | - buildInputs = with pkgs; [ | |
| 114 | - rustc | |
| 115 | - cargo | |
| 116 | - pkg-config | |
| 117 | - xorg.libX11 | |
| 118 | - xorg.libXft | |
| 119 | - xorg.libXrender | |
| 120 | - freetype | |
| 121 | - fontconfig | |
| 122 | - ]; | |
| 123 | -} | |
| 124 | -"#; | |
| 125 | - std::fs::write(config_dir.join("shell.nix"), shell_nix)?; | |
| 126 | - println!("✓ Created shell.nix for NixOS"); | |
| 127 | - } | |
| 128 | - | |
| 129 | - Ok(()) | |
| 130 | -} | |
| 131 | - | |
| 132 | -fn recompile_config() -> Result<()> { | |
| 133 | - let config_dir = get_config_path(); | |
| 134 | - | |
| 135 | - if !config_dir.join("config.rs").exists() { | |
| 136 | - anyhow::bail!("No config found. Run: oxwm --init"); | |
| 137 | - } | |
| 59 | + let config_template = include_str!("../../templates/config.ron"); | |
| 60 | + let config_path = config_dir.join("config.ron"); | |
| 138 | 61 | |
| 139 | - println!("Compiling oxwm configuration..."); | |
| 62 | + std::fs::write(&config_path, config_template)?; | |
| 140 | 63 | |
| 141 | - let build_method = detect_build_method(); | |
| 142 | - | |
| 143 | - let output = match build_method { | |
| 144 | - BuildMethod::NixFlake => { | |
| 145 | - println!("Using nix flake build..."); | |
| 146 | - std::process::Command::new("nix") | |
| 147 | - .args(&["build", ".#", "--no-link"]) | |
| 148 | - .current_dir(&config_dir) | |
| 149 | - .output()? | |
| 150 | - } | |
| 151 | - BuildMethod::NixBuild => { | |
| 152 | - println!("Using nix-shell..."); | |
| 153 | - std::process::Command::new("nix-shell") | |
| 154 | - .args(&["--run", "cargo build --release"]) | |
| 155 | - .current_dir(&config_dir) | |
| 156 | - .output()? | |
| 157 | - } | |
| 158 | - BuildMethod::Cargo => std::process::Command::new("cargo") | |
| 159 | - .args(&["build", "--release"]) | |
| 160 | - .current_dir(&config_dir) | |
| 161 | - .output()?, | |
| 162 | - }; | |
| 163 | - | |
| 164 | - if !output.status.success() { | |
| 165 | - let stderr = String::from_utf8_lossy(&output.stderr); | |
| 166 | - eprintln!("\n❌ Compilation failed:\n{}", stderr); | |
| 167 | - anyhow::bail!("Failed to compile configuration"); | |
| 168 | - } | |
| 169 | - | |
| 170 | - println!("✓ Compiled successfully."); | |
| 171 | - println!(" Restart oxwm to use new config"); | |
| 64 | + println!("✓ Config created at {:?}", config_path); | |
| 65 | + println!(" Edit the file and reload with Mod+Shift+R"); | |
| 66 | + println!(" No compilation needed - changes take effect immediately!"); | |
| 172 | 67 | |
| 173 | 68 | Ok(()) |
| 174 | 69 | } |
| 175 | 70 | |
| 176 | -#[derive(Debug)] | |
| 177 | -enum BuildMethod { | |
| 178 | - NixFlake, | |
| 179 | - NixBuild, | |
| 180 | - Cargo, | |
| 181 | -} | |
| 182 | - | |
| 183 | -fn detect_build_method() -> BuildMethod { | |
| 184 | - let config_dir = get_config_path(); | |
| 185 | - | |
| 186 | - if config_dir.join("flake.nix").exists() { | |
| 187 | - println!("Detected flake.nix, will use nix flake for recompilation"); | |
| 188 | - return BuildMethod::NixFlake; | |
| 189 | - } | |
| 190 | - | |
| 191 | - if config_dir.join("default.nix").exists() || config_dir.join("shell.nix").exists() { | |
| 192 | - println!("Detected nix files, will use nix-shell for recompilation"); | |
| 193 | - return BuildMethod::NixBuild; | |
| 194 | - } | |
| 195 | - | |
| 196 | - println!("Will use cargo for recompilation"); | |
| 197 | - BuildMethod::Cargo | |
| 198 | -} | |
| 199 | - | |
| 200 | -fn is_nixos() -> bool { | |
| 201 | - std::path::Path::new("/etc/NIXOS").exists() | |
| 202 | - || std::path::Path::new("/run/current-system/nixos-version").exists() | |
| 203 | - || std::env::var("NIX_PATH").is_ok() | |
| 204 | -} | |
| 205 | - | |
| 206 | 71 | fn get_config_path() -> PathBuf { |
| 207 | 72 | dirs::config_dir() |
| 208 | 73 | .expect("Could not find config directory") |
| 209 | 74 | .join("oxwm") |
| 210 | 75 | } |
| 211 | 76 | |
| 212 | -fn get_user_binary_path() -> PathBuf { | |
| 213 | - get_config_path().join("oxwm-user") | |
| 214 | -} | |
| 215 | - | |
| 216 | 77 | fn print_help() { |
| 217 | 78 | println!("OXWM - A dynamic window manager written in Rust\n"); |
| 218 | 79 | println!("USAGE:"); |
| 219 | 80 | println!(" oxwm [OPTIONS]\n"); |
| 220 | 81 | println!("OPTIONS:"); |
| 221 | - println!(" --init Create default config in ~/.config/oxwm"); | |
| 222 | - println!(" --recompile Recompile user configuration"); | |
| 82 | + println!(" --init Create default config in ~/.config/oxwm/config.ron"); | |
| 223 | 83 | println!(" --version Print version information"); |
| 224 | 84 | println!(" --help Print this help message\n"); |
| 225 | 85 | println!("CONFIG:"); |
| 226 | - println!(" First run: Creates config at ~/.config/oxwm/config.rs"); | |
| 227 | - println!(" Edit your config and run 'oxwm --recompile'"); | |
| 228 | - println!(" Use Mod+Shift+R to hot-reload after recompiling\n"); | |
| 86 | + println!(" Location: ~/.config/oxwm/config.ron"); | |
| 87 | + println!(" Edit the config file and use Mod+Shift+R to reload"); | |
| 88 | + println!(" No compilation needed - instant hot-reload!\n"); | |
| 89 | + println!("FIRST RUN:"); | |
| 90 | + println!(" Run 'oxwm --init' to create a config file"); | |
| 91 | + println!(" Or just start oxwm and it will create one automatically\n"); | |
| 229 | 92 | } |
+229 −0 src/bin/main.rs.backup new file mode 100644
| @@ -0,0 +1,229 @@ | ||
| 1 | +use anyhow::Result; | |
| 2 | +use std::path::PathBuf; | |
| 3 | + | |
| 4 | +fn main() -> Result<()> { | |
| 5 | + let args: Vec<String> = std::env::args().collect(); | |
| 6 | + | |
| 7 | + match args.get(1).map(|s| s.as_str()) { | |
| 8 | + Some("--version") => { | |
| 9 | + println!("oxwm {}", env!("CARGO_PKG_VERSION")); | |
| 10 | + return Ok(()); | |
| 11 | + } | |
| 12 | + Some("--help") => { | |
| 13 | + print_help(); | |
| 14 | + return Ok(()); | |
| 15 | + } | |
| 16 | + Some("--init") => { | |
| 17 | + init_config()?; | |
| 18 | + println!("✓ Config created at ~/.config/oxwm/config.rs"); | |
| 19 | + println!(" Edit and reload with Mod+Shift+R"); | |
| 20 | + return Ok(()); | |
| 21 | + } | |
| 22 | + Some("--recompile") => { | |
| 23 | + recompile_config()?; | |
| 24 | + return Ok(()); | |
| 25 | + } | |
| 26 | + _ => {} | |
| 27 | + } | |
| 28 | + | |
| 29 | + let config_dir = get_config_path(); | |
| 30 | + let user_bin = config_dir.join("target/release/oxwm-user"); | |
| 31 | + | |
| 32 | + if user_bin.exists() { | |
| 33 | + use std::os::unix::process::CommandExt; | |
| 34 | + let err = std::process::Command::new(&user_bin) | |
| 35 | + .args(&args[1..]) | |
| 36 | + .exec(); | |
| 37 | + eprintln!("Failed to exec user binary: {}", err); | |
| 38 | + std::process::exit(1); | |
| 39 | + } | |
| 40 | + | |
| 41 | + let config = oxwm::Config::default(); | |
| 42 | + run_wm_with_config(config, &args)?; | |
| 43 | + | |
| 44 | + Ok(()) | |
| 45 | +} | |
| 46 | + | |
| 47 | +fn run_wm_with_config(config: oxwm::Config, args: &[String]) -> Result<()> { | |
| 48 | + let mut wm = oxwm::window_manager::WindowManager::new(config)?; | |
| 49 | + let should_restart = wm.run()?; | |
| 50 | + | |
| 51 | + drop(wm); | |
| 52 | + | |
| 53 | + if should_restart { | |
| 54 | + use std::os::unix::process::CommandExt; | |
| 55 | + let err = std::process::Command::new(&args[0]).args(&args[1..]).exec(); | |
| 56 | + eprintln!("Failed to restart: {}", err); | |
| 57 | + } | |
| 58 | + | |
| 59 | + Ok(()) | |
| 60 | +} | |
| 61 | + | |
| 62 | +fn should_recompile(config: &PathBuf, binary: &PathBuf) -> Result<bool> { | |
| 63 | + let config_dir = get_config_path(); | |
| 64 | + let binary_time = std::fs::metadata(binary)?.modified()?; | |
| 65 | + | |
| 66 | + let watch_files = ["config.rs", "Cargo.toml"]; | |
| 67 | + | |
| 68 | + for filename in &watch_files { | |
| 69 | + let path = config_dir.join(filename); | |
| 70 | + if !path.exists() { | |
| 71 | + continue; | |
| 72 | + } | |
| 73 | + | |
| 74 | + let file_time = std::fs::metadata(&path)?.modified()?; | |
| 75 | + if file_time > binary_time { | |
| 76 | + return Ok(true); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + | |
| 80 | + Ok(false) | |
| 81 | +} | |
| 82 | + | |
| 83 | +fn init_config() -> Result<()> { | |
| 84 | + let config_dir = get_config_path(); | |
| 85 | + std::fs::create_dir_all(&config_dir)?; | |
| 86 | + | |
| 87 | + let config_template = include_str!("../../templates/config.rs"); | |
| 88 | + std::fs::write(config_dir.join("config.rs"), config_template)?; | |
| 89 | + | |
| 90 | + let main_template = include_str!("../../templates/main.rs"); | |
| 91 | + std::fs::write(config_dir.join("main.rs"), main_template)?; | |
| 92 | + | |
| 93 | + let cargo_toml = r#"[package] | |
| 94 | +name = "oxwm-user" | |
| 95 | +version = "0.1.0" | |
| 96 | +edition = "2024" | |
| 97 | + | |
| 98 | +[dependencies] | |
| 99 | +oxwm = { git = "https://github.com/tonybanters/oxwm" } | |
| 100 | +anyhow = "1" | |
| 101 | + | |
| 102 | +[[bin]] | |
| 103 | +name = "oxwm-user" | |
| 104 | +path = "main.rs" | |
| 105 | +"#; | |
| 106 | + | |
| 107 | + std::fs::write(config_dir.join("Cargo.toml"), cargo_toml)?; | |
| 108 | + std::fs::write(config_dir.join(".gitignore"), "target/\nCargo.lock\n")?; | |
| 109 | + | |
| 110 | + if is_nixos() { | |
| 111 | + let shell_nix = r#"{ pkgs ? import <nixpkgs> {} }: | |
| 112 | +pkgs.mkShell { | |
| 113 | + buildInputs = with pkgs; [ | |
| 114 | + rustc | |
| 115 | + cargo | |
| 116 | + pkg-config | |
| 117 | + xorg.libX11 | |
| 118 | + xorg.libXft | |
| 119 | + xorg.libXrender | |
| 120 | + freetype | |
| 121 | + fontconfig | |
| 122 | + ]; | |
| 123 | +} | |
| 124 | +"#; | |
| 125 | + std::fs::write(config_dir.join("shell.nix"), shell_nix)?; | |
| 126 | + println!("✓ Created shell.nix for NixOS"); | |
| 127 | + } | |
| 128 | + | |
| 129 | + Ok(()) | |
| 130 | +} | |
| 131 | + | |
| 132 | +fn recompile_config() -> Result<()> { | |
| 133 | + let config_dir = get_config_path(); | |
| 134 | + | |
| 135 | + if !config_dir.join("config.rs").exists() { | |
| 136 | + anyhow::bail!("No config found. Run: oxwm --init"); | |
| 137 | + } | |
| 138 | + | |
| 139 | + println!("Compiling oxwm configuration..."); | |
| 140 | + | |
| 141 | + let build_method = detect_build_method(); | |
| 142 | + | |
| 143 | + let output = match build_method { | |
| 144 | + BuildMethod::NixFlake => { | |
| 145 | + println!("Using nix flake build..."); | |
| 146 | + std::process::Command::new("nix") | |
| 147 | + .args(&["build", ".#", "--no-link"]) | |
| 148 | + .current_dir(&config_dir) | |
| 149 | + .output()? | |
| 150 | + } | |
| 151 | + BuildMethod::NixBuild => { | |
| 152 | + println!("Using nix-shell..."); | |
| 153 | + std::process::Command::new("nix-shell") | |
| 154 | + .args(&["--run", "cargo build --release"]) | |
| 155 | + .current_dir(&config_dir) | |
| 156 | + .output()? | |
| 157 | + } | |
| 158 | + BuildMethod::Cargo => std::process::Command::new("cargo") | |
| 159 | + .args(&["build", "--release"]) | |
| 160 | + .current_dir(&config_dir) | |
| 161 | + .output()?, | |
| 162 | + }; | |
| 163 | + | |
| 164 | + if !output.status.success() { | |
| 165 | + let stderr = String::from_utf8_lossy(&output.stderr); | |
| 166 | + eprintln!("\n❌ Compilation failed:\n{}", stderr); | |
| 167 | + anyhow::bail!("Failed to compile configuration"); | |
| 168 | + } | |
| 169 | + | |
| 170 | + println!("✓ Compiled successfully."); | |
| 171 | + println!(" Restart oxwm to use new config"); | |
| 172 | + | |
| 173 | + Ok(()) | |
| 174 | +} | |
| 175 | + | |
| 176 | +#[derive(Debug)] | |
| 177 | +enum BuildMethod { | |
| 178 | + NixFlake, | |
| 179 | + NixBuild, | |
| 180 | + Cargo, | |
| 181 | +} | |
| 182 | + | |
| 183 | +fn detect_build_method() -> BuildMethod { | |
| 184 | + let config_dir = get_config_path(); | |
| 185 | + | |
| 186 | + if config_dir.join("flake.nix").exists() { | |
| 187 | + println!("Detected flake.nix, will use nix flake for recompilation"); | |
| 188 | + return BuildMethod::NixFlake; | |
| 189 | + } | |
| 190 | + | |
| 191 | + if config_dir.join("default.nix").exists() || config_dir.join("shell.nix").exists() { | |
| 192 | + println!("Detected nix files, will use nix-shell for recompilation"); | |
| 193 | + return BuildMethod::NixBuild; | |
| 194 | + } | |
| 195 | + | |
| 196 | + println!("Will use cargo for recompilation"); | |
| 197 | + BuildMethod::Cargo | |
| 198 | +} | |
| 199 | + | |
| 200 | +fn is_nixos() -> bool { | |
| 201 | + std::path::Path::new("/etc/NIXOS").exists() | |
| 202 | + || std::path::Path::new("/run/current-system/nixos-version").exists() | |
| 203 | + || std::env::var("NIX_PATH").is_ok() | |
| 204 | +} | |
| 205 | + | |
| 206 | +fn get_config_path() -> PathBuf { | |
| 207 | + dirs::config_dir() | |
| 208 | + .expect("Could not find config directory") | |
| 209 | + .join("oxwm") | |
| 210 | +} | |
| 211 | + | |
| 212 | +fn get_user_binary_path() -> PathBuf { | |
| 213 | + get_config_path().join("oxwm-user") | |
| 214 | +} | |
| 215 | + | |
| 216 | +fn print_help() { | |
| 217 | + println!("OXWM - A dynamic window manager written in Rust\n"); | |
| 218 | + println!("USAGE:"); | |
| 219 | + println!(" oxwm [OPTIONS]\n"); | |
| 220 | + println!("OPTIONS:"); | |
| 221 | + println!(" --init Create default config in ~/.config/oxwm"); | |
| 222 | + println!(" --recompile Recompile user configuration"); | |
| 223 | + println!(" --version Print version information"); | |
| 224 | + println!(" --help Print this help message\n"); | |
| 225 | + println!("CONFIG:"); | |
| 226 | + println!(" First run: Creates config at ~/.config/oxwm/config.rs"); | |
| 227 | + println!(" Edit your config and run 'oxwm --recompile'"); | |
| 228 | + println!(" Use Mod+Shift+R to hot-reload after recompiling\n"); | |
| 229 | +} |
+0 −190 src/config.rs.backup deleted file mode 100644
| @@ -1,190 +0,0 @@ | ||
| 1 | -use crate::bar::{BlockCommand, BlockConfig}; | |
| 2 | -use crate::keyboard::handlers::Key; | |
| 3 | -use crate::keyboard::{Arg, KeyAction, keycodes}; | |
| 4 | -use x11rb::protocol::xproto::KeyButMask; | |
| 5 | - | |
| 6 | -// ======================================== | |
| 7 | -// APPEARANCE | |
| 8 | -// ======================================== | |
| 9 | -pub const BORDER_WIDTH: u32 = 2; | |
| 10 | -pub const BORDER_FOCUSED: u32 = 0x6dade3; | |
| 11 | -pub const BORDER_UNFOCUSED: u32 = 0xbbbbbb; | |
| 12 | -pub const FONT: &str = "JetBrainsMono Nerd Font:style=Bold:size=12"; | |
| 13 | - | |
| 14 | -// ======================================== | |
| 15 | -// GAPS (Vanity Gaps) | |
| 16 | -// ======================================== | |
| 17 | -pub const GAPS_ENABLED: bool = false; | |
| 18 | -pub const GAP_INNER_HORIZONTAL: u32 = 3; | |
| 19 | -pub const GAP_INNER_VERTICAL: u32 = 3; | |
| 20 | -pub const GAP_OUTER_HORIZONTAL: u32 = 3; | |
| 21 | -pub const GAP_OUTER_VERTICAL: u32 = 3; | |
| 22 | -// | |
| 23 | -// ======================================== | |
| 24 | -// DEFAULTS | |
| 25 | -// ======================================== | |
| 26 | -pub const TERMINAL: &str = "st"; | |
| 27 | -pub const XCLOCK: &str = "xclock"; | |
| 28 | -pub const MODKEY: KeyButMask = KeyButMask::MOD4; | |
| 29 | - | |
| 30 | -// ======================================== | |
| 31 | -// BAR COLORS | |
| 32 | -// ======================================== | |
| 33 | - | |
| 34 | -// Base colors | |
| 35 | -const GRAY_DARK: u32 = 0x1a1b26; | |
| 36 | -const GRAY_SEP: u32 = 0xa9b1d6; | |
| 37 | -const GRAY_MID: u32 = 0x444444; | |
| 38 | -const GRAY_LIGHT: u32 = 0xbbbbbb; | |
| 39 | -const CYAN: u32 = 0x0db9d7; | |
| 40 | -const MAGENTA: u32 = 0xad8ee6; | |
| 41 | -const RED: u32 = 0xf7768e; | |
| 42 | -const GREEN: u32 = 0x9ece6a; | |
| 43 | -const BLUE: u32 = 0x7aa2f7; | |
| 44 | -const YELLOW: u32 = 0xe0af68; | |
| 45 | - | |
| 46 | -pub struct ColorScheme { | |
| 47 | - pub foreground: u32, | |
| 48 | - pub background: u32, | |
| 49 | - pub underline: u32, | |
| 50 | -} | |
| 51 | - | |
| 52 | -pub const SCHEME_NORMAL: ColorScheme = ColorScheme { | |
| 53 | - foreground: GRAY_LIGHT, | |
| 54 | - background: GRAY_DARK, | |
| 55 | - underline: GRAY_MID, | |
| 56 | -}; | |
| 57 | - | |
| 58 | -pub const SCHEME_OCCUPIED: ColorScheme = ColorScheme { | |
| 59 | - foreground: CYAN, | |
| 60 | - background: GRAY_DARK, | |
| 61 | - underline: CYAN, | |
| 62 | -}; | |
| 63 | - | |
| 64 | -pub const SCHEME_SELECTED: ColorScheme = ColorScheme { | |
| 65 | - foreground: CYAN, | |
| 66 | - background: GRAY_DARK, | |
| 67 | - underline: MAGENTA, | |
| 68 | -}; | |
| 69 | - | |
| 70 | -// ======================================== | |
| 71 | -// Commands | |
| 72 | -// ======================================== | |
| 73 | -const SCREENSHOT_CMD: &[&str] = &[ | |
| 74 | - "sh", | |
| 75 | - "-c", | |
| 76 | - "maim -s | xclip -selection clipboard -t image/png", | |
| 77 | -]; | |
| 78 | - | |
| 79 | -const DMENU_CMD: &[&str] = &["sh", "-c", "dmenu_run -l 10"]; | |
| 80 | - | |
| 81 | -// ======================================== | |
| 82 | -// TAGS | |
| 83 | -// ======================================== | |
| 84 | -pub const TAG_COUNT: usize = 9; | |
| 85 | -pub const TAGS: [&str; TAG_COUNT] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]; | |
| 86 | -//pub const TAGS: [&str; TAG_COUNT] = ["", "", "", "", "", "", "", "", ""]; | |
| 87 | -// pub const TAGS: [&str; TAG_COUNT] = [ | |
| 88 | -// "DEV", "WWW", "SYS", "DOC", "VBOX", "CHAT", "MUS", "VID", "MISC", | |
| 89 | -// ]; | |
| 90 | - | |
| 91 | -// ======================================== | |
| 92 | -// KEYBINDINGS | |
| 93 | -// ======================================== | |
| 94 | -#[rustfmt::skip] | |
| 95 | -pub const KEYBINDINGS: &[Key] = &[ | |
| 96 | - Key::new(&[MODKEY], keycodes::RETURN, KeyAction::Spawn, Arg::Str(TERMINAL)), | |
| 97 | - Key::new(&[MODKEY], keycodes::F, KeyAction::Spawn, Arg::Str(XCLOCK)), | |
| 98 | - | |
| 99 | - Key::new(&[MODKEY], keycodes::S, KeyAction::Spawn, Arg::Array(SCREENSHOT_CMD)), | |
| 100 | - Key::new(&[MODKEY], keycodes::D, KeyAction::Spawn, Arg::Array(DMENU_CMD)), | |
| 101 | - Key::new(&[MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None), | |
| 102 | - Key::new(&[MODKEY, SHIFT], keycodes::F, KeyAction::ToggleFullScreen, Arg::None), | |
| 103 | - Key::new(&[MODKEY], keycodes::A, KeyAction::ToggleGaps, Arg::None), | |
| 104 | - Key::new(&[MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None), | |
| 105 | - Key::new(&[MODKEY, SHIFT], keycodes::R, KeyAction::Restart, Arg::None), | |
| 106 | - Key::new(&[MODKEY], keycodes::J, KeyAction::FocusStack, Arg::Int(-1)), | |
| 107 | - Key::new(&[MODKEY], keycodes::K, KeyAction::FocusStack, Arg::Int(1)), | |
| 108 | - | |
| 109 | - Key::new(&[MODKEY], keycodes::KEY_1, KeyAction::ViewTag, Arg::Int(0)), | |
| 110 | - Key::new(&[MODKEY], keycodes::KEY_2, KeyAction::ViewTag, Arg::Int(1)), | |
| 111 | - Key::new(&[MODKEY], keycodes::KEY_3, KeyAction::ViewTag, Arg::Int(2)), | |
| 112 | - Key::new(&[MODKEY], keycodes::KEY_4, KeyAction::ViewTag, Arg::Int(3)), | |
| 113 | - Key::new(&[MODKEY], keycodes::KEY_5, KeyAction::ViewTag, Arg::Int(4)), | |
| 114 | - Key::new(&[MODKEY], keycodes::KEY_6, KeyAction::ViewTag, Arg::Int(5)), | |
| 115 | - Key::new(&[MODKEY], keycodes::KEY_7, KeyAction::ViewTag, Arg::Int(6)), | |
| 116 | - Key::new(&[MODKEY], keycodes::KEY_8, KeyAction::ViewTag, Arg::Int(7)), | |
| 117 | - Key::new(&[MODKEY], keycodes::KEY_9, KeyAction::ViewTag, Arg::Int(8)), | |
| 118 | - | |
| 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 | -const SHIFT: KeyButMask = KeyButMask::SHIFT; | |
| 190 | -pub const WM_BINARY: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/target/release/oxwm"); |
+343 −0 src/config/mod.rs new file mode 100644
| @@ -0,0 +1,343 @@ | ||
| 1 | +use anyhow::{Context, Result, bail}; | |
| 2 | +use serde::Deserialize; | |
| 3 | + | |
| 4 | +pub fn parse_config(input: &str) -> Result<crate::Config> { | |
| 5 | + let config_data: ConfigData = ron::from_str(input).map_err(|e| { | |
| 6 | + eprintln!("RON Parse Error Details: {}", e); | |
| 7 | + anyhow::anyhow!("Failed to parse RON config: {}", e) | |
| 8 | + })?; | |
| 9 | + | |
| 10 | + config_data_to_config(config_data) | |
| 11 | +} | |
| 12 | + | |
| 13 | +#[derive(Debug, Deserialize)] | |
| 14 | +struct ConfigData { | |
| 15 | + border_width: u32, | |
| 16 | + border_focused: u32, | |
| 17 | + border_unfocused: u32, | |
| 18 | + font: String, | |
| 19 | + | |
| 20 | + gaps_enabled: bool, | |
| 21 | + gap_inner_horizontal: u32, | |
| 22 | + gap_inner_vertical: u32, | |
| 23 | + gap_outer_horizontal: u32, | |
| 24 | + gap_outer_vertical: u32, | |
| 25 | + | |
| 26 | + terminal: String, | |
| 27 | + modkey: String, | |
| 28 | + | |
| 29 | + tags: Vec<String>, | |
| 30 | + keybindings: Vec<KeybindingData>, | |
| 31 | + status_blocks: Vec<StatusBlockData>, | |
| 32 | + | |
| 33 | + scheme_normal: ColorSchemeData, | |
| 34 | + scheme_occupied: ColorSchemeData, | |
| 35 | + scheme_selected: ColorSchemeData, | |
| 36 | +} | |
| 37 | + | |
| 38 | +#[derive(Debug, Deserialize)] | |
| 39 | +struct KeybindingData { | |
| 40 | + modifiers: Vec<String>, | |
| 41 | + key: String, | |
| 42 | + action: String, | |
| 43 | + #[serde(default)] | |
| 44 | + arg: ArgData, | |
| 45 | +} | |
| 46 | + | |
| 47 | +#[derive(Debug, Deserialize)] | |
| 48 | +#[serde(untagged)] | |
| 49 | +enum ArgData { | |
| 50 | + None, | |
| 51 | + String(String), | |
| 52 | + Int(i32), | |
| 53 | + Array(Vec<String>), | |
| 54 | +} | |
| 55 | + | |
| 56 | +impl Default for ArgData { | |
| 57 | + fn default() -> Self { | |
| 58 | + ArgData::None | |
| 59 | + } | |
| 60 | +} | |
| 61 | + | |
| 62 | +#[derive(Debug, Deserialize)] | |
| 63 | +struct StatusBlockData { | |
| 64 | + format: String, | |
| 65 | + command: String, | |
| 66 | + #[serde(default)] | |
| 67 | + command_arg: Option<String>, | |
| 68 | + #[serde(default)] | |
| 69 | + battery_formats: Option<BatteryFormats>, | |
| 70 | + interval_secs: u64, | |
| 71 | + color: u32, | |
| 72 | + underline: bool, | |
| 73 | +} | |
| 74 | + | |
| 75 | +#[derive(Debug, Deserialize)] | |
| 76 | +struct BatteryFormats { | |
| 77 | + charging: String, | |
| 78 | + discharging: String, | |
| 79 | + full: String, | |
| 80 | +} | |
| 81 | + | |
| 82 | +#[derive(Debug, Deserialize)] | |
| 83 | +struct ColorSchemeData { | |
| 84 | + foreground: u32, | |
| 85 | + background: u32, | |
| 86 | + underline: u32, | |
| 87 | +} | |
| 88 | + | |
| 89 | +fn config_data_to_config(data: ConfigData) -> Result<crate::Config> { | |
| 90 | + use crate::keyboard::handlers::Key; | |
| 91 | + use crate::keyboard::{Arg, KeyAction}; | |
| 92 | + use x11rb::protocol::xproto::KeyButMask; | |
| 93 | + | |
| 94 | + // Parse modkey | |
| 95 | + let modkey = parse_modkey(&data.modkey)?; | |
| 96 | + | |
| 97 | + // Parse keybindings | |
| 98 | + let mut keybindings = Vec::new(); | |
| 99 | + for kb_data in data.keybindings { | |
| 100 | + let modifiers = kb_data | |
| 101 | + .modifiers | |
| 102 | + .iter() | |
| 103 | + .map(|s| parse_modkey(s)) | |
| 104 | + .collect::<Result<Vec<_>>>()?; | |
| 105 | + | |
| 106 | + let modifiers_static: &'static [KeyButMask] = Box::leak(modifiers.into_boxed_slice()); | |
| 107 | + | |
| 108 | + let key = string_to_keycode(&kb_data.key)?; | |
| 109 | + let action = parse_key_action(&kb_data.action)?; | |
| 110 | + let arg = arg_data_to_arg(kb_data.arg)?; | |
| 111 | + | |
| 112 | + keybindings.push(Key::new(modifiers_static, key, action, arg)); | |
| 113 | + } | |
| 114 | + | |
| 115 | + // Parse status blocks | |
| 116 | + let mut status_blocks = Vec::new(); | |
| 117 | + for block_data in data.status_blocks { | |
| 118 | + use crate::bar::{BlockCommand, BlockConfig}; | |
| 119 | + | |
| 120 | + let format_static: &'static str = Box::leak(block_data.format.into_boxed_str()); | |
| 121 | + | |
| 122 | + let command = match block_data.command.as_str() { | |
| 123 | + "DateTime" => { | |
| 124 | + let fmt = block_data | |
| 125 | + .command_arg | |
| 126 | + .context("DateTime command requires command_arg")?; | |
| 127 | + let fmt_static: &'static str = Box::leak(fmt.into_boxed_str()); | |
| 128 | + BlockCommand::DateTime(fmt_static) | |
| 129 | + } | |
| 130 | + "Shell" => { | |
| 131 | + let cmd = block_data | |
| 132 | + .command_arg | |
| 133 | + .context("Shell command requires command_arg")?; | |
| 134 | + let cmd_static: &'static str = Box::leak(cmd.into_boxed_str()); | |
| 135 | + BlockCommand::Shell(cmd_static) | |
| 136 | + } | |
| 137 | + "Ram" => BlockCommand::Ram, | |
| 138 | + "Static" => { | |
| 139 | + let text = block_data.command_arg.unwrap_or_default(); | |
| 140 | + let text_static: &'static str = Box::leak(text.into_boxed_str()); | |
| 141 | + BlockCommand::Static(text_static) | |
| 142 | + } | |
| 143 | + "Battery" => { | |
| 144 | + let formats = block_data | |
| 145 | + .battery_formats | |
| 146 | + .context("Battery command requires battery_formats")?; | |
| 147 | + BlockCommand::Battery { | |
| 148 | + format_charging: Box::leak(formats.charging.into_boxed_str()), | |
| 149 | + format_discharging: Box::leak(formats.discharging.into_boxed_str()), | |
| 150 | + format_full: Box::leak(formats.full.into_boxed_str()), | |
| 151 | + } | |
| 152 | + } | |
| 153 | + _ => bail!("Unknown block command: {}", block_data.command), | |
| 154 | + }; | |
| 155 | + | |
| 156 | + status_blocks.push(BlockConfig { | |
| 157 | + format: format_static, | |
| 158 | + command, | |
| 159 | + interval_secs: block_data.interval_secs, | |
| 160 | + color: block_data.color, | |
| 161 | + underline: block_data.underline, | |
| 162 | + }); | |
| 163 | + } | |
| 164 | + | |
| 165 | + Ok(crate::Config { | |
| 166 | + border_width: data.border_width, | |
| 167 | + border_focused: data.border_focused, | |
| 168 | + border_unfocused: data.border_unfocused, | |
| 169 | + font: data.font, | |
| 170 | + gaps_enabled: data.gaps_enabled, | |
| 171 | + gap_inner_horizontal: data.gap_inner_horizontal, | |
| 172 | + gap_inner_vertical: data.gap_inner_vertical, | |
| 173 | + gap_outer_horizontal: data.gap_outer_horizontal, | |
| 174 | + gap_outer_vertical: data.gap_outer_vertical, | |
| 175 | + terminal: data.terminal, | |
| 176 | + modkey, | |
| 177 | + tags: data.tags, | |
| 178 | + keybindings, | |
| 179 | + status_blocks, | |
| 180 | + scheme_normal: crate::ColorScheme { | |
| 181 | + foreground: data.scheme_normal.foreground, | |
| 182 | + background: data.scheme_normal.background, | |
| 183 | + underline: data.scheme_normal.underline, | |
| 184 | + }, | |
| 185 | + scheme_occupied: crate::ColorScheme { | |
| 186 | + foreground: data.scheme_occupied.foreground, | |
| 187 | + background: data.scheme_occupied.background, | |
| 188 | + underline: data.scheme_occupied.underline, | |
| 189 | + }, | |
| 190 | + scheme_selected: crate::ColorScheme { | |
| 191 | + foreground: data.scheme_selected.foreground, | |
| 192 | + background: data.scheme_selected.background, | |
| 193 | + underline: data.scheme_selected.underline, | |
| 194 | + }, | |
| 195 | + }) | |
| 196 | +} | |
| 197 | + | |
| 198 | +fn parse_modkey(s: &str) -> Result<x11rb::protocol::xproto::KeyButMask> { | |
| 199 | + use x11rb::protocol::xproto::KeyButMask; | |
| 200 | + | |
| 201 | + match s { | |
| 202 | + "Mod1" => Ok(KeyButMask::MOD1), | |
| 203 | + "Mod2" => Ok(KeyButMask::MOD2), | |
| 204 | + "Mod3" => Ok(KeyButMask::MOD3), | |
| 205 | + "Mod4" => Ok(KeyButMask::MOD4), | |
| 206 | + "Mod5" => Ok(KeyButMask::MOD5), | |
| 207 | + "Shift" => Ok(KeyButMask::SHIFT), | |
| 208 | + "Control" => Ok(KeyButMask::CONTROL), | |
| 209 | + _ => bail!("Invalid modkey: {}", s), | |
| 210 | + } | |
| 211 | +} | |
| 212 | + | |
| 213 | +fn string_to_keycode(s: &str) -> Result<x11rb::protocol::xproto::Keycode> { | |
| 214 | + use crate::keyboard::keycodes; | |
| 215 | + | |
| 216 | + match s.to_lowercase().as_str() { | |
| 217 | + "return" => Ok(keycodes::RETURN), | |
| 218 | + "q" => Ok(keycodes::Q), | |
| 219 | + "escape" => Ok(keycodes::ESCAPE), | |
| 220 | + "space" => Ok(keycodes::SPACE), | |
| 221 | + "tab" => Ok(keycodes::TAB), | |
| 222 | + "backspace" => Ok(keycodes::BACKSPACE), | |
| 223 | + "delete" => Ok(keycodes::DELETE), | |
| 224 | + | |
| 225 | + // Function keys | |
| 226 | + "f1" => Ok(keycodes::F1), | |
| 227 | + "f2" => Ok(keycodes::F2), | |
| 228 | + "f3" => Ok(keycodes::F3), | |
| 229 | + "f4" => Ok(keycodes::F4), | |
| 230 | + "f5" => Ok(keycodes::F5), | |
| 231 | + "f6" => Ok(keycodes::F6), | |
| 232 | + "f7" => Ok(keycodes::F7), | |
| 233 | + "f8" => Ok(keycodes::F8), | |
| 234 | + "f9" => Ok(keycodes::F9), | |
| 235 | + "f10" => Ok(keycodes::F10), | |
| 236 | + "f11" => Ok(keycodes::F11), | |
| 237 | + "f12" => Ok(keycodes::F12), | |
| 238 | + | |
| 239 | + // Letters | |
| 240 | + "a" => Ok(keycodes::A), | |
| 241 | + "b" => Ok(keycodes::B), | |
| 242 | + "c" => Ok(keycodes::C), | |
| 243 | + "d" => Ok(keycodes::D), | |
| 244 | + "e" => Ok(keycodes::E), | |
| 245 | + "f" => Ok(keycodes::F), | |
| 246 | + "g" => Ok(keycodes::G), | |
| 247 | + "h" => Ok(keycodes::H), | |
| 248 | + "i" => Ok(keycodes::I), | |
| 249 | + "j" => Ok(keycodes::J), | |
| 250 | + "k" => Ok(keycodes::K), | |
| 251 | + "l" => Ok(keycodes::L), | |
| 252 | + "m" => Ok(keycodes::M), | |
| 253 | + "n" => Ok(keycodes::N), | |
| 254 | + "o" => Ok(keycodes::O), | |
| 255 | + "p" => Ok(keycodes::P), | |
| 256 | + "r" => Ok(keycodes::R), | |
| 257 | + "s" => Ok(keycodes::S), | |
| 258 | + "t" => Ok(keycodes::T), | |
| 259 | + "u" => Ok(keycodes::U), | |
| 260 | + "v" => Ok(keycodes::V), | |
| 261 | + "w" => Ok(keycodes::W), | |
| 262 | + "x" => Ok(keycodes::X), | |
| 263 | + "y" => Ok(keycodes::Y), | |
| 264 | + "z" => Ok(keycodes::Z), | |
| 265 | + | |
| 266 | + // Numbers | |
| 267 | + "0" => Ok(keycodes::KEY_0), | |
| 268 | + "1" => Ok(keycodes::KEY_1), | |
| 269 | + "2" => Ok(keycodes::KEY_2), | |
| 270 | + "3" => Ok(keycodes::KEY_3), | |
| 271 | + "4" => Ok(keycodes::KEY_4), | |
| 272 | + "5" => Ok(keycodes::KEY_5), | |
| 273 | + "6" => Ok(keycodes::KEY_6), | |
| 274 | + "7" => Ok(keycodes::KEY_7), | |
| 275 | + "8" => Ok(keycodes::KEY_8), | |
| 276 | + "9" => Ok(keycodes::KEY_9), | |
| 277 | + | |
| 278 | + // Arrows | |
| 279 | + "left" => Ok(keycodes::LEFT), | |
| 280 | + "right" => Ok(keycodes::RIGHT), | |
| 281 | + "up" => Ok(keycodes::UP), | |
| 282 | + "down" => Ok(keycodes::DOWN), | |
| 283 | + "home" => Ok(keycodes::HOME), | |
| 284 | + "end" => Ok(keycodes::END), | |
| 285 | + "pageup" => Ok(keycodes::PAGE_UP), | |
| 286 | + "pagedown" => Ok(keycodes::PAGE_DOWN), | |
| 287 | + "insert" => Ok(keycodes::INSERT), | |
| 288 | + | |
| 289 | + // Symbols | |
| 290 | + "minus" | "-" => Ok(keycodes::MINUS), | |
| 291 | + "equal" | "=" => Ok(keycodes::EQUAL), | |
| 292 | + "bracketleft" | "[" => Ok(keycodes::LEFT_BRACKET), | |
| 293 | + "bracketright" | "]" => Ok(keycodes::RIGHT_BRACKET), | |
| 294 | + "semicolon" | ";" => Ok(keycodes::SEMICOLON), | |
| 295 | + "apostrophe" | "'" => Ok(keycodes::APOSTROPHE), | |
| 296 | + "grave" | "`" => Ok(keycodes::GRAVE), | |
| 297 | + "backslash" | "\\" => Ok(keycodes::BACKSLASH), | |
| 298 | + "comma" | "," => Ok(keycodes::COMMA), | |
| 299 | + "period" | "." => Ok(keycodes::PERIOD), | |
| 300 | + "slash" | "/" => Ok(keycodes::SLASH), | |
| 301 | + | |
| 302 | + _ => bail!("Unknown key: {}", s), | |
| 303 | + } | |
| 304 | +} | |
| 305 | + | |
| 306 | +fn parse_key_action(s: &str) -> Result<crate::keyboard::KeyAction> { | |
| 307 | + use crate::keyboard::KeyAction; | |
| 308 | + | |
| 309 | + match s { | |
| 310 | + "Spawn" => Ok(KeyAction::Spawn), | |
| 311 | + "KillClient" => Ok(KeyAction::KillClient), | |
| 312 | + "FocusStack" => Ok(KeyAction::FocusStack), | |
| 313 | + "Quit" => Ok(KeyAction::Quit), | |
| 314 | + "Restart" => Ok(KeyAction::Restart), | |
| 315 | + "ViewTag" => Ok(KeyAction::ViewTag), | |
| 316 | + "MoveToTag" => Ok(KeyAction::MoveToTag), | |
| 317 | + "ToggleGaps" => Ok(KeyAction::ToggleGaps), | |
| 318 | + "ToggleFullScreen" => Ok(KeyAction::ToggleFullScreen), | |
| 319 | + "ToggleFloating" => Ok(KeyAction::ToggleFloating), | |
| 320 | + _ => bail!("Unknown action: {}", s), | |
| 321 | + } | |
| 322 | +} | |
| 323 | + | |
| 324 | +fn arg_data_to_arg(data: ArgData) -> Result<crate::keyboard::Arg> { | |
| 325 | + use crate::keyboard::Arg; | |
| 326 | + | |
| 327 | + match data { | |
| 328 | + ArgData::None => Ok(Arg::None), | |
| 329 | + ArgData::String(s) => { | |
| 330 | + let static_str: &'static str = Box::leak(s.into_boxed_str()); | |
| 331 | + Ok(Arg::Str(static_str)) | |
| 332 | + } | |
| 333 | + ArgData::Int(n) => Ok(Arg::Int(n)), | |
| 334 | + ArgData::Array(arr) => { | |
| 335 | + let static_strs: Vec<&'static str> = arr | |
| 336 | + .into_iter() | |
| 337 | + .map(|s| Box::leak(s.into_boxed_str()) as &'static str) | |
| 338 | + .collect(); | |
| 339 | + let static_slice: &'static [&'static str] = Box::leak(static_strs.into_boxed_slice()); | |
| 340 | + Ok(Arg::Array(static_slice)) | |
| 341 | + } | |
| 342 | + } | |
| 343 | +} |
+0 −191 src/default_config.rs deleted file mode 100644
| @@ -1,191 +0,0 @@ | ||
| 1 | -use crate::bar::{BlockCommand, BlockConfig}; | |
| 2 | -use crate::keyboard::handlers::Key; | |
| 3 | -use crate::keyboard::{Arg, KeyAction, keycodes}; | |
| 4 | -use x11rb::protocol::xproto::KeyButMask; | |
| 5 | - | |
| 6 | -// ======================================== | |
| 7 | -// APPEARANCE | |
| 8 | -// ======================================== | |
| 9 | -pub const BORDER_WIDTH: u32 = 2; | |
| 10 | -pub const BORDER_FOCUSED: u32 = 0x6dade3; | |
| 11 | -pub const BORDER_UNFOCUSED: u32 = 0xbbbbbb; | |
| 12 | -pub const FONT: &str = "JetBrainsMono Nerd Font:style=Bold:size=12"; | |
| 13 | - | |
| 14 | -// ======================================== | |
| 15 | -// GAPS (Vanity Gaps) | |
| 16 | -// ======================================== | |
| 17 | -pub const GAPS_ENABLED: bool = false; | |
| 18 | -pub const GAP_INNER_HORIZONTAL: u32 = 3; | |
| 19 | -pub const GAP_INNER_VERTICAL: u32 = 3; | |
| 20 | -pub const GAP_OUTER_HORIZONTAL: u32 = 3; | |
| 21 | -pub const GAP_OUTER_VERTICAL: u32 = 3; | |
| 22 | -// | |
| 23 | -// ======================================== | |
| 24 | -// DEFAULTS | |
| 25 | -// ======================================== | |
| 26 | -pub const TERMINAL: &str = "st"; | |
| 27 | -pub const XCLOCK: &str = "xclock"; | |
| 28 | -pub const MODKEY: KeyButMask = KeyButMask::MOD4; | |
| 29 | - | |
| 30 | -// ======================================== | |
| 31 | -// BAR COLORS | |
| 32 | -// ======================================== | |
| 33 | - | |
| 34 | -// Base colors | |
| 35 | -const GRAY_DARK: u32 = 0x1a1b26; | |
| 36 | -const GRAY_SEP: u32 = 0xa9b1d6; | |
| 37 | -const GRAY_MID: u32 = 0x444444; | |
| 38 | -const GRAY_LIGHT: u32 = 0xbbbbbb; | |
| 39 | -const CYAN: u32 = 0x0db9d7; | |
| 40 | -const MAGENTA: u32 = 0xad8ee6; | |
| 41 | -const RED: u32 = 0xf7768e; | |
| 42 | -const GREEN: u32 = 0x9ece6a; | |
| 43 | -const BLUE: u32 = 0x7aa2f7; | |
| 44 | -const YELLOW: u32 = 0xe0af68; | |
| 45 | - | |
| 46 | -pub struct ColorScheme { | |
| 47 | - pub foreground: u32, | |
| 48 | - pub background: u32, | |
| 49 | - pub underline: u32, | |
| 50 | -} | |
| 51 | - | |
| 52 | -pub const SCHEME_NORMAL: ColorScheme = ColorScheme { | |
| 53 | - foreground: GRAY_LIGHT, | |
| 54 | - background: GRAY_DARK, | |
| 55 | - underline: GRAY_MID, | |
| 56 | -}; | |
| 57 | - | |
| 58 | -pub const SCHEME_OCCUPIED: ColorScheme = ColorScheme { | |
| 59 | - foreground: CYAN, | |
| 60 | - background: GRAY_DARK, | |
| 61 | - underline: CYAN, | |
| 62 | -}; | |
| 63 | - | |
| 64 | -pub const SCHEME_SELECTED: ColorScheme = ColorScheme { | |
| 65 | - foreground: CYAN, | |
| 66 | - background: GRAY_DARK, | |
| 67 | - underline: MAGENTA, | |
| 68 | -}; | |
| 69 | - | |
| 70 | -// ======================================== | |
| 71 | -// Commands | |
| 72 | -// ======================================== | |
| 73 | -const SCREENSHOT_CMD: &[&str] = &[ | |
| 74 | - "sh", | |
| 75 | - "-c", | |
| 76 | - "maim -s | xclip -selection clipboard -t image/png", | |
| 77 | -]; | |
| 78 | - | |
| 79 | -const DMENU_CMD: &[&str] = &["sh", "-c", "dmenu_run -l 10"]; | |
| 80 | - | |
| 81 | -// ======================================== | |
| 82 | -// TAGS | |
| 83 | -// ======================================== | |
| 84 | -pub const TAG_COUNT: usize = 9; | |
| 85 | -pub const TAGS: [&str; TAG_COUNT] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]; | |
| 86 | -//pub const TAGS: [&str; TAG_COUNT] = ["", "", "", "", "", "", "", "", ""]; | |
| 87 | -// pub const TAGS: [&str; TAG_COUNT] = [ | |
| 88 | -// "DEV", "WWW", "SYS", "DOC", "VBOX", "CHAT", "MUS", "VID", "MISC", | |
| 89 | -// ]; | |
| 90 | - | |
| 91 | -// ======================================== | |
| 92 | -// KEYBINDINGS | |
| 93 | -// ======================================== | |
| 94 | -#[rustfmt::skip] | |
| 95 | -pub const KEYBINDINGS: &[Key] = &[ | |
| 96 | - Key::new(&[MODKEY], keycodes::RETURN, KeyAction::Spawn, Arg::Str(TERMINAL)), | |
| 97 | - Key::new(&[MODKEY], keycodes::F, KeyAction::Spawn, Arg::Str(XCLOCK)), | |
| 98 | - | |
| 99 | - Key::new(&[MODKEY], keycodes::S, KeyAction::Spawn, Arg::Array(SCREENSHOT_CMD)), | |
| 100 | - Key::new(&[MODKEY], keycodes::D, KeyAction::Spawn, Arg::Array(DMENU_CMD)), | |
| 101 | - Key::new(&[MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None), | |
| 102 | - Key::new(&[MODKEY, SHIFT], keycodes::F, KeyAction::ToggleFullScreen, Arg::None), | |
| 103 | - Key::new(&[MODKEY, SHIFT], keycodes::SPACE, KeyAction::ToggleFloating, Arg::None), | |
| 104 | - Key::new(&[MODKEY], keycodes::A, KeyAction::ToggleGaps, Arg::None), | |
| 105 | - Key::new(&[MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None), | |
| 106 | - Key::new(&[MODKEY, SHIFT], keycodes::R, KeyAction::Restart, Arg::None), | |
| 107 | - Key::new(&[MODKEY], keycodes::J, KeyAction::FocusStack, Arg::Int(-1)), | |
| 108 | - Key::new(&[MODKEY], keycodes::K, KeyAction::FocusStack, Arg::Int(1)), | |
| 109 | - | |
| 110 | - Key::new(&[MODKEY], keycodes::KEY_1, KeyAction::ViewTag, Arg::Int(0)), | |
| 111 | - Key::new(&[MODKEY], keycodes::KEY_2, KeyAction::ViewTag, Arg::Int(1)), | |
| 112 | - Key::new(&[MODKEY], keycodes::KEY_3, KeyAction::ViewTag, Arg::Int(2)), | |
| 113 | - Key::new(&[MODKEY], keycodes::KEY_4, KeyAction::ViewTag, Arg::Int(3)), | |
| 114 | - Key::new(&[MODKEY], keycodes::KEY_5, KeyAction::ViewTag, Arg::Int(4)), | |
| 115 | - Key::new(&[MODKEY], keycodes::KEY_6, KeyAction::ViewTag, Arg::Int(5)), | |
| 116 | - Key::new(&[MODKEY], keycodes::KEY_7, KeyAction::ViewTag, Arg::Int(6)), | |
| 117 | - Key::new(&[MODKEY], keycodes::KEY_8, KeyAction::ViewTag, Arg::Int(7)), | |
| 118 | - Key::new(&[MODKEY], keycodes::KEY_9, KeyAction::ViewTag, Arg::Int(8)), | |
| 119 | - | |
| 120 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_1, KeyAction::MoveToTag, Arg::Int(0)), | |
| 121 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_2, KeyAction::MoveToTag, Arg::Int(1)), | |
| 122 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_3, KeyAction::MoveToTag, Arg::Int(2)), | |
| 123 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_4, KeyAction::MoveToTag, Arg::Int(3)), | |
| 124 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_5, KeyAction::MoveToTag, Arg::Int(4)), | |
| 125 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_6, KeyAction::MoveToTag, Arg::Int(5)), | |
| 126 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_7, KeyAction::MoveToTag, Arg::Int(6)), | |
| 127 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_8, KeyAction::MoveToTag, Arg::Int(7)), | |
| 128 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_9, KeyAction::MoveToTag, Arg::Int(8)), | |
| 129 | -]; | |
| 130 | - | |
| 131 | -// ======================================== | |
| 132 | -// STATUS BAR BLOCKS | |
| 133 | -// ======================================== | |
| 134 | -pub const STATUS_BLOCKS: &[BlockConfig] = &[ | |
| 135 | - BlockConfig { | |
| 136 | - format: "", | |
| 137 | - command: BlockCommand::Battery { | |
| 138 | - format_charging: " Bat: {}%", | |
| 139 | - format_discharging: " Bat:{}%", | |
| 140 | - format_full: " Bat: {}%", | |
| 141 | - }, | |
| 142 | - interval_secs: 30, | |
| 143 | - color: GREEN, | |
| 144 | - underline: true, | |
| 145 | - }, | |
| 146 | - BlockConfig { | |
| 147 | - format: " │ ", | |
| 148 | - command: BlockCommand::Static(""), | |
| 149 | - interval_secs: u64::MAX, | |
| 150 | - color: GRAY_SEP, | |
| 151 | - underline: false, | |
| 152 | - }, | |
| 153 | - BlockConfig { | |
| 154 | - format: " {used}/{total} GB", | |
| 155 | - command: BlockCommand::Ram, | |
| 156 | - interval_secs: 5, | |
| 157 | - color: BLUE, | |
| 158 | - underline: true, | |
| 159 | - }, | |
| 160 | - BlockConfig { | |
| 161 | - format: " │ ", | |
| 162 | - command: BlockCommand::Static(""), | |
| 163 | - interval_secs: u64::MAX, | |
| 164 | - color: GRAY_SEP, | |
| 165 | - underline: false, | |
| 166 | - }, | |
| 167 | - BlockConfig { | |
| 168 | - format: " {}", | |
| 169 | - command: BlockCommand::Shell("uname -r"), | |
| 170 | - interval_secs: u64::MAX, | |
| 171 | - color: RED, | |
| 172 | - underline: true, | |
| 173 | - }, | |
| 174 | - BlockConfig { | |
| 175 | - format: " │ ", | |
| 176 | - command: BlockCommand::Static(""), | |
| 177 | - interval_secs: u64::MAX, | |
| 178 | - color: GRAY_SEP, | |
| 179 | - underline: false, | |
| 180 | - }, | |
| 181 | - BlockConfig { | |
| 182 | - format: " {}", | |
| 183 | - command: BlockCommand::DateTime("%a, %b %d - %-I:%M %P"), | |
| 184 | - interval_secs: 1, | |
| 185 | - color: CYAN, | |
| 186 | - underline: true, | |
| 187 | - }, | |
| 188 | -]; | |
| 189 | - | |
| 190 | -const SHIFT: KeyButMask = KeyButMask::SHIFT; | |
| 191 | -pub const WM_BINARY: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/target/release/oxwm"); |
+2 −1 src/lib.rs
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | pub mod bar; |
| 2 | +pub mod config; | |
| 2 | 3 | pub mod errors; |
| 3 | 4 | pub mod keyboard; |
| 4 | 5 | pub mod layout; |
| @@ -67,7 +68,7 @@ impl Default for Config { | ||
| 67 | 68 | border_width: 2, |
| 68 | 69 | border_focused: 0x6dade3, |
| 69 | 70 | border_unfocused: 0xbbbbbb, |
| 70 | - font: "monospace:size=12".to_string(), | |
| 71 | + font: "monospace:size=10".to_string(), | |
| 71 | 72 | gaps_enabled: false, |
| 72 | 73 | gap_inner_horizontal: 0, |
| 73 | 74 | gap_inner_vertical: 0, |
+0 −23 src/main.rs.backup deleted file mode 100644
| @@ -1,23 +0,0 @@ | ||
| 1 | -use anyhow::Result; | |
| 2 | -mod bar; | |
| 3 | -mod config; | |
| 4 | -mod keyboard; | |
| 5 | -mod layout; | |
| 6 | -mod window_manager; | |
| 7 | - | |
| 8 | -fn main() -> Result<()> { | |
| 9 | - let args: Vec<String> = std::env::args().collect(); | |
| 10 | - | |
| 11 | - let mut window_manager = window_manager::WindowManager::new()?; | |
| 12 | - let should_restart = window_manager.run()?; | |
| 13 | - | |
| 14 | - drop(window_manager); | |
| 15 | - | |
| 16 | - if should_restart { | |
| 17 | - use std::os::unix::process::CommandExt; | |
| 18 | - let err = std::process::Command::new(&args[0]).args(&args[1..]).exec(); | |
| 19 | - eprintln!("Failed to restart: {}", err); | |
| 20 | - } | |
| 21 | - | |
| 22 | - Ok(()) | |
| 23 | -} |
+66 −0 templates/config.ron new file mode 100644
| @@ -0,0 +1,66 @@ | ||
| 1 | +#![enable(implicit_some)] | |
| 2 | +// OXWM Configuration File | |
| 3 | +// Edit this file and reload with Mod+Shift+R (no compilation needed!) | |
| 4 | + | |
| 5 | +( | |
| 6 | + border_width: 2, | |
| 7 | + border_focused: 0x6dade3, | |
| 8 | + border_unfocused: 0xbbbbbb, | |
| 9 | + font: "monospace:style=Bold:size=10", | |
| 10 | + | |
| 11 | + gaps_enabled: true, | |
| 12 | + gap_inner_horizontal: 5, | |
| 13 | + gap_inner_vertical: 5, | |
| 14 | + gap_outer_horizontal: 5, | |
| 15 | + gap_outer_vertical: 5, | |
| 16 | + | |
| 17 | + terminal: "st", | |
| 18 | + modkey: "Mod4", | |
| 19 | + | |
| 20 | + tags: ["1", "2", "3", "4", "5", "6", "7", "8", "9"], | |
| 21 | + | |
| 22 | + keybindings: [ | |
| 23 | + (modifiers: ["Mod4"], key: "return", action: "Spawn", arg: "st"), | |
| 24 | + (modifiers: ["Mod4"], key: "d", action: "Spawn", arg: ["sh", "-c", "dmenu_run -l 10"]), | |
| 25 | + (modifiers: ["Mod4"], key: "s", action: "Spawn", arg: ["sh", "-c", "maim -s | xclip -selection clipboard -t image/png"]), | |
| 26 | + (modifiers: ["Mod4"], key: "q", action: "KillClient"), | |
| 27 | + (modifiers: ["Mod4", "Shift"], key: "f", action: "ToggleFullScreen"), | |
| 28 | + (modifiers: ["Mod4", "Shift"], key: "space", action: "ToggleFloating"), | |
| 29 | + (modifiers: ["Mod4"], key: "a", action: "ToggleGaps"), | |
| 30 | + (modifiers: ["Mod4", "Shift"], key: "q", action: "Quit"), | |
| 31 | + (modifiers: ["Mod4", "Shift"], key: "r", action: "Restart"), | |
| 32 | + (modifiers: ["Mod4"], key: "j", action: "FocusStack", arg: -1), | |
| 33 | + (modifiers: ["Mod4"], key: "k", action: "FocusStack", arg: 1), | |
| 34 | + (modifiers: ["Mod4"], key: "1", action: "ViewTag", arg: 0), | |
| 35 | + (modifiers: ["Mod4"], key: "2", action: "ViewTag", arg: 1), | |
| 36 | + (modifiers: ["Mod4"], key: "3", action: "ViewTag", arg: 2), | |
| 37 | + (modifiers: ["Mod4"], key: "4", action: "ViewTag", arg: 3), | |
| 38 | + (modifiers: ["Mod4"], key: "5", action: "ViewTag", arg: 4), | |
| 39 | + (modifiers: ["Mod4"], key: "6", action: "ViewTag", arg: 5), | |
| 40 | + (modifiers: ["Mod4"], key: "7", action: "ViewTag", arg: 6), | |
| 41 | + (modifiers: ["Mod4"], key: "8", action: "ViewTag", arg: 7), | |
| 42 | + (modifiers: ["Mod4"], key: "9", action: "ViewTag", arg: 8), | |
| 43 | + (modifiers: ["Mod4", "Shift"], key: "1", action: "MoveToTag", arg: 0), | |
| 44 | + (modifiers: ["Mod4", "Shift"], key: "2", action: "MoveToTag", arg: 1), | |
| 45 | + (modifiers: ["Mod4", "Shift"], key: "3", action: "MoveToTag", arg: 2), | |
| 46 | + (modifiers: ["Mod4", "Shift"], key: "4", action: "MoveToTag", arg: 3), | |
| 47 | + (modifiers: ["Mod4", "Shift"], key: "5", action: "MoveToTag", arg: 4), | |
| 48 | + (modifiers: ["Mod4", "Shift"], key: "6", action: "MoveToTag", arg: 5), | |
| 49 | + (modifiers: ["Mod4", "Shift"], key: "7", action: "MoveToTag", arg: 6), | |
| 50 | + (modifiers: ["Mod4", "Shift"], key: "8", action: "MoveToTag", arg: 7), | |
| 51 | + (modifiers: ["Mod4", "Shift"], key: "9", action: "MoveToTag", arg: 8), | |
| 52 | + ], | |
| 53 | + | |
| 54 | + status_blocks: [ | |
| 55 | + (format: " {used}/{total} GB", command: "Ram", interval_secs: 5, color: 0x7aa2f7, underline: true), | |
| 56 | + (format: " │ ", command: "Static", interval_secs: 18446744073709551615, color: 0xa9b1d6, underline: false), | |
| 57 | + (format: " {}", command: "Shell", command_arg: "uname -r", interval_secs: 18446744073709551615, color: 0xf7768e, underline: true), | |
| 58 | + (format: " │ ", command: "Static", interval_secs: 18446744073709551615, color: 0xa9b1d6, underline: false), | |
| 59 | + (format: " {}", command: "DateTime", command_arg: "%a, %b %d - %-I:%M %P", interval_secs: 1, color: 0x0db9d7, underline: true), | |
| 60 | + ], | |
| 61 | + | |
| 62 | + scheme_normal: (foreground: 0xbbbbbb, background: 0x1a1b26, underline: 0x444444), | |
| 63 | + scheme_occupied: (foreground: 0x0db9d7, background: 0x1a1b26, underline: 0x0db9d7), | |
| 64 | + scheme_selected: (foreground: 0x0db9d7, background: 0x1a1b26, underline: 0xad8ee6), | |
| 65 | +) | |
| 66 | + |