Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a function to get the native activity #267

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions native/sapp-android/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ include = ["src/", "Cargo.toml", "LICENSE-MIT", "LICENSE-APACHE", "README.md"]
[dependencies]
libc = "0.2"
ndk-sys = "0.2.1"
ndk = "0.3.0"
13 changes: 12 additions & 1 deletion native/sapp-android/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use std::{
};

use libc::pipe;

use std::ptr::NonNull;
pub const SAPP_MAX_TOUCHPOINTS: usize = 8;

pub const sapp_event_type_SAPP_EVENTTYPE_INVALID: sapp_event_type = 0;
Expand Down Expand Up @@ -439,6 +439,17 @@ unsafe fn lock_shared_state() -> std::sync::MutexGuard<'static, SharedState> {
SHARED_STATE.as_mut().unwrap().lock().unwrap()
}

pub fn get_native_activity() -> Option<ndk::native_activity::NativeActivity> {
unsafe {
if let Some(activity) = NonNull::new(lock_shared_state().activity) {
Some(ndk::native_activity::NativeActivity::from_ptr(activity))
} else {
None
}
}

}

unsafe fn read_shared_state() -> SharedState {
lock_shared_state().clone()
}
Expand Down