You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
[macOS] Fix running with DisplayServerHeadless.
This commit is contained in:
@@ -64,7 +64,7 @@
|
|||||||
#undef CursorShape
|
#undef CursorShape
|
||||||
|
|
||||||
class DisplayServerMacOS : public DisplayServer {
|
class DisplayServerMacOS : public DisplayServer {
|
||||||
// No need to register with GDCLASS, it's platform-specific and nothing is added.
|
GDCLASS(DisplayServerMacOS, DisplayServer); // Note: required for Object::cast_to.
|
||||||
|
|
||||||
_THREAD_SAFE_CLASS_
|
_THREAD_SAFE_CLASS_
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@
|
|||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
DisplayServerMacOS *ds = Object::cast_to<DisplayServerMacOS>(DisplayServer::get_singleton());
|
||||||
if (ds && keycode != Key::NONE) {
|
if (ds && keycode != Key::NONE) {
|
||||||
DisplayServerMacOS::KeyEvent ke;
|
DisplayServerMacOS::KeyEvent ke;
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@
|
|||||||
[self mediaKeyEvent:keyCode state:keyState repeat:keyRepeat];
|
[self mediaKeyEvent:keyCode state:keyState repeat:keyRepeat];
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
DisplayServerMacOS *ds = Object::cast_to<DisplayServerMacOS>(DisplayServer::get_singleton());
|
||||||
if (ds) {
|
if (ds) {
|
||||||
if ([event type] == NSEventTypeLeftMouseDown || [event type] == NSEventTypeRightMouseDown || [event type] == NSEventTypeOtherMouseDown) {
|
if ([event type] == NSEventTypeLeftMouseDown || [event type] == NSEventTypeRightMouseDown || [event type] == NSEventTypeOtherMouseDown) {
|
||||||
if (ds->mouse_process_popups()) {
|
if (ds->mouse_process_popups()) {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
- (void)searchForItemsWithSearchString:(NSString *)searchString resultLimit:(NSInteger)resultLimit matchedItemHandler:(void (^)(NSArray *items))handleMatchedItems {
|
- (void)searchForItemsWithSearchString:(NSString *)searchString resultLimit:(NSInteger)resultLimit matchedItemHandler:(void (^)(NSArray *items))handleMatchedItems {
|
||||||
NSMutableArray *found_items = [[NSMutableArray alloc] init];
|
NSMutableArray *found_items = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
DisplayServerMacOS *ds = Object::cast_to<DisplayServerMacOS>(DisplayServer::get_singleton());
|
||||||
if (ds && ds->_help_get_search_callback().is_valid()) {
|
if (ds && ds->_help_get_search_callback().is_valid()) {
|
||||||
Callable cb = ds->_help_get_search_callback();
|
Callable cb = ds->_help_get_search_callback();
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)performActionForItem:(id)item {
|
- (void)performActionForItem:(id)item {
|
||||||
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
DisplayServerMacOS *ds = Object::cast_to<DisplayServerMacOS>(DisplayServer::get_singleton());
|
||||||
if (ds && ds->_help_get_action_callback().is_valid()) {
|
if (ds && ds->_help_get_action_callback().is_valid()) {
|
||||||
Callable cb = ds->_help_get_action_callback();
|
Callable cb = ds->_help_get_action_callback();
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)system_theme_changed:(NSNotification *)notification {
|
- (void)system_theme_changed:(NSNotification *)notification {
|
||||||
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
DisplayServerMacOS *ds = Object::cast_to<DisplayServerMacOS>(DisplayServer::get_singleton());
|
||||||
if (ds) {
|
if (ds) {
|
||||||
ds->emit_system_theme_changed();
|
ds->emit_system_theme_changed();
|
||||||
}
|
}
|
||||||
@@ -199,7 +199,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)applicationDidResignActive:(NSNotification *)notification {
|
- (void)applicationDidResignActive:(NSNotification *)notification {
|
||||||
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
DisplayServerMacOS *ds = Object::cast_to<DisplayServerMacOS>(DisplayServer::get_singleton());
|
||||||
if (ds) {
|
if (ds) {
|
||||||
ds->mouse_process_popups(true);
|
ds->mouse_process_popups(true);
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)globalMenuCallback:(id)sender {
|
- (void)globalMenuCallback:(id)sender {
|
||||||
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
DisplayServerMacOS *ds = Object::cast_to<DisplayServerMacOS>(DisplayServer::get_singleton());
|
||||||
if (ds) {
|
if (ds) {
|
||||||
return ds->menu_callback(sender);
|
return ds->menu_callback(sender);
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
|
||||||
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
DisplayServerMacOS *ds = Object::cast_to<DisplayServerMacOS>(DisplayServer::get_singleton());
|
||||||
if (ds && ds->has_window(DisplayServerMacOS::MAIN_WINDOW_ID)) {
|
if (ds && ds->has_window(DisplayServerMacOS::MAIN_WINDOW_ID)) {
|
||||||
ds->send_window_event(ds->get_window(DisplayServerMacOS::MAIN_WINDOW_ID), DisplayServerMacOS::WINDOW_EVENT_CLOSE_REQUEST);
|
ds->send_window_event(ds->get_window(DisplayServerMacOS::MAIN_WINDOW_ID), DisplayServerMacOS::WINDOW_EVENT_CLOSE_REQUEST);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class OS_MacOS : public OS_Unix {
|
|||||||
|
|
||||||
id delegate = nullptr;
|
id delegate = nullptr;
|
||||||
bool should_terminate = false;
|
bool should_terminate = false;
|
||||||
|
bool main_stared = false;
|
||||||
|
|
||||||
JoypadApple *joypad_apple = nullptr;
|
JoypadApple *joypad_apple = nullptr;
|
||||||
|
|
||||||
|
|||||||
@@ -51,8 +51,13 @@ void OS_MacOS::pre_wait_observer_cb(CFRunLoopObserverRef p_observer, CFRunLoopAc
|
|||||||
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
@try {
|
@try {
|
||||||
if (DisplayServer::get_singleton()) {
|
// Get rid of pending events.
|
||||||
static_cast<DisplayServerMacOS *>(DisplayServer::get_singleton())->_process_events(false); // Get rid of pending events.
|
DisplayServer *ds = DisplayServer::get_singleton();
|
||||||
|
DisplayServerMacOS *ds_mac = Object::cast_to<DisplayServerMacOS>(ds);
|
||||||
|
if (ds_mac) {
|
||||||
|
ds_mac->_process_events(false);
|
||||||
|
} else if (ds) {
|
||||||
|
ds->process_events();
|
||||||
}
|
}
|
||||||
os->joypad_apple->process_joypads();
|
os->joypad_apple->process_joypads();
|
||||||
|
|
||||||
@@ -839,6 +844,8 @@ void OS_MacOS::start_main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (err == OK) {
|
if (err == OK) {
|
||||||
|
main_stared = true;
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
ret = Main::start();
|
ret = Main::start();
|
||||||
@@ -883,10 +890,12 @@ void OS_MacOS::cleanup() {
|
|||||||
if (main_loop) {
|
if (main_loop) {
|
||||||
main_loop->finalize();
|
main_loop->finalize();
|
||||||
}
|
}
|
||||||
|
if (main_stared) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
Main::cleanup();
|
Main::cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
OS_MacOS::OS_MacOS(const char *p_execpath, int p_argc, char **p_argv) {
|
OS_MacOS::OS_MacOS(const char *p_execpath, int p_argc, char **p_argv) {
|
||||||
execpath = p_execpath;
|
execpath = p_execpath;
|
||||||
|
|||||||
Reference in New Issue
Block a user