Don't call app_main() from OSXApp

This commit is contained in:
David Capello 2016-04-11 16:19:32 -03:00
parent 4acf12a478
commit c900e4aa3c
3 changed files with 29 additions and 27 deletions

View File

@ -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

View File

@ -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

View File

@ -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
}