Skip to content

Commit

Permalink
window manager keyboard redirect test
Browse files Browse the repository at this point in the history
  • Loading branch information
xor-bits committed Feb 6, 2024
1 parent 6f6ab03 commit c505be6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
5 changes: 5 additions & 0 deletions userspace/hyperion-wm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```bash
cargo +stage2 build --target=x86_64-unknown-hyperion --bin=wm --bin=term
cp $CARGO_HOME/target/x86_64-unknown-hyperion/debug/{wm, term} ./asset/bin/
cargo run -- --cpus=1
```
36 changes: 29 additions & 7 deletions userspace/hyperion-wm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use std::os::hyperion::{
};
use std::{
fs::{File, OpenOptions},
io::{stderr, stdout, BufRead, BufReader, Seek, SeekFrom, Write},
io::{stderr, stdout, BufRead, BufReader, Read, Seek, SeekFrom, Write},
ptr::{self, NonNull},
sync::{
atomic::{AtomicUsize, Ordering},
LazyLock, Mutex,
Arc, LazyLock, Mutex,
},
thread,
};
Expand Down Expand Up @@ -123,6 +123,8 @@ struct Window {
info: WindowInfo,
shmem: Option<File>,
shmem_ptr: Option<NonNull<()>>,

events: Arc<dyn Write>,
}

#[derive(Debug, Clone, Copy, Default)]
Expand Down Expand Up @@ -157,6 +159,23 @@ fn main() {
}
}

fn keyboard() {
let windows = &*WINDOWS;

let mut keyboard = File::open("/dev/keyboard").unwrap();

let mut msg_buf;

let mut buf = [0u8; 8];
let n = keyboard.read(&mut buf).unwrap();

let _windows = windows.lock().unwrap();
if let Some(window) = _windows.get(0) {
window.events.write_all("event keyboard {}");
}
drop(_windows);
}

fn blitter() {
let windows = &*WINDOWS;

Expand Down Expand Up @@ -228,17 +247,19 @@ fn blitter() {

// erease the type information for rust-analyzer
// (because rust-analyzer doesn't support x86_64-unknown-hyperion)
fn handle_client(mut client: impl BufRead + Write) {
fn handle_client(client: LocalStream) {
let windows = &*WINDOWS;

println!("new client = tid:{}", get_tid());
let client = Arc::new(client);
let client_send = client.clone() as Arc<dyn Write>;
let client_recv = BufReader::new(client.clone());

// a super simple display protocol
let mut buf = String::new();

loop {
buf.clear();
let len = client.read_line(&mut buf).unwrap();
let len = client_recv.read_line(&mut buf).unwrap();
let line = buf[..len].trim();

match line {
Expand All @@ -263,6 +284,7 @@ fn handle_client(mut client: impl BufRead + Write) {
w: 200,
h: 200,
},
events: client_send.clone(),
});
drop(_windows);

Expand Down Expand Up @@ -292,8 +314,8 @@ fn handle_client(mut client: impl BufRead + Write) {

buf.clear();
use std::fmt::Write;
writeln!(buf, "{window_id}").unwrap();
client.write_all(buf.as_bytes()).unwrap();
writeln!(buf, "return new_window {window_id}").unwrap();
client_send.write_all(buf.as_bytes()).unwrap();
}
_ => {
println!("unknown command")
Expand Down

0 comments on commit c505be6

Please sign in to comment.