Skip to content

Commit

Permalink
[osx] Window::isMinimized() now returns true if the app is hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Dec 4, 2024
1 parent c6cd70a commit 947155e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
4 changes: 3 additions & 1 deletion os/osx/app.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.
// Copyright (C) 2012-2016 David Capello
//
// This file is released under the terms of the MIT license.
Expand All @@ -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();
Expand Down
11 changes: 10 additions & 1 deletion os/osx/app.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-2016 David Capello
//
// This file is released under the terms of the MIT license.
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion os/osx/app_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) 2012-2017 David Capello
//
// This file is released under the terms of the MIT license.
Expand All @@ -22,18 +22,23 @@
// Files that were already processed in the CLI, so we don't need to
// generate a DropFiles event.
std::set<std::string> 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
25 changes: 24 additions & 1 deletion os/osx/app_delegate.mm
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -147,4 +165,9 @@ - (void)resetCliFiles
m_cliFiles.clear();
}

- (BOOL)isHidden
{
return m_isHidden;
}

@end
8 changes: 6 additions & 2 deletions 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 All @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 947155e

Please sign in to comment.