Skip to content

Commit

Permalink
Merge pull request #83243 from bruvzg/macos_sys_def_menu_items
Browse files Browse the repository at this point in the history
[macOS] Fix crash when using system default menu shortcuts.
  • Loading branch information
akien-mga committed Oct 13, 2023
2 parents f6ff415 + 6371cc3 commit 577fbd8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion platform/macos/display_server_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@
}
}

if (value->callback != Callable()) {
if (value->callback.is_valid()) {
MenuCall mc;
mc.tag = value->meta;
mc.callback = value->callback;
Expand Down
26 changes: 14 additions & 12 deletions platform/macos/godot_menu_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ - (void)menuDidClose:(NSMenu *)menu {
- (void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item {
if (item) {
GodotMenuItem *value = [item representedObject];
if (value && value->hover_callback != Callable()) {
if (value && value->hover_callback.is_valid()) {
// If custom callback is set, use it.
value->hover_callback.call(value->meta);
}
Expand All @@ -73,19 +73,21 @@ - (BOOL)menuHasKeyEquivalent:(NSMenu *)menu forEvent:(NSEvent *)event target:(id

if (ev_modifiers == item_modifiers) {
GodotMenuItem *value = [menu_item representedObject];
if (value->key_callback != Callable()) {
// If custom callback is set, use it.
value->key_callback.call(value->meta);
} else {
// Otherwise redirect event to the engine.
if (DisplayServer::get_singleton()) {
[[[NSApplication sharedApplication] keyWindow] sendEvent:event];
if (value) {
if (value->key_callback.is_valid()) {
// If custom callback is set, use it.
value->key_callback.call(value->meta);
} else {
// Otherwise redirect event to the engine.
if (DisplayServer::get_singleton()) {
[[[NSApplication sharedApplication] keyWindow] sendEvent:event];
}
}
}

// Suppress default menu action.
*target = self;
*action = @selector(doNothing:);
// Suppress default menu action.
*target = self;
*action = @selector(doNothing:);
}
return YES;
}
}
Expand Down

0 comments on commit 577fbd8

Please sign in to comment.