1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 use crate::{ 17 input_binding, input_binding::{ CPointerStyle, CPointerStyleColor } 18 }; 19 use fusion_data_rust::FusionResult; 20 use std::ffi::{ c_char, CString }; 21 use hilog_rust::{debug, error, hilog, HiLogLabel, LogType}; 22 const LOG_LABEL: HiLogLabel = HiLogLabel { 23 log_type: LogType::LogCore, 24 domain: 0xD002220, 25 tag: "RustPointerStyle" 26 }; 27 const INPUT_BINDING_OK: i32 = 0; 28 29 impl Default for CPointerStyle { default() -> Self30 fn default() -> Self { 31 Self::new() 32 } 33 } 34 35 impl CPointerStyle { 36 /// Create a CPointerStyle object new() -> Self37 pub fn new() -> Self { 38 Self { 39 size: -1, 40 color: { CPointerStyleColor { 41 r: 0, 42 g: 0, 43 b: 0, 44 } }, 45 id: 0, 46 } 47 } 48 } 49 50 /// struct PointerStyle 51 pub struct PointerStyle { 52 inner: CPointerStyle, 53 } 54 55 impl Default for PointerStyle { default() -> Self56 fn default() -> Self { 57 Self::new() 58 } 59 } 60 61 impl PointerStyle { 62 /// Create a PointerStyle object new() -> Self63 pub fn new() -> Self { 64 Self { 65 inner: CPointerStyle::default() 66 } 67 } 68 69 /// Get pointer style pointer_style(&mut self) -> FusionResult<i32>70 pub fn pointer_style(&mut self) -> FusionResult<i32> { 71 // SAFETY: no `None` here, cause `CPointerStyle` is valid 72 unsafe { 73 if input_binding::CGetPointerStyle(&mut self.inner) != INPUT_BINDING_OK { 74 error!(LOG_LABEL, "get pointer style failed"); 75 return Err(-1); 76 } 77 debug!(LOG_LABEL, "get pointer style success"); 78 Ok(0) 79 } 80 } 81 }