More workarounds. Now things seem reasonably tight even on devices with broken mouse support like Poco F1

This commit is contained in:
Henrik Rydgård 2025-03-05 23:25:34 +01:00
parent 9049139845
commit 725f72a5e3
3 changed files with 16 additions and 7 deletions

View file

@ -134,8 +134,15 @@ public abstract class NativeActivity extends Activity {
public static final int REQUEST_CODE_CAMERA_PERMISSION = 3;
public static final int REQUEST_CODE_MICROPHONE_PERMISSION = 4;
// Once we received a "modern" mouse event, we stop listening to old style mouse
// button events.
public static boolean useModernMouseEvents = false;
// Workaround for bizarre behavior on Pocophone where we get modern events
// for the left mouse button, but wacky BACK keyboard event with source == mouse
// for the right mouse button.
public static boolean useModernMouseEventsB2 = false;
// Functions for the app activity to override to change behaviour.
public native void registerCallbacks();
@ -985,8 +992,9 @@ public abstract class NativeActivity extends Activity {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
Log.i(TAG, "key event" + event.getSource());
if (NativeSurfaceView.isFromSource(event, InputDevice.SOURCE_MOUSE)) {
Log.i(TAG, "Forwarding key event from mouse");
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && !useModernMouseEvents) {
Log.i(TAG, "Forwarding key event from mouse: " + event.getKeyCode());
Log.i(TAG, "usemodernb2: " + useModernMouseEventsB2);
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && !useModernMouseEventsB2) {
// Probably a right click
switch (event.getAction()) {
case KeyEvent.ACTION_DOWN:
@ -1094,6 +1102,9 @@ public abstract class NativeActivity extends Activity {
sendMouseDelta(dx, dy);
}
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
Log.i(TAG, "Erroneous move event"); // should be in touch events
return true;
case MotionEvent.ACTION_HOVER_MOVE:
Log.i(TAG, "Action Hover Move");
// process the mouse hover movement...
@ -1115,6 +1126,9 @@ public abstract class NativeActivity extends Activity {
case MotionEvent.ACTION_BUTTON_PRESS: {
Log.i(TAG, "action button press: button: " + button);
useModernMouseEvents = true;
if (button > 1) {
useModernMouseEventsB2 = true;
}
NativeApp.mouse(event.getX(), event.getY(), button, 1);
return true;
}

View file

@ -61,7 +61,6 @@ public class NativeGLView extends GLSurfaceView implements SensorEventListener,
return ev.getToolType(pointer);
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
private void onMouseEventMotion(final MotionEvent ev) {
switch (ev.getActionMasked()) {

View file

@ -114,10 +114,6 @@ public class NativeSurfaceView extends SurfaceView implements SensorEventListene
public boolean onTouchEvent(final MotionEvent ev) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 && isFromSource(ev, InputDevice.SOURCE_MOUSE)) {
// This is where workable mouse support arrived.
// Also, skip processing if useModernMouseEvents is on.
if (NativeActivity.useModernMouseEvents) {
return true;
}
onMouseEventMotion(ev);
return true;
}