mirror of
https://gitlab.com/hyask/swaysome.git
synced 2025-12-10 07:44:43 +01:00
Improve socket discovery, handling, and logging
Implement the following logic: * first try SWAYSOCK * if failed, then try I3SOCK, the legacy one coming from i3 * if failed, then we abort with an error
This commit is contained in:
parent
cdd5a24dc6
commit
6d26286583
1 changed files with 27 additions and 11 deletions
24
src/main.rs
24
src/main.rs
|
|
@ -91,19 +91,35 @@ struct MoveAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_stream() -> UnixStream {
|
fn get_stream() -> UnixStream {
|
||||||
let socket_path = match env::var("I3SOCK") {
|
for socket_var in ["SWAYSOCK", "I3SOCK"] {
|
||||||
|
let socket_path = match env::var(socket_var) {
|
||||||
Ok(val) => val,
|
Ok(val) => val,
|
||||||
Err(_e) => {
|
Err(_e) => {
|
||||||
panic!("couldn't find i3/sway socket");
|
eprintln!("{} not found in environment", socket_var);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let socket = Path::new(&socket_path);
|
let socket = Path::new(&socket_path);
|
||||||
|
|
||||||
match UnixStream::connect(&socket) {
|
match UnixStream::connect(&socket) {
|
||||||
Err(_) => panic!("couldn't connect to i3/sway socket"),
|
Err(_) => {
|
||||||
Ok(stream) => stream,
|
eprintln!(
|
||||||
|
"counldn't connect to socket '{}' found in ${}",
|
||||||
|
socket_path, socket_var
|
||||||
|
);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
Ok(stream) => {
|
||||||
|
eprintln!(
|
||||||
|
"successful connection to socket '{}' found in ${}",
|
||||||
|
socket_path, socket_var
|
||||||
|
);
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic!("couldn't find any i3/sway socket")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_msg(mut stream: &UnixStream, msg_type: u32, payload: &str) {
|
fn send_msg(mut stream: &UnixStream, msg_type: u32, payload: &str) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue