Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modal window treatment to macOS #116

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading