use wayland_client::{
protocol::{wl_buffer, wl_output, wl_region, wl_surface},
Proxy,
};
pub mod wlr_layer;
pub mod xdg;
#[derive(Debug, Default)]
pub struct Unsupported;
pub trait WaylandSurface: Sized {
fn wl_surface(&self) -> &wl_surface::WlSurface;
fn attach(&self, buffer: Option<&wl_buffer::WlBuffer>, x: u32, y: u32) {
let (attach_x, attach_y) = if self.wl_surface().version() >= 5 { (0, 0) } else { (x, y) };
self.wl_surface().attach(buffer, attach_x as i32, attach_y as i32);
if self.wl_surface().version() >= 5 {
let _ = self.offset(x, y);
}
}
fn set_opaque_region(&self, region: Option<&wl_region::WlRegion>) {
self.wl_surface().set_opaque_region(region);
}
fn set_input_region(&self, region: Option<&wl_region::WlRegion>) {
self.wl_surface().set_input_region(region);
}
fn set_buffer_transform(&self, transform: wl_output::Transform) -> Result<(), Unsupported> {
if self.wl_surface().version() < 2 {
return Err(Unsupported);
}
self.wl_surface().set_buffer_transform(transform);
Ok(())
}
fn set_buffer_scale(&self, scale: u32) -> Result<(), Unsupported> {
if self.wl_surface().version() < 3 {
return Err(Unsupported);
}
self.wl_surface().set_buffer_scale(scale as i32);
Ok(())
}
fn offset(&self, x: u32, y: u32) -> Result<(), Unsupported> {
if self.wl_surface().version() < 5 {
return Err(Unsupported);
}
self.wl_surface().offset(x as i32, y as i32);
Ok(())
}
fn commit(&self) {
self.wl_surface().commit();
}
}