fix(session): keep mouse, pen and unfolded layout correct with the notch inset

Map activity-level mouse and pen events into the surface's space, size the unfolded layout from the padded content area, re-evaluate the inset when the output moves to glasses, the bottom screen or cardboard, and use a clearer Arabic label.
This commit is contained in:
FX192 committed 2026-11-21 17:25:19 +03:00
1 parent c0cc3b46a0
commit ca29850d04
2 files changed
+31 -9

No files matched your search

@@ -182,7 +182,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private fun applyNotchInset(insets: android.view.WindowInsets? = window.decorView.rootWindowInsets) { private fun applyNotchInset(insets: android.view.WindowInsets? = window.decorView.rootWindowInsets) {
if (!::sessionRoot.isInitialized) return if (!::sessionRoot.isInitialized) return
val cutout = if (avoidNotch && Build.VERSION.SDK_INT >= 28 && SessionState.mode == SessionService.MODE_STEAM && val cutout = if (avoidNotch && Build.VERSION.SDK_INT >= 28 && SessionState.mode == SessionService.MODE_STEAM &&
!pipUi && !isInPictureInPictureMode && glassesScreen == null && bottomGame == null && !cardboard.enabled) !pipUi && !isInPictureInPictureMode && glassesScreen == null && bottomGame == null && !activeCardboard.enabled)
insets?.displayCutout else null insets?.displayCutout else null
val left = cutout?.safeInsetLeft ?: 0 val left = cutout?.safeInsetLeft ?: 0
val top = cutout?.safeInsetTop ?: 0 val top = cutout?.safeInsetTop ?: 0
@@ -191,6 +191,23 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (sessionRoot.paddingLeft == left && sessionRoot.paddingTop == top && if (sessionRoot.paddingLeft == left && sessionRoot.paddingTop == top &&
sessionRoot.paddingRight == right && sessionRoot.paddingBottom == bottom) return sessionRoot.paddingRight == right && sessionRoot.paddingBottom == bottom) return
sessionRoot.setPadding(left, top, right, bottom) sessionRoot.setPadding(left, top, right, bottom)
uiHandler.post { applyUnfoldedControls() }
}
private fun rootContentWidth() = sessionRoot.width - sessionRoot.paddingLeft - sessionRoot.paddingRight
private fun rootContentHeight() = sessionRoot.height - sessionRoot.paddingTop - sessionRoot.paddingBottom
private inline fun <T> inSurfaceSpace(event: MotionEvent, block: () -> T): T {
val dx = if (outputView() === surfaceView) -surfaceView.left.toFloat() else 0f
val dy = if (outputView() === surfaceView) -surfaceView.top.toFloat() else 0f
if (dx == 0f && dy == 0f) return block()
event.offsetLocation(dx, dy)
try {
return block()
} finally {
event.offsetLocation(-dx, -dy)
}
} }
private fun applyGameAlignment() { private fun applyGameAlignment() {
@@ -3701,12 +3718,12 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (pen >= 0) when (routePen(event, pen)) { if (pen >= 0) when (routePen(event, pen)) {
PenRouter.Route.TOUCH -> {} PenRouter.Route.TOUCH -> {}
PenRouter.Route.PEN -> { PenRouter.Route.PEN -> {
if (!appUiOwnsPointer()) return penSample(event, pen) || super.dispatchGenericMotionEvent(event) if (!appUiOwnsPointer()) return inSurfaceSpace(event) { penSample(event, pen) } || super.dispatchGenericMotionEvent(event)
if (super.dispatchGenericMotionEvent(event)) { if (super.dispatchGenericMotionEvent(event)) {
penStream.cancel() penStream.cancel()
return true return true
} }
return !touchEditorOpen && penSample(event, pen) return !touchEditorOpen && inSurfaceSpace(event) { penSample(event, pen) }
} }
else -> return super.dispatchGenericMotionEvent(event) else -> return super.dispatchGenericMotionEvent(event)
} }
@@ -3714,10 +3731,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (appUiOwnsPointer()) { if (appUiOwnsPointer()) {
if (super.dispatchGenericMotionEvent(event)) return true if (super.dispatchGenericMotionEvent(event)) return true
if (touchEditorOpen) return false if (touchEditorOpen) return false
if (onMouse(event)) return true if (inSurfaceSpace(event) { onMouse(event) }) return true
return false return false
} }
if (onMouse(event)) return true if (inSurfaceSpace(event) { onMouse(event) }) return true
} }
return super.dispatchGenericMotionEvent(event) return super.dispatchGenericMotionEvent(event)
} }
@@ -4591,14 +4608,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private fun controlsBelowWanted(): Boolean { private fun controlsBelowWanted(): Boolean {
if (!::sessionRoot.isInitialized || glassesScreen != null || bottomGame != null || cardboard.enabled) return false if (!::sessionRoot.isInitialized || glassesScreen != null || bottomGame != null || cardboard.enabled) return false
return SessionPrefs.controlsBelowWanted(this, SessionState.mode, sessionRoot.width, sessionRoot.height, return SessionPrefs.controlsBelowWanted(this, SessionState.mode, rootContentWidth(), rootContentHeight(),
pipUi || isInPictureInPictureMode) pipUi || isInPictureInPictureMode)
} }
private fun applyUnfoldedControls() { private fun applyUnfoldedControls() {
if (!::sessionRoot.isInitialized) return if (!::sessionRoot.isInitialized) return
val width = sessionRoot.width val width = rootContentWidth()
val height = sessionRoot.height val height = rootContentHeight()
val wanted = controlsBelowWanted() val wanted = controlsBelowWanted()
val tabRow = unfoldedColumn?.getChildAt(0)?.height?.let { val tabRow = unfoldedColumn?.getChildAt(0)?.height?.let {
it - (com.droiddeck.launcher.ui.BAR_HEIGHT.value * resources.displayMetrics.density + 0.5f).toInt() it - (com.droiddeck.launcher.ui.BAR_HEIGHT.value * resources.displayMetrics.density + 0.5f).toInt()
@@ -6131,6 +6148,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
val e = effectiveCardboard(c) val e = effectiveCardboard(c)
activeCardboard = e activeCardboard = e
applyGameAlignment() applyGameAlignment()
applyNotchInset()
if (CompositorHost.isStarted) pushCardboard(e) if (CompositorHost.isStarted) pushCardboard(e)
if (e.enabled && !was.enabled) headTracker?.recenter() if (e.enabled && !was.enabled) headTracker?.recenter()
updateHeadTracker() updateHeadTracker()
@@ -6214,6 +6232,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
glassesOutputActive = false glassesOutputActive = false
surfaceW = 0 surfaceW = 0
surfaceH = 0 surfaceH = 0
applyNotchInset()
CompositorHost.detach(screen.holder.surface) CompositorHost.detach(screen.holder.surface)
surfaceView.visibility = View.VISIBLE surfaceView.visibility = View.VISIBLE
applyOutputPacing() applyOutputPacing()
@@ -6263,6 +6282,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
bottomGame = screen bottomGame = screen
surfaceW = 0 surfaceW = 0
surfaceH = 0 surfaceH = 0
applyNotchInset()
screen.setOnDismissListener { screen.setOnDismissListener {
if (bottomGame === screen) { if (bottomGame === screen) {
restoreTopOutput(screen) restoreTopOutput(screen)
@@ -6304,6 +6324,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
updateOnScreenPad() updateOnScreenPad()
surfaceW = 0 surfaceW = 0
surfaceH = 0 surfaceH = 0
applyNotchInset()
CompositorHost.detach(screen.holder.surface) CompositorHost.detach(screen.holder.surface)
if (glassesScreen != null) return if (glassesScreen != null) return
surfaceView.visibility = View.VISIBLE surfaceView.visibility = View.VISIBLE
@@ -6468,6 +6489,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
bottomGame?.let { restoreTopOutput(it); runCatching { it.dismiss() } } bottomGame?.let { restoreTopOutput(it); runCatching { it.dismiss() } }
val screen = GlassesScreen(this, target, Glasses.outputHz(), this, Glasses.outputResolution()) val screen = GlassesScreen(this, target, Glasses.outputHz(), this, Glasses.outputResolution())
glassesScreen = screen glassesScreen = screen
applyNotchInset()
applyOutputPacing() applyOutputPacing()
surfaceW = 0 surfaceW = 0
surfaceH = 0 surfaceH = 0
+1 -1
View File
@@ -2569,7 +2569,7 @@
<string name="display_game_fit">ملاءمة اللعبة لنسبة 16:9</string> <string name="display_game_fit">ملاءمة اللعبة لنسبة 16:9</string>
<string name="display_game_fit_hint">كيفية ملاءمة ألعاب 16:9 لهذه الشاشة. يُطبَّق في الجلسة التالية.</string> <string name="display_game_fit_hint">كيفية ملاءمة ألعاب 16:9 لهذه الشاشة. يُطبَّق في الجلسة التالية.</string>
<string name="display_game_fit_unavailable">اختر «مطابقة الشاشة» أو حجمًا مخصَّصًا أضيق من 16:9.</string> <string name="display_game_fit_unavailable">اختر «مطابقة الشاشة» أو حجمًا مخصَّصًا أضيق من 16:9.</string>
<string name="display_avoid_notch">تجنب الحواف</string> <string name="display_avoid_notch">تجنّب فتحة الكاميرا</string>
<string name="display_avoid_notch_hint">يُبقي الصورة بعيدًا عن فتحة الكاميرا. يُطبَّق عند العودة إلى الجلسة.</string> <string name="display_avoid_notch_hint">يُبقي الصورة بعيدًا عن فتحة الكاميرا. يُطبَّق عند العودة إلى الجلسة.</string>
<string name="display_preserve">الحفاظ على النسب</string> <string name="display_preserve">الحفاظ على النسب</string>
<string name="display_stretch">تمديد لملء الشاشة</string> <string name="display_stretch">تمديد لملء الشاشة</string>