Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
macOS: SculptForge > Preferences... in the app menu opens Preferences (#111, @fenixpoints)
islandmedeccc99a46f7e
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 6379c938..d4054396 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -1,5 +1,8 @@cmake_minimum_required(VERSION 3.24)project(SculptForge VERSION 0.11.15 LANGUAGES C CXX)+if(APPLE)+ enable_language(OBJCXX) # src/app/MacAppMenu.mm (here: enabled later, CMake leaves its rule variables unset)+endif()# "beta.1" while this is a beta of that version (title bar and About: "0.11.0 Beta 1"), "" for a stable release.# scripts/release.sh sets it; release.yml checks the tag against both (v0.11.0-beta.1).set(SCULPTFORGE_PRERELEASE "")@@ -532,6 +535,10 @@ if(SCULPTFORGE_BUILD_APP)endif()endif()if(APPLE)+ # SculptForge > Preferences... in the app menu (#111): SDL's item, given its action (src/app/MacAppMenu.h).+ target_sources(sculptforge PRIVATE src/app/MacAppMenu.mm)+ set_source_files_properties(src/app/MacAppMenu.mm PROPERTIES SKIP_PRECOMPILE_HEADERS ON)+ target_link_libraries(sculptforge PRIVATE "-framework Cocoa")# App icon: assets/branding/sculptforge.icns (tools/brand/make_icons.py: the SF mark on Apple's icon grid).set(ICNS ${CMAKE_CURRENT_SOURCE_DIR}/assets/branding/sculptforge.icns)target_sources(sculptforge PRIVATE ${ICNS})diff --git a/changes/fix-mac-prefs-menu.md b/changes/fix-mac-prefs-menu.mdnew file mode 100644index 00000000..ea92459b--- /dev/null+++ b/changes/fix-mac-prefs-menu.md@@ -0,0 +1,11 @@+---+whats_new: **macOS**: **SculptForge > Preferences...** in the app menu opens Preferences (it was greyed out).+fixed: macOS: **SculptForge > Preferences...** in the app menu was greyed out; it now opens Preferences, as Cmd+, and+ Edit > Preferences do (#111, thanks @fenixpoints).+testers:+ - macOS: open the SculptForge menu (next to the Apple menu). Preferences... is enabled; click it: Preferences opens once.+ - macOS: press Cmd+,: Preferences opens once, not twice (and Edit > Preferences, in the Classic layout, still opens it).+---+SDL builds the app menu with the item's action nil; src/app/MacAppMenu.mm gives it one after SDL_Init. The click+only sets a flag and wakes the loop; the next frame runs ui.palette.preferences. Cmd+, reaches the app through SDL+first and the menu after, so the item ignores its own key equivalent (tests/test_mac_menu.cpp).diff --git a/src/app/App.cpp b/src/app/App.cppindex 37958502..b6efd34a 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -30,6 +30,7 @@#include "app/Theme.h"#include "app/Ui.h"#include "app/UserGlyphs.h"+#include "app/MacAppMenu.h"#include "app/UiServe.h"#include "app/UserData.h"@@ -153,6 +154,7 @@ bool App::init(const AppOptions& options) {SDL_Log("SDL_Init failed: %s", SDL_GetError());return false;}+ if (!headless) macmenu::install(); // SculptForge > Preferences... in the macOS app menu (#111)// Joysticks for a 3Dconnexion SpaceMouse (SpaceMouse.cpp). Not fatal: the app works without them.if (!headless || !options.uiTest.empty()) {if (SDL_InitSubSystem(SDL_INIT_JOYSTICK)) spaceMouseScan();@@ -1202,6 +1204,11 @@ int App::run() {ImGui_ImplSDL3_NewFrame();keepImGuiOnPen();ImGui::NewFrame();+ if (macmenu::takePreferencesRequest()) // the macOS app menu's Preferences... (MacAppMenu.h)+ if (const Action* a = actions().find("ui.palette.preferences"); a && a->run) {+ actions().touch(a->id);+ a->run();+ }drawUi();drawHardwareProfileOverlay();ImGui::Render();diff --git a/src/app/MacAppMenu.h b/src/app/MacAppMenu.hnew file mode 100644index 00000000..285143ba--- /dev/null+++ b/src/app/MacAppMenu.h@@ -0,0 +1,31 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// SculptForge > Preferences... in the macOS app menu (#111). SDL builds that menu with the item greyed out+// (no action); install() gives it one (MacAppMenu.mm). A click only asks: the main loop opens Preferences at the+// start of its next frame, the same action Cmd+, and Edit > Preferences run. Nothing on other systems.+#pragma once++#include <atomic>+#include <cstring>++namespace sf::macmenu {++// SDL hands Cmd+, to the app (our shortcut opens Preferences) before the menu sees it as the item's key+// equivalent, so the item answers only clicks (and Return in a menu opened from the keyboard), not that key.+inline bool isOwnKeyEquivalent(bool keyDown, bool command, const char* chars) {+ return keyDown && command && chars && std::strcmp(chars, ",") == 0;+}++inline std::atomic<bool> preferencesWanted{false};++inline void requestPreferences() { preferencesWanted.store(true); }+inline bool takePreferencesRequest() { return preferencesWanted.exchange(false); } // true once per request++#if defined(__APPLE__)+void install(); // after SDL_Init: gives SDL's Preferences... item its action+#else+inline void install() {}+#endif++} // namespace sf::macmenudiff --git a/src/app/MacAppMenu.mm b/src/app/MacAppMenu.mmnew file mode 100644index 00000000..cb41dd16--- /dev/null+++ b/src/app/MacAppMenu.mm@@ -0,0 +1,44 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// SculptForge > Preferences... in the macOS app menu (#111; MacAppMenu.h).+#import <Cocoa/Cocoa.h>++#include "app/MacAppMenu.h"++namespace sf {+void wakeMainLoop(); // App.h (not included: it pulls in the whole app)+}++@interface SFPreferencesTarget : NSObject+- (void)openPreferences:(id)sender;+@end++@implementation SFPreferencesTarget+- (void)openPreferences:(id)sender {+ NSEvent* e = [NSApp currentEvent];+ if (e && sf::macmenu::isOwnKeyEquivalent(e.type == NSEventTypeKeyDown,+ (e.modifierFlags & NSEventModifierFlagCommand) != 0,+ e.charactersIgnoringModifiers.UTF8String))+ return; // Cmd+,: SDL already gave the key to the app, whose shortcut opens Preferences+ sf::macmenu::requestPreferences();+ sf::wakeMainLoop();+}+@end++namespace sf::macmenu {++void install() {+ static SFPreferencesTarget* target = [[SFPreferencesTarget alloc] init]; // (NSMenuItem keeps its target weakly)+ NSMenu* bar = [NSApp mainMenu];+ if (bar.numberOfItems == 0) return; // (no menu bar: nothing to fill)+ NSMenu* appMenu = [[bar itemAtIndex:0] submenu];+ for (NSMenuItem* item in appMenu.itemArray)+ if ([item.keyEquivalent isEqualToString:@","] && item.action == nil) { // SDL's "Preferences..." (Cmd+,)+ item.target = target;+ item.action = @selector(openPreferences:);+ return;+ }+}++} // namespace sf::macmenudiff --git a/tests/test_mac_menu.cpp b/tests/test_mac_menu.cppnew file mode 100644index 00000000..60c81b05--- /dev/null+++ b/tests/test_mac_menu.cpp@@ -0,0 +1,27 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// SculptForge > Preferences... in the macOS app menu (#111, src/app/MacAppMenu.h): the item answers a click once,+// and leaves Cmd+, to the shortcut so Preferences never opens twice.+#include "TestHarness.h"++#include "app/MacAppMenu.h"++using namespace sf;++TEST(mac_menu_preferences_once) {+ macmenu::takePreferencesRequest(); // (start clean)+ CHECK(!macmenu::takePreferencesRequest());+ macmenu::requestPreferences();+ macmenu::requestPreferences(); // two clicks before the next frame still open it once+ CHECK(macmenu::takePreferencesRequest());+ CHECK(!macmenu::takePreferencesRequest());+}++TEST(mac_menu_skips_its_key_equivalent) {+ CHECK(macmenu::isOwnKeyEquivalent(true, true, ",")); // Cmd+,: the shortcut already ran+ CHECK(!macmenu::isOwnKeyEquivalent(false, false, nullptr)); // a click+ CHECK(!macmenu::isOwnKeyEquivalent(true, false, "\r")); // Return in a menu opened from the keyboard+ CHECK(!macmenu::isOwnKeyEquivalent(true, true, "p"));+ CHECK(!macmenu::isOwnKeyEquivalent(true, true, nullptr));+}