feat fullscreen app setting

This commit is contained in:
xbzk 2026-03-05 17:53:52 -03:00
parent c41209f137
commit c8e109454f
6 changed files with 108 additions and 0 deletions

View file

@ -104,6 +104,8 @@ object Settings {
const val PREF_THEME_MODE = "ThemeMode"
const val PREF_BLACK_BACKGROUNDS = "BlackBackgrounds"
const val PREF_STATIC_THEME_COLOR = "StaticThemeColor"
const val PREF_APP_FULLSCREEN = "AppFullscreen"
const val APP_FULLSCREEN_DEFAULT = false
enum class EmulationOrientation(val int: Int) {
Unspecified(0),

View file

@ -103,6 +103,7 @@ class SettingsActivity : AppCompatActivity() {
)
setInsets()
applyFullscreenPreference()
}
fun navigateBack() {
@ -122,6 +123,18 @@ class SettingsActivity : AppCompatActivity() {
}
}
override fun onResume() {
super.onResume()
applyFullscreenPreference()
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) {
applyFullscreenPreference()
}
}
override fun onStop() {
super.onStop()
Log.info("[SettingsActivity] Settings activity stopping. Saving settings to INI...")
@ -188,4 +201,8 @@ class SettingsActivity : AppCompatActivity() {
windowInsets
}
}
private fun applyFullscreenPreference() {
FullscreenHelper.applyToActivity(this)
}
}

View file

@ -29,6 +29,8 @@ import org.yuzu.yuzu_emu.features.settings.model.view.*
import org.yuzu.yuzu_emu.utils.InputHandler
import org.yuzu.yuzu_emu.utils.NativeConfig
import org.yuzu.yuzu_emu.utils.DirectoryInitialization
import org.yuzu.yuzu_emu.utils.FullscreenHelper
import androidx.core.content.edit
import androidx.fragment.app.FragmentActivity
import org.yuzu.yuzu_emu.fragments.MessageDialogFragment
@ -1187,6 +1189,39 @@ class SettingsFragmentPresenter(
)
)
val fullscreenSetting: AbstractBooleanSetting = object : AbstractBooleanSetting {
override fun getBoolean(needsGlobal: Boolean): Boolean =
FullscreenHelper.isFullscreenEnabled(context)
override fun setBoolean(value: Boolean) {
FullscreenHelper.setFullscreenEnabled(context, value)
settingsViewModel.setShouldRecreate(true)
}
override val key: String = Settings.PREF_APP_FULLSCREEN
override val isRuntimeModifiable: Boolean = true
override val pairedSettingKey: String = ""
override val isSwitchable: Boolean = false
override var global: Boolean = true
override val isSaveable: Boolean = true
override val defaultValue: Boolean = Settings.APP_FULLSCREEN_DEFAULT
override fun getValueAsString(needsGlobal: Boolean): String =
getBoolean(needsGlobal).toString()
override fun reset() {
setBoolean(defaultValue)
}
}
add(
SwitchSetting(
fullscreenSetting,
titleId = R.string.fullscreen_mode,
descriptionId = R.string.fullscreen_mode_description
)
)
add(HeaderSetting(R.string.buttons))
add(BooleanSetting.ENABLE_FOLDER_BUTTON.key)
add(BooleanSetting.ENABLE_QLAUNCH_BUTTON.key)

View file

@ -170,6 +170,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
checkForUpdates()
}
setInsets()
applyFullscreenPreference()
}
private fun checkForUpdates() {
@ -346,6 +347,14 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
override fun onResume() {
ThemeHelper.setCorrectTheme(this)
super.onResume()
applyFullscreenPreference()
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) {
applyFullscreenPreference()
}
}
private fun setInsets() = ViewCompat.setOnApplyWindowInsetsListener(
@ -365,6 +374,10 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
windowInsets
}
private fun applyFullscreenPreference() {
FullscreenHelper.applyToActivity(this)
}
override fun setTheme(resId: Int) {
super.setTheme(resId)
themeId = resId

View file

@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
package org.yuzu.yuzu_emu.utils
import android.app.Activity
import android.content.Context
import androidx.core.content.edit
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.preference.PreferenceManager
import org.yuzu.yuzu_emu.features.settings.model.Settings
object FullscreenHelper {
fun isFullscreenEnabled(context: Context): Boolean {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
Settings.PREF_APP_FULLSCREEN,
Settings.APP_FULLSCREEN_DEFAULT
)
}
fun setFullscreenEnabled(context: Context, enabled: Boolean) {
PreferenceManager.getDefaultSharedPreferences(context).edit {
putBoolean(Settings.PREF_APP_FULLSCREEN, enabled)
}
}
fun applyToActivity(activity: Activity) {
val controller = WindowInsetsControllerCompat(activity.window, activity.window.decorView)
if (isFullscreenEnabled(activity)) {
controller.hide(WindowInsetsCompat.Type.systemBars())
controller.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
} else {
controller.show(WindowInsetsCompat.Type.systemBars())
}
}
}

View file

@ -1160,6 +1160,8 @@
<string name="theme_material_you">Material You</string>
<string name="app_settings">App Settings</string>
<string name="theme_and_color">Theme And Color</string>
<string name="fullscreen_mode">Fullscreen mode</string>
<string name="fullscreen_mode_description">Hide Android system bars across app screens. Swipe from an edge to reveal them temporarily.</string>
<!-- Theme Modes -->
<string name="change_theme_mode">Change theme mode</string>