From b1d8bf32eeb83aed8b92a5552c6a1ed59111a37a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Mon, 14 Jul 2025 10:03:14 +0300 Subject: [PATCH] [macOS] Fix disabling native menu items in system menus. --- platform/macos/godot_application_delegate.h | 2 +- platform/macos/godot_application_delegate.mm | 11 +++++++++++ platform/macos/godot_menu_item.h | 1 + platform/macos/godot_menu_item.mm | 1 + platform/macos/native_menu_macos.mm | 2 ++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/platform/macos/godot_application_delegate.h b/platform/macos/godot_application_delegate.h index 34bd2d878d5..17fb5f65fd6 100644 --- a/platform/macos/godot_application_delegate.h +++ b/platform/macos/godot_application_delegate.h @@ -37,7 +37,7 @@ class OS_MacOS_NSApp; -@interface GodotApplicationDelegate : NSObject +@interface GodotApplicationDelegate : NSObject - (GodotApplicationDelegate *)initWithOS:(OS_MacOS_NSApp *)os; diff --git a/platform/macos/godot_application_delegate.mm b/platform/macos/godot_application_delegate.mm index c166f3996e5..23bacb21f8b 100644 --- a/platform/macos/godot_application_delegate.mm +++ b/platform/macos/godot_application_delegate.mm @@ -31,6 +31,7 @@ #import "godot_application_delegate.h" #import "display_server_macos.h" +#import "godot_menu_item.h" #import "key_mapping_macos.h" #import "native_menu_macos.h" #import "os_macos.h" @@ -282,6 +283,16 @@ constexpr static NSEventModifierFlags FLAGS = NSEventModifierFlagCommand | NSEve } } +- (BOOL)validateMenuItem:(NSMenuItem *)item { + if (item) { + GodotMenuItem *value = [item representedObject]; + if (value) { + return value->enabled; + } + } + return YES; +} + - (void)globalMenuCallback:(id)sender { DisplayServerMacOS *ds = Object::cast_to(DisplayServer::get_singleton()); if (ds) { diff --git a/platform/macos/godot_menu_item.h b/platform/macos/godot_menu_item.h index 33215063c76..23bddeef360 100644 --- a/platform/macos/godot_menu_item.h +++ b/platform/macos/godot_menu_item.h @@ -53,6 +53,7 @@ enum GlobalMenuCheckType { Key accel; GlobalMenuCheckType checkable_type; bool checked; + bool enabled; int max_states; int state; Ref img; diff --git a/platform/macos/godot_menu_item.mm b/platform/macos/godot_menu_item.mm index 49495676271..1450d2fccd0 100644 --- a/platform/macos/godot_menu_item.mm +++ b/platform/macos/godot_menu_item.mm @@ -38,6 +38,7 @@ self->callback = Callable(); self->key_callback = Callable(); self->checkable_type = GlobalMenuCheckType::CHECKABLE_TYPE_NONE; + self->enabled = true; self->checked = false; self->max_states = 0; self->state = 0; diff --git a/platform/macos/native_menu_macos.mm b/platform/macos/native_menu_macos.mm index 821969e247d..613799bef2b 100644 --- a/platform/macos/native_menu_macos.mm +++ b/platform/macos/native_menu_macos.mm @@ -1204,6 +1204,8 @@ void NativeMenuMacOS::set_item_disabled(const RID &p_rid, int p_idx, bool p_disa ERR_FAIL_COND(p_idx >= item_start + item_count); NSMenuItem *menu_item = [md->menu itemAtIndex:p_idx]; if (menu_item) { + GodotMenuItem *obj = [menu_item representedObject]; + obj->enabled = !p_disabled; [menu_item setEnabled:(!p_disabled)]; } }