diff --git a/src/client.rs b/src/client.rs index d3244aa..bf04abb 100644 --- a/src/client.rs +++ b/src/client.rs @@ -22,13 +22,21 @@ pub struct AuthorizedClient { pub struct Client { pub tcp: TcpStream, pub cid: Cid, + pub displays: Vec, } impl Client { pub fn new(server: &str) -> Result { + let cid = load_or_generate_cid()?; + Ok(Client { tcp: TcpStream::connect(server)?, - cid: load_or_generate_cid()?, + cid, + displays: DisplayInfo::all() + .expect("[ERR] failed to get system displays") + .into_iter() + .map(|x| Display::from(x, cid)) + .collect(), }) } @@ -51,8 +59,8 @@ impl Client { let server_disp: Vec = server_disp_map.values().cloned().collect(); /* configure our displays' attach position */ - let displays: Vec = set_display_position(server_disp); - tcp_stream_write!(self.tcp, displays); + self.set_display_position(server_disp); + tcp_stream_write!(self.tcp, self.displays); /* wait server ack */ tcp_stream_read!(self.tcp, buffer); @@ -63,17 +71,12 @@ impl Client { Ok(()) } -} -fn set_display_position(server_disp: Vec) -> Vec { - let system_disp: Vec = DisplayInfo::all() - .expect("[ERR] failed to get system displays") - .into_iter() - .map(|x| Display::from(x, 0)) // TODO: set CID - .collect(); + fn set_display_position(&mut self, server_disp: Vec) { + let mut disp = &self.displays; - // TODO - system_disp + // ! TODO + } } fn load_or_generate_cid() -> Result { diff --git a/src/server.rs b/src/server.rs index e96b06a..5e78f06 100644 --- a/src/server.rs +++ b/src/server.rs @@ -112,7 +112,11 @@ fn handle_client( /* add accepted client */ // TODO - let client = Client { tcp: stream, cid }; + let client = Client { + tcp: stream, + cid, + displays: Vec::new(), // not using at server + }; clients.write().unwrap().insert(cid, client); }