Created
August 20, 2022 15:06
-
-
Save diocletiann/a16add180650300b5230d933fdabcab0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fs; | |
use tokio::io::AsyncReadExt; | |
use tokio::net::{UnixListener, UnixStream}; | |
use crate::runner::{border_color, focus_window, start_move}; | |
use crate::yabai::Y3_ADDR; | |
mod yabai; | |
mod runner; | |
mod mover; | |
// #[tokio::main(flavor = "multi_thread", worker_threads = 4)] | |
#[tokio::main(flavor = "current_thread")] | |
async fn main() -> anyhow::Result<()> { | |
if fs::metadata(Y3_ADDR).is_ok() { | |
fs::remove_file(Y3_ADDR)?; | |
} | |
let listener = UnixListener::bind(Y3_ADDR)?; | |
loop { | |
let (socket, _) = listener.accept().await?; | |
tokio::spawn(async move { | |
if let Err(err) = run(socket).await { | |
println!("{}", err); | |
} | |
}); | |
} | |
} | |
// TODO: add args parser | |
async fn run(mut socket: UnixStream) -> anyhow::Result<()> { | |
let mut message = String::with_capacity(32); | |
socket.read_to_string(&mut message).await?; | |
if message.contains("border") { | |
border_color().await?; | |
} else if message.contains("focus") { | |
focus_window(message.split_whitespace().nth(1).unwrap()).await?; | |
} else if message.contains("move") { | |
start_move(message.split_whitespace().nth(1).unwrap()).await?; | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment