Files
teipe/libeirs/src/seat.rs
2024-08-18 17:43:59 +02:00

42 lines
1.0 KiB
Rust

use std::{ffi::CStr, fmt::Display, ptr::NonNull};
use super::{events::Event, ffi};
pub use ffi::ei_device_capability as DeviceCapability;
pub struct Seat {
seat: NonNull<ffi::ei_seat>,
}
impl Seat {
pub fn from_event(event: &Event) -> Option<Self> {
let seat = unsafe {
let seat = ffi::ei_event_get_seat(event.as_raw());
ffi::ei_seat_ref(seat)
};
NonNull::new(seat).map(|seat| Self { seat })
}
pub fn bind_capabilities(&self, capabilities: DeviceCapability) {
unsafe {
ffi::ei_seat_bind_capabilities(self.seat.as_ptr(), capabilities, 0);
}
}
}
impl Display for Seat {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = unsafe { CStr::from_ptr(ffi::ei_seat_get_name(self.seat.as_ptr())) }
.to_str()
.unwrap();
write!(f, "{str}")
}
}
impl Drop for Seat {
fn drop(&mut self) {
log::trace!("Dropping seat {self}");
unsafe { ffi::ei_seat_unref(self.seat.as_ptr()) };
}
}