@@ -50,7 +50,7 @@ pub enum SourceClass {
5050
5151bitflags ! {
5252 /// Source of the input device or input events.
53- #[ derive( Debug , PartialEq ) ]
53+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
5454 pub struct Source : u32 {
5555 // Constants from SourceClass, added here for compatibility reasons
5656 /// SourceClass::Button
@@ -101,7 +101,7 @@ bitflags! {
101101
102102/// A rust enum representation of a MotionEvent action.
103103#[ repr( u32 ) ]
104- #[ derive( Eq , PartialEq ) ]
104+ #[ derive( Clone , Copy , Eq , PartialEq ) ]
105105pub enum MotionAction {
106106 /// ACTION_DOWN
107107 Down = input_bindgen:: AMOTION_EVENT_ACTION_DOWN ,
@@ -132,9 +132,15 @@ pub enum MotionAction {
132132 /// ACTION_SCROLL
133133 Scroll = input_bindgen:: AMOTION_EVENT_ACTION_SCROLL ,
134134 /// ACTION_BUTTON_PRESS
135- ButtonPress = input_bindgen:: AMOTION_EVENT_ACTION_BUTTON_PRESS ,
135+ ButtonPress {
136+ /// The button being pressed.
137+ action_button : MotionButton ,
138+ } = input_bindgen:: AMOTION_EVENT_ACTION_BUTTON_PRESS ,
136139 /// ACTION_BUTTON_RELEASE
137- ButtonRelease = input_bindgen:: AMOTION_EVENT_ACTION_BUTTON_RELEASE ,
140+ ButtonRelease {
141+ /// The button being released.
142+ action_button : MotionButton ,
143+ } = input_bindgen:: AMOTION_EVENT_ACTION_BUTTON_RELEASE ,
138144}
139145
140146impl fmt:: Display for MotionAction {
@@ -153,14 +159,20 @@ impl fmt::Display for MotionAction {
153159 MotionAction :: Scroll => write ! ( f, "SCROLL" ) ,
154160 MotionAction :: HoverEnter => write ! ( f, "HOVER_ENTER" ) ,
155161 MotionAction :: HoverExit => write ! ( f, "HOVER_EXIT" ) ,
156- MotionAction :: ButtonPress => write ! ( f, "BUTTON_PRESS" ) ,
157- MotionAction :: ButtonRelease => write ! ( f, "BUTTON_RELEASE" ) ,
162+ MotionAction :: ButtonPress { action_button } => {
163+ write ! ( f, "BUTTON_PRESS({action_button:?})" )
164+ }
165+ MotionAction :: ButtonRelease { action_button } => {
166+ write ! ( f, "BUTTON_RELEASE({action_button:?})" )
167+ }
158168 }
159169 }
160170}
161171
162- impl From < u32 > for MotionAction {
163- fn from ( action : u32 ) -> Self {
172+ impl MotionAction {
173+ /// Creates a [`MotionAction`] from an `AMOTION_EVENT_ACTION_…` constant and an action button
174+ /// (which should be empty for all actions except `BUTTON_PRESS` and `…_RELEASE`).
175+ pub fn from_code ( action : u32 , action_button : MotionButton ) -> Self {
164176 let ( action_masked, action_index) = MotionAction :: breakdown_action ( action) ;
165177 match action_masked {
166178 input_bindgen:: AMOTION_EVENT_ACTION_DOWN => MotionAction :: Down ,
@@ -178,14 +190,16 @@ impl From<u32> for MotionAction {
178190 input_bindgen:: AMOTION_EVENT_ACTION_HOVER_MOVE => MotionAction :: HoverMove ,
179191 input_bindgen:: AMOTION_EVENT_ACTION_HOVER_EXIT => MotionAction :: HoverExit ,
180192 input_bindgen:: AMOTION_EVENT_ACTION_SCROLL => MotionAction :: Scroll ,
181- input_bindgen:: AMOTION_EVENT_ACTION_BUTTON_PRESS => MotionAction :: ButtonPress ,
182- input_bindgen:: AMOTION_EVENT_ACTION_BUTTON_RELEASE => MotionAction :: ButtonRelease ,
193+ input_bindgen:: AMOTION_EVENT_ACTION_BUTTON_PRESS => {
194+ MotionAction :: ButtonPress { action_button }
195+ }
196+ input_bindgen:: AMOTION_EVENT_ACTION_BUTTON_RELEASE => {
197+ MotionAction :: ButtonRelease { action_button }
198+ }
183199 _ => panic ! ( "Unknown action: {}" , action) ,
184200 }
185201 }
186- }
187202
188- impl MotionAction {
189203 fn breakdown_action ( action : u32 ) -> ( u32 , usize ) {
190204 let action_masked = action & input_bindgen:: AMOTION_EVENT_ACTION_MASK ;
191205 let index = ( action & input_bindgen:: AMOTION_EVENT_ACTION_POINTER_INDEX_MASK )
@@ -219,7 +233,7 @@ bitflags! {
219233 /// MotionEvent flags.
220234 /// The source of truth for the flag definitions are the MotionEventFlag AIDL enum.
221235 /// The flag values are redefined here as a bitflags API.
222- #[ derive( Debug ) ]
236+ #[ derive( Clone , Copy , Debug ) ]
223237 pub struct MotionFlags : u32 {
224238 /// FLAG_WINDOW_IS_OBSCURED
225239 const WINDOW_IS_OBSCURED = MotionEventFlag :: WINDOW_IS_OBSCURED . 0 as u32 ;
0 commit comments