• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::CPointerEvent
18 };
19 
20 /// PointerEvent packed the native CPointerEvent
21 #[repr(C)]
22 pub struct PointerEvent(*const CPointerEvent);
23 
24 impl PointerEvent {
25     /// Create a PointerEvent object
new(pointer_event: *const CPointerEvent) -> Self26     pub fn new(pointer_event: *const CPointerEvent) -> Self {
27         Self(pointer_event)
28     }
29 
30     /// Extract a raw `CPointerEvent` pointer from this wrapper
31     /// # Safety
as_inner(&self) -> *const CPointerEvent32     pub unsafe fn as_inner(&self) -> *const CPointerEvent {
33         self.0
34     }
35 
36     /// Create an `PointerEvent` wrapper object from a raw `CPointerEvent` pointer.
from_raw(c_pointer_event: *const CPointerEvent) -> Option<Self>37     pub fn from_raw(c_pointer_event: *const CPointerEvent) -> Option<Self> {
38         if c_pointer_event.is_null() {
39             return None;
40         }
41         Some(Self(c_pointer_event))
42     }
43 }
44 
45 impl PointerEvent {
46     /// get pointer id
pointer_id(&self) -> i3247     pub fn pointer_id(&self) -> i32 {
48         // SAFETY:
49         // Rust PointerEvent always hold a valid native CPointerEvent.
50         unsafe {
51             input_binding::CGetPointerId(self.as_inner())
52         }
53     }
54 
55     /// get pointer action
pointer_acttion(&self) -> i3256     pub fn pointer_acttion(&self) -> i32 {
57         // SAFETY:
58         // Rust PointerEvent always hold a valid native CPointerEvent.
59         unsafe {
60             input_binding::CGetPointerAction(self.as_inner())
61         }
62     }
63 
64     /// get target window id
target_window_id(&self) -> i3265     pub fn target_window_id(&self) -> i32 {
66         // SAFETY:
67         // Rust PointerEvent always hold a valid native CPointerEvent.
68         unsafe {
69             input_binding::CGetTargetWindowId(self.as_inner())
70         }
71     }
72 
73     /// get source type
source_type(&self) -> i3274     pub fn source_type(&self) -> i32 {
75         // SAFETY:
76         // Rust PointerEvent always hold a valid native CPointerEvent.
77         unsafe {
78             input_binding::CGetSourceType(self.as_inner())
79         }
80     }
81 
82     /// get taget display id
taget_display_id(&self) -> i3283     pub fn taget_display_id(&self) -> i32 {
84         // SAFETY:
85         // Rust PointerEvent always hold a valid native CPointerEvent.
86         unsafe {
87             input_binding::CGetTargetDisplayId(self.as_inner())
88         }
89     }
90 
91     /// get display x
display_x(&self) -> i3292     pub fn display_x(&self) -> i32 {
93         // SAFETY:
94         // Rust PointerEvent always hold a valid native CPointerEvent.
95         unsafe {
96             input_binding::CGetDisplayX(self.as_inner())
97         }
98     }
99 
100     /// get display y
display_y(&self) -> i32101     pub fn display_y(&self) -> i32 {
102         // SAFETY:
103         // Rust PointerEvent always hold a valid native CPointerEvent.
104         unsafe {
105             input_binding::CGetDisplayY(self.as_inner())
106         }
107     }
108 
109     /// get device id
device_id(&self) -> i32110     pub fn device_id(&self) -> i32 {
111         // SAFETY:
112         // Rust PointerEvent always hold a valid native CPointerEvent.
113         unsafe {
114             input_binding::CGetDeviceId(self.as_inner())
115         }
116     }
117 
118     /// get window pid
window_pid(&self) -> i32119     pub fn window_pid(&self) -> i32 {
120         // SAFETY:
121         // Rust PointerEvent always hold a valid native CPointerEvent.
122         unsafe {
123             input_binding::CGetWindowPid(self.as_inner())
124         }
125     }
126 
127     /// pointer add flag
add_flag(&self)128     pub fn add_flag(&self) {
129         // SAFETY:
130         // Rust PointerEvent always hold a valid native CPointerEvent.
131         unsafe {
132             input_binding::CPointerEventAddFlag(self.as_inner())
133         }
134     }
135 }