Skip to content

Commit

Permalink
Add modal window treatment to macOS
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
Gasparoken committed Dec 4, 2024
1 parent a1c113a commit 8840009
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion os/osx/window.mm
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
}

Expand Down
8 changes: 7 additions & 1 deletion os/osx/window_delegate.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -117,4 +117,10 @@ namespace os {
return YES;
}

- (BOOL)windowShouldBecomeKey:(NSWindow *)sender
{
NSWindow* modalWindow = [NSApp modalWindow];
return !modalWindow || modalWindow == sender;
}

@end
5 changes: 4 additions & 1 deletion os/window_spec.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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; }
Expand All @@ -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; }
Expand All @@ -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;
Expand Down

0 comments on commit 8840009

Please sign in to comment.