Skip to content

Win32 UI provider - #25

Merged
bytetroll merged 7 commits into
masterfrom
win32-ui-provider
Nov 9, 2026
Merged

bytetroll merged 7 commits into
masterfrom
win32-ui-provider

Conversation

@bytetroll

Copy link
Copy Markdown
Contributor

No description provided.

bytetroll and others added 7 commits November 8, 2026 19:31
Desktop UI moves to one provider per platform: GTK stays the Linux
provider, Win32 becomes the Windows provider. The ui.v1 contract in
ui_runtime.hpp is unchanged, and ui_runtime_shared.hpp now carries its
toolkit-independent half -- handle allocation, UTF-8 validation, stored
limits, kind codes and the event/placement records -- moved verbatim out
of the GTK provider so a second backend reproduces those semantics and
error strings instead of restating them. CMake compiles exactly one
provider per platform.

Win32 supplies no box or grid container, so containers are child windows
of a private class and the provider owns the layout pass, measuring text
with the system message font. Events come from WM_COMMAND BN_CLICKED and
EN_CHANGE and from WM_CLOSE, which enqueues a close request without
destroying a live handle. activate uses BM_CLICK, the same path a user
click takes.

Unlike the dynamically loaded GTK provider, this one calls USER32 and
GDI32 directly, so every linked program imports them. user32.lib and
gdi32.lib therefore join ws2_32.lib in both nillinker argument lists,
both nilcompiler link invocations, the nilbuild toolchain-input seal that
forms the incremental build identity, and its test fixture. Without that
the AOT routes and both nilbuild contracts fail on unresolved externals.

nil.ui-windows-loader and its script tested NIL_UI_GTK_DIRECTORY and
libgtk-4-1.dll loading on Windows, which is no longer how Windows gets a
provider, so both are removed; docs/standard-library/ui.md no longer
instructs Windows users to deploy a GTK4 runtime.

The provider builds and links, and the suite passes, but its window
behavior is still undemonstrated: every path runs through initialize(),
which requires an interactive window station, so a headless session can
only reach the refusal path.

Verified at this commit. Linux: 572 registered, 0 failed, 3 environment
skips -- identical to before the change. Windows on the development VM:
573 registered, 568 passed, 4 environment skips, and the one pre-existing
nil.windows-sdk-preflight failure, which cannot run while the machine
PowerShell execution policy is Restricted. 569 tests are shared and all
pass on both hosts.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tests/ui_runtime_tests.cpp inspects loaded GTK modules, dlopen symbol
origins and GTK's internal top-level registry, so it describes the GTK
provider and cannot speak for Win32. The provider fixture now follows
the provider: Windows builds tests/ui_runtime_win32_tests.cpp and both
nil.ui-runtime and the display contract's --provider-test use whichever
fixture matches the platform.

The new fixture runs the published contract against a real desktop --
widget creation and kinds, UTF-8 text round-tripping, the provider's own
layout allocation, button and checkbox activation events, event
suppression for programmatic writes, keyboard focus, inherited
sensitivity, grid placement and overlap rejection, subtree destruction
and close invalidation -- and checks the documented rejection wording.
Without an interactive window station it instead requires that window
creation is refused, so a service session still exercises something.

That fixture immediately found a real defect. WM_COMMAND is delivered to
a control's immediate parent, which for anything inside a row, column or
grid is that container rather than the window, but only windows and
their root containers carried the context pointer in GWLP_USERDATA.
Every button, checkbox and entry notification raised inside a container
was therefore dropped, and no event ever reached poll. Containers now
carry the same pointer.

On a real desktop nil.ui-runtime passes with the Win32 provider, which
is the first demonstration that the provider works rather than merely
builds. nil.ui-display still fails at its lifecycle step: the fixture in
tests/ui_lifecycle_tests.cpp observes GTK's registry directly and
reports "GTK registry observer symbols unavailable", so it needs the
same per-platform treatment next. Headless behaviour is unchanged --
nil.ui-runtime passes through its no-desktop branch and nil.ui-display
still skips for want of a session.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Windows builds the Win32 provider, so ui_runtime.cpp is no longer
compiled there and its Windows half had become unreachable: the
NIL_UI_GTK_DIRECTORY selection, the DLL naming family and search-flag
handling, the already-loaded module matching, the interactive window
station probe and the Windows branches of the loader and of the display
error. Leaving them would invite maintenance of a path no build can
reach and no test can reject.

The one change that is not a deletion is the display error's
`#elif defined(__APPLE__)` becoming `#if`, now that no Windows branch
precedes it; the macOS and Linux messages are unchanged.

