diff --git a/src/Platform.c b/src/Platform.c index c2f04557b..0f5eac9a0 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -14,7 +14,6 @@ #include "freetype/ftglyph.h" static void Platform_InitDisplay(void); -static void Platform_InitStopwatch(void); struct DisplayDevice DisplayDevice_Default; void* DisplayDevice_Meta; @@ -1786,27 +1785,6 @@ int Platform_ConvertString(void* data, const String* src) { return src->length * 2; } -void Platform_Init(void) { - WSADATA wsaData; - ReturnCode res; - - Platform_InitDisplay(); - Platform_InitStopwatch(); - heap = GetProcessHeap(); - - res = WSAStartup(MAKEWORD(2, 2), &wsaData); - if (res) Logger_Abort2(res, "WSAStartup failed"); - - hasDebugger = IsDebuggerPresent(); - if (!AttachConsole(ATTACH_PARENT_PROCESS)) return; - conHandle = GetStdHandle(STD_OUTPUT_HANDLE); -} - -void Platform_Free(void) { - WSACleanup(); - HeapDestroy(heap); -} - static void Platform_InitDisplay(void) { HDC hdc = GetDC(NULL); @@ -1829,6 +1807,27 @@ static void Platform_InitStopwatch(void) { } else { sw_freqDiv = 10; } } +void Platform_Init(void) { + WSADATA wsaData; + ReturnCode res; + + Platform_InitDisplay(); + Platform_InitStopwatch(); + heap = GetProcessHeap(); + + res = WSAStartup(MAKEWORD(2, 2), &wsaData); + if (res) Logger_Warn(res, "starting WSA"); + + hasDebugger = IsDebuggerPresent(); + if (!AttachConsole(ATTACH_PARENT_PROCESS)) return; + conHandle = GetStdHandle(STD_OUTPUT_HANDLE); +} + +void Platform_Free(void) { + WSACleanup(); + HeapDestroy(heap); +} + ReturnCode Platform_SetCurrentDirectory(const String* path) { TCHAR str[300]; Platform_ConvertString(str, path); @@ -1985,11 +1984,10 @@ int Platform_ConvertString(void* data, const String* src) { return len; } -void Platform_Init(void) { +static void Platform_InitCommon(void) { signal(SIGCHLD, SIG_IGN); Platform_InitDisplay(); - Platform_InitStopwatch(); - pthread_mutex_init(&audio_lock, NULL); + pthread_mutex_init(&audio_lock, NULL); } void Platform_Free(void) { @@ -2094,7 +2092,12 @@ ReturnCode Platform_StartOpen(const String* args) { const static String path = String_FromConst("xdg-open"); return Platform_StartProcess(&path, args); } -static void Platform_InitStopwatch(void) { sw_freqDiv = 1000; } + +void Platform_Init(void) { + Platform_InitCommon(); + /* stopwatch always in nanoseconds */ + sw_freqDiv = 1000; +} #endif #ifdef CC_BUILD_LINUX ReturnCode Platform_GetExePath(String* path) { @@ -2166,4 +2169,15 @@ static void Platform_InitStopwatch(void) { sw_freqMul = tb.numer; sw_freqDiv = tb.denom * 1000; } + +void Platform_Init(void) { + ProcessSerialNumber psn; + Platform_InitCommon(); + Platform_InitStopwatch(); + + /* NOTE: Call as soon as possible, otherwise can't click on dialog boxes. */ + GetCurrentProcess(&psn); + /* NOTE: TransformProcessType is OSX 10.3 or later */ + TransformProcessType(&psn, kProcessTransformToForegroundApplication); +} #endif diff --git a/src/Program.c b/src/Program.c index e27b69ca3..f4e4bc8fb 100644 --- a/src/Program.c +++ b/src/Program.c @@ -88,9 +88,9 @@ int main(int argc, char** argv) { uint8_t ip[4]; uint16_t port; - Program_SetCurrentDirectory(); Logger_Hook(); Platform_Init(); + Program_SetCurrentDirectory(); #ifdef CC_TEST_VORBIS main_imdct(); #endif diff --git a/src/Window.c b/src/Window.c index 66a3b3bd0..3c0a92ad5 100644 --- a/src/Window.c +++ b/src/Window.c @@ -2119,10 +2119,7 @@ void Window_Create(int x, int y, int width, int height, struct GraphicsMode* mod title_height = Rect_Height(r); AcquireRootMenu(); - /* TODO: Apparently GetCurrentProcess is needed */ GetCurrentProcess(&psn); - /* NOTE: TransformProcessType is OSX 10.3 or later */ - TransformProcessType(&psn, kProcessTransformToForegroundApplication); SetFrontProcess(&psn); /* TODO: Use BringWindowToFront instead.. (look in the file which has RepositionWindow in it) !!!! */