Skip to content

macOS: Window.Activated never reports Deactivated or re-activation when key-window focus changes #25247

Closed

Description

@MartinZikmund

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:

  • WindowChrome never switches to its inactive title-bar visual state on macOS.
  • App code that dims UI or pauses work on Deactivated never gets it.
  • Every other host sets ActivationState from 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) 🔬

  1. dotnet new unoapp -preset blank -platforms desktop -tfm net10.0 (Uno.Sdk 6.7.30), and run it on macOS.
  2. In App.OnLaunched, before MainWindow.Activate(), add:
    MainWindow.Activated += (_, e) => Console.WriteLine($"Activated: {e.WindowActivationState}");
  3. Run the app. Activated: CodeActivated is printed once.
  4. Click another app (e.g. Finder), then click back on the Uno window. Repeat a few times.
    • Actual: nothing more is printed.
    • Expected: Deactivated when you leave, PointerActivated (or CodeActivated) 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 master at 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 posting NSWindowDidBecomeKeyNotification / NSWindowDidResignKeyNotification for the windows raises no Activated. 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)

How the other hosts do it

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

  1. added
    kind/bug
    platform/macos 🍏
    triage/untriaged
    area/skia ✏️
    difficulty/medium 🤔
    area/windowing
    platform/desktop 🖥️
    on Oct 11, 2026
  2. added
    7.1
    on Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    7.1area/skia ✏️area/windowingdifficulty/medium 🤔kind/bugplatform/desktop 🖥️platform/macos 🍏triage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions