|
|
@@ -9,6 +9,7 @@ use crate::layout::{Layout, LayoutBox, LayoutType, layout_from_str, next_layout} |
| 9 |
9 |
use crate::monitor::{Monitor, detect_monitors}; |
| 10 |
10 |
use crate::overlay::{ErrorOverlay, KeybindOverlay, Overlay}; |
| 11 |
11 |
use std::collections::{HashMap, HashSet}; |
|
12 |
+use std::path::PathBuf; |
| 12 |
13 |
use x11rb::cursor::Handle as CursorHandle; |
| 13 |
14 |
|
| 14 |
15 |
use x11rb::connection::Connection; |
|
|
@@ -340,27 +341,26 @@ impl WindowManager { |
| 340 |
341 |
} |
| 341 |
342 |
|
| 342 |
343 |
fn try_reload_config(&mut self) -> Result<(), String> { |
| 343 |
|
- let config_dir = if let Some(xdg_config) = std::env::var_os("XDG_CONFIG_HOME") { |
| 344 |
|
- std::path::PathBuf::from(xdg_config).join("oxwm") |
| 345 |
|
- } else if let Some(home) = std::env::var_os("HOME") { |
| 346 |
|
- std::path::PathBuf::from(home).join(".config").join("oxwm") |
| 347 |
|
- } else { |
| 348 |
|
- return Err("Could not find config directory".to_string()); |
| 349 |
|
- }; |
| 350 |
|
- |
| 351 |
|
- let lua_path = config_dir.join("config.lua"); |
|
344 |
+ let lua_path = self |
|
345 |
+ .config |
|
346 |
+ .path |
|
347 |
+ .take() |
|
348 |
+ .expect("Could not find config file. Config path should've been set while loading"); |
| 352 |
349 |
|
| 353 |
350 |
if !lua_path.exists() { |
| 354 |
|
- return Err("No config.lua file found".to_string()); |
|
351 |
+ return Err("Could not find config file, has it been moved?".to_string()); |
| 355 |
352 |
} |
| 356 |
353 |
|
| 357 |
354 |
let config_str = std::fs::read_to_string(&lua_path) |
| 358 |
355 |
.map_err(|e| format!("Failed to read config: {}", e))?; |
| 359 |
356 |
|
| 360 |
|
- let new_config = crate::config::parse_lua_config(&config_str, Some(&config_dir)) |
|
357 |
+ let config_dir = lua_path.parent(); |
|
358 |
+ |
|
359 |
+ let new_config = crate::config::parse_lua_config(&config_str, config_dir) |
| 361 |
360 |
.map_err(|e| format!("{}", e))?; |
| 362 |
361 |
|
| 363 |
362 |
self.config = new_config; |
|
363 |
+ self.config.path = Some(lua_path); |
| 364 |
364 |
self.error_message = None; |
| 365 |
365 |
|
| 366 |
366 |
for bar in &mut self.bars { |