347 Commits

Author SHA1 Message Date
Marijn Suijten 3d5e479a4e Merge pull request #118 from rust-mobile/dependabot/github_actions/actions/checkout-4
build(deps): bump actions/checkout from 3 to 4
2023-10-04 22:28:53 +02:00
Robert Bragg 219a14bda1 Merge pull request #122 from fornwall/pointer-away-from-ndk
Avoid exposing Pointer and PointersIter from ndk
2023-09-26 21:41:44 +01:00
Robert Bragg 733fabffd3 Merge pull request #124 from fornwall/enable-ci-on-all-branches
Enable CI on all branches
2023-09-26 20:34:43 +01:00
Fredrik Fornwall f2132c4dab Enable CI on all branches 2023-09-26 08:48:19 +02:00
Fredrik Fornwall 9930b9bf90 Avoid exposing Pointer and PointersIter from ndk 2023-09-26 08:36:49 +02:00
dependabot[bot] 0eefd623ed build(deps): bump actions/checkout from 3 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-25 18:36:49 +00:00
Robert Bragg 83cdb56e24 Merge pull request #123 from rust-mobile/rib/pr/msrv-1.68-v2
Bump MSRV to 1.68
2023-09-25 19:36:15 +01:00
Robert Bragg 942053d88e Bump MSRV to 1.68
- Lets us build with cargo ndk 3+
- Lets us remove suppression for false-negative clippy warning about unsafe
  blocks in unsafe functions

- 1.68.0 notably also builds the standard library with a newer r25 NDK
  toolchain which avoid the need for awkward libgcc workarounds, so it's
  anyway a desirable baseline for Android projects.
2023-09-25 16:50:08 +01:00
Robert Bragg 865cc6a780 Merge pull request #115 from rust-mobile/rib/pr/changelog-fixups
CHANGELOG fixups
2023-08-15 23:17:22 +01:00
Robert Bragg 4f6d7d68de CHANGELOG fixups
Some of the dates were wrong from copy&pasting, there was no changelog
entry for adding `InputEvent::TextEvent`, and the release date for
0.5.0-beta.0/1 was missing.
2023-08-15 22:50:03 +01:00
Robert Bragg 7ea440d6c1 Merge pull request #114 from rust-mobile/release-0.5.0-beta.1
Release 0.5.0-beta.1
v0.5.0-beta.1
2023-08-15 21:59:00 +01:00
Robert Bragg 75e9e8672d Release 0.5.0-beta.1 2023-08-15 21:56:28 +01:00
Robert Bragg 47a073f702 Merge pull request #113 from MarijnS95/ndk-breaking-prep
Upgrade to `ndk-sys 0.5.0-beta.0`, `ndk 0.8.0-beta.0`
v0.5.0-beta.0
2023-08-15 21:55:53 +01:00
Marijn Suijten 499d09595b Upgrade to ndk-sys 0.5.0-beta.0, ndk-0.8.0 beta.0 2023-08-15 22:50:29 +02:00
Robert Bragg 23a8570d48 Merge pull request #112 from rust-mobile/release-0.5.0-beta.0
Release 0.5.0 beta.0
2023-08-15 21:31:23 +01:00
Robert Bragg c9f57a734f Release 0.5.0-beta.0 2023-08-15 21:23:29 +01:00
Robert Bragg e91176cb08 CI: assume NDK + Java in official Ubuntu images 2023-08-15 21:23:29 +01:00
Robert Bragg 2a61f84c70 Remove examples/agdk-mainloop/.idea 2023-08-15 21:23:29 +01:00
Robert Bragg 2654c9659b Merge pull request #110 from rust-mobile/rib/pr/no-missing-input-queue-error
native-activity: don't treat missing input queue as error
2023-08-15 21:13:47 +01:00
Robert Bragg 35fe600235 native-activity: don't treat missing input queue as error
If an app tries to iterate input events while there's no input queue
(e.g. before onStart) then just behave like there are no events
available instead of returning an error.

