From 146c173c1fdc64dd63dcb4c6fd3a97f3a44a0a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marti=CC=81n=20Lucas=20Golini?= Date: Tue, 19 Jul 2022 02:14:19 -0300 Subject: [PATCH] ecode: Fixes problematic default SDL menus. --- premake4.lua | 28 ++++++++++++++-- projects/macos/ecode/Info.plist | 2 +- projects/macos/ee.files | 2 ++ src/tools/ecode/ecode.cpp | 8 +++++ src/tools/ecode/macos/macos.hpp | 14 ++++++++ src/tools/ecode/macos/macos.m | 59 +++++++++++++++++++++++++++++++++ 6 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 src/tools/ecode/macos/macos.hpp create mode 100644 src/tools/ecode/macos/macos.m diff --git a/premake4.lua b/premake4.lua index 169c26af0..874a54a0d 100644 --- a/premake4.lua +++ b/premake4.lua @@ -1168,10 +1168,10 @@ solution "eepp" language "C++" includedirs { "src/thirdparty/efsw/include", "src/thirdparty" } - if not os.is("windows") and not os.is("haiku") then + if not os.is_real("windows") and not os.is_real("haiku") then links { "pthread" } end - if os.is("macosx") then + if os.is_real("macosx") then links { "CoreFoundation.framework", "CoreServices.framework" } end @@ -1179,6 +1179,27 @@ solution "eepp" files { "src/tools/uieditor/*.cpp" } build_link_configuration( "eepp-UIEditor", true ) + if os.is("macosx") then + project "ecode-macos-helper-static" + kind "StaticLib" + language "C++" + files { "src/tools/ecode/macos/*.m" } + set_targetdir("libs/" .. os.get_real() .. "/thirdparty/") + + configuration "debug" + defines { "DEBUG", "EE_DEBUG", "EE_MEMORY_MANAGER" } + flags { "Symbols" } + buildoptions{ "-Wall" } + buildoptions{ "-g3" } + targetname ( "ecode-macos-helper-static-debug" ) + + configuration "release" + defines { "NDEBUG" } + flags { "OptimizeSpeed" } + buildoptions{ "-O3" } + targetname ( "ecode-macos-helper-static" ) + end + project "ecode" set_kind() language "C++" @@ -1189,7 +1210,8 @@ solution "eepp" links { "pthread" } end if os.is("macosx") then - links { "CoreFoundation.framework", "CoreServices.framework" } + links { "CoreFoundation.framework", "CoreServices.framework", "Cocoa.framework" } + links { "ecode-macos-helper-static" } end if os.is_real("linux") then links { "util" } diff --git a/projects/macos/ecode/Info.plist b/projects/macos/ecode/Info.plist index 14506cb6e..1159c1d19 100644 --- a/projects/macos/ecode/Info.plist +++ b/projects/macos/ecode/Info.plist @@ -13,7 +13,7 @@ CFBundleIconFile ecode.icns CFBundleShortVersionString - 0.1 + 0.2 CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType diff --git a/projects/macos/ee.files b/projects/macos/ee.files index 08495769c..efc929bd0 100644 --- a/projects/macos/ee.files +++ b/projects/macos/ee.files @@ -1139,6 +1139,8 @@ ../../src/tools/ecode/globalsearchcontroller.hpp ../../src/tools/ecode/ignorematcher.cpp ../../src/tools/ecode/ignorematcher.hpp +../../src/tools/ecode/macos/macos.hpp +../../src/tools/ecode/macos/macos.m ../../src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp ../../src/tools/ecode/plugins/autocomplete/autocompleteplugin.hpp ../../src/tools/ecode/plugins/formatter/formatterplugin.cpp diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 561260b34..633e9f567 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -6,6 +6,10 @@ #include #include +#if EE_PLATFORM == EE_PLATFORM_MACOSX +#include "macos/macos.hpp" +#endif + namespace ecode { Clock globalClock; @@ -3277,6 +3281,10 @@ void App::init( std::string file, const Float& pidelDensity, const std::string& ecode::Version::getCodename().c_str() ); if ( mWindow->isOpen() ) { +#if EE_PLATFORM == EE_PLATFORM_MACOSX + macOS_CreateApplicationMenus(); +#endif + Log::info( "Window creation took: %.2f ms", globalClock.getElapsedTime().asMilliseconds() ); if ( mConfig.window.position != Vector2i( -1, -1 ) && diff --git a/src/tools/ecode/macos/macos.hpp b/src/tools/ecode/macos/macos.hpp new file mode 100644 index 000000000..2fcf0ed99 --- /dev/null +++ b/src/tools/ecode/macos/macos.hpp @@ -0,0 +1,14 @@ +#ifndef ECODE_MACOS_MACOS +#define ECODE_MACOS_MACOS + +#ifdef __cplusplus +extern "C" { +#endif + +void macOS_CreateApplicationMenus(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/tools/ecode/macos/macos.m b/src/tools/ecode/macos/macos.m new file mode 100644 index 000000000..967cf7a0d --- /dev/null +++ b/src/tools/ecode/macos/macos.m @@ -0,0 +1,59 @@ +#include +#include "macos.hpp" + +/* setAppleMenu disappeared from the headers in 10.4 */ +@interface NSApplication(NSAppleMenu) +- (void)setAppleMenu:(NSMenu *)menu; +@end + +// Recreates the menubar replacing the default SDL menubar +void +macOS_CreateApplicationMenus(void) +{ + NSString *appName; + NSString *title; + NSMenu *appleMenu; + NSMenu *windowMenu; + NSMenuItem *menuItem; + NSMenu *mainMenu; + + if (NSApp == nil) { + return; + } + + mainMenu = [[NSApplication sharedApplication] mainMenu]; + [mainMenu removeAllItems]; + + appName = @"ecode"; + appleMenu = [[NSMenu alloc] initWithTitle:@""]; + + title = [@"About " stringByAppendingString:appName]; + [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; + + [appleMenu addItem:[NSMenuItem separatorItem]]; + + [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; + + [appleMenu addItem:[NSMenuItem separatorItem]]; + + title = [@"Quit " stringByAppendingString:appName]; + [appleMenu addItemWithTitle:title action:@selector(performClose:) keyEquivalent:@"q"]; + + menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; + [menuItem setSubmenu:appleMenu]; + + [[NSApp mainMenu] addItem:menuItem]; + + [NSApp setAppleMenu:appleMenu]; + + windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; + menuItem = [[NSMenuItem alloc] initWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"]; + [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand]; + [windowMenu addItem:menuItem]; + menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; + [menuItem setSubmenu:windowMenu]; + + [[NSApp mainMenu] addItem:menuItem]; + + [NSApp setWindowsMenu:windowMenu]; +}