diff --git a/Cargo.lock b/Cargo.lock index e91e8fa9..77bd5fae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -363,6 +363,7 @@ dependencies = [ "tracing-appender", "tracing-subscriber", "uds_windows", + "which", ] [[package]] @@ -1060,6 +1061,17 @@ version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +[[package]] +name = "which" +version = "4.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea187a8ef279bc014ec368c27a920da2024d2a711109bfbe3440585d5cf27ad9" +dependencies = [ + "either", + "lazy_static", + "libc", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/README.md b/README.md index 4e105b95..053f4ed2 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,9 @@ by `komorebic`. You can similarly stop the process by running `komorebic stop`. +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. + ## Configuration As previously mentioned, this project does not handle anything related to keybindings and shortcuts directly. I diff --git a/komorebi.sample.ahk b/komorebi.sample.ahk index 9d36b27a..4801279e 100644 --- a/komorebi.sample.ahk +++ b/komorebi.sample.ahk @@ -1,3 +1,5 @@ +#SingleInstance Force + ; Enable focus follows mouse Run, komorebic.exe focus-follows-mouse enable diff --git a/komorebi/Cargo.toml b/komorebi/Cargo.toml index 808099a8..4b01e7a1 100644 --- a/komorebi/Cargo.toml +++ b/komorebi/Cargo.toml @@ -27,4 +27,5 @@ sysinfo = "0.20" tracing = "0.1" tracing-appender = "0.1" tracing-subscriber = "0.2" -uds_windows = "1" \ No newline at end of file +uds_windows = "1" +which = "4" \ No newline at end of file diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index dc7d4946..d188c205 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -1,6 +1,7 @@ #![warn(clippy::all, clippy::nursery, clippy::pedantic)] #![allow(clippy::missing_errors_doc)] +use std::process::Command; use std::sync::Arc; use std::sync::Mutex; @@ -13,6 +14,7 @@ use sysinfo::SystemExt; use tracing_appender::non_blocking::WorkerGuard; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::EnvFilter; +use which::which; use crate::process_command::listen_for_commands; use crate::process_event::listen_for_events; @@ -115,6 +117,16 @@ fn main() -> Result<()> { listen_for_commands(wm.clone()); listen_for_events(wm.clone()); + 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() { + Command::new("autohotkey.exe") + .arg(config.as_os_str()) + .output()?; + } + let (ctrlc_sender, ctrlc_receiver) = crossbeam_channel::bounded(1); ctrlc::set_handler(move || { ctrlc_sender