spice_client_glib/
cursor_shape.rs1use std::convert::TryInto;
4
5use crate::{CursorShape, CursorType};
6
7impl CursorShape {
8 pub fn cursor_type(&self) -> Result<CursorType, i32> {
9 unsafe { (*self.as_ptr()).type_.try_into() }
10 }
11
12 pub fn width(&self) -> i32 {
13 unsafe { (*self.as_ptr()).width as _ }
14 }
15
16 pub fn height(&self) -> i32 {
17 unsafe { (*self.as_ptr()).height as _ }
18 }
19
20 pub fn hot_x(&self) -> i32 {
21 unsafe { (*self.as_ptr()).hot_spot_x as _ }
22 }
23
24 pub fn hot_y(&self) -> i32 {
25 unsafe { (*self.as_ptr()).hot_spot_y as _ }
26 }
27
28 pub fn data(&self) -> Result<&[u8], String> {
29 let ps = match self.cursor_type() {
30 Ok(CursorType::Color32) | Ok(CursorType::Alpha) => 4,
31 Ok(CursorType::Color16) => 2,
32 _ => return Err(format!("Unhandled cursor type: {:?}", self.cursor_type())),
33 };
34
35 unsafe {
36 Ok(std::slice::from_raw_parts(
37 (*self.as_ptr()).data as _,
38 (self.width() * self.height() * ps) as _,
39 ))
40 }
41 }
42}