Skip to content

Commit

Permalink
More work, make it work with the GL surface view too.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 23, 2025
1 parent 08c089e commit 06523dc
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 59 deletions.
34 changes: 25 additions & 9 deletions android/src/org/ppsspp/ppsspp/NativeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1082,17 +1082,15 @@ void sendMouseDelta(float dx, float dy) {
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public boolean onGenericMotionEvent(MotionEvent event) {
// Log.d(TAG, "onGenericMotionEvent: " + event);
// Log.i(TAG, "NativeActivity onGenericMotionEvent: " + event);
if (InputDeviceState.inputSourceIsJoystick(event.getSource())) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
InputDeviceState state = getInputDeviceState(event);
if (state == null) {
Log.w(TAG, "Joystick event but failed to get input device state.");
return super.onGenericMotionEvent(event);
}
state.onJoystickMotion(event);
return true;
InputDeviceState state = getInputDeviceState(event);
if (state == null) {
Log.w(TAG, "Joystick event but failed to get input device state.");
return super.onGenericMotionEvent(event);
}
state.onJoystickMotion(event);
return true;
}

if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
Expand All @@ -1107,12 +1105,30 @@ public boolean onGenericMotionEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_HOVER_MOVE:
// process the mouse hover movement...
NativeApp.mouse(event.getX(), event.getY(), 0, 0);
return true;
case MotionEvent.ACTION_SCROLL:
NativeApp.mouseWheelEvent(event.getAxisValue(MotionEvent.AXIS_HSCROLL), event.getAxisValue(MotionEvent.AXIS_VSCROLL));
return true;
}
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_BUTTON_PRESS: {
int button = event.getActionButton();
NativeApp.mouse(event.getX(), event.getY(), button, 1);
return true;
}
case MotionEvent.ACTION_BUTTON_RELEASE: {
int button = event.getActionButton();
NativeApp.mouse(event.getX(), event.getY(), button, 2);
return true;
}
default:
break;
}
}
return super.onGenericMotionEvent(event);
}

Expand Down
38 changes: 38 additions & 0 deletions android/src/org/ppsspp/ppsspp/NativeGLView.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.os.Build;
import android.os.Handler;
import android.util.Log;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.SurfaceControl;
Expand Down Expand Up @@ -60,11 +61,48 @@ private int getToolType(final MotionEvent ev, int pointer) {
return ev.getToolType(pointer);
}


@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
private boolean onMouseEventModern(final MotionEvent ev) {
if (!NativeSurfaceView.isFromSource(ev, InputDevice.SOURCE_MOUSE)) {
return false;
}
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN: {
// Log.i(TAG, "Action down. button state: " + ev.getButtonState());
NativeApp.mouse(ev.getX(), ev.getY(), 1, 1);
break;
}
case MotionEvent.ACTION_UP: {
// Log.i(TAG, "Action up. button state: " + ev.getButtonState());
NativeApp.mouse(ev.getX(), ev.getY(), 1, 2);
break;
}
case MotionEvent.ACTION_MOVE: {
// Log.i(TAG, "Action move. button state: " + ev.getButtonState());
NativeApp.mouse(ev.getX(), ev.getY(), 0, 0);
break;
}
default: {
Log.i(TAG, "Unhandled modern mouse action: " + ev.getAction());
break;
}
}
return true;
}

@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(final MotionEvent ev) {
boolean canReadToolType = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
// This is where workable mouse support arrived.
if (onMouseEventModern(ev)) {
return true;
}
}

for (int i = 0; i < ev.getPointerCount(); i++) {
int pid = ev.getPointerId(i);
int code = 0;
Expand Down
59 changes: 9 additions & 50 deletions android/src/org/ppsspp/ppsspp/NativeSurfaceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,74 +76,33 @@ public static boolean isFromSource(final InputEvent ev, int source) {
return (ev.getSource() & source) == source;
}

// Note: This only has something to override in Android API 12 and later. Below that, it probably
// just won't get called.
@Override
public boolean onGenericMotionEvent(final MotionEvent ev) {
if (!isFromSource(ev, InputDevice.SOURCE_MOUSE)) {
return false;
}
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_HOVER_ENTER:
// Log.i(TAG, "Mouse entered at " + ev.getX() + ", " + ev.getY());
return true;
case MotionEvent.ACTION_HOVER_EXIT:
// Log.i(TAG, "Mouse exited at " + ev.getX() + ", " + ev.getY());
return true;
case MotionEvent.ACTION_HOVER_MOVE:
NativeApp.mouse(ev.getX(), ev.getY(), 0, 0);
return true;
default:
break;
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_BUTTON_PRESS: {
int button = ev.getActionButton();
NativeApp.mouse(ev.getX(), ev.getY(), button, 1);
return true;
}
case MotionEvent.ACTION_BUTTON_RELEASE: {
int button = ev.getActionButton();
NativeApp.mouse(ev.getX(), ev.getY(), button, 2);
return true;
}
default:
break;
}
}

Log.i(TAG, "Other generic motion event " + ev.getActionMasked());
return true;
}

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
private boolean onMouseEventModern(final MotionEvent ev) {
if (!isFromSource(ev, InputDevice.SOURCE_MOUSE)) {
return false;
}
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN: {
Log.i(TAG, "Action down. button state: " + ev.getButtonState());
// Log.i(TAG, "Action down. button state: " + ev.getButtonState());
NativeApp.mouse(ev.getX(), ev.getY(), 1, 1);
return true;
break;
}
case MotionEvent.ACTION_UP: {
Log.i(TAG, "Action up. button state: " + ev.getButtonState());
// Log.i(TAG, "Action up. button state: " + ev.getButtonState());
NativeApp.mouse(ev.getX(), ev.getY(), 1, 2);
return true;
break;
}
case MotionEvent.ACTION_MOVE: {
Log.i(TAG, "Action move. button state: " + ev.getButtonState());
// Log.i(TAG, "Action move. button state: " + ev.getButtonState());
NativeApp.mouse(ev.getX(), ev.getY(), 0, 0);
return true;
break;
}
default: {
Log.i(TAG, "Unhandled modern mouse action: " + ev.getAction());
return true;
break;
}
}
return true;
}

@SuppressLint("ClickableViewAccessibility")
Expand All @@ -152,7 +111,7 @@ public boolean onTouchEvent(final MotionEvent ev) {
boolean canReadToolType = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
// This is where good mouse support arrived.
// This is where workable mouse support arrived.
if (onMouseEventModern(ev)) {
return true;
}
Expand Down

0 comments on commit 06523dc

Please sign in to comment.