* 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>
* Bump MicroCOM to 0.11.4, add workaround for WinRT bug
* menu.h - use ComPtr for COM stored references
* Replaced raw COM pointers with smart ones
* fixes
* Use weak com ref from AvnMenuItem
* Better smart pointer handling
* Avalonia native readme update
* review
* missing dif
* Just call the ctor like a normal person
* Implemented new drawn window decorations API
TODO: check if it works on Win32, bring back titlebar automation peer
* Adjusting naming a bit
* Naming / configuration changes
* Various fixes
* popover fix?
* wip
* Address review
* Extra window roles
* WIP
* Fixed drawn titlebar automation
* Purge ExtendClientAreaChromeHints.
* Fixed dynamically enabling drawn decorations
* api diff
* Add automation IDs for drawn decorations buttons
* Resolved the issues
* build
* Retry a few times when Pager isn't available after test is finished
* Only do faulty test detection if asked
* duplicate package reference
* Try disabling faulty tests on appium1
* Fix ExtendClientAreaWindowTests
* Apply initial button states
* Enable CSD shadow for X11
* net8?
* Address review
* more review comments
* Moar review comments
* Extra hit-test checks
* Moar review
* Prefix integration test app exitfullscreen to avoid clashes
* Disable drawn decorations if parts = None
* Respect SystemDecorations value on mac in extend-client-area mode
* Tidy up logic a bit
* Adjust win32 tests to titlebar not being in the tree when CSD are not enabled
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Add CanMinimize and CanMaximize to Window
* Win32 impl for CanMinimize/CanMaximize
* Add CanResize/CanMinimize/CanMaximize samples to control catalog
* X11 impl for CanMinimize/CanMaximize
* macOS impl for CanMinimize/CanMaximize
* Win32: don't allow restore when the window isn't resizable
* Additional documentation for CanMinimize/CanMaximize
* Add CanMinimize/CanMaximize logic to CaptionButtons
* Use START_COM_ARP_CALL
* Added CanMinimize/CanMaximize integration tests
* Fixed CanMaximize tests on macOS
* feat: Add API for fetching window Z-order
* Addressed PR comments
* Improve X11Window::ZOrder implementation to avoid traversing windows that are not required to compute z-order
* Move zOrder API from Window to IWindowingPlatform
* Revert "Addressed PR comments"
This reverts commit 691541adf6.
* Rename
* Missing methods
* Move GetWindowsZOrder from IWindowingPlatform to IWindowImpl
* Cleanup
* Move SortWindowsByZOrder to Window class as a static method
* Implement zOrder for HeadlessWindowImpl
---------
Co-authored-by: Max Katz <maxkatz6@outlook.com>
Previously, even though the zoom button was disabled the user could still double-click on the title bar to zoom the window. Prevent that by returning the appropriate value from `NSWindow windowShouldZoom` and move the `CanZoom` logic into a central place for use by this method and `UpdateStyle`.
Fixes a problem where we were clearing the fullscreen flag erroneously during a fullscreen transition, and in general it's best to preserve flags we're not interested in controlling anyway.
When a window exits fullscreen, its child windows need to be ordered, but we shouldn't touch the z-order of the window itself as this sometimes seemed to result in the parent window being shown over the child windows. Fixes flaky integration tests (hopefully).
macOS seems to tie resizing of the NSView inside the window to the resizable style mask of the window somehow. If we programmatically transition a non-resizable window to fullscreen, the inner NSView's size isn't changed, so we need to make the window resizable during the fullscreen transition.
Makes the final two failing `WindowState` integration tests pass.
- Make naming more clear - it's not getting the style mask, it's calculating what it should be in order to update the mask
- Make it abstract to prevent it being called from the ctor in future
To do this more easily, merged `HideOrShowTrafficLights` into a virtual `UpdateStyle`. They were always called together, and really _must_ be called together; this enforces that.
7eb95255c regressed disabling the minimize button on owned windows. Split what was previously `IsDialog` into two flags: `IsModal` and `IsOwned` and use `IsOwned` to control the disabled state of the minimize button.
This was preventing owner windows of non-modal dialogs from receiving key window status, meaning that input was broken in combination with embedding (Avalonia controls did work however because the routing was carried out internal to Avalonia).
When a window is closed, its parent window is set to null, which caused this code to run. This line caused the parent window to be brought to front, and should have also caused any other child windows to be brought to front, but it seems OSX ignored those requests, causing #8878.
Simply don't bring the parent window to the front when a child window is closed. I couldn't work out why this code was necessary anyway, and all integration tests still pass.
Fixes#8878.
The previous solution didn't work for owned windows. Hopefully this fixes the problem at its root: that `BringToFront` activates a window even if it's miniaturized.
Previously, `_actualWindowState` was being set after the window state had finished changing, but `ExitFullScreenMode` calls `UpdateStyle` which expects `_actualWindowState` to be up-to-date, meaning that previously we ended up with an invalid size when exiting full screen mode programatically.