Skip to content

Commit

Permalink
[osx] Fix floating window disappears when another app gains focus (fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Gasparoken authored and dacap committed Dec 4, 2024
1 parent 947155e commit a1498f0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions os/osx/app_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
// generate a DropFiles event.
std::set<std::string> m_cliFiles;
bool m_isHidden;
NSMutableArray<NSWindow*>* m_floatingWindows;
}

- (id)init;
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender;
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)app;
Expand All @@ -39,6 +41,7 @@
- (void)markCliFileAsProcessed:(const std::string&)fn;
- (void)resetCliFiles;
- (BOOL)isHidden;
- (NSMutableArray<NSWindow*>*) floatingWindows;
@end

#endif
12 changes: 12 additions & 0 deletions os/osx/app_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ - (id)init
{
if (self = [super init]) {
m_isHidden = false;
m_floatingWindows = [NSMutableArray array];
}
return self;
}
Expand All @@ -92,6 +93,9 @@ - (void)applicationWillTerminate:(NSNotification*)notification

- (void)applicationWillResignActive:(NSNotification*)notification
{
for (NSWindow* floatingWindow in self.floatingWindows)
floatingWindow.level = NSNormalWindowLevel;

NSEvent* event = [NSApp currentEvent];
if (event != nil)
[ViewOSX updateKeyFlags:event];
Expand All @@ -102,6 +106,9 @@ - (void)applicationDidBecomeActive:(NSNotification*)notification
NSEvent* event = [NSApp currentEvent];
if (event != nil)
[ViewOSX updateKeyFlags:event];

for (NSWindow* floatingWindow in self.floatingWindows)
floatingWindow.level = NSFloatingWindowLevel;
}

- (void)applicationDidHide:(NSNotification*)notification
Expand Down Expand Up @@ -170,4 +177,9 @@ - (BOOL)isHidden
return m_isHidden;
}

- (NSMutableArray<NSWindow*>*) floatingWindows
{
return m_floatingWindows;
}

@end
13 changes: 12 additions & 1 deletion os/osx/window.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "os/osx/window.h"

#include "base/debug.h"
#include "os/osx/app_delegate.h"
#include "os/event.h"
#include "os/osx/app.h"
#include "os/osx/event_queue.h"
Expand Down Expand Up @@ -120,7 +121,13 @@ - (WindowOSXObjc*)initWithImpl:(os::WindowOSX*)impl

if (spec->floating()) {
self.level = NSFloatingWindowLevel;
self.hidesOnDeactivate = true;
self.hidesOnDeactivate = false;
// Needed to keep track all the floating windows pointers
// to handle its 'floatingWindow.level' when the application
// turns active/inactive inside 'app_delegate.mm'.
AppDelegateOSX* delegate = (AppDelegateOSX*)[NSApp delegate];
if (delegate)
[delegate.floatingWindows addObject:self];
}

// Hide the "View > Show Tab Bar" menu item
Expand All @@ -137,6 +144,10 @@ - (WindowOSXObjc*)initWithImpl:(os::WindowOSX*)impl

- (void)removeImpl
{
AppDelegateOSX* delegate = (AppDelegateOSX*)[NSApp delegate];
if (delegate)
[delegate.floatingWindows removeObject:self];

[m_view removeImpl];

[self setDelegate:nil];
Expand Down

0 comments on commit a1498f0

Please sign in to comment.