nvda
acb904f8 - Fix Win32 menu item location and label under 64-bit NVDA at display scaling above 100% (#20698)

Commit
93 days ago
Fix Win32 menu item location and label under 64-bit NVDA at display scaling above 100% (#20698) Closes #19225 Closes #20158 ### Summary of the issue: 64-bit NVDA reports a wrong location and a wrong, mostly empty, label for Win32 menu items of 32-bit applications that expose no accessible name, whenever display scaling is above 100%. 32-bit NVDA 2025.3 handled the same menus correctly. The reported examples are StationPlaylist Studio, DVBViewer and Balabolka (#19716), all Delphi style applications with owner drawn menus. #20158 reports the same symptom and regression window for Dev C++. This was verified directly: the unfixed 64-bit beta reproduces the nameless menu items in Dev C++ 5.11 at 125% scaling, and this fix resolves them. The root cause is an inconsistency in the Windows OLEACC menu proxy, not in NVDA. The proxy reports menu locations in the 96 DPI based coordinate space of the menu's window when the querying process and the application differ in bitness, and physical screen coordinates when they match. The window's own DPI awareness plays no role. This was isolated outside of NVDA: two plain Python processes, one 32-bit and one 64-bit, both Per Monitor V2 aware, query the same open menu at the same moment and receive coordinates in different spaces. It was measured on a DPI unaware 32-bit application, on the DPI aware 32-bit DVBViewer and on a DPI aware 64-bit application, where the roles are reversed and the 32-bit client is the one receiving the 96 DPI based space. NVDA expects physical coordinates everywhere, so under 64-bit NVDA the location is wrong for every consumer of a 32-bit application's menu, including the display model text lookup that produces the spoken label. The empty label has a second contributing factor. `windowUtils.physicalToLogicalPoint` silently ignores the BOOL result of `PhysicalToLogicalPointForPerMonitorDPI`, and that function fails for any point outside the physical window rectangle. Fed with virtualized input, some corners of the queried rectangle convert and some stay unchanged. For one of the measured menu items this produced an inside out rectangle whose bottom lay above its top, which intersects no display model chunk and yields an empty label. ### Description of user facing changes: Menu items of 32-bit applications without accessible names are announced correctly again under 64-bit NVDA at display scaling above 100%. Since the object location itself is fixed, everything that consumes it benefits as well, including focus highlighting, screen review and mouse interaction on such menus. ### Description of developer facing changes: * New `winBindings.user32` bindings: `SetThreadDpiAwarenessContext`, `GetWindowDpiAwarenessContext`, `GetMenu`, `GetMenuItemRect` and `GetMenuItemCount`. * New in `windowUtils`: the context manager `threadDpiAwarenessContextOfWindow`, the helpers `getPhysicalWindowRect`, `getWindowRectInWindowDpiContext` and `getWindowRectInUnawareDpiContext`, and the constant `DPI_AWARENESS_CONTEXT_UNAWARE`. * New private helper `locationHelper._remapRectByAnchors` for mapping a rectangle between two coordinate spaces via the same reference rectangle in both spaces. ### Description of development approach: The fix normalizes the location at its source, in an override of `MenuItem._get_location`, instead of patching the display model consumer. The location itself is the wrong value, so fixing it once repairs all consumers. Detection is deliberately based on live state rather than on bitness or Windows version checks: 1. The window rectangle is read twice, once normally, which yields physical coordinates, and once under a DPI unaware thread context, which yields the 96 DPI based view. This works for DPI aware and unaware windows alike. If both readings are equal, for example at 100% scaling, the code does nothing. 2. The raw Win32 menu item rectangles are read via `GetMenuItemRect` in the window's own DPI context and expressed in both candidate spaces using the window rectangles as anchors. The MSAA location is compared against them, with a 1 px tolerance for independent edge rounding. For an OLEACC proxy item, the child ID addresses its rectangle directly. For a menu item that the application exposes through its own `IAccessible` implementation with child ID 0, as Delphi applications do, every item of the menu is a match candidate. A location matching a physical rectangle is already correct and passes through unchanged, so if Windows changes the OLEACC behavior in the future, the workaround disarms itself. A location matching a 96 DPI rectangle is mapped to physical coordinates. Anything else stays untouched and logs a debug warning. 3. The mapping is done by hand with the window rectangles as anchors because `PhysicalToLogicalPointForPerMonitorDPI` and its inverse reject points outside the physical window rectangle, which the involved points regularly are, and the existing wrapper swallows that failure silently. The menu handle of a popup window is obtained via `MN_GETHMENU` with `SendMessageTimeout` and is cached per window handle, with stale handle recovery, so repeated location fetches do not repeat the cross process message. All fallback paths log a debug warning and return the unchanged location, so future reports on this issue stay diagnosable from a debug log. The OLEACC inconsistency was verified with standalone Python probes under both bitnesses and confirmed in NVDA itself by comparing 32-bit NVDA 2025.3.3 with 64-bit master on the same machine, the same application and the same menu geometry. Every measured conversion data point follows the documented failure rule of the point conversion APIs. This PR was developed with AI assistance (Claude Code) with human review and manual testing. ### Testing strategy: Manual testing against three applications at 125% display scaling, each compared by ear and by diagnostic log dumps of the involved rectangles, plus a fourth application as a negative control: 1. A minimal 32-bit DPI unaware Lazarus reproduction application with an owner drawn main menu whose items have empty captions, matching the pattern of the reported applications. It can be shared on request. Unfixed 64-bit master announces one of its three items without a name, 32-bit NVDA 2025.3.3 announces all of them and provides the physical reference values. With the fix, all items are announced correctly at 125% and at 150% scaling and the logged locations match the 32-bit reference within 1 px. 2. Dev C++ 5.11 from #20158, DPI unaware. On the unfixed 64-bit beta, several items in the File and New submenus are announced only as "menu item". With the fix, every item is announced with its name. 3. DVBViewer, which is DPI aware and whose broken menus, reported by several users on the German NVDA mailing list, triggered this analysis. It exposes context menu items both through the OLEACC proxy and through its own `IAccessible` implementation with child ID 0, and none of them have accessible names. Unfixed, they are announced without names or with text from neighboring screen regions. With the fix, every item is announced with its name via the display model. 4. Sao Mai Braille 25.5.5, a 64-bit DPI aware application, as a negative control. Standalone probes show that a 64-bit client already receives physical menu locations here, so the detection matches the physical rectangle and leaves the location untouched. Its menus are announced correctly on the unfixed release, which matches that measurement. The same window queried from a 32-bit client returns the 96 DPI based space, which is where the reversed case above was measured. Six new unit tests cover the rectangle remapping, using the measured 125% and 150% rectangles as fixtures, plus negative coordinates, the round half up tie and the zero area guard. No system test was added, because display scaling cannot be changed in the CI environment. ### Known issues with pull request: * The PR is close to the 500 line guideline, largely due to tests and documentation. If you would prefer a split, for example bindings and helpers first with the fix stacked on top, happy to do that. * The behavior of the OLEACC menu proxy on ARM64 clients is unmeasured. The detection is state based, so a differing behavior degrades to the unchanged location rather than a wrong one. * Whether MSAA mouse hit testing with physical coordinates hits virtualized menu proxies is an open question and needs a separate hands on test. * The underlying OLEACC inconsistency is a Windows issue and may be worth reporting to Microsoft. This fix stays correct either way. * The silent failure mode of `windowUtils.physicalToLogicalPoint` is untouched and worth a separate hardening issue.
Parents
Loading