Get wl_registry global object

This commit is contained in:
2025-03-24 10:13:31 -07:00
parent 6a0b47c57e
commit 59def83bf3

View File

@@ -12,8 +12,30 @@ fn wl_connect() -> Result<UnixStream, Box<dyn Error>> {
Ok(sock) Ok(sock)
} }
fn wl_display_get_registry(wl_sock: &mut UnixStream, wl_current_id: &mut u32) -> Result<(), Box<dyn Error>> {
const OBJECT: u32 = 1;
const OPCODE: u16 = 1;
const MSG_SIZE: u16 = 12;
let mut request = [0u8; MSG_SIZE as usize];
request[0..4].copy_from_slice(&OBJECT.to_ne_bytes());
request[4..6].copy_from_slice(&OPCODE.to_ne_bytes());
request[6..8].copy_from_slice(&MSG_SIZE.to_ne_bytes());
*wl_current_id += 1;
request[8..12].copy_from_slice(&wl_current_id.to_ne_bytes());
let written = wl_sock.write(&request)?;
assert!(written == MSG_SIZE.into());
Ok(())
}
fn main() ->Result<(), Box<dyn Error>> { fn main() ->Result<(), Box<dyn Error>> {
let mut wl_current_id: u32 = 0;
let mut wl_sock = match wl_connect() { let mut wl_sock = match wl_connect() {
Ok(res) => res, Ok(res) => res,
Err(err) => { Err(err) => {
@@ -22,5 +44,7 @@ fn main() ->Result<(), Box<dyn Error>> {
} }
}; };
wl_display_get_registry(&mut wl_sock, &mut wl_current_id);
Ok(()) Ok(())
} }