Merge pull request #15 from tonybanters/rusty-object-notation-refactor
Browse files
feat: replace edit + recompile configuration with actual config file in RON format :)
+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.2.0" | |
| 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" |
+1 −1 default.nix
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | }: |
| 10 | 10 | rustPlatform.buildRustPackage (finalAttrs: { |
| 11 | 11 | pname = "oxwm"; |
| 12 | - version = "0.1.0"; | |
| 12 | + version = "0.2.0"; | |
| 13 | 13 | |
| 14 | 14 | src = ./.; |
| 15 | 15 |
+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 |
+8 −14 readme.org
| @@ -81,13 +81,9 @@ Add this to your =configuration.nix=: | ||
| 81 | 81 | #+end_src |
| 82 | 82 | |
| 83 | 83 | *** Initialize your config |
| 84 | -After rebuilding your system with =sudo nixos-rebuild switch=, log in via your display manager, then run: | |
| 84 | +After rebuilding your system with =sudo nixos-rebuild switch=, log in via your display manager. | |
| 85 | 85 | |
| 86 | -#+begin_src sh | |
| 87 | -oxwm --init | |
| 88 | -#+end_src | |
| 89 | - | |
| 90 | -This creates your personal config at =~/.config/oxwm/config.rs=. Edit it and reload with =Mod+Shift+R=. | |
| 86 | +On first launch, your initial config file will be automatically created and placed in =~/.config/oxwm/config.ron=. Edit it and reload with =Mod+Shift+R=. | |
| 91 | 87 | |
| 92 | 88 | *** Advanced: Using a specific oxwm version |
| 93 | 89 | If you want to pin or customize the oxwm package: |
| @@ -153,25 +149,23 @@ startx | ||
| 153 | 149 | If using a display manager (LightDM, GDM, SDDM), OXWM should appear in the session list after installation. |
| 154 | 150 | |
| 155 | 151 | * Configuration |
| 156 | -OXWM follows the suckless philosophy: configuration is done by editing =~/.config/oxwm/config.rs= and recompiling. | |
| 157 | - | |
| 158 | -On first run with =oxwm --init=, your config is automatically created from the template. Your =config.rs= is gitignored, so you can customize it without worrying about merge conflicts. | |
| 152 | +OXWM was inspired by dwm, but ditched the suckless philosophy. This philosophy quite literally discourages users from using the software for the sake of 'elitism'. I find that quite nonsensical, so I went ahead and created this project to be user friendly. The configuration is done by editing =~/.config/oxwm/config.ron= and the binary can be reloaded with a hotkey (Super+Shift+R by efault). | |
| 159 | 153 | |
| 160 | -Edit =~/.config/oxwm/config.rs= to customize: | |
| 154 | +Edit =~/.config/oxwm/config.ron= to customize: | |
| 161 | 155 | - Keybindings |
| 162 | 156 | - Colors and appearance |
| 163 | 157 | - Status bar blocks |
| 164 | 158 | - Gaps and borders |
| 165 | 159 | - Terminal and applications |
| 166 | 160 | |
| 167 | -After making changes, reload OXWM with =Mod+Shift+R= (auto-recompiles if needed). | |
| 161 | +After making changes, reload OXWM with =Mod+Shift+R= | |
| 168 | 162 | |
| 169 | 163 | * Contributing |
| 170 | 164 | When contributing to OXWM: |
| 171 | 165 | |
| 172 | -1. Never commit your personal =~/.config/oxwm/config.rs= | |
| 173 | -2. Only modify =templates/config.rs= if adding new configuration options | |
| 174 | -3. Test your changes with =just test= using Xephyr | |
| 166 | +1. Never commit your personal =~/.config/oxwm/config.ron= | |
| 167 | +2. Only modify =templates/config.ron= if adding new configuration options | |
| 168 | +3. Test your changes with =just test= using Xephyr/Xwayland | |
| 175 | 169 | 4. Document any new features or keybindings |
| 176 | 170 | |
| 177 | 171 | * Key Bindings |
+11 −11 src/bar/blocks/mod.rs
| @@ -19,7 +19,7 @@ pub trait Block { | ||
| 19 | 19 | |
| 20 | 20 | #[derive(Clone)] |
| 21 | 21 | pub struct BlockConfig { |
| 22 | - pub format: &'static str, | |
| 22 | + pub format: String, | |
| 23 | 23 | pub command: BlockCommand, |
| 24 | 24 | pub interval_secs: u64, |
| 25 | 25 | pub color: u32, |
| @@ -28,28 +28,28 @@ pub struct BlockConfig { | ||
| 28 | 28 | |
| 29 | 29 | #[derive(Clone)] |
| 30 | 30 | pub enum BlockCommand { |
| 31 | - Shell(&'static str), | |
| 32 | - DateTime(&'static str), | |
| 31 | + Shell(String), | |
| 32 | + DateTime(String), | |
| 33 | 33 | Battery { |
| 34 | - format_charging: &'static str, | |
| 35 | - format_discharging: &'static str, | |
| 36 | - format_full: &'static str, | |
| 34 | + format_charging: String, | |
| 35 | + format_discharging: String, | |
| 36 | + format_full: String, | |
| 37 | 37 | }, |
| 38 | 38 | Ram, |
| 39 | - Static(&'static str), | |
| 39 | + Static(String), | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | impl BlockConfig { |
| 43 | 43 | pub fn to_block(&self) -> Box<dyn Block> { |
| 44 | - match self.command { | |
| 44 | + match &self.command { | |
| 45 | 45 | BlockCommand::Shell(cmd) => Box::new(ShellBlock::new( |
| 46 | - self.format, | |
| 46 | + &self.format, | |
| 47 | 47 | cmd, |
| 48 | 48 | self.interval_secs, |
| 49 | 49 | self.color, |
| 50 | 50 | )), |
| 51 | 51 | BlockCommand::DateTime(fmt) => Box::new(DateTime::new( |
| 52 | - self.format, | |
| 52 | + &self.format, | |
| 53 | 53 | fmt, |
| 54 | 54 | self.interval_secs, |
| 55 | 55 | self.color, |
| @@ -65,7 +65,7 @@ impl BlockConfig { | ||
| 65 | 65 | self.interval_secs, |
| 66 | 66 | self.color, |
| 67 | 67 | )), |
| 68 | - BlockCommand::Ram => Box::new(Ram::new(self.format, self.interval_secs, self.color)), | |
| 68 | + BlockCommand::Ram => Box::new(Ram::new(&self.format, self.interval_secs, self.color)), | |
| 69 | 69 | BlockCommand::Static(text) => Box::new(StaticBlock::new( |
| 70 | 70 | &format!("{}{}", self.format, text), |
| 71 | 71 | self.color, |
+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 | } |
+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"); |
+349 −0 src/config/mod.rs new file mode 100644
| @@ -0,0 +1,349 @@ | ||
| 1 | +use crate::bar::{BlockCommand, BlockConfig}; | |
| 2 | +use crate::errors::ConfigError; | |
| 3 | +use crate::keyboard::handlers::Key; | |
| 4 | +use crate::keyboard::keycodes; | |
| 5 | +use crate::keyboard::{Arg, KeyAction}; | |
| 6 | +use serde::Deserialize; | |
| 7 | +use x11rb::protocol::xproto::{KeyButMask, Keycode}; | |
| 8 | + | |
| 9 | +#[derive(Debug, Deserialize)] | |
| 10 | +pub enum ModKey { | |
| 11 | + Mod1, | |
| 12 | + Mod2, | |
| 13 | + Mod3, | |
| 14 | + Mod4, | |
| 15 | + Mod5, | |
| 16 | + Shift, | |
| 17 | + Control, | |
| 18 | +} | |
| 19 | + | |
| 20 | +impl ModKey { | |
| 21 | + fn to_keybut_mask(&self) -> KeyButMask { | |
| 22 | + match self { | |
| 23 | + ModKey::Mod1 => KeyButMask::MOD1, | |
| 24 | + ModKey::Mod2 => KeyButMask::MOD2, | |
| 25 | + ModKey::Mod3 => KeyButMask::MOD3, | |
| 26 | + ModKey::Mod4 => KeyButMask::MOD4, | |
| 27 | + ModKey::Mod5 => KeyButMask::MOD5, | |
| 28 | + ModKey::Shift => KeyButMask::SHIFT, | |
| 29 | + ModKey::Control => KeyButMask::CONTROL, | |
| 30 | + } | |
| 31 | + } | |
| 32 | +} | |
| 33 | + | |
| 34 | +#[derive(Debug, Deserialize)] | |
| 35 | +pub enum KeyData { | |
| 36 | + Return, | |
| 37 | + Q, | |
| 38 | + Escape, | |
| 39 | + Space, | |
| 40 | + Tab, | |
| 41 | + Backspace, | |
| 42 | + Delete, | |
| 43 | + F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, | |
| 44 | + A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, R, S, T, U, V, W, X, Y, Z, | |
| 45 | + Key0, | |
| 46 | + Key1, | |
| 47 | + Key2, | |
| 48 | + Key3, | |
| 49 | + Key4, | |
| 50 | + Key5, | |
| 51 | + Key6, | |
| 52 | + Key7, | |
| 53 | + Key8, | |
| 54 | + Key9, | |
| 55 | + Left, | |
| 56 | + Right, | |
| 57 | + Up, | |
| 58 | + Down, | |
| 59 | + Home, | |
| 60 | + End, | |
| 61 | + PageUp, | |
| 62 | + PageDown, | |
| 63 | + Insert, | |
| 64 | + Minus, | |
| 65 | + Equal, | |
| 66 | + BracketLeft, | |
| 67 | + BracketRight, | |
| 68 | + Semicolon, | |
| 69 | + Apostrophe, | |
| 70 | + Grave, | |
| 71 | + Backslash, | |
| 72 | + Comma, | |
| 73 | + Period, | |
| 74 | + Slash, | |
| 75 | +} | |
| 76 | + | |
| 77 | +impl KeyData { | |
| 78 | + fn to_keycode(&self) -> Keycode { | |
| 79 | + match self { | |
| 80 | + KeyData::Return => keycodes::RETURN, | |
| 81 | + KeyData::Q => keycodes::Q, | |
| 82 | + KeyData::Escape => keycodes::ESCAPE, | |
| 83 | + KeyData::Space => keycodes::SPACE, | |
| 84 | + KeyData::Tab => keycodes::TAB, | |
| 85 | + KeyData::Backspace => keycodes::BACKSPACE, | |
| 86 | + KeyData::Delete => keycodes::DELETE, | |
| 87 | + KeyData::F1 => keycodes::F1, | |
| 88 | + KeyData::F2 => keycodes::F2, | |
| 89 | + KeyData::F3 => keycodes::F3, | |
| 90 | + KeyData::F4 => keycodes::F4, | |
| 91 | + KeyData::F5 => keycodes::F5, | |
| 92 | + KeyData::F6 => keycodes::F6, | |
| 93 | + KeyData::F7 => keycodes::F7, | |
| 94 | + KeyData::F8 => keycodes::F8, | |
| 95 | + KeyData::F9 => keycodes::F9, | |
| 96 | + KeyData::F10 => keycodes::F10, | |
| 97 | + KeyData::F11 => keycodes::F11, | |
| 98 | + KeyData::F12 => keycodes::F12, | |
| 99 | + KeyData::A => keycodes::A, | |
| 100 | + KeyData::B => keycodes::B, | |
| 101 | + KeyData::C => keycodes::C, | |
| 102 | + KeyData::D => keycodes::D, | |
| 103 | + KeyData::E => keycodes::E, | |
| 104 | + KeyData::F => keycodes::F, | |
| 105 | + KeyData::G => keycodes::G, | |
| 106 | + KeyData::H => keycodes::H, | |
| 107 | + KeyData::I => keycodes::I, | |
| 108 | + KeyData::J => keycodes::J, | |
| 109 | + KeyData::K => keycodes::K, | |
| 110 | + KeyData::L => keycodes::L, | |
| 111 | + KeyData::M => keycodes::M, | |
| 112 | + KeyData::N => keycodes::N, | |
| 113 | + KeyData::O => keycodes::O, | |
| 114 | + KeyData::P => keycodes::P, | |
| 115 | + KeyData::R => keycodes::R, | |
| 116 | + KeyData::S => keycodes::S, | |
| 117 | + KeyData::T => keycodes::T, | |
| 118 | + KeyData::U => keycodes::U, | |
| 119 | + KeyData::V => keycodes::V, | |
| 120 | + KeyData::W => keycodes::W, | |
| 121 | + KeyData::X => keycodes::X, | |
| 122 | + KeyData::Y => keycodes::Y, | |
| 123 | + KeyData::Z => keycodes::Z, | |
| 124 | + KeyData::Key0 => keycodes::KEY_0, | |
| 125 | + KeyData::Key1 => keycodes::KEY_1, | |
| 126 | + KeyData::Key2 => keycodes::KEY_2, | |
| 127 | + KeyData::Key3 => keycodes::KEY_3, | |
| 128 | + KeyData::Key4 => keycodes::KEY_4, | |
| 129 | + KeyData::Key5 => keycodes::KEY_5, | |
| 130 | + KeyData::Key6 => keycodes::KEY_6, | |
| 131 | + KeyData::Key7 => keycodes::KEY_7, | |
| 132 | + KeyData::Key8 => keycodes::KEY_8, | |
| 133 | + KeyData::Key9 => keycodes::KEY_9, | |
| 134 | + KeyData::Left => keycodes::LEFT, | |
| 135 | + KeyData::Right => keycodes::RIGHT, | |
| 136 | + KeyData::Up => keycodes::UP, | |
| 137 | + KeyData::Down => keycodes::DOWN, | |
| 138 | + KeyData::Home => keycodes::HOME, | |
| 139 | + KeyData::End => keycodes::END, | |
| 140 | + KeyData::PageUp => keycodes::PAGE_UP, | |
| 141 | + KeyData::PageDown => keycodes::PAGE_DOWN, | |
| 142 | + KeyData::Insert => keycodes::INSERT, | |
| 143 | + KeyData::Minus => keycodes::MINUS, | |
| 144 | + KeyData::Equal => keycodes::EQUAL, | |
| 145 | + KeyData::BracketLeft => keycodes::LEFT_BRACKET, | |
| 146 | + KeyData::BracketRight => keycodes::RIGHT_BRACKET, | |
| 147 | + KeyData::Semicolon => keycodes::SEMICOLON, | |
| 148 | + KeyData::Apostrophe => keycodes::APOSTROPHE, | |
| 149 | + KeyData::Grave => keycodes::GRAVE, | |
| 150 | + KeyData::Backslash => keycodes::BACKSLASH, | |
| 151 | + KeyData::Comma => keycodes::COMMA, | |
| 152 | + KeyData::Period => keycodes::PERIOD, | |
| 153 | + KeyData::Slash => keycodes::SLASH, | |
| 154 | + } | |
| 155 | + } | |
| 156 | +} | |
| 157 | + | |
| 158 | +pub fn parse_config(input: &str) -> Result<crate::Config, ConfigError> { | |
| 159 | + let config_data: ConfigData = ron::from_str(input)?; | |
| 160 | + config_data_to_config(config_data) | |
| 161 | +} | |
| 162 | + | |
| 163 | +#[derive(Debug, Deserialize)] | |
| 164 | +struct ConfigData { | |
| 165 | + border_width: u32, | |
| 166 | + border_focused: u32, | |
| 167 | + border_unfocused: u32, | |
| 168 | + font: String, | |
| 169 | + | |
| 170 | + gaps_enabled: bool, | |
| 171 | + gap_inner_horizontal: u32, | |
| 172 | + gap_inner_vertical: u32, | |
| 173 | + gap_outer_horizontal: u32, | |
| 174 | + gap_outer_vertical: u32, | |
| 175 | + | |
| 176 | + terminal: String, | |
| 177 | + modkey: ModKey, | |
| 178 | + | |
| 179 | + tags: Vec<String>, | |
| 180 | + keybindings: Vec<KeybindingData>, | |
| 181 | + status_blocks: Vec<StatusBlockData>, | |
| 182 | + | |
| 183 | + scheme_normal: ColorSchemeData, | |
| 184 | + scheme_occupied: ColorSchemeData, | |
| 185 | + scheme_selected: ColorSchemeData, | |
| 186 | +} | |
| 187 | + | |
| 188 | +#[derive(Debug, Deserialize)] | |
| 189 | +struct KeybindingData { | |
| 190 | + modifiers: Vec<ModKey>, | |
| 191 | + key: KeyData, | |
| 192 | + action: KeyAction, | |
| 193 | + #[serde(default)] | |
| 194 | + arg: ArgData, | |
| 195 | +} | |
| 196 | + | |
| 197 | +#[derive(Debug, Deserialize)] | |
| 198 | +#[serde(untagged)] | |
| 199 | +enum ArgData { | |
| 200 | + None, | |
| 201 | + String(String), | |
| 202 | + Int(i32), | |
| 203 | + Array(Vec<String>), | |
| 204 | +} | |
| 205 | + | |
| 206 | +impl Default for ArgData { | |
| 207 | + fn default() -> Self { | |
| 208 | + ArgData::None | |
| 209 | + } | |
| 210 | +} | |
| 211 | + | |
| 212 | +#[derive(Debug, Deserialize)] | |
| 213 | +struct StatusBlockData { | |
| 214 | + format: String, | |
| 215 | + command: String, | |
| 216 | + #[serde(default)] | |
| 217 | + command_arg: Option<String>, | |
| 218 | + #[serde(default)] | |
| 219 | + battery_formats: Option<BatteryFormats>, | |
| 220 | + interval_secs: u64, | |
| 221 | + color: u32, | |
| 222 | + underline: bool, | |
| 223 | +} | |
| 224 | + | |
| 225 | +#[derive(Debug, Deserialize)] | |
| 226 | +struct BatteryFormats { | |
| 227 | + charging: String, | |
| 228 | + discharging: String, | |
| 229 | + full: String, | |
| 230 | +} | |
| 231 | + | |
| 232 | +#[derive(Debug, Deserialize)] | |
| 233 | +struct ColorSchemeData { | |
| 234 | + foreground: u32, | |
| 235 | + background: u32, | |
| 236 | + underline: u32, | |
| 237 | +} | |
| 238 | + | |
| 239 | +fn config_data_to_config(data: ConfigData) -> Result<crate::Config, ConfigError> { | |
| 240 | + let modkey = data.modkey.to_keybut_mask(); | |
| 241 | + | |
| 242 | + let mut keybindings = Vec::new(); | |
| 243 | + for kb_data in data.keybindings { | |
| 244 | + let modifiers = kb_data | |
| 245 | + .modifiers | |
| 246 | + .iter() | |
| 247 | + .map(|m| m.to_keybut_mask()) | |
| 248 | + .collect(); | |
| 249 | + | |
| 250 | + let key = kb_data.key.to_keycode(); | |
| 251 | + let action = kb_data.action; | |
| 252 | + let arg = arg_data_to_arg(kb_data.arg)?; | |
| 253 | + | |
| 254 | + keybindings.push(Key::new(modifiers, key, action, arg)); | |
| 255 | + } | |
| 256 | + | |
| 257 | + let mut status_blocks = Vec::new(); | |
| 258 | + for block_data in data.status_blocks { | |
| 259 | + let command = match block_data.command.as_str() { | |
| 260 | + "DateTime" => { | |
| 261 | + let fmt = block_data | |
| 262 | + .command_arg | |
| 263 | + .ok_or_else(|| ConfigError::MissingCommandArg { | |
| 264 | + command: "DateTime".to_string(), | |
| 265 | + field: "command_arg".to_string(), | |
| 266 | + })?; | |
| 267 | + BlockCommand::DateTime(fmt) | |
| 268 | + } | |
| 269 | + "Shell" => { | |
| 270 | + let cmd = block_data | |
| 271 | + .command_arg | |
| 272 | + .ok_or_else(|| ConfigError::MissingCommandArg { | |
| 273 | + command: "Shell".to_string(), | |
| 274 | + field: "command_arg".to_string(), | |
| 275 | + })?; | |
| 276 | + BlockCommand::Shell(cmd) | |
| 277 | + } | |
| 278 | + "Ram" => BlockCommand::Ram, | |
| 279 | + "Static" => { | |
| 280 | + let text = block_data.command_arg.unwrap_or_default(); | |
| 281 | + BlockCommand::Static(text) | |
| 282 | + } | |
| 283 | + "Battery" => { | |
| 284 | + let formats = | |
| 285 | + block_data | |
| 286 | + .battery_formats | |
| 287 | + .ok_or_else(|| ConfigError::MissingCommandArg { | |
| 288 | + command: "Battery".to_string(), | |
| 289 | + field: "battery_formats".to_string(), | |
| 290 | + })?; | |
| 291 | + BlockCommand::Battery { | |
| 292 | + format_charging: formats.charging, | |
| 293 | + format_discharging: formats.discharging, | |
| 294 | + format_full: formats.full, | |
| 295 | + } | |
| 296 | + } | |
| 297 | + _ => return Err(ConfigError::UnknownBlockCommand(block_data.command)), | |
| 298 | + }; | |
| 299 | + | |
| 300 | + status_blocks.push(BlockConfig { | |
| 301 | + format: block_data.format, | |
| 302 | + command, | |
| 303 | + interval_secs: block_data.interval_secs, | |
| 304 | + color: block_data.color, | |
| 305 | + underline: block_data.underline, | |
| 306 | + }); | |
| 307 | + } | |
| 308 | + | |
| 309 | + Ok(crate::Config { | |
| 310 | + border_width: data.border_width, | |
| 311 | + border_focused: data.border_focused, | |
| 312 | + border_unfocused: data.border_unfocused, | |
| 313 | + font: data.font, | |
| 314 | + gaps_enabled: data.gaps_enabled, | |
| 315 | + gap_inner_horizontal: data.gap_inner_horizontal, | |
| 316 | + gap_inner_vertical: data.gap_inner_vertical, | |
| 317 | + gap_outer_horizontal: data.gap_outer_horizontal, | |
| 318 | + gap_outer_vertical: data.gap_outer_vertical, | |
| 319 | + terminal: data.terminal, | |
| 320 | + modkey, | |
| 321 | + tags: data.tags, | |
| 322 | + keybindings, | |
| 323 | + status_blocks, | |
| 324 | + scheme_normal: crate::ColorScheme { | |
| 325 | + foreground: data.scheme_normal.foreground, | |
| 326 | + background: data.scheme_normal.background, | |
| 327 | + underline: data.scheme_normal.underline, | |
| 328 | + }, | |
| 329 | + scheme_occupied: crate::ColorScheme { | |
| 330 | + foreground: data.scheme_occupied.foreground, | |
| 331 | + background: data.scheme_occupied.background, | |
| 332 | + underline: data.scheme_occupied.underline, | |
| 333 | + }, | |
| 334 | + scheme_selected: crate::ColorScheme { | |
| 335 | + foreground: data.scheme_selected.foreground, | |
| 336 | + background: data.scheme_selected.background, | |
| 337 | + underline: data.scheme_selected.underline, | |
| 338 | + }, | |
| 339 | + }) | |
| 340 | +} | |
| 341 | + | |
| 342 | +fn arg_data_to_arg(data: ArgData) -> Result<Arg, ConfigError> { | |
| 343 | + match data { | |
| 344 | + ArgData::None => Ok(Arg::None), | |
| 345 | + ArgData::String(s) => Ok(Arg::Str(s)), | |
| 346 | + ArgData::Int(n) => Ok(Arg::Int(n)), | |
| 347 | + ArgData::Array(arr) => Ok(Arg::Array(arr)), | |
| 348 | + } | |
| 349 | +} |
+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"); |
+41 −0 src/errors.rs
| @@ -3,6 +3,7 @@ pub enum WmError { | ||
| 3 | 3 | X11(X11Error), |
| 4 | 4 | Io(std::io::Error), |
| 5 | 5 | Anyhow(anyhow::Error), |
| 6 | + Config(ConfigError), | |
| 6 | 7 | } |
| 7 | 8 | |
| 8 | 9 | #[derive(Debug)] |
| @@ -16,12 +17,23 @@ pub enum X11Error { | ||
| 16 | 17 | DrawCreateFailed, |
| 17 | 18 | } |
| 18 | 19 | |
| 20 | +#[derive(Debug)] | |
| 21 | +pub enum ConfigError { | |
| 22 | + ParseError(ron::error::SpannedError), | |
| 23 | + InvalidModkey(String), | |
| 24 | + UnknownKey(String), | |
| 25 | + UnknownAction(String), | |
| 26 | + UnknownBlockCommand(String), | |
| 27 | + MissingCommandArg { command: String, field: String }, | |
| 28 | +} | |
| 29 | + | |
| 19 | 30 | impl std::fmt::Display for WmError { |
| 20 | 31 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 21 | 32 | match self { |
| 22 | 33 | Self::X11(error) => write!(f, "{}", error), |
| 23 | 34 | Self::Io(error) => write!(f, "{}", error), |
| 24 | 35 | Self::Anyhow(error) => write!(f, "{}", error), |
| 36 | + Self::Config(error) => write!(f, "{}", error), | |
| 25 | 37 | } |
| 26 | 38 | } |
| 27 | 39 | } |
| @@ -44,6 +56,23 @@ impl std::fmt::Display for X11Error { | ||
| 44 | 56 | |
| 45 | 57 | impl std::error::Error for X11Error {} |
| 46 | 58 | |
| 59 | +impl std::fmt::Display for ConfigError { | |
| 60 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
| 61 | + match self { | |
| 62 | + Self::ParseError(err) => write!(f, "Failed to parse RON config: {}", err), | |
| 63 | + Self::InvalidModkey(key) => write!(f, "Invalid modkey: {}", key), | |
| 64 | + Self::UnknownKey(key) => write!(f, "Unknown key: {}", key), | |
| 65 | + Self::UnknownAction(action) => write!(f, "Unknown action: {}", action), | |
| 66 | + Self::UnknownBlockCommand(cmd) => write!(f, "Unknown block command: {}", cmd), | |
| 67 | + Self::MissingCommandArg { command, field } => { | |
| 68 | + write!(f, "{} command requires {}", command, field) | |
| 69 | + } | |
| 70 | + } | |
| 71 | + } | |
| 72 | +} | |
| 73 | + | |
| 74 | +impl std::error::Error for ConfigError {} | |
| 75 | + | |
| 47 | 76 | impl<T: Into<X11Error>> From<T> for WmError { |
| 48 | 77 | fn from(value: T) -> Self { |
| 49 | 78 | Self::X11(value.into()) |
| @@ -62,6 +91,18 @@ impl From<anyhow::Error> for WmError { | ||
| 62 | 91 | } |
| 63 | 92 | } |
| 64 | 93 | |
| 94 | +impl From<ConfigError> for WmError { | |
| 95 | + fn from(value: ConfigError) -> Self { | |
| 96 | + Self::Config(value) | |
| 97 | + } | |
| 98 | +} | |
| 99 | + | |
| 100 | +impl From<ron::error::SpannedError> for ConfigError { | |
| 101 | + fn from(value: ron::error::SpannedError) -> Self { | |
| 102 | + ConfigError::ParseError(value) | |
| 103 | + } | |
| 104 | +} | |
| 105 | + | |
| 65 | 106 | impl From<x11rb::errors::ConnectError> for X11Error { |
| 66 | 107 | fn from(value: x11rb::errors::ConnectError) -> Self { |
| 67 | 108 | X11Error::ConnectError(value) |
+11 −14 src/keyboard/handlers.rs
| @@ -1,12 +1,13 @@ | ||
| 1 | 1 | use std::io; |
| 2 | 2 | use std::process::Command; |
| 3 | 3 | |
| 4 | +use serde::Deserialize; | |
| 4 | 5 | use x11rb::connection::Connection; |
| 5 | 6 | use x11rb::protocol::xproto::*; |
| 6 | 7 | |
| 7 | 8 | use crate::errors::X11Error; |
| 8 | 9 | |
| 9 | -#[derive(Debug, Copy, Clone)] | |
| 10 | +#[derive(Debug, Copy, Clone, Deserialize)] | |
| 10 | 11 | pub enum KeyAction { |
| 11 | 12 | Spawn, |
| 12 | 13 | KillClient, |
| @@ -26,8 +27,8 @@ pub enum KeyAction { | ||
| 26 | 27 | pub enum Arg { |
| 27 | 28 | None, |
| 28 | 29 | Int(i32), |
| 29 | - Str(&'static str), | |
| 30 | - Array(&'static [&'static str]), | |
| 30 | + Str(String), | |
| 31 | + Array(Vec<String>), | |
| 31 | 32 | } |
| 32 | 33 | |
| 33 | 34 | impl Arg { |
| @@ -38,19 +39,14 @@ impl Arg { | ||
| 38 | 39 | |
| 39 | 40 | #[derive(Clone)] |
| 40 | 41 | pub struct Key { |
| 41 | - pub(crate) modifiers: &'static [KeyButMask], | |
| 42 | + pub(crate) modifiers: Vec<KeyButMask>, | |
| 42 | 43 | pub(crate) key: Keycode, |
| 43 | 44 | pub(crate) func: KeyAction, |
| 44 | 45 | pub(crate) arg: Arg, |
| 45 | 46 | } |
| 46 | 47 | |
| 47 | 48 | impl Key { |
| 48 | - pub const fn new( | |
| 49 | - modifiers: &'static [KeyButMask], | |
| 50 | - key: Keycode, | |
| 51 | - func: KeyAction, | |
| 52 | - arg: Arg, | |
| 53 | - ) -> Self { | |
| 49 | + pub fn new(modifiers: Vec<KeyButMask>, key: Keycode, func: KeyAction, arg: Arg) -> Self { | |
| 54 | 50 | Self { |
| 55 | 51 | modifiers, |
| 56 | 52 | key, |
| @@ -72,7 +68,7 @@ pub fn setup_keybinds( | ||
| 72 | 68 | keybindings: &[Key], |
| 73 | 69 | ) -> Result<(), X11Error> { |
| 74 | 70 | for keybinding in keybindings { |
| 75 | - let modifier_mask = modifiers_to_mask(keybinding.modifiers); | |
| 71 | + let modifier_mask = modifiers_to_mask(&keybinding.modifiers); | |
| 76 | 72 | |
| 77 | 73 | connection.grab_key( |
| 78 | 74 | false, |
| @@ -88,7 +84,7 @@ pub fn setup_keybinds( | ||
| 88 | 84 | |
| 89 | 85 | pub fn handle_key_press(event: KeyPressEvent, keybindings: &[Key]) -> (KeyAction, Arg) { |
| 90 | 86 | for keybinding in keybindings { |
| 91 | - let modifier_mask = modifiers_to_mask(keybinding.modifiers); | |
| 87 | + let modifier_mask = modifiers_to_mask(&keybinding.modifiers); | |
| 92 | 88 | |
| 93 | 89 | if event.detail == keybinding.key && event.state == modifier_mask.into() { |
| 94 | 90 | return (keybinding.func, keybinding.arg.clone()); |
| @@ -102,7 +98,7 @@ pub fn handle_spawn_action(action: KeyAction, arg: &Arg) -> io::Result<()> { | ||
| 102 | 98 | use io::ErrorKind; |
| 103 | 99 | if let KeyAction::Spawn = action { |
| 104 | 100 | match arg { |
| 105 | - Arg::Str(command) => match Command::new(command).spawn() { | |
| 101 | + Arg::Str(command) => match Command::new(command.as_str()).spawn() { | |
| 106 | 102 | Err(err) if err.kind() == ErrorKind::NotFound => { |
| 107 | 103 | eprintln!( |
| 108 | 104 | "KeyAction::Spawn failed: could not spawn \"{}\", command not found", |
| @@ -117,7 +113,8 @@ pub fn handle_spawn_action(action: KeyAction, arg: &Arg) -> io::Result<()> { | ||
| 117 | 113 | return Ok(()); |
| 118 | 114 | }; |
| 119 | 115 | |
| 120 | - match Command::new(cmd).args(args).spawn() { | |
| 116 | + let args_str: Vec<&str> = args.iter().map(|s| s.as_str()).collect(); | |
| 117 | + match Command::new(cmd.as_str()).args(&args_str).spawn() { | |
| 121 | 118 | Err(err) if err.kind() == ErrorKind::NotFound => { |
| 122 | 119 | eprintln!( |
| 123 | 120 | "KeyAction::Spawn failed: could not spawn \"{}\", command not found", |
+34 −32 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, |
| @@ -81,96 +82,97 @@ impl Default for Config { | ||
| 81 | 82 | .collect(), |
| 82 | 83 | keybindings: vec![ |
| 83 | 84 | Key::new( |
| 84 | - &[MODKEY], | |
| 85 | + vec![MODKEY], | |
| 85 | 86 | keycodes::RETURN, |
| 86 | 87 | KeyAction::Spawn, |
| 87 | - Arg::Str(TERMINAL), | |
| 88 | + Arg::Str(TERMINAL.to_string()), | |
| 88 | 89 | ), |
| 89 | 90 | Key::new( |
| 90 | - &[MODKEY], | |
| 91 | + vec![MODKEY], | |
| 91 | 92 | keycodes::D, |
| 92 | 93 | KeyAction::Spawn, |
| 93 | - Arg::Array(&["sh", "-c", "dmenu_run"]), | |
| 94 | + Arg::Array(vec!["sh".to_string(), "-c".to_string(), "dmenu_run -l 10".to_string()]), | |
| 94 | 95 | ), |
| 95 | - Key::new(&[MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None), | |
| 96 | + Key::new(vec![MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None), | |
| 96 | 97 | Key::new( |
| 97 | - &[MODKEY, SHIFT], | |
| 98 | + vec![MODKEY, SHIFT], | |
| 98 | 99 | keycodes::F, |
| 99 | 100 | KeyAction::ToggleFullScreen, |
| 100 | 101 | Arg::None, |
| 101 | 102 | ), |
| 102 | - Key::new(&[MODKEY], keycodes::A, KeyAction::ToggleGaps, Arg::None), | |
| 103 | - Key::new(&[MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None), | |
| 104 | - Key::new(&[MODKEY, SHIFT], keycodes::R, KeyAction::Restart, Arg::None), | |
| 105 | - Key::new(&[MODKEY], keycodes::J, KeyAction::FocusStack, Arg::Int(-1)), | |
| 106 | - Key::new(&[MODKEY], keycodes::K, KeyAction::FocusStack, Arg::Int(1)), | |
| 107 | - Key::new(&[MODKEY], keycodes::KEY_1, KeyAction::ViewTag, Arg::Int(0)), | |
| 108 | - Key::new(&[MODKEY], keycodes::KEY_2, KeyAction::ViewTag, Arg::Int(1)), | |
| 109 | - Key::new(&[MODKEY], keycodes::KEY_3, KeyAction::ViewTag, Arg::Int(2)), | |
| 110 | - Key::new(&[MODKEY], keycodes::KEY_4, KeyAction::ViewTag, Arg::Int(3)), | |
| 111 | - Key::new(&[MODKEY], keycodes::KEY_5, KeyAction::ViewTag, Arg::Int(4)), | |
| 112 | - Key::new(&[MODKEY], keycodes::KEY_6, KeyAction::ViewTag, Arg::Int(5)), | |
| 113 | - Key::new(&[MODKEY], keycodes::KEY_7, KeyAction::ViewTag, Arg::Int(6)), | |
| 114 | - Key::new(&[MODKEY], keycodes::KEY_8, KeyAction::ViewTag, Arg::Int(7)), | |
| 115 | - Key::new(&[MODKEY], keycodes::KEY_9, KeyAction::ViewTag, Arg::Int(8)), | |
| 103 | + Key::new(vec![MODKEY], keycodes::A, KeyAction::ToggleGaps, Arg::None), | |
| 104 | + Key::new(vec![MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None), | |
| 105 | + Key::new(vec![MODKEY, SHIFT], keycodes::R, KeyAction::Restart, Arg::None), | |
| 106 | + Key::new(vec![MODKEY], keycodes::F, KeyAction::ToggleFloating, Arg::None), | |
| 107 | + Key::new(vec![MODKEY], keycodes::J, KeyAction::FocusStack, Arg::Int(-1)), | |
| 108 | + Key::new(vec![MODKEY], keycodes::K, KeyAction::FocusStack, Arg::Int(1)), | |
| 109 | + Key::new(vec![MODKEY], keycodes::KEY_1, KeyAction::ViewTag, Arg::Int(0)), | |
| 110 | + Key::new(vec![MODKEY], keycodes::KEY_2, KeyAction::ViewTag, Arg::Int(1)), | |
| 111 | + Key::new(vec![MODKEY], keycodes::KEY_3, KeyAction::ViewTag, Arg::Int(2)), | |
| 112 | + Key::new(vec![MODKEY], keycodes::KEY_4, KeyAction::ViewTag, Arg::Int(3)), | |
| 113 | + Key::new(vec![MODKEY], keycodes::KEY_5, KeyAction::ViewTag, Arg::Int(4)), | |
| 114 | + Key::new(vec![MODKEY], keycodes::KEY_6, KeyAction::ViewTag, Arg::Int(5)), | |
| 115 | + Key::new(vec![MODKEY], keycodes::KEY_7, KeyAction::ViewTag, Arg::Int(6)), | |
| 116 | + Key::new(vec![MODKEY], keycodes::KEY_8, KeyAction::ViewTag, Arg::Int(7)), | |
| 117 | + Key::new(vec![MODKEY], keycodes::KEY_9, KeyAction::ViewTag, Arg::Int(8)), | |
| 116 | 118 | Key::new( |
| 117 | - &[MODKEY, SHIFT], | |
| 119 | + vec![MODKEY, SHIFT], | |
| 118 | 120 | keycodes::KEY_1, |
| 119 | 121 | KeyAction::MoveToTag, |
| 120 | 122 | Arg::Int(0), |
| 121 | 123 | ), |
| 122 | 124 | Key::new( |
| 123 | - &[MODKEY, SHIFT], | |
| 125 | + vec![MODKEY, SHIFT], | |
| 124 | 126 | keycodes::KEY_2, |
| 125 | 127 | KeyAction::MoveToTag, |
| 126 | 128 | Arg::Int(1), |
| 127 | 129 | ), |
| 128 | 130 | Key::new( |
| 129 | - &[MODKEY, SHIFT], | |
| 131 | + vec![MODKEY, SHIFT], | |
| 130 | 132 | keycodes::KEY_3, |
| 131 | 133 | KeyAction::MoveToTag, |
| 132 | 134 | Arg::Int(2), |
| 133 | 135 | ), |
| 134 | 136 | Key::new( |
| 135 | - &[MODKEY, SHIFT], | |
| 137 | + vec![MODKEY, SHIFT], | |
| 136 | 138 | keycodes::KEY_4, |
| 137 | 139 | KeyAction::MoveToTag, |
| 138 | 140 | Arg::Int(3), |
| 139 | 141 | ), |
| 140 | 142 | Key::new( |
| 141 | - &[MODKEY, SHIFT], | |
| 143 | + vec![MODKEY, SHIFT], | |
| 142 | 144 | keycodes::KEY_5, |
| 143 | 145 | KeyAction::MoveToTag, |
| 144 | 146 | Arg::Int(4), |
| 145 | 147 | ), |
| 146 | 148 | Key::new( |
| 147 | - &[MODKEY, SHIFT], | |
| 149 | + vec![MODKEY, SHIFT], | |
| 148 | 150 | keycodes::KEY_6, |
| 149 | 151 | KeyAction::MoveToTag, |
| 150 | 152 | Arg::Int(5), |
| 151 | 153 | ), |
| 152 | 154 | Key::new( |
| 153 | - &[MODKEY, SHIFT], | |
| 155 | + vec![MODKEY, SHIFT], | |
| 154 | 156 | keycodes::KEY_7, |
| 155 | 157 | KeyAction::MoveToTag, |
| 156 | 158 | Arg::Int(6), |
| 157 | 159 | ), |
| 158 | 160 | Key::new( |
| 159 | - &[MODKEY, SHIFT], | |
| 161 | + vec![MODKEY, SHIFT], | |
| 160 | 162 | keycodes::KEY_8, |
| 161 | 163 | KeyAction::MoveToTag, |
| 162 | 164 | Arg::Int(7), |
| 163 | 165 | ), |
| 164 | 166 | Key::new( |
| 165 | - &[MODKEY, SHIFT], | |
| 167 | + vec![MODKEY, SHIFT], | |
| 166 | 168 | keycodes::KEY_9, |
| 167 | 169 | KeyAction::MoveToTag, |
| 168 | 170 | Arg::Int(8), |
| 169 | 171 | ), |
| 170 | 172 | ], |
| 171 | 173 | status_blocks: vec![crate::bar::BlockConfig { |
| 172 | - format: " {}", | |
| 173 | - command: crate::bar::BlockCommand::DateTime("%a, %b %d - %-I:%M %P"), | |
| 174 | + format: "{}".to_string(), | |
| 175 | + command: crate::bar::BlockCommand::DateTime("%a, %b %d - %-I:%M %P".to_string()), | |
| 174 | 176 | interval_secs: 1, |
| 175 | 177 | color: 0x0db9d7, |
| 176 | 178 | underline: true, |
+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: Key1, action: ViewTag, arg: 0), | |
| 35 | + (modifiers: [Mod4], key: Key2, action: ViewTag, arg: 1), | |
| 36 | + (modifiers: [Mod4], key: Key3, action: ViewTag, arg: 2), | |
| 37 | + (modifiers: [Mod4], key: Key4, action: ViewTag, arg: 3), | |
| 38 | + (modifiers: [Mod4], key: Key5, action: ViewTag, arg: 4), | |
| 39 | + (modifiers: [Mod4], key: Key6, action: ViewTag, arg: 5), | |
| 40 | + (modifiers: [Mod4], key: Key7, action: ViewTag, arg: 6), | |
| 41 | + (modifiers: [Mod4], key: Key8, action: ViewTag, arg: 7), | |
| 42 | + (modifiers: [Mod4], key: Key9, action: ViewTag, arg: 8), | |
| 43 | + (modifiers: [Mod4, Shift], key: Key1, action: MoveToTag, arg: 0), | |
| 44 | + (modifiers: [Mod4, Shift], key: Key2, action: MoveToTag, arg: 1), | |
| 45 | + (modifiers: [Mod4, Shift], key: Key3, action: MoveToTag, arg: 2), | |
| 46 | + (modifiers: [Mod4, Shift], key: Key4, action: MoveToTag, arg: 3), | |
| 47 | + (modifiers: [Mod4, Shift], key: Key5, action: MoveToTag, arg: 4), | |
| 48 | + (modifiers: [Mod4, Shift], key: Key6, action: MoveToTag, arg: 5), | |
| 49 | + (modifiers: [Mod4, Shift], key: Key7, action: MoveToTag, arg: 6), | |
| 50 | + (modifiers: [Mod4, Shift], key: Key8, action: MoveToTag, arg: 7), | |
| 51 | + (modifiers: [Mod4, Shift], key: Key9, action: MoveToTag, arg: 8), | |
| 52 | + ], | |
| 53 | + | |
| 54 | + status_blocks: [ | |
| 55 | + (format: "Ram: {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: "Kernel: {}", 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 | + |
+0 −141 templates/config.rs deleted file mode 100644
| @@ -1,141 +0,0 @@ | ||
| 1 | -use oxwm::ColorScheme; | |
| 2 | -use oxwm::prelude::*; | |
| 3 | - | |
| 4 | -// ======================================== | |
| 5 | -// APPEARANCE | |
| 6 | -// ======================================== | |
| 7 | -pub const BORDER_WIDTH: u32 = 2; | |
| 8 | -pub const BORDER_FOCUSED: u32 = 0x6dade3; | |
| 9 | -pub const BORDER_UNFOCUSED: u32 = 0xbbbbbb; | |
| 10 | -pub const FONT: &str = "monospace:size=12"; | |
| 11 | - | |
| 12 | -// ======================================== | |
| 13 | -// GAPS (Vanity Gaps) | |
| 14 | -// ======================================== | |
| 15 | -pub const GAPS_ENABLED: bool = true; | |
| 16 | -pub const GAP_INNER_HORIZONTAL: u32 = 6; | |
| 17 | -pub const GAP_INNER_VERTICAL: u32 = 6; | |
| 18 | -pub const GAP_OUTER_HORIZONTAL: u32 = 6; | |
| 19 | -pub const GAP_OUTER_VERTICAL: u32 = 6; | |
| 20 | - | |
| 21 | -// ======================================== | |
| 22 | -// DEFAULTS | |
| 23 | -// ======================================== | |
| 24 | -pub const TERMINAL: &str = "st"; | |
| 25 | -pub const MODKEY: KeyButMask = KeyButMask::MOD4; | |
| 26 | - | |
| 27 | -// ======================================== | |
| 28 | -// TAGS (Workspaces) | |
| 29 | -// ======================================== | |
| 30 | -pub const TAG_COUNT: usize = 9; | |
| 31 | -pub const TAGS: [&str; TAG_COUNT] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]; | |
| 32 | - | |
| 33 | -// ======================================== | |
| 34 | -// BAR COLORS | |
| 35 | -// ======================================== | |
| 36 | -const GRAY_DARK: u32 = 0x1a1b26; | |
| 37 | -const GRAY_MID: u32 = 0x444444; | |
| 38 | -const GRAY_LIGHT: u32 = 0xbbbbbb; | |
| 39 | -const CYAN: u32 = 0x0db9d7; | |
| 40 | -const MAGENTA: u32 = 0xad8ee6; | |
| 41 | - | |
| 42 | -pub const SCHEME_NORMAL: ColorScheme = ColorScheme { | |
| 43 | - foreground: GRAY_LIGHT, | |
| 44 | - background: GRAY_DARK, | |
| 45 | - underline: GRAY_MID, | |
| 46 | -}; | |
| 47 | - | |
| 48 | -pub const SCHEME_OCCUPIED: ColorScheme = ColorScheme { | |
| 49 | - foreground: CYAN, | |
| 50 | - background: GRAY_DARK, | |
| 51 | - underline: CYAN, | |
| 52 | -}; | |
| 53 | - | |
| 54 | -pub const SCHEME_SELECTED: ColorScheme = ColorScheme { | |
| 55 | - foreground: CYAN, | |
| 56 | - background: GRAY_DARK, | |
| 57 | - underline: MAGENTA, | |
| 58 | -}; | |
| 59 | - | |
| 60 | -// ======================================== | |
| 61 | -// KEYBINDINGS | |
| 62 | -// ======================================== | |
| 63 | -const SHIFT: KeyButMask = KeyButMask::SHIFT; | |
| 64 | - | |
| 65 | -#[rustfmt::skip] | |
| 66 | -pub const KEYBINDINGS: &[Key] = &[ | |
| 67 | - // Launch applications | |
| 68 | - Key::new(&[MODKEY], keycodes::RETURN, KeyAction::Spawn, Arg::Str(TERMINAL)), | |
| 69 | - Key::new(&[MODKEY], keycodes::D, KeyAction::Spawn, Arg::Array(&["sh", "-c", "dmenu_run"])), | |
| 70 | - | |
| 71 | - // Window management | |
| 72 | - Key::new(&[MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None), | |
| 73 | - Key::new(&[MODKEY, SHIFT], keycodes::F, KeyAction::ToggleFullScreen, Arg::None), | |
| 74 | - Key::new(&[MODKEY], keycodes::A, KeyAction::ToggleGaps, Arg::None), | |
| 75 | - | |
| 76 | - // WM controls | |
| 77 | - Key::new(&[MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None), | |
| 78 | - Key::new(&[MODKEY, SHIFT], keycodes::R, KeyAction::Restart, Arg::None), | |
| 79 | - | |
| 80 | - // Focus | |
| 81 | - Key::new(&[MODKEY], keycodes::J, KeyAction::FocusStack, Arg::Int(-1)), | |
| 82 | - Key::new(&[MODKEY], keycodes::K, KeyAction::FocusStack, Arg::Int(1)), | |
| 83 | - | |
| 84 | - // View tags (workspaces) | |
| 85 | - Key::new(&[MODKEY], keycodes::KEY_1, KeyAction::ViewTag, Arg::Int(0)), | |
| 86 | - Key::new(&[MODKEY], keycodes::KEY_2, KeyAction::ViewTag, Arg::Int(1)), | |
| 87 | - Key::new(&[MODKEY], keycodes::KEY_3, KeyAction::ViewTag, Arg::Int(2)), | |
| 88 | - Key::new(&[MODKEY], keycodes::KEY_4, KeyAction::ViewTag, Arg::Int(3)), | |
| 89 | - Key::new(&[MODKEY], keycodes::KEY_5, KeyAction::ViewTag, Arg::Int(4)), | |
| 90 | - Key::new(&[MODKEY], keycodes::KEY_6, KeyAction::ViewTag, Arg::Int(5)), | |
| 91 | - Key::new(&[MODKEY], keycodes::KEY_7, KeyAction::ViewTag, Arg::Int(6)), | |
| 92 | - Key::new(&[MODKEY], keycodes::KEY_8, KeyAction::ViewTag, Arg::Int(7)), | |
| 93 | - Key::new(&[MODKEY], keycodes::KEY_9, KeyAction::ViewTag, Arg::Int(8)), | |
| 94 | - | |
| 95 | - // Move windows to tags | |
| 96 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_1, KeyAction::MoveToTag, Arg::Int(0)), | |
| 97 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_2, KeyAction::MoveToTag, Arg::Int(1)), | |
| 98 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_3, KeyAction::MoveToTag, Arg::Int(2)), | |
| 99 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_4, KeyAction::MoveToTag, Arg::Int(3)), | |
| 100 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_5, KeyAction::MoveToTag, Arg::Int(4)), | |
| 101 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_6, KeyAction::MoveToTag, Arg::Int(5)), | |
| 102 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_7, KeyAction::MoveToTag, Arg::Int(6)), | |
| 103 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_8, KeyAction::MoveToTag, Arg::Int(7)), | |
| 104 | - Key::new(&[MODKEY, SHIFT], keycodes::KEY_9, KeyAction::MoveToTag, Arg::Int(8)), | |
| 105 | -]; | |
| 106 | - | |
| 107 | -// ======================================== | |
| 108 | -// STATUS BAR BLOCKS | |
| 109 | -// ======================================== | |
| 110 | -pub const STATUS_BLOCKS: &[BlockConfig] = &[BlockConfig { | |
| 111 | - format: "{}", | |
| 112 | - command: BlockCommand::DateTime("%a, %b %d - %-I:%M %P"), | |
| 113 | - interval_secs: 1, | |
| 114 | - color: CYAN, | |
| 115 | - underline: true, | |
| 116 | -}]; | |
| 117 | - | |
| 118 | -// ======================================== | |
| 119 | -// BUILD CONFIG FROM CONSTANTS | |
| 120 | -// ======================================== | |
| 121 | -pub fn build_config() -> oxwm::Config { | |
| 122 | - oxwm::Config { | |
| 123 | - border_width: BORDER_WIDTH, | |
| 124 | - border_focused: BORDER_FOCUSED, | |
| 125 | - border_unfocused: BORDER_UNFOCUSED, | |
| 126 | - font: FONT.to_string(), | |
| 127 | - gaps_enabled: GAPS_ENABLED, | |
| 128 | - gap_inner_horizontal: GAP_INNER_HORIZONTAL, | |
| 129 | - gap_inner_vertical: GAP_INNER_VERTICAL, | |
| 130 | - gap_outer_horizontal: GAP_OUTER_HORIZONTAL, | |
| 131 | - gap_outer_vertical: GAP_OUTER_VERTICAL, | |
| 132 | - terminal: TERMINAL.to_string(), | |
| 133 | - modkey: MODKEY, | |
| 134 | - tags: TAGS.iter().map(|s| s.to_string()).collect(), | |
| 135 | - keybindings: KEYBINDINGS.to_vec(), | |
| 136 | - status_blocks: STATUS_BLOCKS.to_vec(), | |
| 137 | - scheme_normal: SCHEME_NORMAL, | |
| 138 | - scheme_occupied: SCHEME_OCCUPIED, | |
| 139 | - scheme_selected: SCHEME_SELECTED, | |
| 140 | - } | |
| 141 | -} |