* Add keyboard tests for the pickers
* Make the keyboard work inside a picker popup
* Only tab through picker columns that are on screen
Use IsEffectivelyVisible cause a column can be IsVisible while off screen. We don't loop over things that the user cannot see.
* Open a picker popup without claiming the pointer moved focus
* Move the tests to proper place
* Pass the test cancellation token when running dispatcher jobs
* Test HitTestPoint IsInside on lines after the first
Add a test that hit-tests a point over the first character of each line
in a three-line TextLayout, once with hard line breaks and once with
wrapping. HitTestPoint incorrectly returns IsInside = false for a point
over a character on any line below the first. The CharacterHit is
correct.
* Fix HitTestPoint IsInside on lines after the first
Check IsInside against the point's offset from the top of the hit line
instead of from the top of the layout.
* Pass a line-relative point to GetHitTestResult
Translate the hit point into the hit line's coordinates in HitTestPoint
instead of passing the line's top to GetHitTestResult, so the helper
works in a single coordinate space. The check for a point below the
text becomes y > textLine.Height, which is equivalent because only the
last line can have a point below it.
* Test HitTestPoint IsInside on aligned lines
Add a test that hit-tests a point just inside the right edge of a
centered or right-aligned line, in both flow directions. HitTestPoint
incorrectly returns IsInside = false because it ignores the line's
horizontal offset.
* Fix HitTestPoint IsInside on aligned lines
Also translate the hit point horizontally by the line's Start, so the
point passed to GetHitTestResult is relative to the line's top-left
corner as documented.
* Test HitTestPoint outside aligned lines and aligned/left parity
- Points left of, right of, above and below an aligned line must not report IsInside, guarding against the line-relative translation over-correcting.
- An aligned layout hit at Start + dx must give the same CharacterHit, TextPosition, IsInside and IsTrailing as a left-aligned layout hit at dx, which covers the newline trimming that now sees line-relative x.
---------
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
A position translated on ConfigureNotify can be stale if the window manager
was reparenting the window at the time. Openbox sends no later ConfigureNotify
for an undecorated window, so Window.Position stayed (0, 0) for good.
Translate the position again on MapNotify and ReparentNotify, once the pending
events have been handled.
Fixes#22536.
Claude-Session: https://claude.ai/code/session_01Wpudn6Kgv3BNNzdorhxQvo
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Add failing test for hit testing a line that ends in RTL text before a paragraph end
A TextEndOfParagraph run must not change bounds, run indices or caret distances
of the text before it. Lines whose last text run is right-to-left and sits
visually next to the paragraph end report shifted bounds today.
* Derive a text line run's direction from its reordered bidi level
TextLineImpl gave runs without glyphs whatever direction the caller asked about,
while BidiReorderer places TextEndOfLine at level 0. When text ends in RTL, the
paragraph end sits visually after the trailing RTL run, so it was pulled into
that directional span. The right-to-left walk consumes the span visually from
the right, so it consumed the paragraph end first and every glyph after it was
measured one character off: empty bounds for the first RTL character and a
full-range query one character short. Only text sources that end with
TextEndOfParagraph (TextBlock, SelectableTextBlock) are affected.
- Store the level each run was reordered with on IndexedTextRun.
- GetTextBounds and GetDistanceFromCharacterHit read direction from that level;
the duplicated content-based direction helper is gone.
- A range that includes the paragraph end of an LTR paragraph ending in RTL
text now reports the paragraph end as its own empty LTR bounds at the line
end instead of merging it into the RTL span.
* Add failing test for the paragraph end position in right-to-left paragraphs
The paragraph end belongs at the logical end of the paragraph: the right edge
of a left-to-right line and the left edge of a right-to-left line. Caret
distance and bounds put it at the right edge in both directions today.
- A wrapped TextLayout must get the same lines with and without a
TextEndOfParagraph, so moving the paragraph end cannot bring back the
extra line RTL wrapped text used to measure.
* Give the paragraph end the paragraph embedding level
BidiReorderer forced TextEndOfLine to level 0 so it would always be the last
visual run. That hid TextLineImpl reading the visual run array as if its last
run were the logical end of the line: in a right-to-left paragraph the end
run is visually first, FinalizeLine missed the line break and wrapped text
measured an extra line. Level 0 broke the Unicode bidi rule that a paragraph
separator takes the paragraph level, and put the paragraph end of a
right-to-left line at its right edge, where the line starts.
- TextEndOfLine takes the paragraph level again.
- FinalizeLine and GetCharacterHitFromDistance find the end run through the
logical run order, wherever it sits visually.
- Caret distance and bounds at the paragraph end of a right-to-left line now
land on the left edge.
* Add tests for indexer bindings notified with Item[] or Item[key]
Indexer bindings only refresh when the source raises "Item", so they miss
"Item[]" from ObservableCollection and "Item[key]" from AvaloniaDictionary.
Also checks that an indexer binding on an ObservableCollection publishes once
per change.
* Refresh indexer bindings on Item[] and Item[key] notifications
Treat "Item", "Item[]" and "Item[key]" as an indexer change in the reflection
indexer node and in both compiled property accessors. Compiled bindings to an
AvaloniaDictionary entry now update when the entry changes.
Accessors that already listen to CollectionChanged ignore these names, since
CollectionChanged says exactly which indexes changed and ObservableCollection
raises "Item[]" for every change.
Fixes#20313
* Require closing bracket in an Item[...] name
* Use MicroCom smart pointer wrappers in Avalonia.Native
Switch the native backend to the CppSmartPointerWrappers mode of
MicroCom 0.11.7. Implementations override ComPtr-shaped methods, and the
generated thunks open an autorelease pool and keep `this` and all
interface arguments alive for every COM call, replacing START_COM_CALL
and START_COM_ARP_CALL.
- ComPtr has no raw pointer conversions or constructors; comnew and
comself(this) are the ways in, getRetainedReference the way out
- ComPtr::dynamicCast goes through a private IID, so it is safe on
objects implemented in C#
- implementation classes derive only from MicroComImpl<I>
- factories, string helpers and Obj-C methods take and return ComPtr
Fixes found along the way: wrong IID for PlatformBehaviorInhibition,
missing AddRef in GetInputMethod, leaks in cursors, the input method and
automation peers, manual delete of a shared automation node,
over-release of C#-owned IAvnString arguments, null dereferences on
failed menu casts, and missing teardown of the display reconfiguration
callback and the render timer display link.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Use atomic reference counting in Avalonia.Native ComObject
C# releases native objects from other threads, for example the GC
finalizer and the render thread. The reference counter is now atomic.
ComObjectWeakPtr::tryGet() is safe against a concurrent last Release:
the weak token holds a mutex and a target pointer. The object clears
the target under the mutex before it is deleted. tryGet() increments
the counter only from a non-zero value, so it never resurrects an
object in destruction. The token is created with std::call_once.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Keep the macOS app delegate alive and do not release .NET callbacks at exit
NSApplication.delegate is weak. The delegate stayed alive only through an
autoreleased reference that leaked into a pool that never drained. The
generated COM call thunks drain an autorelease pool, so the delegate was
deallocated right after setDelegate:. App delegate callbacks did not run,
and ReleaseAvnAppEvents() did not release the C# events object.
The global ComPtr then released it from exit(), after .NET shut down.
With a managed debugger attached, the app hung on close.
Keep a strong static reference to the delegate. Hold the process-wide C#
callbacks in ComStaticPtr, so that exit() never calls into .NET.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Remove SkiaSharp.props/HarfBuzzSharp.props - instead reference packages directly, with centralized versioning
* Switch to .NET 11 SDK
* Add net11.0-browser target to the Avalonia.Browser
* Remove manual skiasharp NativeFileReference from Avalonia.Browser - since 3.x it's included with the SkiaSharp itself
* Remove dotnet/runtime#109289 workaround
* Fix DetectThreadSupport on .NET 11 WASM
* ControlCatalog: Allow to set `PreferManagedThreadDispatcher` via browser URL arguments
* ControlCatalog: fix value.Normalize crashing on browser
* Fix global.json version syntax. CI task doesn't support * globs.
* Is includePreviewVersions: true necessary in UseDotNet@2 task?
* Use SDK 11.0.100-rc.1
* Disable roll forward?
* Full SDK version
* Install .NET 10 runtime alognside the .NET 11 SDK
* Fix windowsdesktop not being installed on CI
* Try without DOTNET_CLI_ENABLEAOT
* Try to remove .NET 8 runtime and see what fails
* Add AvsSkipBuildingNextTargetFrameworks, to allow disabling .NET 11 TFMs
* Try to cleanup disk space on linux job
* Fix space cleanup script
* Try to skip Nuke bootstrap, as it seems to be confusing new AOT CLI
* More of DOTNET_CLI_ENABLEAOT=false
* Remove DOTNET_CLI_ENABLEAOT=false hack, downgrade to .NET 10 for integration tests on macOS
* Update browser launch config
* Log PreferManagedThreadDispatcher when starting browser ControlCatalog
* Bump to rc2
* Remove dotnet-version: 8.0, as it shouldn't be needed anymore
* Remove ImageSharp added in a merge conflict
* Ignore global.json altogether on integration tests CI
* Missing --test-runner override
* Remove unnoticed SkiaSharp.props reference
* Update outdated build packages readme
* Fix Avalonia.Native.macOS.proj typo
* Temporary disable UseOptimizedPublish globally
* Missing UseOptimizedPublish in a nested directory.build.props
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
UIKit doesn't report the end of the touches in progress when the view leaves
its window, for example when switching tabs with a finger held down. Their
pointers stayed in the touch device, captured to the control under the finger,
and every later touch on that view counted as a second finger, which broke
double taps. Raise a touch cancel for them, or a leave window for a pen or
trackpad pointer, like the Windows backends do.
Touches that end are now forgotten before their event is raised, so a handler
that removes the view doesn't cancel them a second time. Once a handler
cancelled them, the other touches of the same event are no longer raised.
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
Reset() made the AvaloniaView first responder before SetClient handed it to the next text box. AvaloniaView is not a text input, so UIKit dismissed the keyboard and presented it again on every focus change between text boxes.
Reset() is now a no-op, as on Android. The input method manager always calls SetClient right after it, which makes the next text box's responder first responder directly. When focus leaves text input, SetClient(null) still dismisses the keyboard.
Adds LoggingExtensions.LogToTraceAreaVerbosity and LogToTrace/LogToDelegate overloads that take it, so each log area can have its own minimum level.
Fixes#21810
* Rotate render target output in the compositor
Expose the required surface orientation through render target properties and rotate retained-layer copies and overlays. Replace the DRM rotation framebuffer and shaders with the shared EGL render target.
Validate quarter-turn output, orientation changes and rotated overlays with Mesa render tests.
* Rename RequiredRotationForOrientation
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Add failing tests for dispatcher timers on the wrong clock
* Align Dispatcher to the platform clock with an offset
`Dispatcher` stamped due times with a clock fixed in its constructor, but
the platform layer reads them against its own. When the platform layer
is installed after construction, such as in `InitializeUIThreadDispatcher`,
those clocks differ and timers fire early or late.
`Now` follows the current platform clock, with an offset that keeps it
continuous across the swap. Due times are converted back to the
platform's clock when handed over.
* Add failing test for Popup.InheritsTransform Y scale
* Fix Popup.InheritsTransform using the X scale for the Y axis
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Browser: fix storage stream writes, seeking and reads
- StreamHelper.write fallback wrote the marshalled ArraySegment instead of the
copied buffer, breaking every save stream when the heap is a SharedArrayBuffer
(WasmEnableThreads). The fast path kept a raw heap view alive across an await,
which could be detached by memory growth. Always slice synchronously and
dispose the view.
- WriteableStream: Position setter seeked to the old position, Seek never
updated _position, and writes past the end never grew Length.
- WriteableStream.WriteAsync(ReadOnlyMemory) avoids ToArray for array-backed memory.
- BlobReadableStream.ReadAsync copies blob data directly into the managed
buffer in one interop call instead of slice -> JS array -> byte[] -> buffer.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Blob stream seek is now actually implemented
* OpenWriteAsync opens with "keepExistingData: false", so it's initial length is 0
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Browser: JS-wakeable managed dispatcher for multithreaded WASM
ManagedDispatcherImpl gets a pluggable IWakeupEvent plus BeforeWait/AfterWakeup hooks. The browser MT build backs it with an int32 in linear memory (native/avalonia_browser_dispatcher.c, atomic.wait32/notify) so JS on the main thread can wake the dispatcher thread via MultiThreadedDispatcherHelper.signal without entering managed code.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Update browser launch config
* RawEventGrouper: add DrainAll and keep platform points when merging moves
- Add HasJobs and DrainAll to AutomaticRawEventGrouperDispatchQueue for
inline, synchronous dispatch.
- Dequeue under the lock in DispatchFromQueue; only re-post when jobs remain.
- When merging move events, keep intermediate points the platform already
attached to the merged-in event, and take the newest point with all of
its properties.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Browser: pass input through a queue in WASM memory
Pointer, wheel and key events are encoded by JS into a queue in WASM linear
memory and decoded by C# in one batch per burst, instead of one interop call
per DOM event.
- The queue is a chain of segments. C# allocates the first one and the
control block; JS appends records to the last segment and allocates a new
one with Module._malloc when a record doesn't fit. C# follows the links and
frees segments it has read past. _malloc is added to EmccExportedFunction.
- JS sets wakeRequested in the control block after publishing a tail and
signals the dispatcher if it was clear; C# clears it before reading the
tail, so a record published after the consumer's last read always wakes it.
- Decoded events go through the per-top-level RawEventGrouper on both
runtimes. Pointer moves carry getCoalescedEvents points as intermediate
points, replacing the getCoalescedEvents interop call.
- Single-threaded: JS posts the dispatcher signal, and OnSignaled drains the
queue before running jobs, so a burst costs one macrotask and one managed
entry. Key events and pointer presses are flushed synchronously: the handled
state is known before preventDefault, and actions that need a user gesture
(focusing the text input for the iOS on-screen keyboard) run inside the DOM
handler.
- Multithreaded: JS wakes the dispatcher thread directly through
MultiThreadedDispatcherHelper.signal. BrowserQueueDispatcherInputProvider
drains the queue on every pending-input query, which replaces the
BrowserMultiThreadedDispatcherHooks.
- Composition and drag events bypass the queue and flush it first to keep
ordering.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Browser: use the DOM event clock for text input timestamps
Queued pointer, wheel and key events carry the DOM event.timeStamp, but text
input from composition end used a per-top-level Stopwatch. Pass the
compositionend timeStamp through instead, so all input shares one clock.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Browser: convert line and page wheel deltas to pixels
Wheel deltas were passed through as-is and scaled as pixels, so line-mode
wheels barely scrolled. JS now converts line and page deltas to pixels before
queuing, reading the deltas before deltaMode so Firefox keeps reporting pixels
where it can.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Browser: compute MT dispatcher wait timeout from ticks
Convert the timeout with integer ticks instead of a double round-trip, and
treat timeouts too long to express in nanoseconds as an infinite wait.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Browser: generate the input queue layout for JS from C# structs
The queue layout was written twice, as offset constants in BrowserInputQueue.cs
and inputQueue.ts, kept in sync by hand and an ABI version.
- BrowserInputLayout holds the control block, segment header and record
layouts as sequential structs and the enums they use; C# reads records
through them.
- The new Avalonia.Browser.BuildTasks project links BrowserInputLayout.cs and
its GenerateInputLayoutTask writes inputLayout.g.ts before the web app
build: a const enum per struct with field offsets and $size, and a const
enum per enum. It fails the build on implicit padding, so the generated
offsets match the struct layout on any runtime.
- JS writes records through typed-array views over the heap instead of a
DataView.
- JS copies DOM event fields as they are. Mapping buttons and modifier keys,
and converting line and page wheel deltas to pixels, moves to C#, including
for drag events.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Browser: suppress default actions only for input Avalonia handled
Keys and mouse/pen presses are dispatched inside their DOM handler on the
single-threaded runtime, so the handled state is known before the browser
applies the default action. Use it: unhandled keys (browser shortcuts, page
scroll keys) and unhandled mouse/pen presses now reach the browser.
FlushSync reports the handled state of the record just posted rather than
the last event dispatched, which differ when the record produced no event.
Presses are still suppressed while the hidden text input has focus, so the
compatibility mousedown can't take focus away from it, and for touch, which
doesn't report a handled state. Moves and wheel are not flushed and stay
suppressed, as does everything on the multithreaded runtime, where the
handled state isn't known in time.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Disable dispatcher warnings where it's expected to block the thread
* New dispatcher hooks should be internal, only used in tests
* Use >>> in TypeScript input queue code to be safe
* Ensure Pack=1 on browser queue interop structures
* Validate browser input record sizes before decoding
Check that each record is large enough for its type, and that coalesced
points and key/code strings fit within the record before reading them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Remove "Count: > 0" check for IntermediatePoints, so we still dispose the pooled list
* Use Dispatcher.UIThread.Post for MT direct input events
* Remove new unused code
* DrainAll method was actually used, IDE fooled me
---------
Co-authored-by: Nikita Tsukanov <keks9n@gmail.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
shcore!GetDpiForMonitor returns a 32-bit HRESULT, but the P/Invoke was
declared as returning long. On 32-bit (win-x86) processes a 64-bit return
is marshalled from EDX:EAX; shcore only writes EAX, so the upper half holds
whatever was left in EDX. WindowImpl applies the DPI only when the result
== 0, so the window frequently stayed at RenderScaling 1.0 on >100 %
displays while Screens (which ignores the return value) reported the right
scaling. Reproduces 100 % under Windows 11 on ARM x86 emulation.
Fixes#22418
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Keep an iOS main thread display link alive while touches are down
UIKit delivers touches at the rate the main thread is animating at, and the
render timer's display link runs on a background thread, so drags updated at
60 Hz even with a 120 Hz render timer. When the display can go above 60 Hz,
keep one process-wide main thread display link with the same frame rate
range while any view has touches down, and stop it when the last touch ends.
A view forgets its touches in progress when it leaves its window or is
disposed, since UIKit doesn't report their end then, for example when
switching tabs with a finger held down.
* Run iOS trackpad scroll momentum at the display rate with time-based decay
The momentum link decayed the velocity per callback, assuming 60 callbacks
per second, so momentum would end twice as fast at 120 Hz. Give it the
display's frame rate range and decay the velocity by elapsed time, capped at
4 frames after a stall. Behaviour at 60 Hz is unchanged.
* Use the view's screen instead of UIScreen.MainScreen on iOS
UIScreen.MainScreen is deprecated and may not be the screen the app is on
when it runs on an external display. The touch display link now checks the
touched view's screen, and the 60 Hz warning checks the screen of the window
a view moves to. Also shortens the momentum comments.
* add tabbed page test to check against changing page while focus is owned by content
* tabbed page - do not change page on keyboard nav if focus is owned by content.
* add some details.
* fix typo
* handle tab navigation
- Send one remove per child that leaves, with its old index, before detaching it.
- Send one add per child that arrives, with its new index.
- Stop sending an add that names the parent as its own child.
- Send nothing for nodes whose children no client has read.
- Add unit tests for the child list comparison.
Fixes#22397
Co-authored-by: Renaud Lepage <387759+cybik@users.noreply.github.com>
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* fix: Support StylableElement for styles inside ContainerQueries
* chore: Add container query sample for TableView columns
Demonstrates a container query that targets a non-visual StyledElement, as requested in the PR review. The option row wraps so that it does not clip while the page is narrowed.
* Expose TextPresenter.CursorRectangle as a public property.
API review for #18325 preferred a readonly CursorRectangle property over
making GetCursorRectangle public. Keep the internal helper as a thin wrapper
and add a unit test covering caret position.
Co-authored-by: Cursor <cursoragent@cursor.com>
* refactor: use CursorRectangle internally
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
Mesa before 24.1 merges the alpha configs of the 32-bit visual into the ones of the 24-bit default visual, so EGL_NATIVE_VISUAL_ID never points at a 32-bit visual and EGL windows can't be transparent.
Claude-Session: https://claude.ai/code/session_018hqMwAPQ1DfZNny7Fo1QB9
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
* test(rendering): cover visuals removed while rendering is stopped
A stopped CompositingRenderer skips its update pass, so nothing drains the
pending visuals. A visual that leaves the tree in that state must not stay
referenced by the renderer. Visuals that remain in the tree must stay queued
until rendering resumes.
The test fails: the renderer still references the removed visuals.
HasPendingUpdateForUnitTests exposes the pending state so that the test does
not depend on garbage collection.
* fix(rendering): release detached visuals from a stopped renderer
A minimized or hidden window stops its renderer. A stopped CompositingRenderer
skips its update pass, and that pass is the only place that clears the dirty
and recalculate-children sets. Each visual that detached in that state stayed
in the sets, so a window that kept changing its content while minimized
retained every removed visual until rendering resumed.
A visual reports itself dirty one last time when it detaches, after it has
dropped its composition visual. The update pass ignores such an entry. Remove
the visual from both sets at that point instead of adding it, and still request
a composition update so that the detach is committed.
Visuals that remain in the tree stay queued, so a restart still resumes the
pending update.
* chore: trim code comments