Skip to content
Closed
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
3 changes: 2 additions & 1 deletion docs/02-gamenative-drm.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ in the app's `jniLibs/arm64-v8a/` and is loaded via
- session inputs, before `nativeStart`: `nativeSetPanelRefreshHz(hz)` (the mode's
rate) and `nativeSetScanoutGeometry(w, h)` (the mode's size — the app's
Upscaling Resolution; `0, 0` clears it).
- injector calls: `nativePointerAbsolute(x, y)`, `nativePointerMotion(dx, dy)`,
- injector calls: `nativePointerAbsolute(x, y, width, height)` ((x, y) on a
width x height extent that covers the output), `nativePointerMotion(dx, dy)`,
`nativePointerButton(btn, pressed)`, `nativePointerAxis(axis, value)`,
`nativeKey(evdevCode, pressed)`.

Expand Down
24 changes: 17 additions & 7 deletions modules/gndrm-android/src/injector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ const XKB_KEYMAP_FORMAT_TEXT_V1: u32 = 1;

/// Input events posted from JNI (any thread) into the injector thread.
enum InputEvent {
PointerAbsolute(i32, i32),
/// (x, y) on a width x height extent that covers the output.
PointerAbsolute(i32, i32, i32, i32),
PointerMotion(i32, i32),
PointerButton(i32, bool),
PointerAxis(i32, f32),
Expand Down Expand Up @@ -262,8 +263,8 @@ fn post(ev: InputEvent) {
}
}

pub fn pointer_absolute(x: i32, y: i32) {
post(InputEvent::PointerAbsolute(x, y));
pub fn pointer_absolute(x: i32, y: i32, width: i32, height: i32) {
post(InputEvent::PointerAbsolute(x, y, width, height));
}
pub fn pointer_motion(dx: i32, dy: i32) {
post(InputEvent::PointerMotion(dx, dy));
Expand Down Expand Up @@ -742,11 +743,20 @@ fn connect_and_run(
fn apply(state: &State, ev: InputEvent) {
let t = now_ms();
match ev {
InputEvent::PointerAbsolute(x, y) => {
InputEvent::PointerAbsolute(x, y, width, height) => {
if let Some(p) = &state.pointer {
// Extent = the gamescope output size; coordinates arrive in
// the same space (the view the user touches IS the output).
p.motion_absolute(t, x as u32, y as u32, 0, 0);
// The compositor maps (x, y) / (width, height) onto the
// output; wlroots drops a motion_absolute with a 0 extent.
if width <= 0 || height <= 0 {
return;
}
p.motion_absolute(
t,
x.max(0) as u32,
y.max(0) as u32,
width as u32,
height as u32,
);
p.frame();
}
}
Expand Down
7 changes: 5 additions & 2 deletions modules/gndrm-android/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1598,17 +1598,20 @@ pub extern "system" fn Java_app_gamenative_display_GameNativeDrm_nativeDisplayIn
.unwrap_or(std::ptr::null_mut())
}

/// `GameNativeDrm.nativePointerAbsolute(x, y)`.
/// `GameNativeDrm.nativePointerAbsolute(x, y, width, height)` — (x, y) on a
/// width x height extent that covers the output.
#[no_mangle]
pub extern "system" fn Java_app_gamenative_display_GameNativeDrm_nativePointerAbsolute(
_env: JNIEnv,
_class: JClass,
x: jint,
y: jint,
width: jint,
height: jint,
) {
// Input handlers are a subsystem too: a poisoned injector lock must not
// abort the app (see injector.rs), and anything else is contained here.
if let Err(e) = std::panic::catch_unwind(|| injector::pointer_absolute(x, y)) {
if let Err(e) = std::panic::catch_unwind(|| injector::pointer_absolute(x, y, width, height)) {
report_panic("gndrm-input", e.as_ref());
}
}
Expand Down