Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git
src/server/tablet.rs (1.4K)
1 use crate::ffi;
2 use crate::input_device::InputDevice;
3 use crate::seat::Seat;
4
5 pub struct Tablet {
6 pub device: *mut InputDevice,
7 pub wp_tablet: *mut ffi::wlr_tablet_v2_tablet,
8 }
9
10 impl Tablet {
11 pub unsafe fn create(
12 seat: *mut Seat,
13 wlr_device: *mut ffi::wlr_input_device,
14 virtual_device: bool,
15 ) -> Result<*mut Self, &'static str> {
16 let server = (*seat).server;
17 let tablet_manager = (*server).input_manager.tablet_manager;
18 if tablet_manager.is_null() {
19 return Err("Tablet manager is null");
20 }
21
22 let wp_tablet = ffi::wlr_tablet_create(tablet_manager, (*seat).wlr_seat, wlr_device);
23 if wp_tablet.is_null() {
24 return Err("Failed to create wp_tablet");
25 }
26
27 let device = InputDevice::new(seat, wlr_device, virtual_device);
28 if device.is_null() {
29 return Err("Failed to create input device");
30 }
31
32 let tablet = Box::into_raw(Box::new(Self {
33 device,
34 wp_tablet,
35 }));
36
37 // Set up the custom destroy callback on the input device
38 (*device).destroy_fn = Some(destroy_tablet_callback);
39 (*device).destroy_data = tablet as *mut _;
40
41 Ok(tablet)
42 }
43
44 pub unsafe fn destroy(tablet: *mut Self) {
45 let _boxed = Box::from_raw(tablet);
46 }
47 }
48
49 unsafe extern "C" fn destroy_tablet_callback(data: *mut std::ffi::c_void) {
50 Tablet::destroy(data as *mut Tablet);
51 }