Diff
diff --git a/src/bin/main.rs b/src/bin/main.rs
index 1955638..d67ac47 100644
--- a/src/bin/main.rs
+++ b/src/bin/main.rs
@@ -87,7 +87,10 @@ fn load_config(
let config_directory = config_path.parent();
match oxwm::config::parse_lua_config(&config_string, config_directory) {
- Ok(config) => Ok((config, false)),
+ Ok(mut config) => {
+ config.path = Some(config_path);
+ Ok((config, false))
+ }
Err(_error) => {
let template = include_str!("../../templates/config.lua");
let config = oxwm::config::parse_lua_config(template, None)
diff --git a/src/config/lua.rs b/src/config/lua.rs
index e651a83..f97797a 100644
--- a/src/config/lua.rs
+++ b/src/config/lua.rs
@@ -49,5 +49,6 @@ pub fn parse_lua_config(
scheme_selected: builder_data.scheme_selected,
autostart: builder_data.autostart,
auto_tile: builder_data.auto_tile,
+ path: None,
});
}
diff --git a/src/lib.rs b/src/lib.rs
index e2cd37d..bab7d55 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,3 +1,5 @@
+use std::path::PathBuf;
+
pub mod bar;
pub mod client;
pub mod config;
@@ -56,6 +58,9 @@ impl WindowRule {
#[derive(Debug, Clone)]
pub struct Config {
+ // Meta
+ pub path: Option<PathBuf>,
+
// Appearance
pub border_width: u32,
pub border_focused: u32,
@@ -117,6 +122,7 @@ impl Default for Config {
const TERMINAL: &str = "st";
Self {
+ path: None,
border_width: 2,
border_focused: 0x6dade3,
border_unfocused: 0xbbbbbb,
diff --git a/src/window_manager.rs b/src/window_manager.rs
index adaebe3..d9ab936 100644
--- a/src/window_manager.rs
+++ b/src/window_manager.rs
@@ -9,6 +9,7 @@ use crate::layout::{Layout, LayoutBox, LayoutType, layout_from_str, next_layout}
use crate::monitor::{Monitor, detect_monitors};
use crate::overlay::{ErrorOverlay, KeybindOverlay, Overlay};
use std::collections::{HashMap, HashSet};
+use std::path::PathBuf;
use x11rb::cursor::Handle as CursorHandle;
use x11rb::connection::Connection;
@@ -340,27 +341,26 @@ impl WindowManager {
}
fn try_reload_config(&mut self) -> Result<(), String> {
- let config_dir = if let Some(xdg_config) = std::env::var_os("XDG_CONFIG_HOME") {
- std::path::PathBuf::from(xdg_config).join("oxwm")
- } else if let Some(home) = std::env::var_os("HOME") {
- std::path::PathBuf::from(home).join(".config").join("oxwm")
- } else {
- return Err("Could not find config directory".to_string());
- };
-
- let lua_path = config_dir.join("config.lua");
+ let lua_path = self
+ .config
+ .path
+ .take()
+ .expect("Could not find config file. Config path should've been set while loading");
if !lua_path.exists() {
- return Err("No config.lua file found".to_string());
+ return Err("Could not find config file, has it been moved?".to_string());
}
let config_str = std::fs::read_to_string(&lua_path)
.map_err(|e| format!("Failed to read config: {}", e))?;
- let new_config = crate::config::parse_lua_config(&config_str, Some(&config_dir))
+ let config_dir = lua_path.parent();
+
+ let new_config = crate::config::parse_lua_config(&config_str, config_dir)
.map_err(|e| format!("{}", e))?;
self.config = new_config;
+ self.config.path = Some(lua_path);
self.error_message = None;
for bar in &mut self.bars {