diff --git a/os/osx/app.h b/os/osx/app.h index 0d7b23369..12353b640 100644 --- a/os/osx/app.h +++ b/os/osx/app.h @@ -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-2016 David Capello // // This file is released under the terms of the MIT license. @@ -25,6 +25,8 @@ namespace os { bool init(); void setAppMode(AppMode appMode); + bool isHidden() const; + void markCliFileAsProcessed(const std::string& fn); void finishLaunching(); void activateApp(); diff --git a/os/osx/app.mm b/os/osx/app.mm index 758365516..a1700bf79 100644 --- a/os/osx/app.mm +++ b/os/osx/app.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-2016 David Capello // // This file is released under the terms of the MIT license. @@ -44,6 +44,10 @@ void setAppMode(AppMode appMode) { } } + bool isHidden() const { + return [m_appDelegate isHidden]; + } + void markCliFileAsProcessed(const std::string& fn) { [m_appDelegate markCliFileAsProcessed:fn]; } @@ -93,6 +97,11 @@ void activateApp() { m_impl->setAppMode(appMode); } +bool AppOSX::isHidden() const +{ + return m_impl->isHidden(); +} + void AppOSX::markCliFileAsProcessed(const std::string& fn) { m_impl->markCliFileAsProcessed(fn); diff --git a/os/osx/app_delegate.h b/os/osx/app_delegate.h index 0853b9cb7..0bbaf04a9 100644 --- a/os/osx/app_delegate.h +++ b/os/osx/app_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) 2012-2017 David Capello // // This file is released under the terms of the MIT license. @@ -22,18 +22,23 @@ // Files that were already processed in the CLI, so we don't need to // generate a DropFiles event. std::set m_cliFiles; + bool m_isHidden; } +- (id)init; - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender; - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)app; - (void)applicationWillTerminate:(NSNotification*)notification; - (void)applicationWillResignActive:(NSNotification*)notification; - (void)applicationDidBecomeActive:(NSNotification*)notification; +- (void)applicationDidHide:(NSNotification*)notification; +- (void)applicationDidUnhide:(NSNotification*)notification; - (BOOL)application:(NSApplication*)app openFiles:(NSArray*)filenames; - (void)executeMenuItem:(id)sender; - (BOOL)validateMenuItem:(NSMenuItem*)menuItem; - (void)markCliFileAsProcessed:(const std::string&)fn; - (void)resetCliFiles; +- (BOOL)isHidden; @end #endif diff --git a/os/osx/app_delegate.mm b/os/osx/app_delegate.mm index 5e34a74a3..61ac23601 100644 --- a/os/osx/app_delegate.mm +++ b/os/osx/app_delegate.mm @@ -1,5 +1,5 @@ // LAF OS Library -// Copyright (C) 2020-2022 Igara Studio S.A. +// Copyright (C) 2020-2024 Igara Studio S.A. // Copyright (C) 2012-2017 David Capello // // This file is released under the terms of the MIT license. @@ -65,6 +65,14 @@ - (void)validateLafMenuItem; @implementation AppDelegateOSX +- (id)init +{ + if (self = [super init]) { + m_isHidden = false; + } + return self; +} + - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender { os::Event ev; @@ -96,6 +104,16 @@ - (void)applicationDidBecomeActive:(NSNotification*)notification [ViewOSX updateKeyFlags:event]; } +- (void)applicationDidHide:(NSNotification*)notification +{ + m_isHidden = true; +} + +- (void)applicationDidUnhide:(NSNotification*)notification +{ + m_isHidden = false; +} + - (BOOL)application:(NSApplication*)app openFiles:(NSArray*)filenames { // TODO similar to generate_drop_files_from_nsarray() but with a @@ -147,4 +165,9 @@ - (void)resetCliFiles m_cliFiles.clear(); } +- (BOOL)isHidden +{ + return m_isHidden; +} + @end diff --git a/os/osx/window.mm b/os/osx/window.mm index 1658845a1..38148f919 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. @@ -13,6 +13,7 @@ #include "base/debug.h" #include "os/event.h" +#include "os/osx/app.h" #include "os/osx/event_queue.h" #include "os/osx/view.h" #include "os/osx/window_delegate.h" @@ -386,7 +387,10 @@ - (void)noResponderFor:(SEL)eventSelector bool WindowOSX::isMinimized() const { - return (m_nsWindow.miniaturized ? true: false); + // Return true if the NSWindow is minimized or if the NSApplication + // is hidden. + return (m_nsWindow.miniaturized || + os::AppOSX::instance()->isHidden()); } bool WindowOSX::isFullscreen() const