Skip to content

hle: read Windows caption and high contrast settings - #23

Merged
simnJS merged 2 commits into
MiamiGame:mainfrom
AliceWood:hle/accessibility-settings
Nov 24, 2026
Merged

simnJS merged 2 commits into
MiamiGame:mainfrom
AliceWood:hle/accessibility-settings

Conversation

@AliceWood

@AliceWood AliceWood commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Fixes #6. No PR dependencies.

Titles can read the player's Windows closed-caption appearance and high-contrast mode. Each query refreshes its Windows settings at most once per second. Captions initially follow ShowSounds. A title can change its own enabled flag immediately for the session. When Windows supplies no preference, XTP returns disabled captions with opaque white text on black, a transparent window, default font and edge, and 100% size.

Area

xtp-hle implements the three accessibility provider methods and enables two features of the existing Windows bindings. The README documents where to find ShowSounds and how high-contrast mode is reported. The HLE plan marks R7 complete.

Tests

  • cargo xtask pr-check passes on my machine
  • New or changed behaviour has tests that need no game files, or I explain below why it cannot
  • Ran on the title: no.

A synthetic caller invoked the same three provider slots on the unmodified upstream base 0f08e4c and PR head bd8e20a in an offline Windows Sandbox. Both builds used Rust 1.98.1 MSVC, debug, and WARP. The runner verified the guest's ShowSounds setting before starting each probe.

Observation Upstream This PR
Get caption properties with ShowSounds off, then on Returned E_NOTIMPL and left the output untouched Wrote all 28 bytes and returned enabled values 0, then 1
Set enabled to 0, 2, 0, 255, 1, 0 and read immediately after each call All calls returned E_NOTIMPL All succeeded and read back 0, 1, 0, 1, 1, 0 with ShowSounds both off and on
Query high contrast with the guest's contrast theme off Returned E_NOTIMPL and left the output untouched Returned success and mode off

cargo test --locked -p xtp-hle --lib modules::speech:: passed all six tests. They cover the entire default output, enabled overrides including 2 and 255, null arguments, cache reuse and expiry, independent colors and opacity, font scaling and light/dark palette classification. A second probe kept one process alive and changed Windows ShowSounds from off to on to off. The getter read back 0, 1, 0 after 1.1 seconds per change. Custom colors and active contrast themes were covered with synthetic values only.

The same synthetic caller timed repeated getter calls on the previous and revised PR heads in the same guest, with high contrast off. Each value is the median of five batch averages in nanoseconds per call, after one warm-up call and with 250 calls per batch. These measurements cover the cached path on the revised head.

Getter Before cache (985bca7) With cache (bd8e20a)
Caption properties 87,754 ns 84 ns
High contrast 3,240 ns 58 ns

cargo xtask pr-check --base origin/main passed formatting, both Clippy configurations, policy and conventions. Its workspace test stopped at the same seven GPU test names as cargo test --workspace --locked on the unmodified base. A separate cargo test --locked -p xtp-hle --lib on both revisions reproduced the same single failure, modules::xmem::tests::title_calls_succeed_under_open_heaps. The PR's HLE run passed 156 tests and ignored two.

Provenance

  • I wrote all of this change myself for XTP, or it only moves code already in XTP.
  • Some of it comes from elsewhere. Each source, its licence and the files concerned are listed here, and every licence is compatible with GPL-3.0-or-later:

AI assistance: OpenAI Codex wrote and reviewed the implementation, tests and documentation, ran the comparison and prepared this PR. Direct references included XTP's provider and contribution docs, its R7 plan, the windows-rs API bindings, and Microsoft's public API pages for Windows captions, ShowSounds, the caption properties and enum values. Codex inspected xcl's public accessibility reference for caller-visible defaults, byte layout and error behavior. The implementation and tests are original to XTP. The issue and R7 also summarize xcl's behavior second-hand. xcl reference revision · Windows caption settings · Windows ShowSounds

AliceWood personally reviewed 985bca7. Codex implemented and tested the subsequent review fixes in bd8e20a.

Checklist

  • No game data, keys, console SDK code or headers, and nothing that circumvents DRM (asset policy)
  • No code copied from xcl or AnyPS5 (references only: read them to understand, write your own)
  • I agree to license this contribution under GPL-3.0-or-later
  • Title and every commit follow <area>: <summary>; one topic; under 400 changed lines, or the reason is above
  • Docs updated where behaviour, commands or variables changed (README, docs/)

@github-actions github-actions Bot added area/hle touches crates/xtp-hle area/docs docs/, Markdown size/M 100 to 399 changed lines overlap another open PR changes the same files labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

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.

Pull request Files changed by both
#20 README.md
#22 README.md, crates/xtp-hle/Cargo.toml, crates/xtp-hle/src/modules/speech.rs
#24 README.md
#26 README.md

This comment is kept up to date automatically and removed when the overlap ends.

@AliceWood

Copy link
Copy Markdown
Contributor Author

This PR and #22 both implement the three accessibility methods in #6. I claimed the issue before #22 opened, and the two implementations were developed independently. For maintainers comparing them, #23 reads caption appearance through WinRT ClosedCaptionProperties and uses the live Windows ShowSounds setting until a title sets its own caption flag. #22 describes reading caption appearance from the Windows registry.

The test table above includes a synthetic caller reading caption state with ShowSounds off and on, then setting and reading the title override. Both PRs cover the same feature. Please let us know which one you’d like to carry forward.

@simnJS simnJS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a clean implementation of #6, and it avoids the problems found in #22:

  • the documented ClosedCaptionProperties API instead of registry guesses;
  • an original high-contrast classifier;
  • the C++ bool taken as u8 != 0.

I checked slots 0x18/0x20/0x28, the 28-byte layout (ARGB in memory order) and the style/edge/opacity/size mapping against the public GDK pages and the windows 0.62.2 bindings: they all match. The COM handling is sound too. windows-rs joins the implicit MTA only when the thread is uninitialised, and never changes an existing STA/MTA.

A few small things before I approve:

  1. Cost per call. properties() makes 12 WinRT static calls on every call, and high_contrast() creates AccessibilitySettings (and UISettings when contrast is on) every time. If the class can't be activated, windows-rs retries the factory load and DLL search on each of those calls. Could you either post a per-call timing from your Sandbox run, or cache the snapshot and refresh it at most every second or so (as gameinput/triggers.rs does with RELIST)?
  2. Module doc. speech/captions.rs needs a //! header like every other file in xtp-hle/src.
  3. Sentinel test. Please add a case that set_enabled(2) (and e.g. 0xFF) reads back 1. 2 is your FOLLOW_WINDOWS sentinel, so that's the value worth pinning.
  4. Nits. Please keep the module pointers in the Cargo.toml comment (add modules::speech::captions rather than dropping gameinput::triggers and audio::capture), and rewrap the first doc line of speech.rs. The vtable re-alignment is fine if you prefer it, but please keep the "closed captions" and "high contrast" labels on 0x18 and 0x28.
  5. Optional.
    • A host run with a custom caption style (e.g. yellow on blue) and with the Aquatic and Desert contrast themes would cover the WinRT paths the unit tests can't.
    • A README line saying where ShowSounds lives (Control Panel > Ease of Access > "Use text or visual alternatives for sounds") would help, since Windows 11 Settings doesn't name it.
    • Returning Other only when the palette can't be read is fine; a sentence saying so would help.
    • The R7 row in docs/analysis/hle.md can be marked done.

CI is green. Once these are in, I'll approve and merge. You claimed #6 first, so this PR goes ahead, and #22 will be closed once this lands.

@AliceWood

Copy link
Copy Markdown
Contributor Author

@simnJS, could you review bd8e20a? Caption properties and high-contrast mode now each refresh from Windows at most once per second. A title's enabled override takes effect on the next call, even within that second.

In the same offline Windows Sandbox, warm caption reads went from 87,754 to 84 ns per call and high-contrast reads went from 3,240 to 58 ns. These are medians of five 250-call batches in a debug build with high contrast off. A single running process also picked up ShowSounds changing from off to on to off after each refresh interval.

All six speech-module tests passed. The provider test covers set_enabled(2) and set_enabled(0xFF), and a synthetic caller verified both read back 1 with ShowSounds on and off. The new cache test covers reuse and expiry. I restored the module pointers and vtable labels, added the module header, documented ShowSounds and the Other fallback, and marked R7 complete. Active contrast palettes and custom caption colors have synthetic coverage. The full sandbox results and baseline failures are in the PR description.

@AliceWood
AliceWood requested a review from simnJS November 24, 2026 19:28
@simnJS

simnJS commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks, bd8e20a covers everything I asked for:

  • the 1 s cache, with timings;
  • the module header;
  • the 2/0xFF sentinel test;
  • the Cargo.toml pointers, the rewrap and the slot labels.

I checked the cache: the two statics are independent, the lock is never nested and never calls back into the title, Instant is monotonic, and the override is applied after the cache, so set_enabled shows up on the next call.

One thing before I merge: the description says Codex made this commit. Could you confirm here that you've read it yourself and take responsibility for it, as you did for the first one?

Optional, not blocking:

  • README: on that Control Panel page, ShowSounds is the "Turn on text captions for spoken dialog (when available)" checkbox. Naming it would stop people ticking Sound Sentry instead. Saying where the caption style is set (Settings > Accessibility > Captions) would help too.
  • docs/analysis/hle.md line 38 still lists speech at 151 lines and 1 test.
  • The Aquatic (#202020) and Desert (#FFFAEF) window colours would make good cases for the light/dark test.

CI ran just before #20 and #24 landed. Neither touches these files, and the README merges cleanly, so I'll approve and merge once you've confirmed.

@AliceWood

AliceWood commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

. Could you confirm here that you've read it yourself and take responsibility for it, as you did for the first one?

Yea, i confirm,

@simnJS simnJS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @AliceWood for confirming. Approving and merging.

@simnJS
simnJS merged commit d18ad85 into MiamiGame:main Nov 24, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs docs/, Markdown area/hle touches crates/xtp-hle overlap another open PR changes the same files size/M 100 to 399 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closed captions and high contrast from the Windows settings

2 participants