removed old conf
Browse files
+0 −229 src/bin/main.rs.backup deleted file mode 100644
| @@ -1,229 +0,0 @@ | ||
| 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 −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 | -} |