diff --git a/os/osx/window.mm b/os/osx/window.mm index 1658845a1..44c80f880 100644 --- a/os/osx/window.mm +++ b/os/osx/window.mm @@ -1,5 +1,5 @@ // LAF OS Library -// Copyright (C) 2019-2021 Igara Studio S.A. +// Copyright (C) 2019-2024 Igara Studio S.A. // Copyright (C) 2012-2017 David Capello // // This file is released under the terms of the MIT license. @@ -122,6 +122,9 @@ - (WindowOSXObjc*)initWithImpl:(os::WindowOSX*)impl self.hidesOnDeactivate = true; } + if (spec->modal()) + self.level = NSModalPanelWindowLevel; + // Hide the "View > Show Tab Bar" menu item if ([self respondsToSelector:@selector(setTabbingMode:)]) [self setTabbingMode:NSWindowTabbingModeDisallowed]; @@ -366,6 +369,9 @@ - (void)noResponderFor:(SEL)eventSelector void WindowOSX::activate() { + if ([m_nsWindow.delegate respondsToSelector:@selector(windowShouldBecomeKey:)] && + ![(id)m_nsWindow.delegate windowShouldBecomeKey:m_nsWindow]) + return; [m_nsWindow makeKeyWindow]; } diff --git a/os/osx/window_delegate.h b/os/osx/window_delegate.h index 8b93892a8..9d05cfee4 100644 --- a/os/osx/window_delegate.h +++ b/os/osx/window_delegate.h @@ -1,5 +1,5 @@ // LAF OS Library -// Copyright (C) 2020-2021 Igara Studio S.A. +// Copyright (C) 2020-2024 Igara Studio S.A. // Copyright (C) 2015 David Capello // // This file is released under the terms of the MIT license. @@ -117,4 +117,10 @@ namespace os { return YES; } +- (BOOL)windowShouldBecomeKey:(NSWindow *)sender +{ + NSWindow* modalWindow = [NSApp modalWindow]; + return !modalWindow || modalWindow == sender; +} + @end diff --git a/os/window_spec.h b/os/window_spec.h index 1be9f0b89..7a721c1f5 100644 --- a/os/window_spec.h +++ b/os/window_spec.h @@ -1,5 +1,5 @@ // LAF OS Library -// Copyright (C) 2019-2021 Igara Studio S.A. +// Copyright (C) 2019-2024 Igara Studio S.A. // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -43,6 +43,7 @@ namespace os { bool resizable() const { return m_resizable; } bool floating() const { return m_floating; } bool transparent() const { return m_transparent; } + bool modal() const { return m_modal; } // Parent window used for floating windows Window* parent() const { return m_parent; } @@ -57,6 +58,7 @@ namespace os { void floating(const bool s) { m_floating = s; } void transparent(const bool s) { m_transparent = s; } void parent(Window* p) { m_parent = p; } + void modal(const bool s) { m_modal = s; } const gfx::Rect& frame() const { return m_frame; } const gfx::Rect& contentRect() const { return m_contentRect; } @@ -78,6 +80,7 @@ namespace os { bool m_resizable = true; bool m_floating = false; bool m_transparent = false; + bool m_modal = false; gfx::Rect m_frame; gfx::Rect m_contentRect; int m_scale = 1;