Gamebar: Implement "take screenshot" in gesture quick actions menu

Signed-off-by: kenway214 <kenway214@outlook.com>
This commit is contained in:
kenway214
2025-11-02 23:42:02 +05:30
parent 05b030340d
commit f02dbfe9fc
3 changed files with 42 additions and 0 deletions

View File

@@ -83,11 +83,13 @@
<item>Toggle Full/Minimal Format</item>
<item>Start/Stop Log Capture</item>
<item>Open GameBar Settings</item>
<item>Take Screenshot</item>
</string-array>
<string-array name="gesture_function_values">
<item>toggle_format</item>
<item>capture_logs</item>
<item>open_settings</item>
<item>take_screenshot</item>
</string-array>
<!-- Long press timeouts -->

View File

@@ -202,6 +202,9 @@ class GameBar private constructor(context: Context) {
"open_settings" -> {
openOverlaySettings()
}
"take_screenshot" -> {
takeScreenshot()
}
}
}
@@ -1152,6 +1155,16 @@ class GameBar private constructor(context: Context) {
}
}
private fun takeScreenshot() {
try {
// Trigger system screenshot using shell command
Runtime.getRuntime().exec("input keyevent KEYCODE_SYSRQ")
Toast.makeText(context, "Screenshot taken", Toast.LENGTH_SHORT).show()
} catch (e: Exception) {
Toast.makeText(context, "Failed to take screenshot", Toast.LENGTH_SHORT).show()
}
}
private fun openOverlaySettings() {
try {
val intent = Intent(context, GameBarSettingsActivity::class.java)

View File

@@ -278,6 +278,15 @@ class GameBarFragment : SettingsBasePreferenceFragment() {
true
}
// Single tap function change
singleTapFunctionPref?.setOnPreferenceChangeListener { _, _ ->
// Reload preferences to apply new function
android.os.Handler(android.os.Looper.getMainLooper()).post {
gameBar?.applyPreferences()
}
true
}
// Double tap enable/disable and visibility
doubleTapEnablePref?.setOnPreferenceChangeListener { _, newValue ->
val enabled = newValue as Boolean
@@ -285,6 +294,15 @@ class GameBarFragment : SettingsBasePreferenceFragment() {
true
}
// Double tap function change
doubleTapFunctionPref?.setOnPreferenceChangeListener { _, _ ->
// Reload preferences to apply new function
android.os.Handler(android.os.Looper.getMainLooper()).post {
gameBar?.applyPreferences()
}
true
}
// Long press enable/disable and visibility
longPressEnablePref?.setOnPreferenceChangeListener { _, newValue ->
val enabled = newValue as Boolean
@@ -293,6 +311,15 @@ class GameBarFragment : SettingsBasePreferenceFragment() {
true
}
// Long press function change
longPressFunctionPref?.setOnPreferenceChangeListener { _, _ ->
// Reload preferences to apply new function
android.os.Handler(android.os.Looper.getMainLooper()).post {
gameBar?.applyPreferences()
}
true
}
// Long press timeout
longPressTimeoutPref?.setOnPreferenceChangeListener { _, newValue ->
if (newValue is String) {