Now we can read messages from the socket
This commit is contained in:
parent
020980faef
commit
400c1cf004
|
@ -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
|
||||
|
|
|
@ -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
26
src/msg_listener.rs
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue