Skip to content

Commit

Permalink
[osx] Fix sometimes the floating window flickers during app activation
Browse files Browse the repository at this point in the history
This solution sends floating window to the background of
the main window on app deactivation to avoid the flickering.
  • Loading branch information
Gasparoken committed Dec 5, 2024
1 parent a1498f0 commit 97a64e7
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions os/osx/app_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,29 @@ - (void)applicationWillTerminate:(NSNotification*)notification

- (void)applicationWillResignActive:(NSNotification*)notification
{
for (NSWindow* floatingWindow in self.floatingWindows)
floatingWindow.level = NSNormalWindowLevel;
// Identify the main window
NSWindow* mainWindow = nil;
for (NSWindow* window in [NSApp windows]) {
if (!window.isFloatingPanel) {
mainWindow = window;
break;
}
}
if (mainWindow) {
AppDelegateOSX* delegate = (AppDelegateOSX*)[NSApp delegate];
for (NSWindow* floatingWindow in delegate.floatingWindows) {
floatingWindow.level = NSNormalWindowLevel;
// Send floating window to the background of the main window.
// This is done to avoid a small glitch in floating windows when
// our application is activated (sometimes the floating window
// flickers during application activation). This happens due to
// the manipulation of the window 'level' between
// 'NSNormalWindowLevel' (inside 'applicationWillResignActive')
// and 'NSFloatingWindowLevel' (inside
// 'applicationDidBecomeActive').
floatingWindow.orderedIndex = mainWindow.orderedIndex + 1;
}
}

NSEvent* event = [NSApp currentEvent];
if (event != nil)
Expand All @@ -107,7 +128,8 @@ - (void)applicationDidBecomeActive:(NSNotification*)notification
if (event != nil)
[ViewOSX updateKeyFlags:event];

for (NSWindow* floatingWindow in self.floatingWindows)
AppDelegateOSX* delegate = (AppDelegateOSX*)[NSApp delegate];
for (NSWindow* floatingWindow in delegate.floatingWindows)
floatingWindow.level = NSFloatingWindowLevel;
}

Expand Down

0 comments on commit 97a64e7

Please sign in to comment.