Skip to content

Commit ec0719a

Browse files
implement KeepSwapRatio
1 parent 50233eb commit ec0719a

File tree

6 files changed

+66
-0
lines changed

6 files changed

+66
-0
lines changed

SplitScreenMods/Readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Keep the split screen ratio, when switching one of the split apps.
1717
Only usable on Android 14 and later,
1818
since previous versions did not force a split resize in this situation.
1919

20+
## KeepSwapRatio
21+
22+
Keep the split ratio while swapping sides.
23+
2024
## SnapMode
2125

2226
Change the snap mode used by the system:

SplitScreenMods/src/main/assets/xposed_init

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ com.programminghoch10.SplitScreenMods.CalculateRatiosHook
44
com.programminghoch10.SplitScreenMods.CustomFixedRatioHook
55
com.programminghoch10.SplitScreenMods.FreeSnapHook
66
com.programminghoch10.SplitScreenMods.KeepSplitScreenRatioHook
7+
com.programminghoch10.SplitScreenMods.KeepSwapRatioHook
78
com.programminghoch10.SplitScreenMods.RemoveMinimalTaskSizeHook
89
com.programminghoch10.SplitScreenMods.SnapModeHook
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.programminghoch10.SplitScreenMods
2+
3+
import java.util.function.*
4+
import android.content.Context
5+
import android.graphics.Rect
6+
import android.os.Build
7+
import com.programminghoch10.SplitScreenMods.BuildConfig.SHARED_PREFERENCES_NAME
8+
import com.programminghoch10.SplitScreenMods.KeepSwapRatioHookConfig.enabled
9+
import de.binarynoise.logger.Logger.log
10+
import de.robv.android.xposed.IXposedHookLoadPackage
11+
import de.robv.android.xposed.XC_MethodReplacement
12+
import de.robv.android.xposed.XSharedPreferences
13+
import de.robv.android.xposed.XposedBridge
14+
import de.robv.android.xposed.XposedHelpers
15+
import de.robv.android.xposed.callbacks.XC_LoadPackage
16+
17+
object KeepSwapRatioHookConfig {
18+
@JvmField
19+
val enabled = Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE
20+
}
21+
22+
class KeepSwapRatioHook : IXposedHookLoadPackage {
23+
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
24+
if (lpparam.packageName != "com.android.systemui") return
25+
if (!enabled) return
26+
log("handleLoadPackage(${lpparam.packageName} in process ${lpparam.processName})")
27+
val preferences = XSharedPreferences(BuildConfig.APPLICATION_ID, SHARED_PREFERENCES_NAME)
28+
val enabled = preferences.getBoolean("KeepSwapRatio", false)
29+
if (!enabled) return
30+
31+
val SplitLayoutClass = XposedHelpers.findClass("com.android.wm.shell.common.split.SplitLayout", lpparam.classLoader)
32+
val playSwapAnimationMethod =
33+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) SplitLayoutClass.declaredMethods.single { it.name == "playSwapAnimation" }
34+
else SplitLayoutClass.declaredMethods.single { it.name == "splitSwitching" }
35+
val getDisplayStableInsetsMethod = XposedHelpers.findMethodExact(SplitLayoutClass, "getDisplayStableInsets", Context::class.java)
36+
37+
XposedBridge.hookMethod(
38+
playSwapAnimationMethod,
39+
object : XC_MethodReplacement() {
40+
override fun replaceHookedMethod(param: MethodHookParam): Any? {
41+
@Suppress("UNCHECKED_CAST")
42+
val callback = param.args[3] as Consumer<Rect>
43+
val context = XposedHelpers.getObjectField(param.thisObject, "mContext") as Context
44+
val insets = getDisplayStableInsetsMethod.invoke(param.thisObject, context) as Rect
45+
callback.accept(insets)
46+
log("replaced ${playSwapAnimationMethod.name} with dummy implementation to prevent swapping")
47+
return null
48+
}
49+
},
50+
)
51+
}
52+
}

SplitScreenMods/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@
3838
</string>
3939
<string name="snaptargets_title">SnapTargets</string>
4040
<string name="CustomRatio_title">Custom Fixed Ratio</string>
41+
<string name="keepswapratio_summary">Keep split ratio when swapping sides</string>
42+
<string name="keepswapratio_title">KeepSwapRatio</string>
4143
</resources>

SplitScreenMods/src/main/res/xml/root_preferences.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
app:summary="@string/keepsplitscreenratio_summary"
1919
app:title="@string/keepsplitscreenratio_title"
2020
/>
21+
<SwitchPreference
22+
app:iconSpaceReserved="false"
23+
app:key="KeepSwapRatio"
24+
app:summary="@string/keepswapratio_summary"
25+
app:title="@string/keepswapratio_title"
26+
/>
2127
</PreferenceCategory>
2228
<PreferenceCategory
2329
app:iconSpaceReserved="false"

metadata/com.programminghoch10.SplitScreenMods/en-US/full_description.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ A collection of various SplitScreen modifications.
22

33
* AlwaysAllowMultiInstanceSplit
44
* KeepSplitScreenRatio
5+
* KeepSwapRatio
56
* SnapMode
67
* FreeSnap
78
* AdditionalSnapTargets

0 commit comments

Comments
 (0)