From 13310ee7dce177a24252970f607c08f3d658e676 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 22 Nov 2015 04:02:19 -0300 Subject: Add socket functionality. Something simple, but it works pretty well. The mapping between the strings that comes from the socket and functions, modifiers, keys, etc. needs some rewrite because now there's a manual mapping. The autostart file shows some functionality on how it will work. Since the next_xevent is ticking on 1s, it's preferible to make the writes on the socket all together, otherwise will pass 1 sec between two calls. --- src/socket.rs | 63 ----------------------------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 src/socket.rs (limited to 'src/socket.rs') diff --git a/src/socket.rs b/src/socket.rs deleted file mode 100644 index b3bb9cc..0000000 --- a/src/socket.rs +++ /dev/null @@ -1,63 +0,0 @@ -// See LICENSE file for copyright and license details. - -use std::io::{Read,Write}; -use std::sync::mpsc::{Receiver, TryRecvError}; - -use unix_socket::UnixStream; - -use dotwm::DotWM; -use command::*; - -#[allow(unused_variables)] -fn handle_socket(dotwm: &mut DotWM, stream: UnixStream) { - let mut s = stream.try_clone().unwrap(); - let mut buf = String::new(); - s.read_to_string(&mut buf).unwrap(); - println!("buf: {}", buf); - - let _ = write!(s, "ok"); -} - -#[allow(unused_variables)] -/// Handles the configuration and returns true when we're finished. -fn handle_configure(dotwm: &mut DotWM, s: UnixStream) -> bool { - let mut stream = match s.try_clone() { - Ok(s) => s, - Err(_) => { println!("Error"); return true }, - }; - - let mut input = String::new(); - stream.read_to_string(&mut input).unwrap(); - - if input != "done" { - let _ = write!(stream, "ok"); - false - } else { - let _ = write!(stream, "exit"); - true - } -} - -pub fn configure_wm(dotwm: &mut DotWM, rx: &Receiver) { - exec_cmd("./autostart", &[]).unwrap(); - loop { - match rx.recv() { - Ok(stream) => { - if handle_configure(dotwm, stream) { - break; - } - }, - Err(e) => panic!("Socket: {}", e), - } - } -} - -pub fn listen_socket(dotwm: &mut DotWM, rx: &Receiver) { - loop { - match rx.try_recv() { - Ok(stream) => handle_socket(dotwm, stream) , - Err(TryRecvError::Empty) => break, - Err(TryRecvError::Disconnected) => panic!("Socket disconnected"), - } - } -} -- cgit v1.2.3-70-g09d2