started display structure

This commit is contained in:
neo_1993
2026-08-25 12:13:27 +02:00
parent 0cb4086729
commit e692e4837d
+31
View File
@@ -0,0 +1,31 @@
use std::{io::Error, ptr::NonNull};
use std::io::{ErrorKind, Result};
// pull in the ffi-bindings
use crate::ffi::{wl_display,
wl_display_create, wl_display_destroy, wl_display_destroy_clients, wl_display_add_client_created_listener,
wl_display_add_destroy_listener, wl_display_add_global, wl_display_add_protocol_logger, wl_display_add_shm_format,
wl_display_add_socket, wl_display_add_socket_auto, wl_display_add_socket_fd, wl_display_flush_clients, wl_display_run,
wl_display_get_client_list, wl_display_get_destroy_listener, wl_display_get_event_loop, wl_display_get_serial,
wl_display_init_shm, wl_display_next_serial, wl_display_remove_global, wl_display_set_global_filter, wl_display_terminate
};
pub struct Display {
raw: NonNull<wl_display>,
}
impl Display {
pub fn new() -> Result<Self> {
let ptr = unsafe { wl_display_create() };
let raw = match NonNull::<wl_display>::new(ptr) {
Some(raw) => raw,
None => return Err(Error::new(ErrorKind::AddrNotAvailable, "cannot create display")),
};
Ok(Self { raw })
}
}
impl Drop for Display {
fn drop(&mut self) {
unsafe { wl_display_destroy(self.raw.as_ptr()) };
}
}