Skip to content

Commit

Permalink
Pass the VR controller "back" button to the application on the Oculus…
Browse files Browse the repository at this point in the history
… Quest
  • Loading branch information
slouken committed May 14, 2024
1 parent 84fa11f commit 9b7f88e
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ protected SDLSurface createSDLSurface(Context context) {
// 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()");
Expand Down Expand Up @@ -1260,7 +1261,17 @@ public static boolean isAndroidTV() {
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()
Expand Down Expand Up @@ -1454,15 +1465,20 @@ public static boolean handleKeyEvent(View v, int keyCode, KeyEvent event, InputC
}

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;
}
}
}
}
Expand Down

0 comments on commit 9b7f88e

Please sign in to comment.