summaryrefslogtreecommitdiff
path: root/platform/osx
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-01-06 11:39:18 +0100
committerGitHub <noreply@github.com>2020-01-06 11:39:18 +0100
commit845480497207839bef48997d152f00b60b6176a8 (patch)
tree8a4b65992148e55897e33c9b09c9664c2dda3e6b /platform/osx
parent7c3543380fe9ecd3d9a2d2dd3319e1c37e06820f (diff)
parent21a392341034169fff18db626e1c356545289af5 (diff)
Merge pull request #33967 from Calinou/add-os-is-window-focused
Add an `OS.is_window_focused()` getter
Diffstat (limited to 'platform/osx')
-rw-r--r--platform/osx/os_osx.h2
-rw-r--r--platform/osx/os_osx.mm18
2 files changed, 15 insertions, 5 deletions
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index 53b44af867..44c5412a39 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -121,6 +121,7 @@ public:
bool maximized;
bool zoomed;
bool resizable;
+ bool window_focused;
Size2 window_size;
Rect2 restore_rect;
@@ -274,6 +275,7 @@ public:
virtual bool is_window_maximized() const;
virtual void set_window_always_on_top(bool p_enabled);
virtual bool is_window_always_on_top() const;
+ virtual bool is_window_focused() const;
virtual void request_attention();
virtual String get_joy_guid(int p_device) const;
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index 7225fbf43d..95c103bd28 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -393,9 +393,6 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
}
- (void)windowDidBecomeKey:(NSNotification *)notification {
- //_GodotInputWindowFocus(window, GL_TRUE);
- //_GodotPlatformSetCursorMode(window, window->cursorMode);
-
if (OS_OSX::singleton->get_main_loop()) {
get_mouse_pos(
[OS_OSX::singleton->window_object mouseLocationOutsideOfEventStream],
@@ -404,25 +401,31 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
}
+
+ OS_OSX::singleton->window_focused = true;
}
- (void)windowDidResignKey:(NSNotification *)notification {
- //_GodotInputWindowFocus(window, GL_FALSE);
- //_GodotPlatformSetCursorMode(window, Godot_CURSOR_NORMAL);
if (OS_OSX::singleton->get_main_loop())
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
+
+ OS_OSX::singleton->window_focused = false;
}
- (void)windowDidMiniaturize:(NSNotification *)notification {
OS_OSX::singleton->wm_minimized(true);
if (OS_OSX::singleton->get_main_loop())
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
+
+ OS_OSX::singleton->window_focused = false;
};
- (void)windowDidDeminiaturize:(NSNotification *)notification {
OS_OSX::singleton->wm_minimized(false);
if (OS_OSX::singleton->get_main_loop())
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
+
+ OS_OSX::singleton->window_focused = true;
};
@end
@@ -2607,6 +2610,10 @@ bool OS_OSX::is_window_always_on_top() const {
return [window_object level] == NSFloatingWindowLevel;
}
+bool OS_OSX::is_window_focused() const {
+ return window_focused;
+}
+
void OS_OSX::request_attention() {
[NSApp requestUserAttention:NSCriticalRequest];
@@ -3059,6 +3066,7 @@ OS_OSX::OS_OSX() {
window_size = Vector2(1024, 600);
zoomed = false;
resizable = false;
+ window_focused = true;
Vector<Logger *> loggers;
loggers.push_back(memnew(OSXTerminalLogger));