Debian Codegraph @

platform/macos/godot_window.mm

raw
1 /**************************************************************************/
2 /* godot_window.mm */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #import "godot_window.h"
32
33 #import "display_server_macos.h"
34
35 @implementation GodotWindow
36
37 - (id)init {
38 self = [super init];
39 window_id = DisplayServer::INVALID_WINDOW_ID;
40 anim_duration = -1.0f;
41 return self;
42 }
43
44 - (void)setAnimDuration:(NSTimeInterval)duration {
45 anim_duration = duration;
46 }
47
48 - (NSTimeInterval)animationResizeTime:(NSRect)newFrame {
49 if (anim_duration > 0) {
50 return anim_duration;
51 } else {
52 return [super animationResizeTime:newFrame];
53 }
54 }
55
56 - (void)setWindowID:(DisplayServerMacOS::WindowID)wid {
57 window_id = wid;
58 }
59
60 - (BOOL)canBecomeKeyWindow {
61 // Required for NSWindowStyleMaskBorderless windows.
62 DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
63 if (!ds || !ds->has_window(window_id)) {
64 return YES;
65 }
66
67 DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
68 return !wd.no_focus;
69 }
70
71 - (BOOL)canBecomeMainWindow {
72 // Required for NSWindowStyleMaskBorderless windows.
73 DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
74 if (!ds || !ds->has_window(window_id)) {
75 return YES;
76 }
77
78 DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
79 return !wd.no_focus && !wd.is_popup;
80 }
81
82 @end