Repository navigation
hle/accessibility, docs: implement closed captions and high contrast - #22
PrivacyOnion wants to merge 2 commits into
Conversation
simnJS
left a comment
There was a problem hiding this comment.
Thanks for this, and for the tests and the AI disclosure. A few things need changing before it can go in.
1. Five of the nine registry value names don't exist. On Windows 11, the Settings app writes these DWORDs under HKCU\Software\Microsoft\Windows\CurrentVersion\ClosedCaptioning:
CaptionColor,CaptionOpacity,CaptionSize,CaptionFontStyle,CaptionEdgeEffect;BackgroundColor,BackgroundOpacity,RegionColor,RegionOpacity;- plus
CurrentSelectedTheme, a string.
FontColor, FontOpacity, FontEffect, FontStyle and FontSize (speech.rs:229-235) are property names of the WinRT ClosedCaptionProperties class, not registry values. So text colour, text opacity, size, font style and edge always fall back to the defaults: "yellow on blue" comes out white on blue. The tests start from a filled-in HostCaptionSettings, so they don't catch it.
The simplest fix is to drop the registry and use the documented API, Windows.Media.ClosedCaptioning.ClosedCaptionProperties. xtp-hle already depends on windows, so this only needs its Media_ClosedCaptioning feature. If you keep the registry, please use the real names, and make the reader testable so that a test pins the names.
2. Overlap with xcl. classify_high_contrast (speech.rs:172-186) has the same name, signature and body as the function of the same name in xcl's hle/xgameruntime/accessibility.rs: the same early return, the same COLORREF unpacking, Rec. 601 luma, and the same threshold to within 500. The defaults (including the transparent window colour), the three layout asserts and the high-contrast test vectors match it too, in the same order and with the same u32::MAX sentinel.
xcl is GPL-2.0-only, and CONTRIBUTING rule 6 rules out code copied or translated from it, "not even a function". You wrote that you didn't read that file, but AI assistants may have seen it. Please rewrite the high-contrast classification and these tests your own way. Using xcl's defaults as behaviour is fine (issue #6 points there), but please say so under Provenance rather than calling them "documented defaults".
3. Smaller points
closed_caption_set_enabled(_: This, enabled: bool)(speech.rs:299): a Rustboolholding anything other than 0 or 1 is undefined behaviour. When XTP reads a C++boolargument, it takes au8and tests!= 0(seem_get_statusinxasync.rs).- Each
XClosedCaptionGetPropertiescall re-reads the settings: cache them if the title turns out to poll every frame. - The docs box is ticked, but no docs changed: the "Runtime services" row in README.md and R7 in
docs/analysis/hle.md.
4. Coordination. AliceWood claimed #6 before this PR was opened, and #23 implements the same issue in the same files. As the claim came first, we'll review #23 first. Please hold off on a big rework until we've decided, and next time please comment on the issue to claim it before starting, so that nobody duplicates work.
What's already right:
- the slot assignment (0x18/0x20/0x28) and the signatures;
- the 28-byte layout and the enum mappings;
- the null checks through
put, and theREG_DWORDand length checks; - the
SPI_GETHIGHCONTRASTcall and the SAFETY comments; - adding only windows-sys features to an existing dependency.
|
Understood — apologies for missing @AliceWood's claim on #6, I'll make sure to check and comment to claim issues before starting next time. Holding off on changes here while #23 is reviewed, and thanks for the detailed feedback on the registry value names, u8 ABI for C++ �ool, and WinRT Media_ClosedCaptioning. |
|
Heads-up: #23 implements the same issue (#6). It was claimed on the issue first, and it uses the documented WinRT caption API. It is going ahead, and this PR will be closed when #23 lands. Thanks for the effort. For the next one, please claim the issue first (CONTRIBUTING, "Before you start"), so that two people don't build the same thing. |
|
Pushed a follow-up commit addressing all review items (still happy for #23 to be reviewed first):
|
|
Other open pull requests change the same files. Check that they do not do the same work, and agree with their authors on which lands first: the other one will then need a rebase.
This comment is kept up to date automatically and removed when the overlap ends. |
c8d5349 to
f4b1add
Compare
|
Closing as a duplicate of #23, which implemented #6 and has now been merged. Thanks @PrivacyOnion for the work and for understanding. |
What and why
Implement the accessibility vtable slots in
crates/xtp-hle/src/modules/speech.rsfrom the host Windows settings:0x18(XClosedCaptionGetProperties): reads closed-caption colours, opacity, edge attribute, font style, and scale through the WinRTWindows.Media.ClosedCaptioning.ClosedCaptionPropertiesAPI (cached in aOnceLockso per-frame polling stays cheap), falling back to default properties (opaque black background, opaque white text, transparent window, default edge/style, 100% scale, disabled) when unavailable.0x20(XClosedCaptionSetEnabled): acceptsu8(!= 0) to match C++boolABI safely and stores the enabled override atomically so subsequentXClosedCaptionGetPropertiescalls read it back.0x28(XHighContrastGetMode): queriesSystemParametersInfoW(SPI_GETHIGHCONTRAST)and comparesGetSysColor(COLOR_WINDOW)againstGetSysColor(COLOR_WINDOWTEXT)brightness to distinguishDark,Light, andOther(orOffwhen inactive).Fixes: #6
Depends on: none
Area
crates/xtp-hle/src/modules/speech.rscrates/xtp-hle/Cargo.toml(windowsfeatureMedia_ClosedCaptioning;windows-sysfeaturesWin32_Graphics_Gdi,Win32_UI_Accessibility)README.md(update "Runtime services" row)Tests
cargo xtask pr-checkpasses on my machineUnit tests in
crates/xtp-hle/src/modules/speech.rsverify:XColor, edge, style, and scale fields;XClosedCaptionSetEnabledaccepts any non-zero byte (0xff) and0and is read back throughXClosedCaptionGetProperties, plus null-pointer rejection;high_contrast_from_pairdistinguishesOff,Dark,Light, andOther, and slot0x28rejects null pointers and returns a valid mode.Provenance
Written from scratch for XTP using public Microsoft Learn documentation for
XAccessibility.h,Windows.Media.ClosedCaptioning.ClosedCaptionProperties, and Win32SystemParametersInfoW(SPI_GETHIGHCONTRAST)/GetSysColor. Fallback default values follow the behaviour described in issue #6.AI assistance: Antigravity assisted with implementation, review fixes, and unit tests; all changes were reviewed and verified locally.
Checklist
<area>: <summary>; one topic; under 400 changed lines, or the reason is above