From f09e3f19759722529ce9df0e2ace45712941700f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Capello?= Date: Thu, 2 Jan 2025 16:44:36 -0300 Subject: [PATCH] [osx] Mimic Windows OS's floating windows behavior Fix aseprite/aseprite#4265 Fix aseprite/aseprite#4774 --- os/osx/app_delegate.mm | 14 ++++++++++++++ os/osx/window.h | 2 ++ os/osx/window.mm | 10 +++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/os/osx/app_delegate.mm b/os/osx/app_delegate.mm index d8e055927..a0beef206 100644 --- a/os/osx/app_delegate.mm +++ b/os/osx/app_delegate.mm @@ -12,6 +12,7 @@ #include #include "os/osx/app_delegate.h" +#include "os/osx/window.h" #include "base/fs.h" #include "os/event.h" @@ -93,6 +94,13 @@ - (void)applicationWillTerminate:(NSNotification*)notification - (void)applicationWillResignActive:(NSNotification*)notification { + for (id window : [NSApp windows]) { + if ([window isKindOfClass:[WindowOSXObjc class]] && [window isFloating]) { + [window setLevel:NSNormalWindowLevel]; + [window orderWindow:NSWindowAbove relativeTo:0]; + } + } + NSEvent* event = [NSApp currentEvent]; if (event != nil) [ViewOSX updateKeyFlags:event]; @@ -100,6 +108,12 @@ - (void)applicationWillResignActive:(NSNotification*)notification - (void)applicationDidBecomeActive:(NSNotification*)notification { + for (id window : [NSApp windows]) { + if ([window isKindOfClass:[WindowOSXObjc class]] && [window isFloating]) { + [window setLevel:NSFloatingWindowLevel]; + } + } + NSEvent* event = [NSApp currentEvent]; if (event != nil) [ViewOSX updateKeyFlags:event]; diff --git a/os/osx/window.h b/os/osx/window.h index a14fb9a76..307e7bcf5 100644 --- a/os/osx/window.h +++ b/os/osx/window.h @@ -41,6 +41,7 @@ class WindowOSX; WindowOSXDelegate* __strong m_delegate; ViewOSX* __strong m_view; int m_scale; + bool m_floating; } - (WindowOSXObjc*)initWithImpl:(os::WindowOSX*)impl spec:(const os::WindowSpec*)spec; - (os::WindowOSX*)impl; @@ -51,6 +52,7 @@ class WindowOSX; - (void)setMousePosition:(const gfx::Point&)position; - (BOOL)setNativeCursor:(os::NativeCursor)cursor; - (BOOL)canBecomeKeyWindow; +- (BOOL)isFloating; @end using WindowOSXObjc_id = WindowOSXObjc*; diff --git a/os/osx/window.mm b/os/osx/window.mm index 855c7c2d7..e1db83671 100644 --- a/os/osx/window.mm +++ b/os/osx/window.mm @@ -121,10 +121,9 @@ - (WindowOSXObjc*)initWithImpl:(os::WindowOSX*)impl spec:(const os::WindowSpec*) [self makeKeyAndOrderFront:self]; - if (spec->floating()) { + m_floating = spec->floating(); + if (spec->floating()) self.level = NSFloatingWindowLevel; - self.hidesOnDeactivate = true; - } if (spec->modal()) self.level = NSModalPanelWindowLevel; @@ -255,6 +254,11 @@ - (BOOL)canBecomeKeyWindow return NO; } +- (BOOL)isFloating +{ + return m_floating; +} + - (void)noResponderFor:(SEL)eventSelector { if (eventSelector == @selector(keyDown:)) {