2022-01-26 17:01:27 +08:00
|
|
|
/**************************************************************************/
|
|
|
|
/* godot_window_delegate.mm */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
#include "godot_window_delegate.h"
|
|
|
|
|
2022-07-20 14:28:22 +08:00
|
|
|
#include "display_server_macos.h"
|
2022-09-20 16:12:49 +08:00
|
|
|
#include "godot_button_view.h"
|
2022-09-22 17:06:11 +08:00
|
|
|
#include "godot_window.h"
|
2022-01-26 17:01:27 +08:00
|
|
|
|
|
|
|
@implementation GodotWindowDelegate
|
|
|
|
|
|
|
|
- (void)setWindowID:(DisplayServer::WindowID)wid {
|
|
|
|
window_id = wid;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)windowShouldClose:(id)sender {
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
2022-01-26 17:01:27 +08:00
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2022-07-20 14:28:22 +08:00
|
|
|
ds->send_window_event(ds->get_window(window_id), DisplayServerMacOS::WINDOW_EVENT_CLOSE_REQUEST);
|
2022-01-26 17:01:27 +08:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowWillClose:(NSNotification *)notification {
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
2022-01-26 17:01:27 +08:00
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-24 17:21:23 +08:00
|
|
|
ds->popup_close(window_id);
|
|
|
|
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
2022-01-26 17:01:27 +08:00
|
|
|
while (wd.transient_children.size()) {
|
2022-07-20 14:28:22 +08:00
|
|
|
ds->window_set_transient(*wd.transient_children.begin(), DisplayServerMacOS::INVALID_WINDOW_ID);
|
2022-01-26 17:01:27 +08:00
|
|
|
}
|
|
|
|
|
2022-07-20 14:28:22 +08:00
|
|
|
if (wd.transient_parent != DisplayServerMacOS::INVALID_WINDOW_ID) {
|
|
|
|
ds->window_set_transient(window_id, DisplayServerMacOS::INVALID_WINDOW_ID);
|
2022-01-26 17:01:27 +08:00
|
|
|
}
|
|
|
|
|
2023-08-09 15:23:57 +08:00
|
|
|
ds->mouse_exit_window(window_id);
|
2022-01-26 17:01:27 +08:00
|
|
|
ds->window_destroy(window_id);
|
|
|
|
}
|
|
|
|
|
2022-12-09 02:34:15 +08:00
|
|
|
- (void)windowWillEnterFullScreen:(NSNotification *)notification {
|
2022-09-22 17:06:11 +08:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
2022-12-09 02:34:15 +08:00
|
|
|
return;
|
2022-09-22 17:06:11 +08:00
|
|
|
}
|
|
|
|
|
2022-12-09 02:34:15 +08:00
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
|
|
|
wd.fs_transition = true;
|
2023-11-10 05:25:48 +08:00
|
|
|
|
|
|
|
// Temporary disable borderless and transparent state.
|
|
|
|
if ([wd.window_object styleMask] == NSWindowStyleMaskBorderless) {
|
|
|
|
[wd.window_object setStyleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable];
|
|
|
|
}
|
|
|
|
if (wd.layered_window) {
|
|
|
|
ds->set_window_per_pixel_transparency_enabled(false, window_id);
|
|
|
|
}
|
2022-09-22 17:06:11 +08:00
|
|
|
}
|
|
|
|
|
2022-12-09 02:34:15 +08:00
|
|
|
- (void)windowDidFailToEnterFullScreen:(NSWindow *)window {
|
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
|
|
|
wd.fs_transition = false;
|
2022-09-22 17:06:11 +08:00
|
|
|
}
|
|
|
|
|
2022-01-26 17:01:27 +08:00
|
|
|
- (void)windowDidEnterFullScreen:(NSNotification *)notification {
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
2022-01-26 17:01:27 +08:00
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
2022-01-26 17:01:27 +08:00
|
|
|
wd.fullscreen = true;
|
2022-12-09 02:34:15 +08:00
|
|
|
wd.fs_transition = false;
|
2022-09-21 16:15:19 +08:00
|
|
|
|
2022-01-26 17:01:27 +08:00
|
|
|
// Reset window size limits.
|
|
|
|
[wd.window_object setContentMinSize:NSMakeSize(0, 0)];
|
|
|
|
[wd.window_object setContentMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
|
|
|
|
|
2022-09-21 16:15:19 +08:00
|
|
|
// Reset custom window buttons.
|
|
|
|
if ([wd.window_object styleMask] & NSWindowStyleMaskFullSizeContentView) {
|
|
|
|
ds->window_set_custom_window_buttons(wd, false);
|
|
|
|
}
|
|
|
|
|
2022-09-22 17:06:11 +08:00
|
|
|
ds->send_window_event(wd, DisplayServerMacOS::WINDOW_EVENT_TITLEBAR_CHANGE);
|
2022-12-09 02:34:15 +08:00
|
|
|
|
|
|
|
// Force window resize event and redraw.
|
|
|
|
[self windowDidResize:notification];
|
2022-09-22 17:06:11 +08:00
|
|
|
}
|
|
|
|
|
2022-12-09 02:34:15 +08:00
|
|
|
- (void)windowWillExitFullScreen:(NSNotification *)notification {
|
2022-09-22 17:06:11 +08:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
2022-12-09 02:34:15 +08:00
|
|
|
return;
|
2022-09-22 17:06:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
2022-12-09 02:34:15 +08:00
|
|
|
wd.fs_transition = true;
|
2022-09-22 17:06:11 +08:00
|
|
|
|
|
|
|
// Restore custom window buttons.
|
|
|
|
if ([wd.window_object styleMask] & NSWindowStyleMaskFullSizeContentView) {
|
|
|
|
ds->window_set_custom_window_buttons(wd, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
ds->send_window_event(wd, DisplayServerMacOS::WINDOW_EVENT_TITLEBAR_CHANGE);
|
|
|
|
}
|
|
|
|
|
2022-12-09 02:34:15 +08:00
|
|
|
- (void)windowDidFailToExitFullScreen:(NSWindow *)window {
|
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
|
|
|
wd.fs_transition = false;
|
|
|
|
|
|
|
|
if ([wd.window_object styleMask] & NSWindowStyleMaskFullSizeContentView) {
|
|
|
|
ds->window_set_custom_window_buttons(wd, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
ds->send_window_event(wd, DisplayServerMacOS::WINDOW_EVENT_TITLEBAR_CHANGE);
|
2022-01-26 17:01:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidExitFullScreen:(NSNotification *)notification {
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
2022-01-26 17:01:27 +08:00
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
2022-11-04 22:23:01 +08:00
|
|
|
if (wd.exclusive_fullscreen) {
|
2023-09-27 14:01:42 +08:00
|
|
|
ds->update_presentation_mode();
|
2022-11-04 22:23:01 +08:00
|
|
|
}
|
|
|
|
|
2022-01-26 17:01:27 +08:00
|
|
|
wd.fullscreen = false;
|
2022-11-04 22:23:01 +08:00
|
|
|
wd.exclusive_fullscreen = false;
|
2022-12-09 02:34:15 +08:00
|
|
|
wd.fs_transition = false;
|
2022-09-22 17:06:11 +08:00
|
|
|
|
2022-01-26 17:01:27 +08:00
|
|
|
// Set window size limits.
|
|
|
|
const float scale = ds->screen_get_max_scale();
|
|
|
|
if (wd.min_size != Size2i()) {
|
|
|
|
Size2i size = wd.min_size / scale;
|
|
|
|
[wd.window_object setContentMinSize:NSMakeSize(size.x, size.y)];
|
|
|
|
}
|
|
|
|
if (wd.max_size != Size2i()) {
|
|
|
|
Size2i size = wd.max_size / scale;
|
|
|
|
[wd.window_object setContentMaxSize:NSMakeSize(size.x, size.y)];
|
|
|
|
}
|
|
|
|
|
2023-11-10 05:25:48 +08:00
|
|
|
// Restore borderless, transparent and resizability state.
|
|
|
|
if (wd.borderless || wd.layered_window) {
|
|
|
|
[wd.window_object setStyleMask:NSWindowStyleMaskBorderless];
|
|
|
|
} else {
|
|
|
|
[wd.window_object setStyleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | (wd.extend_to_title ? NSWindowStyleMaskFullSizeContentView : 0) | (wd.resize_disabled ? 0 : NSWindowStyleMaskResizable)];
|
|
|
|
}
|
|
|
|
if (wd.layered_window) {
|
|
|
|
ds->set_window_per_pixel_transparency_enabled(true, window_id);
|
2022-01-26 17:01:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Restore on-top state.
|
|
|
|
if (wd.on_top) {
|
|
|
|
[wd.window_object setLevel:NSFloatingWindowLevel];
|
|
|
|
}
|
|
|
|
|
2022-12-09 02:34:15 +08:00
|
|
|
// Force window resize event and redraw.
|
2022-01-26 17:01:27 +08:00
|
|
|
[self windowDidResize:notification];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidChangeBackingProperties:(NSNotification *)notification {
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
2022-01-26 17:01:27 +08:00
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
2022-01-26 17:01:27 +08:00
|
|
|
|
|
|
|
CGFloat new_scale_factor = [wd.window_object backingScaleFactor];
|
|
|
|
CGFloat old_scale_factor = [[[notification userInfo] objectForKey:@"NSBackingPropertyOldScaleFactorKey"] doubleValue];
|
|
|
|
|
|
|
|
if (new_scale_factor != old_scale_factor) {
|
|
|
|
// Set new display scale and window size.
|
|
|
|
const float scale = ds->screen_get_max_scale();
|
|
|
|
const NSRect content_rect = [wd.window_view frame];
|
|
|
|
|
|
|
|
wd.size.width = content_rect.size.width * scale;
|
|
|
|
wd.size.height = content_rect.size.height * scale;
|
|
|
|
|
2022-07-20 14:28:22 +08:00
|
|
|
ds->send_window_event(wd, DisplayServerMacOS::WINDOW_EVENT_DPI_CHANGE);
|
2022-01-26 17:01:27 +08:00
|
|
|
|
|
|
|
CALayer *layer = [wd.window_view layer];
|
|
|
|
if (layer) {
|
|
|
|
layer.contentsScale = scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Force window resize event
|
|
|
|
[self windowDidResize:notification];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-04 16:25:39 +08:00
|
|
|
- (void)windowWillStartLiveResize:(NSNotification *)notification {
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
2022-09-13 20:33:51 +08:00
|
|
|
if (ds && ds->has_window(window_id)) {
|
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
|
|
|
wd.last_frame_rect = [wd.window_object frame];
|
2022-03-04 16:25:39 +08:00
|
|
|
ds->set_is_resizing(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidEndLiveResize:(NSNotification *)notification {
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
2022-03-04 16:25:39 +08:00
|
|
|
if (ds) {
|
|
|
|
ds->set_is_resizing(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-26 17:01:27 +08:00
|
|
|
- (void)windowDidResize:(NSNotification *)notification {
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
2022-01-26 17:01:27 +08:00
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
2022-01-26 17:01:27 +08:00
|
|
|
const NSRect content_rect = [wd.window_view frame];
|
|
|
|
const float scale = ds->screen_get_max_scale();
|
|
|
|
wd.size.width = content_rect.size.width * scale;
|
|
|
|
wd.size.height = content_rect.size.height * scale;
|
|
|
|
|
|
|
|
CALayer *layer = [wd.window_view layer];
|
|
|
|
if (layer) {
|
|
|
|
layer.contentsScale = scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
ds->window_resize(window_id, wd.size.width, wd.size.height);
|
|
|
|
|
|
|
|
if (!wd.rect_changed_callback.is_null()) {
|
2023-07-11 22:18:10 +08:00
|
|
|
wd.rect_changed_callback.call(Rect2i(ds->window_get_position(window_id), ds->window_get_size(window_id)));
|
2022-01-26 17:01:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-20 04:25:43 +08:00
|
|
|
- (void)windowDidChangeScreen:(NSNotification *)notification {
|
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ds->reparent_check(window_id);
|
|
|
|
}
|
|
|
|
|
2022-01-26 17:01:27 +08:00
|
|
|
- (void)windowDidMove:(NSNotification *)notification {
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
2022-01-26 17:01:27 +08:00
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
2022-01-26 17:01:27 +08:00
|
|
|
ds->release_pressed_events();
|
|
|
|
|
|
|
|
if (!wd.rect_changed_callback.is_null()) {
|
2023-07-11 22:18:10 +08:00
|
|
|
wd.rect_changed_callback.call(Rect2i(ds->window_get_position(window_id), ds->window_get_size(window_id)));
|
2022-01-26 17:01:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidBecomeKey:(NSNotification *)notification {
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
2022-01-26 17:01:27 +08:00
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
2022-01-26 17:01:27 +08:00
|
|
|
|
2022-09-20 16:12:49 +08:00
|
|
|
if (wd.window_button_view) {
|
|
|
|
[(GodotButtonView *)wd.window_button_view displayButtons];
|
|
|
|
}
|
|
|
|
|
2022-01-26 17:01:27 +08:00
|
|
|
if (ds->mouse_get_mode() == DisplayServer::MOUSE_MODE_CAPTURED) {
|
|
|
|
const NSRect content_rect = [wd.window_view frame];
|
|
|
|
NSRect point_in_window_rect = NSMakeRect(content_rect.size.width / 2, content_rect.size.height / 2, 0, 0);
|
|
|
|
NSPoint point_on_screen = [[wd.window_view window] convertRectToScreen:point_in_window_rect].origin;
|
|
|
|
CGPoint mouse_warp_pos = { point_on_screen.x, CGDisplayBounds(CGMainDisplayID()).size.height - point_on_screen.y };
|
|
|
|
CGWarpMouseCursorPosition(mouse_warp_pos);
|
|
|
|
} else {
|
|
|
|
ds->update_mouse_pos(wd, [wd.window_object mouseLocationOutsideOfEventStream]);
|
|
|
|
}
|
|
|
|
|
2022-12-09 02:34:15 +08:00
|
|
|
[self windowDidResize:notification]; // Emit resize event, to ensure content is resized if the window was resized while it was hidden.
|
|
|
|
|
2023-06-15 15:53:31 +08:00
|
|
|
wd.focused = true;
|
2022-01-26 17:01:27 +08:00
|
|
|
ds->set_last_focused_window(window_id);
|
2022-07-20 14:28:22 +08:00
|
|
|
ds->send_window_event(wd, DisplayServerMacOS::WINDOW_EVENT_FOCUS_IN);
|
2022-01-26 17:01:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidResignKey:(NSNotification *)notification {
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
2022-01-26 17:01:27 +08:00
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
2022-01-26 17:01:27 +08:00
|
|
|
|
2022-09-20 16:12:49 +08:00
|
|
|
if (wd.window_button_view) {
|
|
|
|
[(GodotButtonView *)wd.window_button_view displayButtons];
|
|
|
|
}
|
|
|
|
|
2023-06-15 15:53:31 +08:00
|
|
|
wd.focused = false;
|
2022-01-26 17:01:27 +08:00
|
|
|
ds->release_pressed_events();
|
2022-07-20 14:28:22 +08:00
|
|
|
ds->send_window_event(wd, DisplayServerMacOS::WINDOW_EVENT_FOCUS_OUT);
|
2022-01-26 17:01:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidMiniaturize:(NSNotification *)notification {
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
2022-01-26 17:01:27 +08:00
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
2022-01-26 17:01:27 +08:00
|
|
|
|
2023-06-15 15:53:31 +08:00
|
|
|
wd.focused = false;
|
2022-01-26 17:01:27 +08:00
|
|
|
ds->release_pressed_events();
|
2022-07-20 14:28:22 +08:00
|
|
|
ds->send_window_event(wd, DisplayServerMacOS::WINDOW_EVENT_FOCUS_OUT);
|
2022-01-26 17:01:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidDeminiaturize:(NSNotification *)notification {
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
2022-01-26 17:01:27 +08:00
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-20 14:28:22 +08:00
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
2024-01-22 17:35:37 +08:00
|
|
|
wd.is_visible = ([wd.window_object occlusionState] & NSWindowOcclusionStateVisible) && [wd.window_object isVisible];
|
2023-06-15 15:53:31 +08:00
|
|
|
if ([wd.window_object isKeyWindow]) {
|
|
|
|
wd.focused = true;
|
|
|
|
ds->set_last_focused_window(window_id);
|
|
|
|
ds->send_window_event(wd, DisplayServerMacOS::WINDOW_EVENT_FOCUS_IN);
|
|
|
|
}
|
2022-01-26 17:01:27 +08:00
|
|
|
}
|
|
|
|
|
2023-10-10 17:06:08 +08:00
|
|
|
- (void)windowDidChangeOcclusionState:(NSNotification *)notification {
|
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
|
|
|
if (!ds || !ds->has_window(window_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
|
|
|
|
wd.is_visible = ([wd.window_object occlusionState] & NSWindowOcclusionStateVisible) && [wd.window_object isVisible];
|
|
|
|
}
|
|
|
|
|
2022-01-26 17:01:27 +08:00
|
|
|
@end
|