Skip to content

Commit

Permalink
fix(macos): Bring window to top when activated
Browse files Browse the repository at this point in the history
(cherry picked from commit 6f1da0e)
  • Loading branch information
spouliot authored and mergify[bot] committed Oct 31, 2024
1 parent ad61cdf commit 5bae5b2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Uno.UI.Runtime.Skia.MacOS/MacOSWindowWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ public override string Title
set => NativeUno.uno_window_set_title(_window.Handle, value);
}

public override void Activate()
{
NativeUno.uno_window_activate(_window.Handle);
}

protected override void ShowCore()
{
// the first call to `Window.Activate` does not reach the above `Activate` method
// https://github.com/unoplatform/uno/blob/fc8e58d77f8cf31d651135c22ea3105099c26fb7/src/Uno.UI/UI/Xaml/Window/Implementations/BaseWindowImplementation.cs#L81-L98
NativeUno.uno_window_activate(_window.Handle);
}

private void OnHostSizeChanged(Size size)
{
Bounds = new Rect(default, size);
Expand Down
3 changes: 3 additions & 0 deletions src/Uno.UI.Runtime.Skia.MacOS/NativeUno.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ internal static unsafe partial void uno_set_window_events_callbacks(
[LibraryImport("libUnoNativeMac.dylib")]
internal static partial nint uno_window_create(double width, double height);

[LibraryImport("libUnoNativeMac.dylib")]
internal static partial void uno_window_activate(nint window);

[LibraryImport("libUnoNativeMac.dylib")]
internal static partial void uno_window_invalidate(nint window);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void uno_set_resize_callback(resize_fn_ptr p);
NSWindow* uno_app_get_main_window(void);

NSWindow* uno_window_create(double width, double height);
void uno_window_activate(NSWindow *window);
void uno_window_invalidate(NSWindow *window);
bool uno_window_resize(NSWindow *window, double width, double height);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ - (void) applicationDidChangeScreenParametersNotification:(NSNotification*) note
return window;
}

void uno_window_activate(NSWindow *window)
{
#if DEBUG
NSLog(@"uno_window_activate %@", window);
#endif
[window orderFront:nil];
}

void uno_window_notify_screen_change(NSWindow *window)
{
assert(windowDidChangeScreen);
Expand Down

0 comments on commit 5bae5b2

Please sign in to comment.