diff --git a/ndk-glue/CHANGELOG.md b/ndk-glue/CHANGELOG.md index 91230363..70d219b0 100644 --- a/ndk-glue/CHANGELOG.md +++ b/ndk-glue/CHANGELOG.md @@ -1,5 +1,12 @@ # Unreleased +# 0.3.0 (2021-01-30) + +- **Breaking** Looper `ident` not passed in `data` pointer anymore. + If you are relying on `Poll::Event::data` to tell event fd and + input queue apart, please use `Poll::Event::ident` and the new + constants introduced in `ndk-glue`! + # 0.2.1 (2020-10-15) - Fix documentation build on docs.rs diff --git a/ndk-glue/Cargo.toml b/ndk-glue/Cargo.toml index 750cb9dc..334a2c3e 100644 --- a/ndk-glue/Cargo.toml +++ b/ndk-glue/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ndk-glue" -version = "0.2.1" +version = "0.3.0" authors = ["The Rust Windowing contributors"] edition = "2018" description = "Startup code for android binaries" @@ -12,7 +12,7 @@ homepage = "https://github.com/rust-windowing/android-ndk-rs" repository = "https://github.com/rust-windowing/android-ndk-rs" [dependencies] -ndk = { path = "../ndk", version = "0.2.1" } +ndk = { path = "../ndk", version = "0.3.0" } ndk-sys = { path = "../ndk-sys", version = "0.2.1" } ndk-macro = { path = "../ndk-macro", version = "0.2.0" } lazy_static = "1.4.0" diff --git a/ndk-glue/src/lib.rs b/ndk-glue/src/lib.rs index 58f070ac..886bd031 100644 --- a/ndk-glue/src/lib.rs +++ b/ndk-glue/src/lib.rs @@ -16,6 +16,18 @@ use std::thread; pub use ndk_macro::main; +/// `ndk-glue` macros register the reading end of an event pipe with the +/// main [`ThreadLooper`] under this `ident`. +/// When returned from [`ThreadLooper::poll_*`](ThreadLooper::poll_once) +/// an event can be retrieved from [`poll_events()`]. +pub const NDK_GLUE_LOOPER_EVENT_PIPE_IDENT: i32 = 0; + +/// The [`InputQueue`] received from Android is registered with the main +/// [`ThreadLooper`] under this `ident`. +/// When returned from [`ThreadLooper::poll_*`](ThreadLooper::poll_once) +/// an event can be retrieved from [`input_queue()`]. +pub const NDK_GLUE_LOOPER_INPUT_QUEUE_IDENT: i32 = 1; + pub fn android_log(level: Level, tag: &CStr, msg: &CStr) { let prio = match level { Level::Error => ndk_sys::android_LogPriority_ANDROID_LOG_ERROR, @@ -164,7 +176,12 @@ pub unsafe fn init( let looper = ThreadLooper::prepare(); let foreign = looper.into_foreign(); foreign - .add_fd(PIPE[0], 0, ALOOPER_EVENT_INPUT as _, 0 as _) + .add_fd( + PIPE[0], + NDK_GLUE_LOOPER_EVENT_PIPE_IDENT, + ALOOPER_EVENT_INPUT as _, + std::ptr::null_mut(), + ) .unwrap(); LOOPER = Some(foreign); main() @@ -253,7 +270,7 @@ unsafe extern "C" fn on_input_queue_created( ) { let input_queue = InputQueue::from_ptr(NonNull::new(queue).unwrap()); let looper = LOOPER.as_ref().unwrap(); - input_queue.attach_looper(looper, 1); + input_queue.attach_looper(looper, NDK_GLUE_LOOPER_INPUT_QUEUE_IDENT); *INPUT_QUEUE.write().unwrap() = Some(input_queue); wake(activity, Event::InputQueueCreated); } diff --git a/ndk/CHANGELOG.md b/ndk/CHANGELOG.md index 2bd586bb..24d372b8 100644 --- a/ndk/CHANGELOG.md +++ b/ndk/CHANGELOG.md @@ -1,5 +1,14 @@ # Unreleased +# 0.3.0 (2021-01-30) + +- **Breaking** Looper `ident` not passed in `data` pointer anymore. + `attach_looper` now only sets the `ident` field when attaching an + `InputQueue` to a `ForeignLooper`. + If you are relying on `Poll::Event::data` to tell event fd and + input queue apart, please use `Poll::Event::ident` and the new + constants introduced in `ndk-glue`! + # 0.2.1 (2020-10-15) - Fix documentation build on docs.rs diff --git a/ndk/Cargo.toml b/ndk/Cargo.toml index 346529be..33cd751d 100644 --- a/ndk/Cargo.toml +++ b/ndk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ndk" -version = "0.2.1" +version = "0.3.0" authors = ["The Rust Windowing contributors"] edition = "2018" description = "Safe Rust bindings to the Android NDK" diff --git a/ndk/src/input_queue.rs b/ndk/src/input_queue.rs index 05d02705..62d72d79 100644 --- a/ndk/src/input_queue.rs +++ b/ndk/src/input_queue.rs @@ -71,14 +71,14 @@ impl InputQueue { } } - pub fn attach_looper(&self, looper: &ForeignLooper, id: u32) { + pub fn attach_looper(&self, looper: &ForeignLooper, id: i32) { unsafe { ffi::AInputQueue_attachLooper( self.ptr.as_ptr(), looper.ptr().as_ptr(), - id as _, + id, None, - id as _, + std::ptr::null_mut(), ); } }