This also reduces the logging level of some messages to reduce the
verbosity of info logs.
2023-08-15 20:59:26 +01:00
Robert Bragg 242285b205 Merge pull request #108 from rust-mobile/dependabot/cargo/num_enum-0.7
build(deps): update num_enum requirement from 0.6 to 0.7
2023-08-15 20:50:59 +01:00
Robert Bragg 379f064170 Merge pull request #107 from rust-mobile/rib/pr/consolidate-more-input-types
Consolidate input types to avoid portability hazards
2023-08-15 20:42:59 +01:00
dependabot[bot] e2f69421a0 build(deps): update num_enum requirement from 0.6 to 0.7
Updates the requirements on [num_enum](https://github.com/illicitonion/num_enum) to permit the latest version.
- [Commits](https://github.com/illicitonion/num_enum/commits)

---
updated-dependencies:
- dependency-name: num_enum
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-08-14 15:13:55 +00:00
Robert Bragg 1b3334178b Consolidate input types to avoid portability hazards
The following types have been moved from game_activity/input.rs to
input.rs so they can be shared by both backends:

Axis, ButtonState, EdgeFlags, KeyAction, KeyEventFlags, Keycode,
MetaState, MotionAction, MotionEventFlags

This addresses a portability hazard whereby code (such as Winit)
would inadvertently use the `ndk` type which works OK with the
native-activity backend but then wouldn't compile against the
game-activity backend.

The alternative of consolidating on the `ndk::events` types instead was
considered but we've repeatedly needed to diverge from the `ndk` API for
the sake of maintaining a consistent input API across the
`game-activity` and `native-activity` backends (input is an area where
the backends differ significantly in their implementation) and so it
generally seems slightly preferable to consolidate on types from this
crate (though it shouldn't make much difference for these types which
are almost direct bindings from ndk_sys).

The types can be converted to their `ndk::events` counterpart
via the `From` trait.

For now some of the `From` trait implementations rely on
`try_from().unwrap()` but the intention is to replace these with
infallible implementations once we bump the MSRV > 1.66
where we can use `num_enum::FromPrimitive` after adding a
catch-all `Other(u32)` to these enums.
2023-08-08 13:46:24 +01:00
Robert Bragg 535994f4a2 Merge pull request #106 from rust-mobile/rib/pr/game-activity-disable-get-unicode-char
GameActivity PATCH: Don't read unicode via getUnicodeChar
2023-08-07 23:21:42 +01:00
Robert Bragg 6b3307410e GameActivity PATCH: Don't read unicode via getUnicodeChar
The `unicodeChar` in `GameActivityKeyEvent` wasn't being exposed by
`android-activity` because we couldn't expose the unicode character in
the same way with the native-activity backend - due to how events are
received via an `InputQueue` that doesn't expose the underlying Java
references for the key events.

Now that we have a consistent way of supporting unicode character
mapping via `KeyCharacterMap` bindings it's redundant for the
`GameActivity` backend to call `getUnicodeChar` automatically for
each key press.
2023-08-07 21:34:31 +01:00
Robert Bragg b4cf0eeabf Merge pull request #102 from rust-mobile/rib/pr/input-api-rework-with-key-character-maps
Rework `input_events` API and expose `KeyCharacterMap` bindings
2023-08-07 20:26:50 +01:00
Robert Bragg af331e3bff Rework input_events API and expose KeyCharacterMap bindings
With the way events are delivered via an `InputQueue` with
`NativeActivity` there is no direct access to the underlying KeyEvent
and MotionEvent Java objects and no `ndk` API that supports the
equivalent of `KeyEvent.getUnicodeChar()`

What `getUnicodeChar` does under the hood though is to do lookups into a
`KeyCharacterMap` for the corresponding `InputDevice` based on the
event's `key_code` and `meta_state` - which are things we can do via
some JNI bindings for `KeyCharacterMap`.

Although it's still awkward to expose an API like
`key_event.get_unicode_char()` we can instead provide an API that
lets you look up a `KeyCharacterMap` for any `device_id` and
applications can then use that for character mapping.

This approach is also more general than the `getUnicodeChar` utility
since it exposes other useful state, such as being able to check what
kind of keyboard input events are coming from (such as a full physical
keyboard vs a virtual / 'predictive' keyboard)

For consistency this exposes the same API through the game-activity
backend, even though the game-activity backend is technically able to
support unicode lookups via `getUnicodeChar` (since it has access to the
Java `KeyEvent` object).

This highlighted a need to be able to use other `AndroidApp` APIs while
processing input, which wasn't possible with the `.input_events()` API
design because the `AndroidApp` held a lock over the backend while
iterating events.

This changes `input_events()` to `input_events_iter()` which now returns
a form of lending iterator and instead of taking a callback that gets
called repeatedly by `input_events()` a similar callback is now passed
to `iter.next(callback)`.

The API isn't as ergonomic as I would have liked, considering that
lending iterators aren't a standard feature for Rust yet but also since
we still want to have the handling for each individual event go via a
callback that can report whether an event was "handled". I think the
slightly awkward ergonomics are acceptable though considering that
the API will generally be used as an implementation detail within
middleware frameworks like Winit.

Since this is the first example where we're creating non-trivial Java
bindings for an Android SDK API this adds some JNI utilities and
establishes a pattern for how we can implement a class binding.

It's an implementation detail but with how I wrote the binding I tried
to keep in mind the possibility of creating a procmacro later that would
generate some of the JNI boilerplate involved.
2023-08-07 18:36:50 +01:00
Robert Bragg 6f72dde55d Merge pull request #105 from rust-mobile/rib/pr/agdk-mainloop-update-v2.0.2
agdk-mainloop: update for GameActivity 2.0.2
2023-08-07 18:29:21 +01:00
Robert Bragg d0f10a0dd9 agdk-mainloop: update for GameActivity 2.0.2 2023-08-07 16:44:07 +01:00
Robert Bragg 3464ba20bc Merge pull request #104 from rust-mobile/rib/pr/revert-msrv-bump-for-winit
Revert 'Bump MSRV to 1.68'
2023-08-07 16:32:14 +01:00
Robert Bragg 1abb02c820 Revert 'Bump MSRV to 1.68'
This effectively reverts 66cfc68dac
and adds some comments explaining that we're currently blocked by
Winit's MSRV policy + CI from being able to increase our
rust-version.

This is a frustrating conflict that I hope can be addressed by
updating Winit's CI system to allow different platforms to require
more recent versions of Rust (which notably isn't in conflict with
setting a conservative rust-version in Winit for supporting Debian
on Linux)

This re-instates building android-activity with cargo-ndk 2 because
building on Android with 1.64 requires a linker workaround that's
not implemented in newer version of cargo-ndk.

This also reinstates the clippy false-negative warning suppression
for unsafe blocks. Again it's frustrating that we can't have good
things because of how Winit wants to support Debian which shouldn't
be relevant for Android development.

Here is an upstream issue to discuss a potential solution for this:
https://github.com/rust-windowing/winit/issues/3000
2023-08-04 17:49:20 +01:00
Robert Bragg c0a9e20c5a Merge pull request #103 from rust-mobile/rib/pr/msrv-1.68
Bump MSRV to 1.68
2023-08-03 17:20:02 +01:00
Robert Bragg 66cfc68dac Bump MSRV to 1.68
- Lets us build with cargo ndk 3+
- Lets us remove suppression for false-negative clippy warning about unsafe
  blocks in unsafe functions
- Should unblock CI for #102

- 1.68.0 notably also builds the standard library with a newer r25 NDK
  toolchain which avoid the need for awkward libgcc workarounds, so it's
  anyway a desirable baseline for Android projects.
2023-08-03 17:10:53 +01:00
Robert Bragg ed2dc53ee4 Merge pull request #85 from daxpedda/bitflags-v2
Bump `bitflags` to v2
2023-08-03 11:16:14 +01:00
dAxpeDDa 74f510a99a Bump bitflags to v2 2023-08-03 11:09:47 +01:00
Robert Bragg 741e633ea8 Merge pull request #24 from rust-mobile/ime-support
Input method (soft keyboard) support
2023-08-01 15:40:44 +01:00
Robert Bragg 41f30c39ad Expose TextEvent and input method state
This also adds `InputEvent::TextEvent` for notifying applications of IME
state changes as well as explicit getter/setter APIs for tracking IME
selection + compose region state. (only supported with GameActivity)

Fixes: #18
2023-07-31 22:29:09 +01:00
Robert Bragg 96497f9da9 Merge pull request #100 from rust-mobile/rib/pr/game-activity-no-input-deref
game-activity: Remove Deref implementations for Key/MotionEvent types
2023-07-30 22:02:12 +01:00
Robert Bragg c22a5453df game-activity: Remove Deref implementations for Key/MotionEvent types 2023-07-30 21:20:54 +01:00
Robert Bragg 9bb5f9c9cf Merge pull request #88 from lexi-the-cute/main
Updated To Games-Activity 2.0.2
2023-07-30 20:56:58 +01:00
Robert Bragg a604c0aa9f game-activity: Integrate GameActivity 2.0.2 2023-07-30 20:46:49 +01:00
Robert Bragg b09526a4a9 game-activity: update ffi bindings for 2.0.2 via ./generate-bindings.sh 2023-07-30 20:42:32 +01:00
Robert Bragg cc3983ca21 generate-bindings: add comment about installing bindgen-cli 2023-07-30 20:42:32 +01:00
Robert Bragg 2a2f27637f GameActivity PATCH: fix deadlocks in java callbacks after app destroyed
This ensures that any java Activity callbacks take into account the
possibility that the `android_app` may have already been marked
destroyed if `android_main` has returned - and so they mustn't block
and wait for a thread that is no longer running.
2023-07-30 20:41:38 +01:00
Robert Bragg d2d18154d9 GameActivity PATCH: Support InputAvailable events
This makes a small change to the C glue code for GameActivity to send
looper wake ups when new input is received (only sending a single wake
up, until the application next handles input).

This makes it possible to recognise that new input is available and send
an `InputAvailable` event to the application - consistent with how
NativeActivity can deliver `InputAvailable` events.

This addresses a significant feature disparity between GameActivity and
NativeActivity that meant GameActivity was not practically usable for
GUI applications that wouldn't want to render continuously like a game.
2023-07-30 20:38:19 +01:00
Robert Bragg 3e3fb84c03 GameActivity PATCH: remove unused variable 2023-07-30 20:38:19 +01:00
Robert Bragg 202ab4c1e9 GameActivity PATCH: Rename android_main _rust_glue_entry
The real `android_main` is going to be written in Rust and
android-activity needs to handle its own initialization before calling
the application's `android_main` and so the C/C++ code
calls an intermediate `_rust_glue_entry` function.
2023-07-30 20:38:19 +01:00
Robert Bragg d6345abb2a GameActivity PATCH: rename C symbols that need export
Give C symbols that need to be exported a `_C` suffix so that they can
be linked into a Rust symbol with the correct name (Since we can't
directly export from C/C++ with Rust+Cargo)

See: https://github.com/rust-lang/rfcs/issues/2771
2023-07-30 20:38:18 +01:00
Alexis c471fdf903 Import unmodified GameActivity 2.0.2 Source
See: https://developer.android.com/jetpack/androidx/releases/games#games-activity_version_20_2
2023-07-30 20:38:14 +01:00