From c900e4aa3cee35c7ff92a2ca0950a62034bb5fda Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 11 Apr 2016 16:19:32 -0300 Subject: [PATCH] Don't call app_main() from OSXApp --- src/she/osx/app.h | 9 ++++----- src/she/osx/app.mm | 33 ++++++++++++++++++++------------- src/she/skia/she.cpp | 14 +++++--------- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/she/osx/app.h b/src/she/osx/app.h index ff1ebcdcb..fa039f8eb 100644 --- a/src/she/osx/app.h +++ b/src/she/osx/app.h @@ -1,5 +1,5 @@ // SHE library -// Copyright (C) 2012-2015 David Capello +// Copyright (C) 2012-2016 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -16,15 +16,14 @@ namespace she { class OSXApp { public: - static OSXApp* instance() { return g_instance; } - OSXApp(); ~OSXApp(); - int run(int argc, char* argv[]); + bool init(); private: - static OSXApp* g_instance; + class Impl; + Impl* m_impl; }; } // namespace she diff --git a/src/she/osx/app.mm b/src/she/osx/app.mm index 2f537cf1f..327829a2a 100644 --- a/src/she/osx/app.mm +++ b/src/she/osx/app.mm @@ -19,29 +19,36 @@ extern int app_main(int argc, char* argv[]); namespace she { -OSXApp* OSXApp::g_instance = nullptr; +class OSXApp::Impl { +public: + bool init() { + m_app = [NSApplication sharedApplication]; + m_appDelegate = [OSXAppDelegate new]; + + [m_app setActivationPolicy:NSApplicationActivationPolicyRegular]; + [m_app setDelegate:m_appDelegate]; + [m_app activateIgnoringOtherApps:YES]; + + return true; + } + +private: + NSApplication* m_app; + id m_appDelegate; +}; OSXApp::OSXApp() + : m_impl(new Impl) { - g_instance = this; } OSXApp::~OSXApp() { - g_instance = nullptr; } -int OSXApp::run(int argc, char* argv[]) +bool OSXApp::init() { - NSApplication* app = [NSApplication sharedApplication]; - id appDelegate = [OSXAppDelegate new]; - - [app setActivationPolicy:NSApplicationActivationPolicyRegular]; - [app setDelegate:appDelegate]; - [app activateIgnoringOtherApps:YES]; - - app_main(argc, argv); - return 0; + return m_impl->init(); } } // namespace she diff --git a/src/she/skia/she.cpp b/src/she/skia/she.cpp index de5674b31..e45ac5d21 100644 --- a/src/she/skia/she.cpp +++ b/src/she/skia/she.cpp @@ -54,8 +54,7 @@ extern int app_main(int argc, char* argv[]); #if _WIN32 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - LPSTR lpCmdLine, int nCmdShow) -{ + LPSTR lpCmdLine, int nCmdShow) { int argc = 0; LPWSTR* argvW = CommandLineToArgvW(GetCommandLineW(), &argc); char** argv; @@ -70,19 +69,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, argv[0] = base_strdup(""); } #else -int main(int argc, char* argv[]) -{ +int main(int argc, char* argv[]) { #endif #if __APPLE__ she::OSXApp app; - return app.run(argc, argv); -#else - -#ifndef _WIN32 + if (!app.init()) + return 1; +#elif !defined(_WIN32) she::X11 x11; #endif return app_main(argc, argv); -#endif }