1
0
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:
Pāvels Nadtočajevs
2025-03-26 20:27:11 +02:00
parent 594d64ec24
commit 5665e55f9a
5 changed files with 23 additions and 13 deletions

View File

@@ -64,7 +64,7 @@
#undef CursorShape
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_

View File

@@ -81,7 +81,7 @@
} break;
}
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
DisplayServerMacOS *ds = Object::cast_to<DisplayServerMacOS>(DisplayServer::get_singleton());
if (ds && keycode != Key::NONE) {
DisplayServerMacOS::KeyEvent ke;
@@ -109,7 +109,7 @@
[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 ([event type] == NSEventTypeLeftMouseDown || [event type] == NSEventTypeRightMouseDown || [event type] == NSEventTypeOtherMouseDown) {
if (ds->mouse_process_popups()) {

View File

@@ -48,7 +48,7 @@
- (void)searchForItemsWithSearchString:(NSString *)searchString resultLimit:(NSInteger)resultLimit matchedItemHandler:(void (^)(NSArray *items))handleMatchedItems {
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()) {
Callable cb = ds->_help_get_search_callback();
@@ -77,7 +77,7 @@
}
- (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()) {
Callable cb = ds->_help_get_action_callback();
@@ -118,7 +118,7 @@
}
- (void)system_theme_changed:(NSNotification *)notification {
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
DisplayServerMacOS *ds = Object::cast_to<DisplayServerMacOS>(DisplayServer::get_singleton());
if (ds) {
ds->emit_system_theme_changed();
}
@@ -199,7 +199,7 @@
}
- (void)applicationDidResignActive:(NSNotification *)notification {
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
DisplayServerMacOS *ds = Object::cast_to<DisplayServerMacOS>(DisplayServer::get_singleton());
if (ds) {
ds->mouse_process_popups(true);
}
@@ -215,7 +215,7 @@
}
- (void)globalMenuCallback:(id)sender {
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
DisplayServerMacOS *ds = Object::cast_to<DisplayServerMacOS>(DisplayServer::get_singleton());
if (ds) {
return ds->menu_callback(sender);
}
@@ -239,7 +239,7 @@
}
- (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)) {
ds->send_window_event(ds->get_window(DisplayServerMacOS::MAIN_WINDOW_ID), DisplayServerMacOS::WINDOW_EVENT_CLOSE_REQUEST);
}

View File

@@ -46,6 +46,7 @@ class OS_MacOS : public OS_Unix {
id delegate = nullptr;
bool should_terminate = false;
bool main_stared = false;
JoypadApple *joypad_apple = nullptr;

View File

@@ -51,8 +51,13 @@ void OS_MacOS::pre_wait_observer_cb(CFRunLoopObserverRef p_observer, CFRunLoopAc
@autoreleasepool {
@try {
if (DisplayServer::get_singleton()) {
static_cast<DisplayServerMacOS *>(DisplayServer::get_singleton())->_process_events(false); // Get rid of pending events.
// 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();
@@ -839,6 +844,8 @@ void OS_MacOS::start_main() {
}
if (err == OK) {
main_stared = true;
int ret;
@autoreleasepool {
ret = Main::start();
@@ -883,9 +890,11 @@ void OS_MacOS::cleanup() {
if (main_loop) {
main_loop->finalize();
}
if (main_stared) {
@autoreleasepool {
Main::cleanup();
}
}
}
OS_MacOS::OS_MacOS(const char *p_execpath, int p_argc, char **p_argv) {