tony / oxwm

Fixed main.rs to just launch with sane defaults and accomdate for rare situation where user will not have a Cargo.toml but will have a config.rs... Browse files
tonybtw committed 2025-10-13 parent 76d5d6e commit 18f19a12bdc7eb4280b7dc3ba555be82c7e5bba4
Showing 2 changed files with 34 additions and 86 deletions. UnifiedSplit
+20 −1 src/bin/main.rs
@@ -28,10 +28,23 @@ fn main() -> Result<()> {
28 28 "OXWM First Run",
29 29 "Config created at ~/.config/oxwm/config.rs\nEdit and reload with Mod+Shift+R",
30 30 );
31 + } else {
32 + let config_dir = get_config_path();
33 + if !config_dir.join("Cargo.toml").exists() || !config_dir.join("main.rs").exists() {
34 + ensure_build_files(&config_dir)?;
35 + }
31 36 }
32 37
33 38 if !cache_binary.exists() || should_recompile(&config_path, &cache_binary)? {
34 - recompile_config()?;
39 + if let Err(e) = recompile_config() {
40 + eprintln!("\nCompilation failed: {}", e);
41 + eprintln!("\nYour config may be incompatible with this version of OXWM.");
42 + eprintln!("Options:");
43 + eprintln!(" 1. Fix the errors in ~/.config/oxwm/config.rs");
44 + eprintln!(" 2. Run 'oxwm --init' to regenerate default config");
45 + eprintln!("\nBackup your config first if you have customizations!");
46 + std::process::exit(1);
47 + }
35 48 }
36 49
37 50 use std::os::unix::process::CommandExt;
@@ -71,6 +84,12 @@ fn init_config() -> Result<()> {
71 84 let config_template = include_str!("../../templates/config.rs");
72 85 std::fs::write(config_dir.join("config.rs"), config_template)?;
73 86
87 + ensure_build_files(&config_dir)?;
88 +
89 + Ok(())
90 +}
91 +
92 +fn ensure_build_files(config_dir: &PathBuf) -> Result<()> {
74 93 let main_template = include_str!("../../templates/main.rs");
75 94 std::fs::write(config_dir.join("main.rs"), main_template)?;
76 95
+14 −85 templates/config.rs
@@ -7,16 +7,16 @@ use oxwm::prelude::*;
7 7 pub const BORDER_WIDTH: u32 = 2;
8 8 pub const BORDER_FOCUSED: u32 = 0x6dade3;
9 9 pub const BORDER_UNFOCUSED: u32 = 0xbbbbbb;
10 -pub const FONT: &str = "JetBrainsMono Nerd Font:style=Bold:size=12";
10 +pub const FONT: &str = "monospace:size=12";
11 11
12 12 // ========================================
13 13 // GAPS (Vanity Gaps)
14 14 // ========================================
15 -pub const GAPS_ENABLED: bool = false;
16 -pub const GAP_INNER_HORIZONTAL: u32 = 3;
17 -pub const GAP_INNER_VERTICAL: u32 = 3;
18 -pub const GAP_OUTER_HORIZONTAL: u32 = 3;
19 -pub const GAP_OUTER_VERTICAL: u32 = 3;
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 20
21 21 // ========================================
22 22 // DEFAULTS
@@ -30,23 +30,14 @@ pub const MODKEY: KeyButMask = KeyButMask::MOD4;
30 30 pub const TAG_COUNT: usize = 9;
31 31 pub const TAGS: [&str; TAG_COUNT] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"];
32 32
33 -// Alternative tag styles you can use:
34 -// pub const TAGS: [&str; TAG_COUNT] = ["", "󰊯", "", "", "󰙯", "󱇤", "", "󱘶", "󰧮"];
35 -// pub const TAGS: [&str; TAG_COUNT] = ["DEV", "WWW", "SYS", "DOC", "VBOX", "CHAT", "MUS", "VID", "MISC"];
36 -
37 33 // ========================================
38 34 // BAR COLORS
39 35 // ========================================
40 36 const GRAY_DARK: u32 = 0x1a1b26;
41 -const GRAY_SEP: u32 = 0xa9b1d6;
42 37 const GRAY_MID: u32 = 0x444444;
43 38 const GRAY_LIGHT: u32 = 0xbbbbbb;
44 39 const CYAN: u32 = 0x0db9d7;
45 40 const MAGENTA: u32 = 0xad8ee6;
46 -const RED: u32 = 0xf7768e;
47 -const GREEN: u32 = 0x9ece6a;
48 -const BLUE: u32 = 0x7aa2f7;
49 -const YELLOW: u32 = 0xe0af68;
50 41
51 42 pub const SCHEME_NORMAL: ColorScheme = ColorScheme {
52 43 foreground: GRAY_LIGHT,
@@ -66,17 +57,6 @@ pub const SCHEME_SELECTED: ColorScheme = ColorScheme {
66 57 underline: MAGENTA,
67 58 };
68 59
69 -// ========================================
70 -// COMMANDS
71 -// ========================================
72 -const SCREENSHOT_CMD: &[&str] = &[
73 - "sh",
74 - "-c",
75 - "maim -s | xclip -selection clipboard -t image/png",
76 -];
77 -
78 -const DMENU_CMD: &[&str] = &["sh", "-c", "dmenu_run -l 10"];
79 -
80 60 // ========================================
81 61 // KEYBINDINGS
82 62 // ========================================
@@ -86,9 +66,7 @@ const SHIFT: KeyButMask = KeyButMask::SHIFT;
86 66 pub const KEYBINDINGS: &[Key] = &[
87 67 // Launch applications
88 68 Key::new(&[MODKEY], keycodes::RETURN, KeyAction::Spawn, Arg::Str(TERMINAL)),
89 - Key::new(&[MODKEY], keycodes::F, KeyAction::Spawn, Arg::Str("xclock")),
90 - Key::new(&[MODKEY], keycodes::S, KeyAction::Spawn, Arg::Array(SCREENSHOT_CMD)),
91 - Key::new(&[MODKEY], keycodes::D, KeyAction::Spawn, Arg::Array(DMENU_CMD)),
69 + Key::new(&[MODKEY], keycodes::D, KeyAction::Spawn, Arg::Array(&["sh", "-c", "dmenu_run"])),
92 70
93 71 // Window management
94 72 Key::new(&[MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None),
@@ -98,7 +76,6 @@ pub const KEYBINDINGS: &[Key] = &[
98 76 // WM controls
99 77 Key::new(&[MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None),
100 78 Key::new(&[MODKEY, SHIFT], keycodes::R, KeyAction::Restart, Arg::None),
101 - Key::new(&[MODKEY, SHIFT], keycodes::C, KeyAction::Recompile, Arg::None),
102 79
103 80 // Focus
104 81 Key::new(&[MODKEY], keycodes::J, KeyAction::FocusStack, Arg::Int(-1)),
@@ -130,61 +107,13 @@ pub const KEYBINDINGS: &[Key] = &[
130 107 // ========================================
131 108 // STATUS BAR BLOCKS
132 109 // ========================================
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 -];
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 +}];
188 117
189 118 // ========================================
190 119 // BUILD CONFIG FROM CONSTANTS