use std::ptr;
use wlroots_sys::{wlr_backend, wl_display, wlr_wl_backend_create,
wlr_wl_output_create, wlr_input_device_is_wl, wlr_output_is_wl};
use {backend::UnsafeRenderSetupFunction,
output::{self, Output},
input,
utils::{Handleable, safe_as_cstring}};
#[derive(Debug, Hash, Eq, PartialEq)]
pub struct Wayland {
pub(crate) backend: *mut wlr_backend
}
impl Wayland {
pub unsafe fn new(display: *mut wl_display,
remote: Option<String>,
render_setup_func: Option<UnsafeRenderSetupFunction>)
-> Self {
let remote_cstr = remote.map(|remote| safe_as_cstring(remote));
let remote_ptr = remote_cstr.as_ref()
.map(|s| s.as_ptr())
.unwrap_or_else(|| ptr::null_mut());
let backend = wlr_wl_backend_create(display, remote_ptr, render_setup_func);
if backend.is_null() {
panic!("Could not construct Wayland backend");
}
Wayland { backend }
}
pub fn create_output(&self) -> Option<output::Handle> {
unsafe {
let output_ptr = wlr_wl_output_create(self.backend);
if output_ptr.is_null() {
None
} else {
Some(output::Handle::from_ptr(output_ptr))
}
}
}
pub fn is_wl_input_device(&self, input_device: &input::Device) -> bool {
unsafe {
wlr_input_device_is_wl(input_device.as_ptr())
}
}
pub fn is_wl_output_device(&self, output: &Output) -> bool {
unsafe {
wlr_output_is_wl(output.as_ptr())
}
}
}