Pass the VR controller "back" button to the application on the Oculus Quest

This commit is contained in:
Sam Lantinga 2024-05-13 21:01:04 -07:00
parent 84fa11f740
commit 9b7f88e512
1 changed files with 26 additions and 10 deletions

View File

@ -338,6 +338,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
// Setup
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.v(TAG, "Manufacturer: " + Build.MANUFACTURER);
Log.v(TAG, "Device: " + Build.DEVICE);
Log.v(TAG, "Model: " + Build.MODEL);
Log.v(TAG, "onCreate()");
@ -1260,7 +1261,17 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
if (Build.MANUFACTURER.equals("Amlogic") && Build.MODEL.equals("X96-W")) {
return true;
}
return Build.MANUFACTURER.equals("Amlogic") && Build.MODEL.startsWith("TV");
if (Build.MANUFACTURER.equals("Amlogic") && Build.MODEL.startsWith("TV")) {
return true;
}
return false;
}
public static boolean isVRHeadset() {
if (Build.MANUFACTURER.equals("Oculus") && Build.MODEL.startsWith("Quest")) {
return true;
}
return false;
}
public static double getDiagonal()
@ -1454,15 +1465,20 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
}
if ((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) {
// on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses
// they are ignored here because sending them as mouse input to SDL is messy
if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) {
switch (event.getAction()) {
case KeyEvent.ACTION_DOWN:
case KeyEvent.ACTION_UP:
// mark the event as handled or it will be handled by system
// handling KEYCODE_BACK by system will call onBackPressed()
return true;
if (SDLActivity.isVRHeadset()) {
// The Oculus Quest controller back button comes in as source mouse, so accept that
} else {
// on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses
// they are ignored here because sending them as mouse input to SDL is messy
if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) {
Log.v("SDL", "keycode is back or forward");
switch (event.getAction()) {
case KeyEvent.ACTION_DOWN:
case KeyEvent.ACTION_UP:
// mark the event as handled or it will be handled by system
// handling KEYCODE_BACK by system will call onBackPressed()
return true;
}
}
}
}