Skip to content

Commit

Permalink
primitive window manager mouse cursor support
Browse files Browse the repository at this point in the history
  • Loading branch information
xor-bits committed Feb 15, 2024
1 parent 458685a commit d433a9a
Show file tree
Hide file tree
Showing 9 changed files with 457 additions and 179 deletions.
97 changes: 97 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions userspace/hyperion-term/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use hyperion_color::Color;
use hyperion_syscall::get_pid;
use hyperion_windowing::{client::Connection, shared::Event};
use hyperion_windowing::{
client::Connection,
shared::{ElementState, Event},
};

//

Expand All @@ -19,11 +22,11 @@ fn main() {
match wm.next_event() {
Event::Keyboard {
code: 88 | 101, // up or left
state: 1,
state: ElementState::Pressed,
} => i = i.wrapping_add(1),
Event::Keyboard {
code: 102 | 103, // down or right
state: 1,
state: ElementState::Pressed,
} => i = i.wrapping_sub(1),
_ => {}
}
Expand Down
2 changes: 2 additions & 0 deletions userspace/hyperion-windowing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ version.workspace = true
edition.workspace = true

[dependencies]
rmp-serde = "1.1"
serde.workspace = true
hyperion-syscall.path = "../../crates/syscall"

[lints]
Expand Down
33 changes: 22 additions & 11 deletions userspace/hyperion-windowing/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
fs::File,
io::{self, BufRead, BufReader, Write},
io::{self, BufReader},
ptr::NonNull,
sync::{mpsc, Arc},
thread,
Expand Down Expand Up @@ -81,7 +81,8 @@ impl Connection {
}

pub fn send_request(&self, req: Request) {
writeln!(&mut &*self.inner.socket_w, "{req}").unwrap();
rmp_serde::encode::write(&mut &*self.inner.socket_w, &req).unwrap();
// (&*self.inner.socket_w).write_all(&[0]).unwrap();
}
}

Expand Down Expand Up @@ -130,16 +131,26 @@ pub fn conn_handler(
event_buf_tx: mpsc::Sender<Event>,
pending_windows_tx: mpsc::Sender<usize>,
) {
let mut buf = String::new();
// let mut buf = [0u8; 256];

loop {
// wait for the result
buf.clear();
let len = socket_r.read_line(&mut buf).unwrap();
let line = buf[..len].trim();

let Some(res) = Message::parse(line) else {
eprintln!("invalid result from the server ({line}), closing the connection");
// if socket_r.read_until(0, &mut buf).unwrap() == 0 {
// break;
// }
// if buf.last() == Some(&0) {
// buf.pop();
// }
// if buf.len() == 0 {
// continue
// }

// let Ok(res) = rmp_serde::from_slice(&buf) else {
// eprintln!("invalid request from a server, closing the connection");
// break;
// };

let Ok(res) = rmp_serde::from_read(&mut socket_r) else {
eprintln!("invalid request from a server, closing the connection");
break;
};

Expand All @@ -149,7 +160,7 @@ pub fn conn_handler(
};

if is_err {
eprintln!("connection closed");
// eprintln!("connection closed");
// connection closed
break;
}
Expand Down
21 changes: 6 additions & 15 deletions userspace/hyperion-windowing/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
fs::{self, File},
io::{self, BufRead, BufReader, Seek, SeekFrom, Write},
io::{self, BufReader, Seek, SeekFrom, Write},
ptr::{self, NonNull},
sync::{
mpsc::{self, Sender},
Expand Down Expand Up @@ -34,11 +34,11 @@ impl Server {
pub fn accept(&self) -> io::Result<Connection> {
let conn = Arc::new(self.listener.accept()?);
let result_stream = MessageStream { conn: conn.clone() };
let cmd_stream = BufReader::new(conn);
let socket_r = BufReader::new(conn);

let (request_buf_tx, request_buf) = mpsc::channel();

thread::spawn(move || handle_client(cmd_stream, request_buf_tx));
thread::spawn(move || handle_client(socket_r, request_buf_tx));

Ok(Connection {
request_buf,
Expand Down Expand Up @@ -77,7 +77,7 @@ pub struct MessageStream {

impl MessageStream {
pub fn send_message(&self, msg: Message) {
writeln!(&mut &*self.conn, "{msg}").unwrap();
rmp_serde::encode::write(&mut &*self.conn, &msg).unwrap();
}
}

Expand Down Expand Up @@ -111,18 +111,9 @@ pub fn new_window_framebuffer(
(window_file, shmem_ptr)
}

fn handle_client(mut cmd_stream: BufReader<Arc<LocalStream>>, request_buf_tx: Sender<Request>) {
let mut buf = String::new();

fn handle_client(mut socket_r: BufReader<Arc<LocalStream>>, request_buf_tx: Sender<Request>) {
loop {
buf.clear();
let n = cmd_stream.read_line(&mut buf).unwrap();
if n == 0 {
break;
}
let line = buf[..n].trim();

let Some(req) = Request::parse(line) else {
let Ok(req) = rmp_serde::from_read(&mut socket_r) else {
eprintln!("invalid request from a client, closing the connection");
break;
};
Expand Down
Loading

0 comments on commit d433a9a

Please sign in to comment.