Now we can read messages from the socket

This commit is contained in:
Yash Karandikar 2022-06-27 11:50:10 +05:30
parent 020980faef
commit 400c1cf004
3 changed files with 35 additions and 1 deletions

View file

@ -13,7 +13,7 @@ pub struct XcrabConfig {
#[derive(Clone, Debug, Deserialize)]
pub struct XcrabMsgConfig {
socket_path: PathBuf,
pub socket_path: PathBuf,
}
const DEFAULT_BORDER_COLOR: u32 = 0xff_00_00; // red

View file

@ -13,6 +13,7 @@ use breadx::{
use lazy_static::lazy_static;
mod config;
mod msg_listener;
mod x11;
use x11::client::{may_not_exist, XcrabWindowManager};
@ -106,6 +107,13 @@ async fn main() -> Result<()> {
conn.ungrab_server_async().await?;
if let Some(ref msg) = CONFIG.msg {
tokio::spawn(async move {
msg_listener::listener_task(&msg.socket_path).await?;
Ok::<(), XcrabError>(())
});
}
loop {
let ev = conn.wait_for_event_async().await?;

26
src/msg_listener.rs Normal file
View file

@ -0,0 +1,26 @@
use crate::Result;
use std::path::Path;
use tokio::io::AsyncReadExt;
use tokio::net::UnixListener;
macro_rules! unwrap_or_continue {
($e:expr) => {
match $e {
Ok(v) => v,
Err(_) => continue,
}
};
}
// TODO: Accept some sort of handle to perform tasks on the WM
pub async fn listener_task(socket_path: &Path) -> Result<()> {
let listener = UnixListener::bind(socket_path)?;
loop {
let (mut stream, _) = unwrap_or_continue!(listener.accept().await);
let mut buf = String::new();
stream.read_to_string(&mut buf).await?;
println!("{}", buf);
}
}