tony / oxwm

Fix config reload to reuse original config file path Browse files
Fixes #77
emzywastaken committed 2025-12-14 parent 5bf5485 commit 54ea2dc54db1dcd6e9dc848b37f59d5457a25f8c
Showing 4 changed files with 22 additions and 12 deletions. UnifiedSplit
+4 −1 src/bin/main.rs
@@ -87,7 +87,10 @@ fn load_config(
87 let config_directory = config_path.parent(); 87 let config_directory = config_path.parent();
88 88
89 match oxwm::config::parse_lua_config(&config_string, config_directory) { 89 match oxwm::config::parse_lua_config(&config_string, config_directory) {
90 - Ok(config) => Ok((config, false)), 90 + Ok(mut config) => {
91 + config.path = Some(config_path);
92 + Ok((config, false))
93 + }
91 Err(_error) => { 94 Err(_error) => {
92 let template = include_str!("../../templates/config.lua"); 95 let template = include_str!("../../templates/config.lua");
93 let config = oxwm::config::parse_lua_config(template, None) 96 let config = oxwm::config::parse_lua_config(template, None)
+1 −0 src/config/lua.rs
@@ -49,5 +49,6 @@ pub fn parse_lua_config(
49 scheme_selected: builder_data.scheme_selected, 49 scheme_selected: builder_data.scheme_selected,
50 autostart: builder_data.autostart, 50 autostart: builder_data.autostart,
51 auto_tile: builder_data.auto_tile, 51 auto_tile: builder_data.auto_tile,
52 + path: None,
52 }); 53 });
53 } 54 }
+6 −0 src/lib.rs
@@ -1,3 +1,5 @@
1 +use std::path::PathBuf;
2 +
1 pub mod bar; 3 pub mod bar;
2 pub mod client; 4 pub mod client;
3 pub mod config; 5 pub mod config;
@@ -56,6 +58,9 @@ impl WindowRule {
56 58
57 #[derive(Debug, Clone)] 59 #[derive(Debug, Clone)]
58 pub struct Config { 60 pub struct Config {
61 + // Meta
62 + pub path: Option<PathBuf>,
63 +
59 // Appearance 64 // Appearance
60 pub border_width: u32, 65 pub border_width: u32,
61 pub border_focused: u32, 66 pub border_focused: u32,
@@ -117,6 +122,7 @@ impl Default for Config {
117 const TERMINAL: &str = "st"; 122 const TERMINAL: &str = "st";
118 123
119 Self { 124 Self {
125 + path: None,
120 border_width: 2, 126 border_width: 2,
121 border_focused: 0x6dade3, 127 border_focused: 0x6dade3,
122 border_unfocused: 0xbbbbbb, 128 border_unfocused: 0xbbbbbb,
+11 −11 src/window_manager.rs
@@ -9,6 +9,7 @@ use crate::layout::{Layout, LayoutBox, LayoutType, layout_from_str, next_layout}
9 use crate::monitor::{Monitor, detect_monitors}; 9 use crate::monitor::{Monitor, detect_monitors};
10 use crate::overlay::{ErrorOverlay, KeybindOverlay, Overlay}; 10 use crate::overlay::{ErrorOverlay, KeybindOverlay, Overlay};
11 use std::collections::{HashMap, HashSet}; 11 use std::collections::{HashMap, HashSet};
12 +use std::path::PathBuf;
12 use x11rb::cursor::Handle as CursorHandle; 13 use x11rb::cursor::Handle as CursorHandle;
13 14
14 use x11rb::connection::Connection; 15 use x11rb::connection::Connection;
@@ -340,27 +341,26 @@ impl WindowManager {
340 } 341 }
341 342
342 fn try_reload_config(&mut self) -> Result<(), String> { 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 + let lua_path = self
344 - std::path::PathBuf::from(xdg_config).join("oxwm") 345 + .config
345 - } else if let Some(home) = std::env::var_os("HOME") { 346 + .path
346 - std::path::PathBuf::from(home).join(".config").join("oxwm") 347 + .take()
347 - } else { 348 + .expect("Could not find config file. Config path should've been set while loading");
348 - return Err("Could not find config directory".to_string());
349 - };
350 -
351 - let lua_path = config_dir.join("config.lua");
352 349
353 if !lua_path.exists() { 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 let config_str = std::fs::read_to_string(&lua_path) 354 let config_str = std::fs::read_to_string(&lua_path)
358 .map_err(|e| format!("Failed to read config: {}", e))?; 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 .map_err(|e| format!("{}", e))?; 360 .map_err(|e| format!("{}", e))?;
362 361
363 self.config = new_config; 362 self.config = new_config;
363 + self.config.path = Some(lua_path);
364 self.error_message = None; 364 self.error_message = None;
365 365
366 for bar in &mut self.bars { 366 for bar in &mut self.bars {