Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
luftaquila committed Apr 29, 2024
1 parent 97209bc commit 1acf1f9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
27 changes: 15 additions & 12 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ pub struct AuthorizedClient {
pub struct Client {
pub tcp: TcpStream,
pub cid: Cid,
pub displays: Vec<Display>,
}

impl Client {
pub fn new(server: &str) -> Result<Client, Error> {
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(),
})
}

Expand All @@ -51,8 +59,8 @@ impl Client {
let server_disp: Vec<Display> = server_disp_map.values().cloned().collect();

/* configure our displays' attach position */
let displays: Vec<Display> = 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);
Expand All @@ -63,17 +71,12 @@ impl Client {

Ok(())
}
}

fn set_display_position(server_disp: Vec<Display>) -> Vec<Display> {
let system_disp: Vec<Display> = 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<Display>) {
let mut disp = &self.displays;

// TODO
system_disp
// ! TODO
}
}

fn load_or_generate_cid() -> Result<Cid, Error> {
Expand Down
6 changes: 5 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 1acf1f9

Please sign in to comment.