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

[osx] Mimic Windows OS's floating windows behavior #124

Merged
merged 1 commit into from
Jan 3, 2025
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
14 changes: 14 additions & 0 deletions os/osx/app_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Cocoa/Cocoa.h>

#include "os/osx/app_delegate.h"
#include "os/osx/window.h"

#include "base/fs.h"
#include "os/event.h"
Expand Down Expand Up @@ -93,13 +94,26 @@ - (void)applicationWillTerminate:(NSNotification*)notification

- (void)applicationWillResignActive:(NSNotification*)notification
{
for (id window : [NSApp windows]) {
if ([window isKindOfClass:[WindowOSXObjc class]] && [window isFloating]) {
[window setLevel:NSNormalWindowLevel];
[window orderWindow:NSWindowAbove relativeTo:0];
}
}

NSEvent* event = [NSApp currentEvent];
if (event != nil)
[ViewOSX updateKeyFlags:event];
}

- (void)applicationDidBecomeActive:(NSNotification*)notification
{
for (id window : [NSApp windows]) {
if ([window isKindOfClass:[WindowOSXObjc class]] && [window isFloating]) {
[window setLevel:NSFloatingWindowLevel];
}
}

NSEvent* event = [NSApp currentEvent];
if (event != nil)
[ViewOSX updateKeyFlags:event];
Expand Down
2 changes: 2 additions & 0 deletions os/osx/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class WindowOSX;
WindowOSXDelegate* __strong m_delegate;
ViewOSX* __strong m_view;
int m_scale;
bool m_floating;
}
- (WindowOSXObjc*)initWithImpl:(os::WindowOSX*)impl spec:(const os::WindowSpec*)spec;
- (os::WindowOSX*)impl;
Expand All @@ -51,6 +52,7 @@ class WindowOSX;
- (void)setMousePosition:(const gfx::Point&)position;
- (BOOL)setNativeCursor:(os::NativeCursor)cursor;
- (BOOL)canBecomeKeyWindow;
- (BOOL)isFloating;
@end

using WindowOSXObjc_id = WindowOSXObjc*;
Expand Down
10 changes: 7 additions & 3 deletions os/osx/window.mm
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,9 @@ - (WindowOSXObjc*)initWithImpl:(os::WindowOSX*)impl spec:(const os::WindowSpec*)

[self makeKeyAndOrderFront:self];

if (spec->floating()) {
m_floating = spec->floating();
if (spec->floating())
self.level = NSFloatingWindowLevel;
self.hidesOnDeactivate = true;
}

if (spec->modal())
self.level = NSModalPanelWindowLevel;
Expand Down Expand Up @@ -255,6 +254,11 @@ - (BOOL)canBecomeKeyWindow
return NO;
}

- (BOOL)isFloating
{
return m_floating;
}

- (void)noResponderFor:(SEL)eventSelector
{
if (eventSelector == @selector(keyDown:)) {
Expand Down
Loading