#239

android: report the UI safe area from the always-visible outer frame

Openbigjokeryowants to merge intofrom

What changed

  1. 窗口安全区(WindowInsets.Type.displayCutout())的上报从触屏层挪到游戏画面(DmActivity 的 SurfaceView),另开一条只报安全区、不布局控件的通道 TouchOverlay.feedUiSafeInsets → nativeUiSafeInsets → dm_android_ui_safe_insets;surfaceChanged() 里画面尺寸落定后再要一次 insets(那一刻 getHeight() 才是真值)。触屏层自己那份(摆控件用的 setSafeInsets)照旧,不动。
  2. 游戏自己的界面(左上角佣兵 / 召唤物头像栏)的左内移量不再拿触屏层那个 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:

没有跑: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.sh makes to dm/gfx/tools/dmsh_chain.lock, dm/gfx/nvn/dmsh_chain.h and dm/gfx/nvn/c1_full.tsv

Comments

  • New and changed comments are in both Chinese and English
  • 这里只处理「游戏界面让开圆角 / 挖孔」。右上角小地图与地名那侧沿用原有逻辑(含真全屏 0.07 高的缺省内移),没改。

Activity

2
yyan16010d ago

把安全区挂到一直在屏上的 SurfaceView 上这个思路对:手柄模式下触屏层是 GONE,收不到 insets。有两处想请你看一下:

  1. 右安全区两条路径打架。 主线上 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,但没有这个下限,用的高度也不一样(整窗高度对游戏视图高度)。

    • 手柄模式下只有新路径在跑,所以右侧没有挖孔、又是真全屏的手机,右安全区会回到 0。
    • 触屏模式下谁后跑谁说了算。

    建议新路径只写左边,或者用同样的下限和同一个高度。

  2. 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:

  1. The two paths fight over the right inset. On main, touch_android.c gives dm_ui_safe_right a 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 new dm_android_ui_safe_insets also writes dm_ui_safe_right, but without that minimum and against a different height (the whole window rather than the game view).

    • In controller mode only the new path runs, so a true-fullscreen phone without a right-side cutout drops back to 0 on the right.
    • In touch mode whichever runs last wins.

    Writing only the left side here, or applying the same minimum and the same height, would avoid it.

  2. view_safe_left only ever grows. It is written only when lu > 0 and 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 after surfaceChanged.

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.