diff --git a/komorebi-client/src/lib.rs b/komorebi-client/src/lib.rs index e57e5e0c..9a9662e9 100644 --- a/komorebi-client/src/lib.rs +++ b/komorebi-client/src/lib.rs @@ -57,16 +57,10 @@ const KOMOREBI: &str = "komorebi.sock"; pub fn send_message(message: &SocketMessage) -> std::io::Result<()> { let socket = DATA_DIR.join(KOMOREBI); - let mut connected = false; - while !connected { - if let Ok(mut stream) = UnixStream::connect(&socket) { - connected = true; - stream.write_all(serde_json::to_string(message)?.as_bytes())?; - } - } - - Ok(()) + let mut stream = UnixStream::connect(socket)?; + stream.write_all(serde_json::to_string(message)?.as_bytes()) } + pub fn send_query(message: &SocketMessage) -> std::io::Result { let socket = DATA_DIR.join(KOMOREBI); diff --git a/komorebi/src/lib.rs b/komorebi/src/lib.rs index a22d88bc..e22bd084 100644 --- a/komorebi/src/lib.rs +++ b/komorebi/src/lib.rs @@ -163,7 +163,7 @@ lazy_static! { ])); static ref SUBSCRIPTION_PIPES: Arc>> = Arc::new(Mutex::new(HashMap::new())); - static ref SUBSCRIPTION_SOCKETS: Arc>> = + pub static ref SUBSCRIPTION_SOCKETS: Arc>> = Arc::new(Mutex::new(HashMap::new())); static ref TCP_CONNECTIONS: Arc>> = Arc::new(Mutex::new(HashMap::new())); diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index 13d4f288..5f28bffc 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -7,6 +7,7 @@ clippy::doc_markdown )] +use std::net::Shutdown; use std::path::PathBuf; use std::sync::atomic::Ordering; use std::sync::Arc; @@ -23,6 +24,7 @@ use sysinfo::Process; use tracing_appender::non_blocking::WorkerGuard; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::EnvFilter; +use uds_windows::UnixStream; use komorebi::border_manager; use komorebi::focus_manager; @@ -287,5 +289,15 @@ fn main() -> Result<()> { WindowsApi::disable_focus_follows_mouse()?; } + let sockets = komorebi::SUBSCRIPTION_SOCKETS.lock(); + for path in (*sockets).values() { + if let Ok(stream) = UnixStream::connect(path) { + stream.shutdown(Shutdown::Both)?; + } + } + + let socket = DATA_DIR.join("komorebi.sock"); + let _ = std::fs::remove_file(socket); + std::process::exit(130); } diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index a1453f8f..24479fa3 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -4,6 +4,7 @@ use std::fs::OpenOptions; use std::io::BufRead; use std::io::BufReader; use std::io::Read; +use std::net::Shutdown; use std::net::TcpListener; use std::net::TcpStream; use std::num::NonZeroUsize; @@ -779,6 +780,16 @@ impl WindowManager { WindowsApi::disable_focus_follows_mouse()?; } + let sockets = SUBSCRIPTION_SOCKETS.lock(); + for path in (*sockets).values() { + if let Ok(stream) = UnixStream::connect(path) { + stream.shutdown(Shutdown::Both)?; + } + } + + let socket = DATA_DIR.join("komorebi.sock"); + let _ = std::fs::remove_file(socket); + std::process::exit(0) } SocketMessage::MonitorIndexPreference(index_preference, left, top, right, bottom) => {