You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the Source is currently bound as a enum, I wouldn't expect it to contain bitmask values from the C API.
Maybe if it were instead exposed via bitflags::bitflags! {} it could be good to expose this, but I think sticking with an enum, with mutually exclusive source variants, seems appropriate here.
For the case where the source is unknown it could potentially be useful to have an .any() method (or similar) that would be able to internally use this bitmask against the unknown source value.
The text was updated successfully, but these errors were encountered:
It looks like this AINPUT_SOURCE_ANY has the inverse value of AINPUT_SOURCE_CLASS_MASK. Perhaps we could turn it into a getter of sorts? For now Source appears to only contain unique variants, besides being built up from a bitmask of a class and a per-class-unique incrementing integer. I don't think bitflags! would fit there.
If this mask is not useful for anything, we ought just remove it.
But there are a few other enums that I'm tracking in my notes, that I'd like to convert to bitflags!, specifically ButtonState, MetaState, EdgeFlags, KeyEventFlags, anything that's a newtype wrapper with bool mask-getters: wdyt?
Not entirely sure what to do with this one or what it's expected to be used for, right now I just hacked it into:
diff --git a/ndk/src/event.rs b/ndk/src/event.rs
index ef447da..fa8406c 100644
--- a/ndk/src/event.rs+++ b/ndk/src/event.rs@@ -69,7 +69,6 @@ pub enum Source {
Hdmi = ffi::AINPUT_SOURCE_HDMI as i32,
Sensor = ffi::AINPUT_SOURCE_SENSOR as i32,
RotaryEncoder = ffi::AINPUT_SOURCE_ROTARY_ENCODER as i32,
- Any = ffi::AINPUT_SOURCE_ANY as i32,
#[doc(hidden)]
#[num_enum(catch_all)]
@@ -77,6 +76,10 @@ pub enum Source {
}
impl Source {
+ /// Bitmask of [`Source`] excluding [`SourceClass`] bits.+ // pub const ANY: i32 = ffi::AINPUT_SOURCE_ANY as i32;+ pub const ANY: Self = Self::__Unknown(ffi::AINPUT_SOURCE_ANY as i32);+
pub fn class(self) -> SourceClass {
let class = i32::from(self) & ffi::AINPUT_SOURCE_CLASS_MASK as i32;
// The mask fits in a u8.
We could also do or add:
/// TODO: Document what to use this for?#[doc(alias = "AINPUT_SOURCE_ANY")]pubfnany(self) -> i32{
i32::from(self)& ffi::AINPUT_SOURCE_ANYasi32}
But again I'm not sure what to document here. If it's an unknown value, get at least the (hopefully known) class out of it, and then keep these bits as describing an unknown-to-the-NDK-crate source for the known class?
Since the
Source
is currently bound as aenum
, I wouldn't expect it to contain bitmask values from the C API.Maybe if it were instead exposed via
bitflags::bitflags! {}
it could be good to expose this, but I think sticking with anenum
, with mutually exclusive source variants, seems appropriate here.For the case where the source is unknown it could potentially be useful to have an
.any()
method (or similar) that would be able to internally use this bitmask against the unknown source value.The text was updated successfully, but these errors were encountered: