summaryrefslogtreecommitdiff
path: root/platform/osx/os_osx.mm
diff options
context:
space:
mode:
authorHugo Locurcio <hugo.locurcio@hugo.pro>2019-11-28 13:41:07 +0100
committerHugo Locurcio <hugo.locurcio@hugo.pro>2019-11-28 16:42:51 +0100
commit21a392341034169fff18db626e1c356545289af5 (patch)
tree945dd4cd61bdfd052e9e9ec1302d0c9a977b4c19 /platform/osx/os_osx.mm
parent7735af7e768e16efb4b3b6de1c72c3dfb50c9412 (diff)
Add an `OS.is_window_focused()` getter
This makes it possible to know whether the window is focused at a given time, without having to track the focus state manually using `NOTIFICATION_WM_FOCUS_IN` and `NOTIFICATION_WM_FOCUS_OUT`. This partially addresses #33928.
Diffstat (limited to 'platform/osx/os_osx.mm')
-rw-r--r--platform/osx/os_osx.mm18
1 files changed, 13 insertions, 5 deletions
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index dac6721fb4..17836e9f94 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -397,9 +397,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],
@@ -408,25 +405,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
@@ -2618,6 +2621,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];
@@ -3070,6 +3077,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));