* Fix duplicate insertion of shared StyleInstance into the same ValueStore
StyleBase cached a single shared StyleInstance per ControlTheme and reused
it for every attach, regardless of the FrameType it was attached as and
regardless of whether it was already present in the target's ValueStore.
The same ControlTheme can legitimately be attached to one control twice
(once as its own Theme and once via the templated parent's theme), and on
re-attach / re-application of styling the cached shared instance was
inserted a second time into the same store, triggering
- Cache shared instances per FrameType (Theme / TemplatedParentTheme)
- Only reuse a shared instance if it is not already in the target store
* Cache shared style instances per FrameType; drop redundant ContainsFrame
Address review feedback on #22276:
- Replace the two shared-instance fields with a fixed-size array indexed
by FrameType, giving one cached instance per frame type (Style,
TemplatedParentTheme, Theme). InlineDictionary was considered but
requires a class type key, so an array indexed by the enum is the
equivalent zero-allocation structure.
- Remove the ContainsFrame linear scan: with one instance per frame type
a duplicate insert of the same instance into the same ValueStore is no
longer possible, because OnControlThemeChanged /
OnTemplatedParentControlThemeChanged always RemoveFrames(type) before
re-attaching. This is now proven by unit tests.
- Add unit tests:
- ControlTheme attached as both Theme and TemplatedParentTheme to the
same control creates two distinct instances.
- Re-attaching after RemoveFrames does not duplicate the instance.
- The same instance is shared between different controls for the same
frame type.
* Avoid per-style array allocation for the single shared instance case
Address review feedback: the vast majority of styles only ever have a
single shared instance, so keep a plain field + FrameType for that case
and only allocate the FrameType-indexed array lazily once a second frame
type is shared. This removes the extra array allocation added to every
style by the previous implementation.
* Address review nits: succinct comment, avoid eager GetSharedInstance call
- Shorten the shared-instance comment per the AI guidelines.
- Invert the condition so GetSharedInstance is only called when
canShareInstance is true.
* Comment shortened to two lines :)
* Add failing test for focus staying on a removed or hidden element
When a focus scope is removed or hidden while its focused element has the
focus and the root scope's focused element can't be focused (e.g. a button
disabled while its command waits for a choice in a flyout), the keyboard
focus stays on the removed or hidden element.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Clear focus when the focused element is removed or hidden and can't be restored
Focus(null) leaves the focus alone when the focused element is in another
focus scope than the focus root, but a removed or hidden element also passes
that check. Only apply it while the focused element is attached and visible.
Fixes#22342
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Add popup tests with actual focus services
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Add a failing test for re-attaching a cleared child visual
A control that sets a child visual on attach and clears it on detach cannot
attach the same visual again: the cleared child stays parented to the
element's discarded composition visual.
* Un-parent the previous child visual when replacing it
SetElementChildVisual left removing the old child to the renderer's next
sync of the element's children. That sync may never come: a control that
clears its child visual in OnDetachedFromVisualTree does so before
DetachFromCompositor discards the element's composition visual, so the old
child stays parented to it and attaching it anywhere later throws.
Remove the previous child from the element's composition visual directly.
* Rewrite PointerCanvas page making it more useful and easy to use
(cherry picked from commit aef6fff3965c29d34702db7513b566e289b541de)
* Remove "Clear" button to reduce vertical toolbar space
* Add render tests for StreamGeometry Clone and Open with a Transform
* Fix StreamGeometry Clone and Open when a Transform is set
* Add tests for when a geometry reports that its drawing changed
* Report the change when the drawing finishes, and let PathGeometry.Open add figures
* Remove the comments and revert the interface type
* Report deselected items and batch SelectAll in TreeView
Selecting a different item clears and repopulates SelectedItems. The clear
raises a Reset, which carries no OldItems, so the deselection was dropped and
only the addition was reported. Track the previous selection so the reset can
work out what was deselected, and raise the clear and the add as one event.
SelectAll added items one at a time, raising an event per item. Batch it the
same way.
* Simplify TreeView selection tracking
Keep a single snapshot of the last reported selection and diff against it,
instead of tracking the snapshot and the pending changes separately. A reset
that keeps some items no longer reports them as added.
Co-authored-by: Steven Kirk <grokys@users.noreply.github.com>
* Simplify comments
* Remove comment.
No other fields have comments, pretty much in the whole codebase. This isn't an exception.
---------
Co-authored-by: Steven Kirk <grokys@users.noreply.github.com>
CreateTextLayoutCore measured the inline embedded controls whenever the
layout was built. The compositor renders dirty visuals under hidden
ancestors too, and layout never measures those, so a TextBlock in a
hidden subtree built its layout from RenderCore and measured its
InlineUIContainer children there. A child measured for the first time
applies its template, attaching visuals inside the render pass, and
CompositingRenderer.AddDirty throws "Visual was invalidated during the
render pass".
- Only measure the embedded controls from CreateTextLayoutCore when the
block's own measure is valid. An invalid block has a measure pass
pending, and MeasureOverride measures the children once the block is
reachable.
- Cover a block hidden at first render, an embedded control shown while
its page is hidden, and a page hidden after it was shown.
Fixes#22380
* Update caret bounds after TextLayout recreation
* Drop redundant TextLayout access from the centered caret test
- Arrange already recreates the layout when the constraint changes, so the explicit getter call added nothing
---------
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
* test(menu): cover NativeMenuItem command parameter changes
A NativeMenuItem keeps the CanExecute result from the moment its Command
is set. When CommandParameter is set or cleared afterwards, IsEnabled
does not change.
Add tests that set and clear CommandParameter after Command. Both fail
at present. A third test records that a parameter change does not enable
an item that has no command.
* fix(menu): update NativeMenuItem state when CommandParameter changes
A NativeMenuItem queries CanExecute only when its Command changes. If
CommandParameter is assigned afterwards, IsEnabled keeps the result for
the previous parameter.
This occurs in XAML when the data context is set before the XAML is
loaded. The Command binding resolves when it is applied, which is before
a CommandParameter property element is assigned. A command that rejects
a null parameter, such as RelayCommand<int>, then leaves the item
disabled permanently.
Query CanExecute again when CommandParameter changes, as Button and
MenuItem do. Skip the query when the item has no command, because there
is no result to refresh and the query would reset IsEnabled to true.
Fixes#21914
* chore: trim code comments
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* test(datepicker): cover Shift+Tab out of CalendarDatePicker
Shift+Tab from the text box of a CalendarDatePicker does not reach the
previous control. The previous tab stop is the picker, and the picker
moves focus back to its text box, so focus stays in the text box.
The test fails until the picker leaves the tab order.
* fix(datepicker): allow Shift+Tab out of CalendarDatePicker
CalendarDatePicker is a tab stop, and it moves focus to its text box
when it receives focus. Shift+Tab from the text box selects the picker
as the previous tab stop, so focus returns to the text box and the
keyboard cannot leave the picker backwards.
Remove the picker from the tab order, as AutoCompleteBox and
NumericUpDown do. Tab navigation then reaches the text box directly in
both directions. The picker stays focusable, so pointer focus and
Focus() calls behave as before.
Fixes#15193
* chore: trim code comments
* test(controls): cover CanExecuteChanged subscription for a style-set Command
The existing tests set Command as a local value. A Command that a style
setter supplies takes a different path: the style applies the value during
attach, and removes the value during detach, before the control overrides run.
For Button and MenuItem the new tests fail. Each control subscribes two times
on attach, and both subscriptions remain after the control leaves the logical
tree, so the command keeps the control alive.
The SplitButton test passes. SplitButton already handles this sequence, and
the test guards that behaviour.
* fix(controls): release a style-set Command when Button or MenuItem detaches
When a style setter supplies Command, Button and MenuItem subscribe to
CanExecuteChanged two times on attach and do not unsubscribe on detach. The
command then holds the control, and every control behind it, for the lifetime
of the command.
Both controls decide whether to move the subscription from
ILogical.IsAttachedToLogicalTree. StyledElement changes that state before the
styles change and before the attach and detach overrides run:
- On attach, the style sets Command while the control already reports
attached. The property handler subscribes, then OnAttachedToLogicalTree
subscribes again.
- On detach, the style value goes away while the control already reports
detached. The property handler skips the unsubscribe, then
OnDetachedFromLogicalTree finds no Command to unsubscribe from.
Track the subscription state in the control instead. Set the flag where
OnAttachedToLogicalTree subscribes and clear the flag where
OnDetachedFromLogicalTree unsubscribes. The Command property handler then
moves the subscription only while the control owns one. SplitButton already
uses this approach.
Fixes#20588Fixes#19619
* chore: trim code comments
* chore: remove the comment on _isSubscribedToCommand
The field name states its purpose. The comment only gave the history of
the change.
* Wayland : Add the AppId in WaylandPlatformOptions or in Windows WaylandProperties to overload the app id if the executable name don't match the app name of the .desktop file
* Rework AppId handling in Wayland backend:
- Centralize default AppId definition in WaylandGlobals
- Use fallback to `Globals.AppId` where applicable.
- Add detailed documentation for the `WaylandProperties.AppId` attached property.
* Make WaylandProperties static
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Stop radial gradients with a moved origin from hiding the background
When the gradient origin differs from the center, the gradient is composed
over a solid shader of the colour it clamps to, because Skia leaves the area
no gradient circle reaches unpainted. That backdrop sits behind the whole
brush, so it also shows through transparent stops. Only compose it when the
origin is outside the circle, which is the only case that leaves such an area.
* Fix regression when the origin lies on the circle
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Fix showing ellipsis when word wrap and limited by height or MaxLines.
* Simplify fix based on comment
* Align height clip behavior with WPF/HTML when last visible line fits in the available width
No ellipsis is shown in this case so I guess it makes sense for Avalonia to behave the same.
* Clarify truncation comments and cover them at the TextLayout level
- Reword the MaxHeight and MaxLines truncation comments: the two limits
differ on purpose (a height cut only ellipsizes a soft-wrapped line, a
line-count cut ellipsizes after a hard break too, like CSS line-clamp).
- Add TextLayout tests with the real shaper for MaxLines at a hard break,
MaxHeight at a hard break and MaxHeight at a wrapped line, so the
behavior is guarded below the TextBlock layer.
---------
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
* Add failing tests for bidi controls being ignored after the first paragraph
* Allow embedding and isolate flags to be set after a reset
Append only set HasEmbeddings and HasIsolates if they had no value, but Reset
sets them to false. Once a BidiData had been reset, explicit formatting
characters could no longer raise them, so overrides, embeddings and isolates
were only applied only applied in the first paragraph formatted on a thread.
HasBrackets is reset the same way, this makes the flags match.
* Escape bidi control characters in tests
---------
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
* DiagnosticTextRenderer: Make numbers monospace
* Center diagnostic digits in their own cell and derive line height from metrics
- Digits were centered against the widest printable ASCII glyph instead of the digit cell, so each digit was drawn right of its cell, overlapped the next glyph and the last one left the background rect. Center against the digit cell and drop the unused max glyph width.
- Compute the line height once from the font metrics (LineSpacing scaled to the em size) instead of scanning glyph run bounds, which already resolve to that value.
- Add tests for fixed digit width, cell centering, stable trailing text and the metrics-based height.
* Draw the FPS line from shaped labels and a fixed digit grid
- Shape the static labels once into single glyph runs and draw the frame number, FPS and visual counts as zero-padded digits in fixed cells. A frame no longer formats a string or measures text.
- Rebuild the memory text only when the pool sizes change, and compute the background rect width once.
- RenderFps takes the raw memory and visual counts instead of a preformatted string. Counters now have a fixed width (frame 8 digits, FPS 3, visual counts 5) and clamp instead of growing.
- Hoist the translucent layer brush into a static field.
---------
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
* [Text] Fix RunIndex mapping in BidiReorderer
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* [Text] Cover BidiReorderer run index mapping at both layers
- BidiReordererTests: assert RunIndex is the visual position of each logical IndexedTextRun, and that textRuns ends up in visual order, for level sequences that form non-involutive permutations (the old lookup only worked for swaps and reversals).
- TextLayoutTests: splitting runs with style spans must not change line width, per-character bounds or hit-test results, across LTR and RTL paragraphs with mixed Hebrew/Latin/digit text.
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
* Add regression tests for empty text layout ranges
Exercise empty ranges at interior and CRLF boundaries using real text layouts, and retain checks for completed-line geometry and existing negative-range behavior.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Handle empty ranges in TextLayout hit testing
Return empty geometry for zero-length requests and stop traversing lines when the remaining range is empty. Keep negative-range behavior and TextLine validation unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Add direct TextLine empty range regressions
Expect no text bounds for zero-length ranges at caret and CRLF line boundaries. Retain checks for normal nonempty geometry. Before the fix, the TextLine suite has 8 failures and 81 passes, with all failures throwing for textLength = 0.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Return no text bounds for empty ranges
Handle zero-length ranges in TextLineImpl.GetTextBounds so all consumers share the empty bounds contract. Remove the TextLayout-only guards and document the result. Negative-length behavior is unchanged.
Verified 168 passing TextLine/TextLayout tests, with one existing profiling test skipped.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: adirh <27368554+adirh3@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cecil cannot produce a real signature with a public-only key, so treat PublicSign like DelaySign and keep the public-signed image as produced by Roslyn.
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
With a pointer moving faster than handlers drain it, isInputPending stays true, so Input and lower priority jobs never ran, MediaContext's input marker never fired and after a second every render was scheduled at Input priority, stalling rendering. The browser dispatches input between our tasks anyway, so explicit background processing with its time slice is sufficient.
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Max Katz <maxkatz6@outlook.com>
The runtime resets SynchronizationContext.Current on the main thread after each thread pool work item, so callbacks entered from JS saw a null context. Input, DOM and canvas exports now enter through JsCallbackHelper; animation frame and dispatcher timer callbacks are intentionally left out.
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Max Katz <maxkatz6@outlook.com>
* MenuItem automation: expand/collapse and invoke.
Implement `IExpandCollapseProvider` and `IInvokeProvider` on the `MenuItemAutomationPeer`. This was surprisingly involved so got Claude to generate some tests for it.
- The provider split matches WPF: `Invoke` for leaf items, `ExpandCollapse` for items with a submenu.
- `Invoke()` goes through `DefaultMenuInteractionHandler.Click`, so checkable items toggle and the menu closes. This works for a `Menu`, a `ContextMenu` and a `MenuFlyout`.
- `MenuItem.MenuInteractionHandler` is now exposed internally so we don't need to do the lookup in two places
* Close the menu when collapsing a top-level menu item.
Collapse on a top-level item now closes the whole menu, matching a click on an
open top-level header. Menu tests now open menus via the peer and assert
Menu.IsOpen, and cover collapsing top-level and nested items.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BZgdE18BxKaTJZQZKUppXW
* Make Collapse a no-op when the menu item is already collapsed.
Previously, collapsing an already-collapsed top-level item closed the whole
menu, including another top-level item's open submenu.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BZgdE18BxKaTJZQZKUppXW
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
UI Automation calls GetPatternProvider and the provider-based InvokeSync
overloads on a background thread, where they called Peer.GetProvider
directly. MenuItemAutomationPeer.GetProviderCore reads ToggleType, which
throws off the UI thread, so checkable menu items never exposed the
Toggle pattern.
Co-authored-by: Steven Kirk <grokys@users.noreply.github.com>
* [wasm] Use scheduler/messagechannel APIs instead of setTimeout for dispatcher
* [wasm] Obsolete PreferManagedThreadDispatcher, MT always uses the managed dispatcher
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Max Katz <maxkatz6@outlook.com>
* Drive Win32 composition effects from RenderTargetSceneInfo on the render thread
Adds an opaque CompositionTarget.TopLevelSpecificSceneInfo bag (with the
corresponding ITopLevelImpl property and changed callback) that travels
through the composition transport and arrives in RenderTargetSceneInfo.
The Win32 backend publishes the theme variant through it.
The WinUI/DComp composited window render targets now apply blur/mica
visual state in BeginDraw, based on the transparency level and theme
variant from the scene info, inside the same transaction as the frame.
The UI-thread ICompositionEffectsSurface.SetBlur path is removed, so
effect changes can no longer race the render thread and produce frames
with mismatched alpha mode and blur state.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TrfgSxPjyUvvKsAPFZoLR1
* Our api diff system leaves much to be desired...
* Rename TopLevelSpecificSceneInfo to PlatformSpecificSceneInfo and document RenderTargetSceneInfo
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
* Add support for EglExternalObjectsFeature, Fix conflicts
* Move inside context
* Clank a demo
* Add SupportedDmaBufFormats
* Use an aux class
* EglExternalObjectsFeature.Drm
* VulkanDmaBufImage
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Use `Microsoft.NET.Sdk.StaticWebAssets` in Avalonia.Browser, rely on built-in assets packaging
* Update ControlCatalog.Browser to use OverrideHtmlAssetPlaceholders + fingerprint
* Fix default BrowserPlatformOptions.FrameworkAssetPathResolver behavior
* Remove outdated ShouldIncludeNativeSkiaSharp/ShouldIncludeNativeHarfBuzzSharp
* Update BuildTests.Browser
* Support static web assets in single project browser apps
The browser TFM now layers Microsoft.NET.Sdk.WebAssembly on top of Microsoft.NET.Sdk,
so Avalonia.Browser's javascript resolves from _content/Avalonia.Browser/.
The static web assets SDK only discovers wwwroot at the project root and offers no
property to relocate it, so define the assets under $(BrowserProjectFolder)wwwroot
directly. WasmExtraFilesToDeploy is kept for the legacy WasmApp model and is now
guarded so the two paths cannot both run.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Restore WasmExtraFilesToDeploy fallback
* Remove unused runtimeconfig.template.json
* Fingerprint Avalonia.Browser javascript from the app build
Avalonia.Browser no longer packs its javascript as static web assets.
build/Avalonia.Browser.targets defines them in the consuming app instead,
the same way Microsoft.NET.Sdk.BlazorWebAssembly handles blazor.webassembly.js.
A hard fingerprint renames the file, which plain static hosting needs,
but it does not survive dotnet pack on the .NET 10 SDK:
the packed props record the resolved name and drop the marker,
so no import map entry is emitted and package consumers request a file that was never renamed.
Evaluating the expression in the app keeps it intact.
.NET 11 fixes pack, but only for consumers on the .NET 11 SDK.
avalonia.js and storage.js are fingerprinted, sw.js and the source maps are not:
those load by URL through serviceWorker.register and sourceMappingURL,
which the import map does not rewrite.
The project drops back to Microsoft.NET.Sdk,
so it no longer emits staticwebassets.runtime.json and .endpoints.json next to the assembly.
A project reference carried those into the app output and made the wasm dev server
serve the app from the wrong manifest, 404ing the icu .dat and .pdb files.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V1TywZ5LUqgagfuzPcxjf5
* Only fingerprint Avalonia javascript when an import map is generated
A renamed file resolves only through the import map,
which the SDK emits only when OverrideHtmlAssetPlaceholders is true.
Apps that do not opt in got renamed files and an empty import map placeholder,
so JSHost.ImportAsync requested a file that no longer existed.
$(StaticWebAssetsFingerprintContent)=false is now honoured too.
Prefer wwwroot/ over staticwebassets/ when locating the javascript.
esbuild wrote to staticwebassets/ before this branch and both are gitignored,
so a leftover directory would otherwise shadow the current output forever.
Skip the assets, and AVA3002, in design time builds.
Those do not build the project reference, so wwwroot may legitimately be absent.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V1TywZ5LUqgagfuzPcxjf5
* Serve the Avalonia service worker from the app root
A service worker is scoped to its own directory,
and the save picker polyfill looks the registration up with getRegistration(),
which matches against the document URL.
From _content/Avalonia.Browser/ the lookup found nothing,
so every save fell back to buffering the whole file into a Blob
instead of streaming through the worker.
Rename the entry point to avalonia-sw.ts and place the output at the app root,
which is the only location whose default scope covers the document.
The polyfill builds its URLs from sw.scope, so nothing else has to change.
Registration was already broken before this branch for a different reason:
the path resolved to ./sw.js while the file shipped under _framework/,
so register() hit a 404 that nothing observed.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V1TywZ5LUqgagfuzPcxjf5
* Remove unused modulepreload
* Fix duplicated _AvaloniaBrowserStaticWebAsset for AvaloniaSingleProject.targets
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Fix TrayIcon being added to the system tray on creation
- Create the native tray icon only after it is attached to Application
- Unsubscribe from the previous TrayIcons collection when it is replaced
- Ensure tray icons cannot escape cleanup during application shutdown
* Add tray icon test.
* Remove tray icon visibility toggle to verify macOS integration tests
* Unified code style
* Keep the native icon hidden until all properties have been initialized.
* Handling invalid waits in testing
* Fix bad auto-merge
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Fix duplicated and crashing DBus tray icon
The StatusNotifierItem object was exported before the well-known name
was requested, and the name was released and re-taken with a new
instance id whenever the watcher came back. A host that scans the bus
then finds the object on a connection owning no such name and registers
it under the unique connection name, so RegisterStatusNotifierItem adds
a second entry for the same process. The object is now exported only
while the name is owned, and the name is kept for the lifetime of the
icon.
WatchAsync and CreateTrayIcon are async void: the OperationCanceledException
from disposal escaped onto the dispatcher and terminated the process,
as would any failing DBus call during registration. Both are handled now.
* Track the tray name request instead of an owned flag
The flag was set before awaiting RequestName, so a refused acquisition left it
true: every later CreateTrayIcon skipped the request and registered the item
under a name the connection does not own. Keeping the request task tells the
three states apart - in flight, acquired, failed - so a failure is retried,
and a hide racing the request now waits for it before releasing the name
instead of releasing one that is not owned yet.
* Re-check state after every await in CreateTrayIcon
Its entry conditions were only checked before the first await, so a hide or a
dispose while the bus answered RequestName still ran into the export: the
release queued on that same task runs after this continuation, leaving the
object exported under a name no longer owned - the state the duplicate item
grows from. The conditions are re-read after each await, and the request is
compared by reference so a stale continuation gives way to a newer one.
Releasing the name is now awaited before requesting it again: the bus keeps a
name registered until the release is acknowledged, and since the name is reused
for the lifetime of the icon, a show right after a hide would otherwise fail
outright and leave no icon until the next toggle.
* Shorten the comments and use Simplified Technical English
The comments explained the same rule more than one time and used long
sentences. Each comment is now one or two short sentences in ASD-STE100
style. The code does not change.
* Make the export in CreateTrayIcon safe to re-enter
Quick visibility toggles start more than one CreateTrayIcon. They wait on the
same release and the same name request, so the reference check does not tell
them apart, and the second call to AddMethodHandler throws "A method handler is
already registered". A flag now records the export: the second call skips it,
and DestroyTrayIcon clears the flag when it removes the handler.
* Set _isVisible before CreateTrayIcon in SetIsVisible
CreateTrayIcon checks _isVisible after it awaits the release. When the
release is complete, the check runs at once with the old value and the
icon stays hidden. SetIsVisible(false) now also releases the name while
the watcher is away.
* Catch all exceptions in WatchAsync and trim the tray icon code
An exception after Dispose did not match the filter in WatchAsync and
left the async void method. The catch now takes all exceptions and only
skips the log after Dispose.
CreateTrayIcon waits for every pending release. The release task returns
when the request failed, so one failure gives one log entry.
DestroyTrayIcon is guarded by _itemExported. Comments are shorter.
* Request a new tray name after a failed request
Tmds.DBus keeps a refused name registered on the connection. A second request for the same name throws "The name is already registered".
* Register the tray icon again when the watcher changes owner
A watcher can take org.kde.StatusNotifierWatcher from another owner with no gap. The new owner does not know the item, and the icon was lost.
* Request the tray name before a watcher comes
A watcher that starts after the application scans the bus. If the connection gets the name during the scan, the host adds a second item for the unique name.
* Reset a refused tray name also after a hide
A hide during the request clears the request, and the catch in CreateTrayIcon did not reset the name. The next show then asked for the same name and failed with "The name is already registered". The request task now resets the name itself.
* Check the tray name before the watcher registers it
The name is now set only when a new request starts, so the compiler cannot prove it is not null at this line. CI treats CS8604 as an error.
---------
Co-authored-by: bolikcraft <bolikcraft@users.noreply.github.com>
* Fix X11 default window size being scaled twice on HiDPI screens
The default size is computed in pixels while RenderScaling is still 1,
so UpdateScaling() later treated it as DIPs and multiplied it by the
monitor scaling. Initialize the scaling from the same monitor.
Fixes#22254
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Respect XEmbed scaling override when initializing X11 window scaling
XEmbedClientWindowMode sets a scaling override of 1 in OnHandleCreated,
which runs after RenderScaling was initialized from the monitor. The
mismatch caused the next UpdateScaling() to trigger a spurious DPI
resize of the embedded window on HiDPI screens.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Introduced a better opengl context management API on top of existing interop APIs
* Rename ICompositionGlTexture.Texture to TextureInfo
* Wait for potentially pending import and present
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>