From 69bd5cc54d8370945b1830c9c0cf120757eb1bc9 Mon Sep 17 00:00:00 2001 From: Gaspar Capello Date: Tue, 3 Dec 2024 10:59:32 -0300 Subject: [PATCH] Add modal window treatment to macOS Before this addition, when a modal window was active, it was allowed to bring other windows to the front (which should be prohibited). This addition is part of the solution for the issue aseprite/aseprite#4561 'Inactive windows in multiple-window UI mode pass events to below windows' --- os/osx/window.mm | 7 ++++++- os/osx/window_delegate.h | 8 +++++++- os/window_spec.h | 5 ++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/os/osx/window.mm b/os/osx/window.mm index 1658845a1..e59de1ec8 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. @@ -120,6 +120,8 @@ - (WindowOSXObjc*)initWithImpl:(os::WindowOSX*)impl if (spec->floating()) { self.level = NSFloatingWindowLevel; self.hidesOnDeactivate = true; + if (spec->modal()) + [self setLevel:NSModalPanelWindowLevel]; } // Hide the "View > Show Tab Bar" menu item @@ -366,6 +368,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;