@@ -1039,14 +1039,16 @@ static uint32_t glfm__getUnicodeChar(GLFMPlatformData *platformData, jint keyCod
1039
1039
}
1040
1040
1041
1041
/*
1042
- * Move task to the back if it is root task. This make the back button have the same behavior
1043
- * as the home button.
1042
+ * Hide the virtual keyboard if it is visible.
1044
1043
*
1045
- * Without this, when the user presses the back button, the loop in glfm__mainLoop() is exited, the
1046
- * OpenGL context is destroyed, and the main thread is destroyed. The glfm__mainLoop() function
1047
- * would be called again in the same process if the user returns to the app.
1044
+ * Otherwise, if the current task is the root task, move the task to the back. This makes the back button have the same
1045
+ * behavior as the home button.
1048
1046
*
1049
- * When this, when the app is in the background, the app will pause in the ALooper_pollAll() call.
1047
+ * Without this, when the user presses the back button, the loop in glfm__mainLoop() is exited, the OpenGL context is
1048
+ * destroyed, and the main thread is destroyed. The glfm__mainLoop() function would be called again in the same process
1049
+ * if the user returns to the app.
1050
+ *
1051
+ * With this, when the app is in the background, the app will pause in the ALooper_pollAll() call.
1050
1052
*/
1051
1053
static bool glfm__handleBackButton (GLFMPlatformData * platformData ) {
1052
1054
if (!platformData || !platformData -> activity ) {
@@ -1057,9 +1059,18 @@ static bool glfm__handleBackButton(GLFMPlatformData *platformData) {
1057
1059
return false;
1058
1060
}
1059
1061
1062
+ if (platformData -> keyboardVisible ) {
1063
+ glfmSetKeyboardVisible (platformData -> display , false);
1064
+ return true;
1065
+ }
1066
+
1067
+ #if GLFM_HANDLE_BACK_BUTTON
1060
1068
jboolean handled = glfm__callJavaMethodWithArgs (jni , platformData -> activity -> clazz ,
1061
1069
"moveTaskToBack" , "(Z)Z" , Boolean , false);
1062
1070
return !glfm__wasJavaExceptionThrown (jni ) && handled ;
1071
+ #else
1072
+ return false;
1073
+ #endif
1063
1074
}
1064
1075
1065
1076
static bool glfm__onKeyEvent (GLFMPlatformData * platformData , AInputEvent * event ) {
@@ -1250,11 +1261,9 @@ static bool glfm__onKeyEvent(GLFMPlatformData *platformData, AInputEvent *event)
1250
1261
}
1251
1262
}
1252
1263
1253
- #if GLFM_HANDLE_BACK_BUTTON
1254
1264
if (!handled && aAction == AKEY_EVENT_ACTION_UP && aKeyCode == AKEYCODE_BACK ) {
1255
1265
handled = glfm__handleBackButton (platformData );
1256
1266
}
1257
- #endif
1258
1267
1259
1268
if (display -> charFunc && (aAction == AKEY_EVENT_ACTION_DOWN || aAction == AKEY_EVENT_ACTION_MULTIPLE )) {
1260
1269
uint32_t unicode = glfm__getUnicodeChar (platformData , aKeyCode , aMetaState );
@@ -1337,9 +1346,13 @@ static bool glfm__onTouchEvent(GLFMPlatformData *platformData, AInputEvent *even
1337
1346
static void glfm__onInputEvent (GLFMPlatformData * platformData ) {
1338
1347
AInputEvent * event = NULL ;
1339
1348
while (AInputQueue_getEvent (platformData -> inputQueue , & event ) >= 0 ) {
1340
- if (AInputQueue_preDispatchEvent (platformData -> inputQueue , event )) {
1349
+ bool skipPreDispatch = (AInputEvent_getType (event ) == AINPUT_EVENT_TYPE_KEY &&
1350
+ AKeyEvent_getKeyCode (event ) == AKEYCODE_BACK );
1351
+
1352
+ if (!skipPreDispatch && AInputQueue_preDispatchEvent (platformData -> inputQueue , event )) {
1341
1353
continue ;
1342
1354
}
1355
+
1343
1356
bool handled = false;
1344
1357
int32_t eventType = AInputEvent_getType (event );
1345
1358
if (eventType == AINPUT_EVENT_TYPE_KEY ) {
0 commit comments