#239
android: report the UI safe area from the always-visible outer frame
What changed
- 窗口安全区(
WindowInsets.Type.displayCutout())的上报从触屏层挪到游戏画面(DmActivity的 SurfaceView),另开一条只报安全区、不布局控件的通道TouchOverlay.feedUiSafeInsets → nativeUiSafeInsets → dm_android_ui_safe_insets;surfaceChanged()里画面尺寸落定后再要一次 insets(那一刻getHeight()才是真值)。触屏层自己那份(摆控件用的setSafeInsets)照旧,不动。 - 游戏自己的界面(左上角佣兵 / 召唤物头像栏)的左内移量不再拿触屏层那个
sl:sl是「落在游戏视图里的那部分」,扣掉了视图原点;真全屏下它就是 0。而游戏界面按整屏定位,不该跟着视图原点走。- 系统的 displayCutout 只报有挖孔的那一侧。本机横屏(
rotation=3)实测InsetsSource type=displayCutout frame=[2620,0][2772,1280] sideHint=RIGHT,即right=152px、left=0;但屏幕四角都是圆角,左上角等的是那份圆角内移。所以改成按整屏取左右两侧的较大值。 - 只有拿到有效值才写,并留一份在宿主侧,后面的 layout 过程不能再把它清回 0。
触屏控件的布局仍然用 sl / sr(该扣视图原点的地方照旧扣)。
Why
手柄模式下 Java 侧把触屏层 setInputEnabled(false) + setVisibility(GONE),系统不再向它派发 insets,挂在它身上的监听不跑,于是宿主根本收不到左安全区——左上角头像栏贴着屏幕边,被左上圆角切掉一截。真机日志里「安全区:头像 0 x 0 → 257」这一行只在触屏模式出现,切到手柄模式就没了。
另外,即使停在触屏模式,真全屏下 sl 也会被视图原点扣成 0,所以真全屏那条线合进来以后,两种输入模式都不再让位(这是升级到 v2.3.0 后观察到的回归)。
Checks run
No game files needed:
-
python3 dm/i18n/scan_literals.py→I18N OK:中文字面量 474 条全在白名单(111 行),其余走中英表 -
python3 dm/ios/tools/dm_i18n.py --check→dm_i18n OK 486 条
Anything else you ran, and on what:
-
python3 dm/host/tests/mode_scan.py→✓ 模式登记闸门:每帧泵 24 个都已分类,散判模式与替按键的处数没有超出登记,登记项函数齐全 -
python3 dm/host/tests/native_write_scan.py dm/host→✓ …宿主 77 个源文件没有绕过守卫直接写可见位;dm_cursor.c 写控件矩形只在 mv_offset / ui_move_ours 里 - 真机:红米 K80 Ultra(
25060RK16C,2772×1280,Mali-G925,Android 16),横屏挖孔在右侧;adb install -r覆盖在 2.3.0 上,存档与导入包不动。- 改之前:头像栏贴着屏幕左边;宿主的位置守卫只登记 2 条(小地图 + 信息栏),整份日志里没有一条「安全区:头像」。
- 改之后:头像栏内移 152px,手柄模式与触屏模式位置一致;位置守卫登记 18 条,日志出现
安全区:头像 0 x 0 → 257;手柄 ↔ 触屏来回切,界面重建后 6 帧内又补回内移。 - 截图(同一存档、罗·高因;左上角头像栏):
- 改前 / 改后并排(左上角 2 倍放大):https://raw.githubusercontent.com/bigjokeryo/d2r-mobile/pr-assets/2026-11-05-safe-insets-compare.png
- 改前整图:https://raw.githubusercontent.com/bigjokeryo/d2r-mobile/pr-assets/2026-11-05-safe-insets-before.png
- 改后整图:https://raw.githubusercontent.com/bigjokeryo/d2r-mobile/pr-assets/2026-11-05-safe-insets-after.png
- 改后(触屏模式,位置与手柄模式一致):https://raw.githubusercontent.com/bigjokeryo/d2r-mobile/pr-assets/2026-11-05-safe-insets-after-touch-mode.png
没有跑:make -C dm/host/tests run 与 dm/verify/regress.sh(这台机器没有 ./setup.sh 产出的 build/main.orig.bin),make -C dm/gfx/tests run(要 Metal),cd dm/ios && ./run.sh build / smoke_mac.sh / check_hud_gen.sh(要 Mac 与游戏文件)。
Visible changes
- Something on screen changes — 左上角佣兵 / 召唤物头像栏内移,截图见上
No game content
- This change contains no game files, nothing generated from game files, no keys, and no built package
- It does not carry the local rewrites
./setup.shmakes todm/gfx/tools/dmsh_chain.lock,dm/gfx/nvn/dmsh_chain.handdm/gfx/nvn/c1_full.tsv
Comments
- New and changed comments are in both Chinese and English
- 这里只处理「游戏界面让开圆角 / 挖孔」。右上角小地图与地名那侧沿用原有逻辑(含真全屏 0.07 高的缺省内移),没改。
把安全区挂到一直在屏上的 SurfaceView 上这个思路对:手柄模式下触屏层是 GONE,收不到 insets。有两处想请你看一下:
右安全区两条路径打架。 主线上
touch_android.c在真全屏(vr_x/vr_y> 0.5)时给dm_ui_safe_right设了下限 0.07 × 2160,好让右上角小地图和地名不被切掉。新的dm_android_ui_safe_insets也写dm_ui_safe_right,但没有这个下限,用的高度也不一样(整窗高度对游戏视图高度)。建议新路径只写左边,或者用同样的下限和同一个高度。
view_safe_left只增不减。 只有lu > 0才写,不会清零。显示变了(折叠屏内外屏切换、外接屏)时会一直留着旧值。也许可以在surfaceChanged之后第一次拿到 insets 时照实写,包括 0。另外,圆角的半径 Android 12(API 31)起可以直接从
WindowInsets.getRoundedCorner()拿到,可能比拿挖孔那一侧的值顶替更准。Moving the report onto the always-visible SurfaceView makes sense: in controller mode the touch layer is GONE and never gets insets. Two things to look at:
The two paths fight over the right inset. On main,
touch_android.cgivesdm_ui_safe_righta minimum of 0.07 × 2160 in true fullscreen (vr_x/vr_y> 0.5), so the top-right minimap and area name aren't cut off. The newdm_android_ui_safe_insetsalso writesdm_ui_safe_right, but without that minimum and against a different height (the whole window rather than the game view).Writing only the left side here, or applying the same minimum and the same height, would avoid it.
view_safe_leftonly ever grows. It is written only whenlu > 0and never cleared, so after a display change (a foldable's inner / outer screen, an external display) the old value sticks. Maybe write the value as it is, 0 included, on the first insets aftersurfaceChanged.Also, from Android 12 (API 31) the corner radius is available directly from
WindowInsets.getRoundedCorner(), which may be more accurate than reusing the cutout side's value.