Repository navigation
Description
Current behavior 🐛
On the macOS desktop (Skia) host, Window.Activated only fires once, with CodeActivated, when Window.Activate() is called at startup. Native focus changes never reach it:
- clicking an inactive window to bring it to the front doesn't raise
PointerActivated/CodeActivated - switching to another app, or to another window of the same app, doesn't raise
Deactivated
NativeWindowWrapperBase.ActivationState is never set by the macOS host. UNOWindow is its own NSWindowDelegate but doesn't implement windowDidBecomeKey: / windowDidResignKey: (or observe the app's became/resigned-active notifications), so nothing tells managed code when key status changes.
Consequences:
WindowChromenever switches to its inactive title-bar visual state on macOS.- App code that dims UI or pauses work on
Deactivatednever gets it. - Every other host sets
ActivationStatefrom native focus (Win32, X11, WebAssembly, Android, iOS). macOS is the only one that doesn't.
Expected behavior 🎯
Same as WinUI: Window.Activated fires with CodeActivated or PointerActivated whenever the window becomes the active (key) window, and with Deactivated whenever it loses that status.
In WinUI, DesktopWindowImpl::OnActivate handles WM_ACTIVATE and raises Activated with CodeActivated for WA_ACTIVE, PointerActivated for WA_CLICKACTIVE, and Deactivated for WA_INACTIVE (skipping activation while minimized):
https://github.com/microsoft/microsoft-ui-xaml/blob/fe9d01273af3382ea570e203ab700772528d98df/dxaml/xcp/dxaml/lib/DesktopWindowImpl.cpp#L1409-L1443
How to reproduce it (as minimally and precisely as possible) 🔬
dotnet new unoapp -preset blank -platforms desktop -tfm net10.0(Uno.Sdk 6.7.30), and run it on macOS.- In
App.OnLaunched, beforeMainWindow.Activate(), add:MainWindow.Activated += (_, e) => Console.WriteLine($"Activated: {e.WindowActivationState}");
- Run the app.
Activated: CodeActivatedis printed once. - Click another app (e.g. Finder), then click back on the Uno window. Repeat a few times.
- Actual: nothing more is printed.
- Expected:
Deactivatedwhen you leave,PointerActivated(orCodeActivated) when you come back.
The same thing happens with two Uno windows: opening a second Window and calling Activate() doesn't raise Deactivated on the first one.
You can also see the missing hook from inside the app, without switching apps. This asks the native window's delegate (the UNOWindow itself) which NSWindowDelegate callbacks it implements:
using System.Runtime.InteropServices;
static class ObjC
{
[DllImport("/usr/lib/libobjc.dylib")] static extern IntPtr objc_getClass(string n);
[DllImport("/usr/lib/libobjc.dylib")] static extern IntPtr sel_registerName(string n);
[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] static extern IntPtr Send(IntPtr r, IntPtr s);
[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] static extern IntPtr SendIdx(IntPtr r, IntPtr s, nuint i);
[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] static extern bool Responds(IntPtr r, IntPtr s, IntPtr sel);
public static void Dump()
{
var app = Send(objc_getClass("NSApplication"), sel_registerName("sharedApplication"));
var window = SendIdx(Send(app, sel_registerName("windows")), sel_registerName("objectAtIndex:"), 0);
var d = Send(window, sel_registerName("delegate"));
foreach (var sel in new[] { "windowDidMove:", "windowDidBecomeKey:", "windowDidResignKey:" })
{
Console.WriteLine($"{sel} {Responds(d, sel_registerName("respondsToSelector:"), sel_registerName(sel))}");
}
}
}Calling ObjC.Dump() a moment after the window is shown prints:
windowDidMove: True
windowDidBecomeKey: False
windowDidResignKey: False
Workaround 🛠️
None inside Uno. An app can watch focus itself, for example by observing NSApplicationDidBecomeActiveNotification / NSApplicationDidResignActiveNotification through Objective-C interop.
Affected platforms 📱💻🖥️
Desktop (macOS)
Uno.Sdk version (and other relevant versions) 📦
- Runtime: Uno.Sdk 6.7.30,
net10.0-desktop, macOS 26.2 (Apple Silicon). - Source: the missing wiring is the same on
masterat cc48541.
IDE version 🧑💻
Command line (dotnet build / dotnet run)
Anything else we need to know? 💬
Works on WinUI: yes. This is based on the WinUI sources (DesktopWindowImpl::OnActivate, linked above), not a native WinUI run. Uno's own Win32 and X11 hosts already behave like WinUI here.
What I verified, and how
- From source on
master: there's no activation wiring in the macOS host. - At runtime on 6.7.30: the delegate doesn't respond to
windowDidBecomeKey:/windowDidResignKey:, and postingNSWindowDidBecomeKeyNotification/NSWindowDidResignKeyNotificationfor the windows raises noActivated. In my environment I couldn't make the app frontmost programmatically, so the click-away / click-back steps above are expected behaviour based on the source.
Root cause (permalinks at cc48541)
NativeWindowWrapperBase.ActivationStateraisesActivationChanged→BaseWindowImplementation.OnNativeActivationChanged→Window.Activated: NativeWindowWrapperBase.cs#L111-L122, BaseWindowImplementation.cs#L227-L250- The only activation on macOS is the managed one from
TryActivate: BaseWindowImplementation.cs#L393 MacOSWindowWrappernever setsActivationState: MacOSWindowWrapper.csUNOWindowsets itself as delegate (UNOWindow.m#L1284) and implements miniaturize/move/resize/close callbacks, but not key-status ones: UNOWindow.m#L1589-L1656
How the other hosts do it
- Win32 maps
WM_ACTIVATEexactly like WinUI: Win32WindowWrapper.cs#L615-L643 - X11 maps
FocusIn/FocusOuttoPointerActivated/Deactivated: X11XamlRootHost.x11events.cs#L203-L206, X11WindowWrapper.cs#L103
Suggested fix
Add windowDidBecomeKey: / windowDidResignKey: to UNOWindow, forward them through a new native→managed callback, and set ActivationState in MacOSWindowWrapper: Deactivated on resign-key, and PointerActivated on become-key when the current event is a mouse-down (otherwise CodeActivated). Skip activation while miniaturized, like WinUI. A runtime test can then check that Deactivated / Activated follow key-window changes between two windows.
A fix is in progress in #25203.
Activity