Skip to content

Fix app activation for macOS - #21799

Merged
MrJul merged 1 commit into
AvaloniaUI:mainfrom
JakobScholer:fix-macos-degraded-activation
Jul 24, 2026
Merged

Fix app activation for macOS#21799
MrJul merged 1 commit into
AvaloniaUI:mainfrom
JakobScholer:fix-macos-degraded-activation

Conversation

@JakobScholer

Copy link
Copy Markdown
Contributor

What does the pull request do?

On macOS, opening a file picker shortly after launch can leave it permanently
unresponsive: the dialog appears and Cancel, path navigation and right-click work,
but the file list and left sidebar don't respond to clicks for the rest of the
app's lifetime. The only user workaround is switching to another app and back.

What is the current behavior?

Avalonia shows the main window and activates the app via [NSApp activateIgnoringOtherApps:YES]
from Show, which runs during OnFrameworkInitializationCompleted — before the
native run loop is entered (-[NSApplication run]). Activating the app before it has
finished launching produces a degraded activation: the app reports as active and is
frontmost in the menu bar, but the WindowServer never performs a real become-active
transition. As a result the out-of-process open/save panel view never starts routing
mouse-selection events to its file list and sidebar. A genuine app switch (resign →
become active) is the only thing that repairs it.

This is timing-dependent; anything that slows early startup makes the window easier to
hit — e.g. WindowState="Maximized" or running under a debugger.

What is the updated/expected behavior?

The first app activation is deferred to the next run-loop turn when the app isn't
running yet, so it becomes a clean WindowServer transition and the picker is fully
interactive immediately. Activations once the app is running are unchanged.

How was the solution implemented (if it's not obvious)?

Added a small ActivateApplication() helper in WindowBaseImpl.mm used by Show
and Activate:

if ([NSApp isRunning]) {
    [NSApp activateIgnoringOtherApps:YES];
} else {
    dispatch_async(dispatch_get_main_queue(), ^{
        [NSApp activateIgnoringOtherApps:YES];
    });
}

Checklist

  • Added unit tests — N/A: native macOS launch-timing/activation race in libAvaloniaNative; not reproducible in the unit or Appium integration test suites.
  • Added XML documentation — N/A: change is Objective-C++ (WindowBaseImpl.mm), no public API affected.
  • avalonia-docs PR — N/A: internal fix, no user-facing documentation impact.

Breaking changes

Obsoletions / Deprecations

Fixed issues

Fixes #21718

@JakobScholer
JakobScholer marked this pull request as ready for review July 18, 2026 15:03
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0067522-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@JakobScholer
JakobScholer marked this pull request as draft July 18, 2026 16:40
@JakobScholer
JakobScholer marked this pull request as ready for review July 18, 2026 16:40
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0067527-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@JakobScholer
JakobScholer marked this pull request as draft July 19, 2026 18:53
@JakobScholer
JakobScholer marked this pull request as ready for review July 19, 2026 18:53
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0067533-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added bug os-macos backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Jul 20, 2026

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, works as expected.
LGTM!

@MrJul
MrJul added this pull request to the merge queue Jul 24, 2026
Merged via the queue into AvaloniaUI:main with commit 935853a Jul 24, 2026
11 checks passed
MrJul pushed a commit that referenced this pull request Jul 29, 2026
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File picker becomes permanently unresponsive when opened shortly after app launch

3 participants