summaryrefslogtreecommitdiff
path: root/src/socket/mod.rs
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2015-11-28 22:16:43 -0300
committerMatias Linares <matiaslina@openmailbox.org>2015-11-28 22:16:43 -0300
commite1ec354306742a5804a20e2651cf49945cd17287 (patch)
tree7f607096fa43f96680d933b7a046f603227e566c /src/socket/mod.rs
parent901d03b3a8ac0b7d8533fd9a8d43238d665d9cb8 (diff)
downloaddotwm-e1ec354306742a5804a20e2651cf49945cd17287.tar.gz
Better socket handling
The socket interface now allows almost everything that vould be done by the internals of the window manager. Also the Window manager now closes fine (on a success exit).
Diffstat (limited to 'src/socket/mod.rs')
-rw-r--r--src/socket/mod.rs49
1 files changed, 28 insertions, 21 deletions
diff --git a/src/socket/mod.rs b/src/socket/mod.rs
index e260284..667969b 100644
--- a/src/socket/mod.rs
+++ b/src/socket/mod.rs
@@ -2,7 +2,6 @@
pub mod parser;
-use std::io::{Read,Write};
use std::sync::mpsc::{Receiver, TryRecvError};
use unix_socket::UnixStream;
@@ -10,6 +9,34 @@ use unix_socket::UnixStream;
use dotwm::DotWM;
use command::*;
+#[derive(Debug,PartialEq)]
+pub enum FnType {
+ Bind,
+ Exec,
+}
+
+pub struct ParsedCmd<'a> {
+ pub f: FnType,
+ pub modifiers: Vec<u32>,
+ pub key: u32,
+ pub args: Vec<&'a str>,
+ pub func: ExecFn,
+}
+
+impl<'a> ParsedCmd<'a> {
+ pub fn handle(self, wm: &mut DotWM, bindings: &mut BindingHash) {
+ match self.f {
+ FnType::Bind => {
+ let modifier = self.modifiers.iter()
+ .fold(0, |acc, x| acc | x );
+ add_binding(wm, bindings,
+ self.key, modifier, self.func, &self.args);
+ },
+ _ => (),
+ }
+ }
+}
+
pub fn next_socket_event(rx: &Receiver<UnixStream>) -> Option<UnixStream> {
match rx.try_recv() {
Ok(stream) => Some(stream),
@@ -17,23 +44,3 @@ pub fn next_socket_event(rx: &Receiver<UnixStream>) -> Option<UnixStream> {
Err(TryRecvError::Disconnected) => panic!("Socket disconnected"),
}
}
-
-/// Listen a socket parsing and executing all the commands.
-pub fn listen_socket(dotwm: &mut DotWM, bindings: &mut BindingHash, rx: &Receiver<UnixStream>) {
- loop {
- match rx.try_recv() {
- Ok(stream) => {
- let mut s = stream.try_clone().unwrap();
- let mut buf = String::new();
- s.read_to_string(&mut buf).unwrap();
-
- for line in buf.lines() {
- let result = parser::parse(dotwm, bindings, &line);
- let _ = write!(s, "{}", result);
- }
- },
- Err(TryRecvError::Empty) => break,
- Err(TryRecvError::Disconnected) => panic!("Socket disconnected"),
- }
- }
-}