diff --git a/README.md b/README.md index 20f2f271..bb192eee 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,11 @@ Once `komorebi` is running, you can execute the `komorebi.sample.ahk` script to If you have AutoHotKey installed and a `komorebi.ahk` file in your home directory (run `$Env:UserProfile` at a PowerShell prompt to find your home directory), `komorebi` will automatically try to load it when starting. +There is also tentative support for loading a AutoHotKey v2, if the file is named `komorebi.ahk2` and +the `AutoHotKey64.exe` executable for AutoHotKey v2 is in your `Path`. If both `komorebi.ahk` and `komorebi.ahk2` files +exist in your home directory, only `komorebi.ahk` will be loaded. An example of an AutoHotKey v2 configuration file +for _komorebi_ can be found [here](https://gist.github.com/crosstyan/dafacc0778dabf693ce9236c57b201cd). + If you are experiencing behaviour where [closing a window leaves a blank tile, but minimizing the same window does not](https://github.com/LGUG2Z/komorebi/issues/6) , you have probably enabled a 'close/minimize to tray' option for that application. You can tell _komorebi_ to handle diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index e1c32c31..ab344e02 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -118,14 +118,38 @@ fn setup() -> Result { pub fn load_configuration() -> Result<()> { let home = dirs::home_dir().context("there is no home directory")?; - let mut config = home; - config.push("komorebi.ahk"); - if config.exists() && which("autohotkey.exe").is_ok() { + let mut config_v1 = home.clone(); + config_v1.push("komorebi.ahk"); + + let mut config_v2 = home; + config_v2.push("komorebi.ahk2"); + + if config_v1.exists() && which("autohotkey.exe").is_ok() { + tracing::info!( + "loading configuration file: {}", + config_v1 + .as_os_str() + .to_str() + .context("cannot convert path to string")? + ); + Command::new("autohotkey.exe") - .arg(config.as_os_str()) + .arg(config_v1.as_os_str()) .output()?; - } + } else if config_v2.exists() && which("AutoHotkey64.exe").is_ok() { + tracing::info!( + "loading configuration file: {}", + config_v2 + .as_os_str() + .to_str() + .context("cannot convert path to string")? + ); + + Command::new("AutoHotkey64.exe") + .arg(config_v2.as_os_str()) + .output()?; + }; Ok(()) } diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index eaa9f4dc..eda822d1 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -1,6 +1,7 @@ use std::collections::VecDeque; use std::io::ErrorKind; use std::num::NonZeroUsize; +use std::path::PathBuf; use std::sync::Arc; use std::sync::Mutex; use std::thread; @@ -121,12 +122,32 @@ impl WindowManager { #[tracing::instrument(skip(self))] pub fn watch_configuration(&mut self, enable: bool) -> Result<()> { let home = dirs::home_dir().context("there is no home directory")?; - let mut config = home; - config.push("komorebi.ahk"); + let mut config_v1 = home.clone(); + config_v1.push("komorebi.ahk"); + + let mut config_v2 = home; + config_v2.push("komorebi.ahk2"); + + if config_v1.exists() { + self.configure_watcher(enable, config_v1)?; + } else if config_v2.exists() { + self.configure_watcher(enable, config_v2)?; + } + + Ok(()) + } + + fn configure_watcher(&mut self, enable: bool, config: PathBuf) -> Result<()> { if config.exists() { if enable { - tracing::info!("watching configuration for changes"); + tracing::info!( + "watching configuration for changes: {}", + config + .as_os_str() + .to_str() + .context("cannot convert path to string")? + ); // Always make absolutely sure that there isn't an already existing watch, because // hotwatch allows multiple watches to be registered for the same path match self.hotwatch.unwatch(config.clone()) { @@ -144,7 +165,6 @@ impl WindowManager { // Editing in Notepad sends a NoticeWrite while editing in (Neo)Vim sends // a NoticeRemove, presumably because of the use of swap files? DebouncedEvent::NoticeWrite(_) | DebouncedEvent::NoticeRemove(_) => { - tracing::info!("reloading changed configuration file"); thread::spawn(|| { load_configuration().expect("could not load configuration"); }); @@ -152,7 +172,14 @@ impl WindowManager { _ => {} })?; } else { - tracing::info!("no longer watching configuration for changes"); + tracing::info!( + "no longer watching configuration for changes: {}", + config + .as_os_str() + .to_str() + .context("cannot convert path to string")? + ); + self.hotwatch.unwatch(config)?; }; }