From 68cbf67f4c852d0dc3745dcacc8f0a40e4595f1d Mon Sep 17 00:00:00 2001 From: t895 Date: Thu, 25 Jan 2024 20:39:52 -0500 Subject: [PATCH 1/6] android: Focus on the in game menu when opened --- .../yuzu_emu/activities/EmulationActivity.kt | 8 +++++ .../yuzu_emu/fragments/EmulationFragment.kt | 29 ++++++++++++++----- .../yuzu/yuzu_emu/model/EmulationViewModel.kt | 8 +++++ .../main/res/layout/fragment_emulation.xml | 1 + 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt index 9b08f008d..26cddecf4 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt @@ -193,6 +193,10 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { return super.dispatchKeyEvent(event) } + if (emulationViewModel.drawerOpen.value) { + return super.dispatchKeyEvent(event) + } + return InputHandler.dispatchKeyEvent(event) } @@ -203,6 +207,10 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { return super.dispatchGenericMotionEvent(event) } + if (emulationViewModel.drawerOpen.value) { + return super.dispatchGenericMotionEvent(event) + } + // Don't attempt to do anything if we are disconnecting a device. if (event.actionMasked == MotionEvent.ACTION_CANCEL) { return true diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt index d17e087fe..22da1d0e5 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt @@ -38,6 +38,7 @@ import androidx.window.layout.WindowLayoutInfo import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.slider.Slider import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import org.yuzu.yuzu_emu.HomeNavigationDirections @@ -184,10 +185,13 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { override fun onDrawerOpened(drawerView: View) { binding.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED) + binding.inGameMenu.requestFocus() + emulationViewModel.setDrawerOpen(true) } override fun onDrawerClosed(drawerView: View) { binding.drawerLayout.setDrawerLockMode(IntSetting.LOCK_DRAWER.getInt()) + emulationViewModel.setDrawerOpen(false) } override fun onDrawerStateChanged(newState: Int) { @@ -239,6 +243,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { requireContext().theme ) } + binding.inGameMenu.requestFocus() true } @@ -247,6 +252,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { null, Settings.MenuTag.SECTION_ROOT ) + binding.inGameMenu.requestFocus() binding.root.findNavController().navigate(action) true } @@ -256,6 +262,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { args.game, Settings.MenuTag.SECTION_ROOT ) + binding.inGameMenu.requestFocus() binding.root.findNavController().navigate(action) true } @@ -287,6 +294,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { ) } } + binding.inGameMenu.requestFocus() NativeConfig.saveGlobalConfig() true } @@ -295,7 +303,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { emulationState.stop() emulationViewModel.setIsEmulationStopping(true) binding.drawerLayout.close() - binding.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) + binding.inGameMenu.requestFocus() true } @@ -312,12 +320,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { if (!NativeLibrary.isRunning()) { return } - - if (binding.drawerLayout.isOpen) { - binding.drawerLayout.close() - } else { - binding.drawerLayout.open() - } + emulationViewModel.setDrawerOpen(!binding.drawerLayout.isOpen) } } ) @@ -408,6 +411,18 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { } } } + launch { + repeatOnLifecycle(Lifecycle.State.CREATED) { + emulationViewModel.drawerOpen.collect { + if (it) { + binding.drawerLayout.open() + binding.inGameMenu.requestFocus() + } else { + binding.drawerLayout.close() + } + } + } + } } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/EmulationViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/EmulationViewModel.kt index f34870c2d..b66f47fe7 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/EmulationViewModel.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/EmulationViewModel.kt @@ -6,6 +6,7 @@ package org.yuzu.yuzu_emu.model import androidx.lifecycle.ViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow class EmulationViewModel : ViewModel() { val emulationStarted: StateFlow get() = _emulationStarted @@ -23,6 +24,9 @@ class EmulationViewModel : ViewModel() { val shaderMessage: StateFlow get() = _shaderMessage private val _shaderMessage = MutableStateFlow("") + private val _drawerOpen = MutableStateFlow(false) + val drawerOpen = _drawerOpen.asStateFlow() + fun setEmulationStarted(started: Boolean) { _emulationStarted.value = started } @@ -49,6 +53,10 @@ class EmulationViewModel : ViewModel() { setTotalShaders(max) } + fun setDrawerOpen(value: Boolean) { + _drawerOpen.value = value + } + fun clear() { setEmulationStarted(false) setIsEmulationStopping(false) diff --git a/src/android/app/src/main/res/layout/fragment_emulation.xml b/src/android/app/src/main/res/layout/fragment_emulation.xml index 5252adf54..988bbb373 100644 --- a/src/android/app/src/main/res/layout/fragment_emulation.xml +++ b/src/android/app/src/main/res/layout/fragment_emulation.xml @@ -160,6 +160,7 @@ android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" + android:focusedByDefault="true" app:headerLayout="@layout/header_in_game" app:menu="@menu/menu_in_game" tools:visibility="gone" /> From 91636deaaf58c82d8352f8c51e4e20c26e5b402d Mon Sep 17 00:00:00 2001 From: t895 Date: Thu, 25 Jan 2024 20:42:23 -0500 Subject: [PATCH 2/6] android: Disable focus for the root of cards that contain buttons --- src/android/app/src/main/res/layout/card_driver_option.xml | 1 + src/android/app/src/main/res/layout/card_folder.xml | 6 ++---- src/android/app/src/main/res/layout/list_item_addon.xml | 2 +- .../app/src/main/res/layout/list_item_settings_header.xml | 1 + 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/android/app/src/main/res/layout/card_driver_option.xml b/src/android/app/src/main/res/layout/card_driver_option.xml index 1dd9a6d7d..bda524f0f 100644 --- a/src/android/app/src/main/res/layout/card_driver_option.xml +++ b/src/android/app/src/main/res/layout/card_driver_option.xml @@ -23,6 +23,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" + android:focusable="false" android:clickable="false" android:checked="false" /> diff --git a/src/android/app/src/main/res/layout/card_folder.xml b/src/android/app/src/main/res/layout/card_folder.xml index 4e0c04b6b..ed4a7ca8f 100644 --- a/src/android/app/src/main/res/layout/card_folder.xml +++ b/src/android/app/src/main/res/layout/card_folder.xml @@ -6,16 +6,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginHorizontal="16dp" - android:layout_marginVertical="12dp" - android:focusable="true"> + android:layout_marginVertical="12dp"> + android:layout_gravity="center_vertical"> diff --git a/src/android/app/src/main/res/layout/list_item_settings_header.xml b/src/android/app/src/main/res/layout/list_item_settings_header.xml index 21276b19e..615860368 100644 --- a/src/android/app/src/main/res/layout/list_item_settings_header.xml +++ b/src/android/app/src/main/res/layout/list_item_settings_header.xml @@ -12,4 +12,5 @@ android:textAlignment="viewStart" android:textColor="?attr/colorPrimary" android:textStyle="bold" + android:focusable="false" tools:text="CPU Settings" /> From b24a111136888e685f74f0a67649d993e578ebeb Mon Sep 17 00:00:00 2001 From: t895 Date: Thu, 25 Jan 2024 20:43:12 -0500 Subject: [PATCH 3/6] android: Fix button click listener for build version name Was set to the text instead of the parent view by mistake --- .../src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt index 5b5f800c1..5ab38ffda 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt @@ -77,7 +77,7 @@ class AboutFragment : Fragment() { } binding.textVersionName.text = BuildConfig.VERSION_NAME - binding.textVersionName.setOnClickListener { + binding.buttonVersionName.setOnClickListener { val clipBoard = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager val clip = ClipData.newPlainText(getString(R.string.build), BuildConfig.GIT_HASH) From d23c4393fdb7a78a2f6e3db40ffccf5aa2fdeb79 Mon Sep 17 00:00:00 2001 From: t895 Date: Thu, 25 Jan 2024 20:46:03 -0500 Subject: [PATCH 4/6] android: Add 600dp layout for GameInfoFragment --- .../res/layout-w600dp/fragment_game_info.xml | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/android/app/src/main/res/layout-w600dp/fragment_game_info.xml diff --git a/src/android/app/src/main/res/layout-w600dp/fragment_game_info.xml b/src/android/app/src/main/res/layout-w600dp/fragment_game_info.xml new file mode 100644 index 000000000..90d95dbb7 --- /dev/null +++ b/src/android/app/src/main/res/layout-w600dp/fragment_game_info.xml @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From ee540c712c9517319e61f1aebf23eebc88cb63c6 Mon Sep 17 00:00:00 2001 From: t895 Date: Thu, 25 Jan 2024 20:48:58 -0500 Subject: [PATCH 5/6] android: Allow controller to focus on toolbar menu items Workaround for this https://issuetracker.google.com/issues/256948272 --- src/android/app/src/main/res/layout-w600dp/fragment_about.xml | 4 +++- src/android/app/src/main/res/layout/fragment_about.xml | 4 +++- src/android/app/src/main/res/layout/fragment_addons.xml | 2 ++ .../app/src/main/res/layout/fragment_applet_launcher.xml | 4 +++- .../app/src/main/res/layout/fragment_driver_manager.xml | 2 ++ src/android/app/src/main/res/layout/fragment_early_access.xml | 4 +++- src/android/app/src/main/res/layout/fragment_folders.xml | 2 ++ src/android/app/src/main/res/layout/fragment_game_info.xml | 2 ++ src/android/app/src/main/res/layout/fragment_installables.xml | 4 +++- src/android/app/src/main/res/layout/fragment_licenses.xml | 4 +++- src/android/app/src/main/res/layout/fragment_settings.xml | 2 ++ 11 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/android/app/src/main/res/layout-w600dp/fragment_about.xml b/src/android/app/src/main/res/layout-w600dp/fragment_about.xml index 655e49219..221428740 100644 --- a/src/android/app/src/main/res/layout-w600dp/fragment_about.xml +++ b/src/android/app/src/main/res/layout-w600dp/fragment_about.xml @@ -11,12 +11,14 @@ android:id="@+id/appbar_about" android:layout_width="match_parent" android:layout_height="wrap_content" - android:fitsSystemWindows="true"> + android:fitsSystemWindows="true" + android:touchscreenBlocksFocus="false"> diff --git a/src/android/app/src/main/res/layout/fragment_about.xml b/src/android/app/src/main/res/layout/fragment_about.xml index 38090fa50..1520bccee 100644 --- a/src/android/app/src/main/res/layout/fragment_about.xml +++ b/src/android/app/src/main/res/layout/fragment_about.xml @@ -11,12 +11,14 @@ android:id="@+id/appbar_about" android:layout_width="match_parent" android:layout_height="wrap_content" - android:fitsSystemWindows="true"> + android:fitsSystemWindows="true" + android:touchscreenBlocksFocus="false"> diff --git a/src/android/app/src/main/res/layout/fragment_addons.xml b/src/android/app/src/main/res/layout/fragment_addons.xml index a25e82766..d8d522dca 100644 --- a/src/android/app/src/main/res/layout/fragment_addons.xml +++ b/src/android/app/src/main/res/layout/fragment_addons.xml @@ -11,6 +11,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" + android:touchscreenBlocksFocus="false" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> @@ -19,6 +20,7 @@ android:id="@+id/toolbar_addons" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" + android:touchscreenBlocksFocus="false" app:navigationIcon="@drawable/ic_back" /> diff --git a/src/android/app/src/main/res/layout/fragment_applet_launcher.xml b/src/android/app/src/main/res/layout/fragment_applet_launcher.xml index fe8fae40f..95e6d6a6b 100644 --- a/src/android/app/src/main/res/layout/fragment_applet_launcher.xml +++ b/src/android/app/src/main/res/layout/fragment_applet_launcher.xml @@ -10,12 +10,14 @@ android:id="@+id/appbar_applets" android:layout_width="match_parent" android:layout_height="wrap_content" - android:fitsSystemWindows="true"> + android:fitsSystemWindows="true" + android:touchscreenBlocksFocus="false"> diff --git a/src/android/app/src/main/res/layout/fragment_driver_manager.xml b/src/android/app/src/main/res/layout/fragment_driver_manager.xml index 6cea2d164..56d8e6bb8 100644 --- a/src/android/app/src/main/res/layout/fragment_driver_manager.xml +++ b/src/android/app/src/main/res/layout/fragment_driver_manager.xml @@ -15,12 +15,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" + android:touchscreenBlocksFocus="false" app:liftOnScrollTargetViewId="@id/list_drivers"> diff --git a/src/android/app/src/main/res/layout/fragment_early_access.xml b/src/android/app/src/main/res/layout/fragment_early_access.xml index 644b4dd45..24b130543 100644 --- a/src/android/app/src/main/res/layout/fragment_early_access.xml +++ b/src/android/app/src/main/res/layout/fragment_early_access.xml @@ -11,12 +11,14 @@ android:id="@+id/appbar_ea" android:layout_width="match_parent" android:layout_height="wrap_content" - android:fitsSystemWindows="true"> + android:fitsSystemWindows="true" + android:touchscreenBlocksFocus="false"> diff --git a/src/android/app/src/main/res/layout/fragment_folders.xml b/src/android/app/src/main/res/layout/fragment_folders.xml index 74f2f3754..d7c4c7cb0 100644 --- a/src/android/app/src/main/res/layout/fragment_folders.xml +++ b/src/android/app/src/main/res/layout/fragment_folders.xml @@ -15,12 +15,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" + android:touchscreenBlocksFocus="false" app:liftOnScrollTargetViewId="@id/list_folders"> diff --git a/src/android/app/src/main/res/layout/fragment_game_info.xml b/src/android/app/src/main/res/layout/fragment_game_info.xml index 53af15787..7daca72df 100644 --- a/src/android/app/src/main/res/layout/fragment_game_info.xml +++ b/src/android/app/src/main/res/layout/fragment_game_info.xml @@ -11,12 +11,14 @@ android:id="@+id/appbar_info" android:layout_width="match_parent" android:layout_height="wrap_content" + android:touchscreenBlocksFocus="false" android:fitsSystemWindows="true"> diff --git a/src/android/app/src/main/res/layout/fragment_installables.xml b/src/android/app/src/main/res/layout/fragment_installables.xml index 3a4df81a6..47ef3869f 100644 --- a/src/android/app/src/main/res/layout/fragment_installables.xml +++ b/src/android/app/src/main/res/layout/fragment_installables.xml @@ -10,12 +10,14 @@ android:id="@+id/appbar_installables" android:layout_width="match_parent" android:layout_height="wrap_content" - android:fitsSystemWindows="true"> + android:fitsSystemWindows="true" + android:touchscreenBlocksFocus="false"> diff --git a/src/android/app/src/main/res/layout/fragment_licenses.xml b/src/android/app/src/main/res/layout/fragment_licenses.xml index 6b31ff5b4..59d68b112 100644 --- a/src/android/app/src/main/res/layout/fragment_licenses.xml +++ b/src/android/app/src/main/res/layout/fragment_licenses.xml @@ -10,12 +10,14 @@ android:id="@+id/appbar_licenses" android:layout_width="match_parent" android:layout_height="wrap_content" - android:fitsSystemWindows="true"> + android:fitsSystemWindows="true" + android:touchscreenBlocksFocus="false"> diff --git a/src/android/app/src/main/res/layout/fragment_settings.xml b/src/android/app/src/main/res/layout/fragment_settings.xml index ebedbf1ec..110c70eef 100644 --- a/src/android/app/src/main/res/layout/fragment_settings.xml +++ b/src/android/app/src/main/res/layout/fragment_settings.xml @@ -11,6 +11,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" + android:touchscreenBlocksFocus="false" app:elevation="0dp"> From 677c2c2cd2bb01352885cb5caea654d3f900461f Mon Sep 17 00:00:00 2001 From: t895 Date: Thu, 25 Jan 2024 20:49:57 -0500 Subject: [PATCH 6/6] android: Disable default focus highlight on views that shouldn't be selected --- .../app/src/main/res/layout-w600dp/fragment_about.xml | 1 + .../main/res/layout-w600dp/fragment_game_properties.xml | 1 + src/android/app/src/main/res/layout/fragment_about.xml | 1 + src/android/app/src/main/res/layout/fragment_addons.xml | 2 ++ .../app/src/main/res/layout/fragment_early_access.xml | 1 + src/android/app/src/main/res/layout/fragment_emulation.xml | 7 +++++-- src/android/app/src/main/res/layout/fragment_folders.xml | 1 + src/android/app/src/main/res/layout/fragment_game_info.xml | 1 + .../app/src/main/res/layout/fragment_game_properties.xml | 5 +++-- src/android/app/src/main/res/layout/fragment_games.xml | 1 + .../app/src/main/res/layout/fragment_home_settings.xml | 3 ++- 11 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/android/app/src/main/res/layout-w600dp/fragment_about.xml b/src/android/app/src/main/res/layout-w600dp/fragment_about.xml index 221428740..a5eba6474 100644 --- a/src/android/app/src/main/res/layout-w600dp/fragment_about.xml +++ b/src/android/app/src/main/res/layout-w600dp/fragment_about.xml @@ -30,6 +30,7 @@ android:layout_height="match_parent" android:fadeScrollbars="false" android:scrollbars="vertical" + android:defaultFocusHighlightEnabled="false" app:layout_behavior="@string/appbar_scrolling_view_behavior"> diff --git a/src/android/app/src/main/res/layout/fragment_about.xml b/src/android/app/src/main/res/layout/fragment_about.xml index 1520bccee..7f32e139a 100644 --- a/src/android/app/src/main/res/layout/fragment_about.xml +++ b/src/android/app/src/main/res/layout/fragment_about.xml @@ -30,6 +30,7 @@ android:layout_height="match_parent" android:scrollbars="vertical" android:fadeScrollbars="false" + android:defaultFocusHighlightEnabled="false" app:layout_behavior="@string/appbar_scrolling_view_behavior"> @@ -24,7 +25,8 @@ android:layout_height="match_parent" android:layout_gravity="center" android:focusable="false" - android:focusableInTouchMode="false" /> + android:focusableInTouchMode="false" + android:defaultFocusHighlightEnabled="false" />