Linux is unaffected at 572 registered, 0 failed and 3 environment skips.
Windows cannot be affected, because this file is not part of its build.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
nil.ui-display now passes on Windows: the provider contract, the
lifecycle fixture, the Matrix desktop suite and the interaction suite
that drives real synthetic keyboard input all run against the Win32
provider on a real desktop.

Three things were missing.

The lifecycle fixture observed GTK's top-level registry directly and
failed with "GTK registry observer symbols unavailable". The observer's
purpose is platform-neutral -- prove a window was really released rather
than merely invalidated -- so only its mechanism moves: GTK is asked for
its registry, while Windows counts this process's live top-level windows
of the provider's own class. The fixture's assertions are unchanged, and
it still reports exactly the 235 checks the display contract requires,
so that constant did not have to become per-platform.

Tab order and the activations that go with it are the dialog manager's
work on Win32, where GTK does them inside the toolkit, so poll runs
messages through IsDialogMessageW and containers carry
WS_EX_CONTROLPARENT; without that, Tab cannot reach a control nested in
a row, column or grid.

The real defect was routing. Windows delivers keystrokes straight to the
focused control, so a top level only ever sees keys posted to it
deliberately -- which is exactly how the contract drives a window it has
not typed into, because GTK routes such input through the toplevel. The
pump now retargets that input to the focused control before the dialog
manager sees it. An earlier attempt to forward inside the window
procedure could not work, because IsDialogMessageW consumed the message
first; that code is removed rather than left to confuse.

Diagnosis came from a new --input-probe mode, which posts the contract's
own key sequence and reports which events arrive. It turned a 30-second
deadline into "direct_to_edit=1" with nothing arriving via the top
level, naming the fault immediately. That coverage now also runs inside
--display, quietly, so a regression reports which event went missing
instead of timing out.

Linux is unchanged at 572 registered, 0 failed and 3 environment skips.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
docs/platform-support.md still said the GTK provider supports Linux and
Windows, which stopped being true when Win32 became the Windows
provider. The notebook records what the interactive session proved, the
three defects it found that a headless suite could not reach, and the
Defender-induced sharing violation that can fail
nilbuild.incremental-contract once after a full rebuild without
reproducing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The macOS provider becomes AppKit, completing one provider per
platform. It implements the same ui.v1 contract as the GTK and Win32
providers and shares the toolkit-independent half through
ui_runtime_shared.hpp, so handles, limits, kind codes, event kinds and
error text are identical; only the toolkit differs. AppKit has no box
or grid container, so containers are plain flipped views and the
provider owns the layout pass, as it does on Win32.

AppKit replaces the GTK-on-macOS work because a GTK process never runs
-[NSApplication run], and AppKit answers accessibility requests from the
main run loop; such a process therefore has no accessibility hierarchy
at all, which is what the directed-input evidence showed when every
query returned kAXErrorCannotComplete.

Events come from target/action for buttons and switches, from
controlTextDidChange: for fields, and from windowShouldClose:, which
enqueues a close request and returns NO so AppKit cannot destroy a live
handle. poll drains pending events and gives the run loop one bounded
nonblocking turn, never waiting for input.

Linking follows the Windows precedent rather than rediscovering it:
because the provider calls Cocoa and CoreGraphics directly, both are
declared on the runtime targets, in nillinker's POSIX argument list and
in the compiler's own Darwin link command, so AOT-compiled programs
link against what nil.a now calls.

tests/ui_runtime_appkit_tests.mm is the Darwin counterpart of the Win32
fixture and runs the published contract against a real session; without
a window server it instead requires that window creation is refused.
A workflow_dispatch workflow builds just this provider with LLVM off, so
a macOS cycle costs minutes rather than a full source campaign -- which
matters because there is no Mac here and every iteration is a CI run.

Not yet verified: this is Objective-C++ that cannot be compiled on this
host, so the first CI run is its first compile. Linux is unchanged at
572 registered, 0 failed and 3 environment skips.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
With no Mac here, every compile is a CI run, so the provider was read
again before spending one.

Context::Impl is private to Context, so an Objective-C class outside
that scope cannot name it -- the same access wall the Win32 callbacks
hit. The delegate now carries a block built inside Impl, which closes
over a weak reference and takes the access with it, so the target never
names the private type.

AppKit has no -[NSControl sizeThatFits:]; that is UIKit. Natural sizes
come from NSView fittingSize.

Objective-C pointer downcasts are not C++ class casts, so the
static_casts from NSView * to the concrete control types become
ordinary Objective-C casts.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@bytetroll
bytetroll merged commit 070fdb2 into master Nov 9, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant