From 7a4fc529d097359a985556cb2f5ba601c8de3a0f Mon Sep 17 00:00:00 2001 From: Gerasim Troeglazov <3dEyes@gmail.com> Date: Wed, 12 Jan 2022 11:59:06 +1000 Subject: Workaround for gcc2 diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 5c3f012..6fc3c14 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -33,6 +33,10 @@ #include #endif +#if __GNUC__ == 2 +#define va_copy(to, from) __va_copy(to, from) +#endif + #if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD) || !defined(HAVE_STRTOLL) || !defined(HAVE_STRTOULL) #define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F')) #define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f')) -- 2.37.3 From 66219afffdd033230f687202256eb0d9249845f2 Mon Sep 17 00:00:00 2001 From: Jerome Duval Date: Wed, 29 Mar 2023 21:28:21 +0200 Subject: Haiku: use a BLooper for events. only create a BApplication when it doesn't already exist. diff --git a/src/main/haiku/SDL_BApp.h b/src/main/haiku/SDL_BApp.h index 868b4ed..f7d7af4 100644 --- a/src/main/haiku/SDL_BApp.h +++ b/src/main/haiku/SDL_BApp.h @@ -53,6 +53,7 @@ extern "C" { /* Forward declarations */ +class SDL_BLooper; class SDL_BWin; /* Message constants */ @@ -78,32 +79,24 @@ enum ToSDL { }; +extern "C" SDL_BLooper *SDL_Looper; -/* Create a descendant of BApplication */ -class SDL_BApp : public BApplication { + +/* Create a descendant of BLooper */ +class SDL_BLooper : public BLooper { public: - SDL_BApp(const char* signature) : - BApplication(signature) { + SDL_BLooper(const char* name) : + BLooper(name) { #if SDL_VIDEO_OPENGL _current_context = NULL; #endif } - virtual ~SDL_BApp() { + virtual ~SDL_BLooper() { } - virtual void RefsReceived(BMessage* message) { - char filePath[512]; - entry_ref entryRef; - for (int32 i = 0; message->FindRef("refs", i, &entryRef) == B_OK; i++) { - BPath referencePath = BPath(&entryRef); - SDL_SendDropFile(NULL, referencePath.Path()); - } - return; - } - /* Event-handling functions */ virtual void MessageReceived(BMessage* message) { /* Sort out SDL-related messages */ @@ -173,7 +166,7 @@ public: break; default: - BApplication::MessageReceived(message); + BLooper::MessageReceived(message); break; } } diff --git a/src/main/haiku/SDL_BeApp.cc b/src/main/haiku/SDL_BeApp.cc index 9acbc54..5dea3a4 100644 --- a/src/main/haiku/SDL_BeApp.cc +++ b/src/main/haiku/SDL_BeApp.cc @@ -31,7 +31,7 @@ #include #include -#include "SDL_BApp.h" /* SDL_BApp class definition */ +#include "SDL_BApp.h" /* SDL_BLooper class definition */ #include "SDL_BeApp.h" #include "SDL_timer.h" #include "SDL_error.h" @@ -44,13 +44,39 @@ extern "C" { #include "../../thread/SDL_systhread.h" -/* Flag to tell whether or not the Be application is active or not */ +/* Flag to tell whether or not the Be application and looper are active or not */ static int SDL_BeAppActive = 0; static SDL_Thread *SDL_AppThread = NULL; +SDL_BLooper *SDL_Looper = NULL; + /* Default application signature */ const char *signature = "application/x-SDL-executable"; + +/* Create a descendant of BApplication */ +class SDL_BApp : public BApplication { +public: + SDL_BApp(const char* signature) : + BApplication(signature) { + } + + + virtual ~SDL_BApp() { + } + + + virtual void RefsReceived(BMessage* message) { + entry_ref entryRef; + for (int32 i = 0; message->FindRef("refs", i, &entryRef) == B_OK; i++) { + BPath referencePath = BPath(&entryRef); + SDL_SendDropFile(NULL, referencePath.Path()); + } + return; + } +}; + + static int StartBeApp(void *unused) { @@ -78,35 +104,49 @@ StartBeApp(void *unused) return (0); } -/* Initialize the Be Application, if it's not already started */ -int -SDL_InitBeApp(void) + +static int +StartBeLooper() { - /* Create the BApplication that handles appserver interaction */ - if (SDL_BeAppActive <= 0) { + if (!be_app) { SDL_AppThread = SDL_CreateThreadInternal(StartBeApp, "SDLApplication", 0, NULL); if (SDL_AppThread == NULL) { return SDL_SetError("Couldn't create BApplication thread"); } - /* Change working directory to that of executable */ - app_info info; - if (B_OK == be_app->GetAppInfo(&info)) { - entry_ref ref = info.ref; - BEntry entry; - if (B_OK == entry.SetTo(&ref)) { - BPath path; - if (B_OK == path.SetTo(&entry)) { - if (B_OK == path.GetParent(&path)) { - chdir(path.Path()); - } + do { + SDL_Delay(10); + } while ((be_app == NULL) || be_app->IsLaunching()); + } + + /* Change working directory to that of executable */ + app_info info; + if (B_OK == be_app->GetAppInfo(&info)) { + entry_ref ref = info.ref; + BEntry entry; + if (B_OK == entry.SetTo(&ref)) { + BPath path; + if (B_OK == path.SetTo(&entry)) { + if (B_OK == path.GetParent(&path)) { + chdir(path.Path()); } } } + } - do { - SDL_Delay(10); - } while ((be_app == NULL) || be_app->IsLaunching()); + SDL_Looper = new SDL_BLooper("SDLLooper"); + SDL_Looper->Run(); + return (0); +} + + +/* Initialize the Be Application, if it's not already started */ +int +SDL_InitBeApp(void) +{ + /* Create the BApplication that handles appserver interaction */ + if (SDL_BeAppActive <= 0) { + StartBeLooper(); /* Mark the application active */ SDL_BeAppActive = 0; @@ -128,6 +168,9 @@ SDL_QuitBeApp(void) /* If the reference count reached zero, clean up the app */ if (SDL_BeAppActive == 0) { + SDL_Looper->Lock(); + SDL_Looper->Quit(); + SDL_Looper = NULL; if (SDL_AppThread != NULL) { if (be_app != NULL) { /* Not tested */ be_app->PostMessage(B_QUIT_REQUESTED); @@ -144,7 +187,7 @@ SDL_QuitBeApp(void) #endif /* SDL_BApp functions */ -void SDL_BApp::ClearID(SDL_BWin *bwin) { +void SDL_BLooper::ClearID(SDL_BWin *bwin) { _SetSDLWindow(NULL, bwin->GetID()); int32 i = _GetNumWindowSlots() - 1; while(i >= 0 && GetSDLWindow(i) == NULL) { diff --git a/src/video/haiku/SDL_BApp.h b/src/video/haiku/SDL_BApp.h index 868b4ed..f7d7af4 100644 --- a/src/video/haiku/SDL_BApp.h +++ b/src/video/haiku/SDL_BApp.h @@ -53,6 +53,7 @@ extern "C" { /* Forward declarations */ +class SDL_BLooper; class SDL_BWin; /* Message constants */ @@ -78,32 +79,24 @@ enum ToSDL { }; +extern "C" SDL_BLooper *SDL_Looper; -/* Create a descendant of BApplication */ -class SDL_BApp : public BApplication { + +/* Create a descendant of BLooper */ +class SDL_BLooper : public BLooper { public: - SDL_BApp(const char* signature) : - BApplication(signature) { + SDL_BLooper(const char* name) : + BLooper(name) { #if SDL_VIDEO_OPENGL _current_context = NULL; #endif } - virtual ~SDL_BApp() { + virtual ~SDL_BLooper() { } - virtual void RefsReceived(BMessage* message) { - char filePath[512]; - entry_ref entryRef; - for (int32 i = 0; message->FindRef("refs", i, &entryRef) == B_OK; i++) { - BPath referencePath = BPath(&entryRef); - SDL_SendDropFile(NULL, referencePath.Path()); - } - return; - } - /* Event-handling functions */ virtual void MessageReceived(BMessage* message) { /* Sort out SDL-related messages */ @@ -173,7 +166,7 @@ public: break; default: - BApplication::MessageReceived(message); + BLooper::MessageReceived(message); break; } } diff --git a/src/video/haiku/SDL_BWin.h b/src/video/haiku/SDL_BWin.h index e711ee0..d9f0340 100644 --- a/src/video/haiku/SDL_BWin.h +++ b/src/video/haiku/SDL_BWin.h @@ -125,8 +125,8 @@ class SDL_BWin: public BWindow #if SDL_VIDEO_OPENGL if (_SDL_GLView) { - if (((SDL_BApp*)be_app)->GetCurrentContext() == _SDL_GLView) - ((SDL_BApp*)be_app)->SetCurrentContext(NULL); + if (SDL_Looper->GetCurrentContext() == _SDL_GLView) + SDL_Looper->SetCurrentContext(NULL); if (_SDL_GLView == _cur_view) RemoveChild(_SDL_GLView); _SDL_GLView = NULL; @@ -205,8 +205,8 @@ class SDL_BWin: public BWindow void RemoveGLView() { Lock(); if(_SDL_GLView != NULL) { - if (((SDL_BApp*)be_app)->GetCurrentContext() == _SDL_GLView) - ((SDL_BApp*)be_app)->SetCurrentContext(NULL); + if (SDL_Looper->GetCurrentContext() == _SDL_GLView) + SDL_Looper->SetCurrentContext(NULL); _SDL_GLView = NULL; UpdateCurrentView(); // _SDL_GLView deleted by HAIKU_GL_DeleteContext @@ -549,7 +549,7 @@ private: if (keyUtf8 != NULL) { msg.AddData("key-utf8", B_INT8_TYPE, (const void*)keyUtf8, len); } - be_app->PostMessage(&msg); + SDL_Looper->PostMessage(&msg); } void _RepaintEvent() { @@ -559,7 +559,7 @@ private: } void _PostWindowEvent(BMessage &msg) { msg.AddInt32("window-id", _id); - be_app->PostMessage(&msg); + SDL_Looper->PostMessage(&msg); } /* Command methods (functions called upon by SDL) */ diff --git a/src/video/haiku/SDL_bframebuffer.cc b/src/video/haiku/SDL_bframebuffer.cc index bf7a002..3c297a1 100644 --- a/src/video/haiku/SDL_bframebuffer.cc +++ b/src/video/haiku/SDL_bframebuffer.cc @@ -39,8 +39,8 @@ static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { return ((SDL_BWin*)(window->driverdata)); } -static SDL_INLINE SDL_BApp *_GetBeApp() { - return ((SDL_BApp*)be_app); +static SDL_INLINE SDL_BLooper *_GetBeLooper() { + return SDL_Looper; } int HAIKU_CreateWindowFramebuffer(_THIS, SDL_Window * window, diff --git a/src/video/haiku/SDL_bmodes.cc b/src/video/haiku/SDL_bmodes.cc index 62ec4ec..5d44a88 100644 --- a/src/video/haiku/SDL_bmodes.cc +++ b/src/video/haiku/SDL_bmodes.cc @@ -52,8 +52,8 @@ static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { return ((SDL_BWin*)(window->driverdata)); } -static SDL_INLINE SDL_BApp *_GetBeApp() { - return ((SDL_BApp*)be_app); +static SDL_INLINE SDL_BLooper *_GetBeLooper() { + return SDL_Looper; } static SDL_INLINE display_mode * _ExtractBMode(SDL_DisplayMode *mode) { diff --git a/src/video/haiku/SDL_bopengl.cc b/src/video/haiku/SDL_bopengl.cc index d1ab6b8..f64ca2f 100644 --- a/src/video/haiku/SDL_bopengl.cc +++ b/src/video/haiku/SDL_bopengl.cc @@ -39,8 +39,8 @@ static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { return ((SDL_BWin*)(window->driverdata)); } -static SDL_INLINE SDL_BApp *_GetBeApp() { - return ((SDL_BApp*)be_app); +static SDL_INLINE SDL_BLooper *_GetBeLooper() { + return SDL_Looper; } /* Passing a NULL path means load pointers from the application */ @@ -97,7 +97,7 @@ int HAIKU_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) { return SDL_SetError("MakeCurrent failed"); } } - _GetBeApp()->SetCurrentContext(glView); + _GetBeLooper()->SetCurrentContext(glView); return 0; } @@ -138,7 +138,7 @@ SDL_GLContext HAIKU_GL_CreateContext(_THIS, SDL_Window * window) { } #endif bwin->CreateGLView(gl_flags); - _GetBeApp()->SetCurrentContext(bwin->GetGLView()); + _GetBeLooper()->SetCurrentContext(bwin->GetGLView()); return (SDL_GLContext)(bwin->GetGLView()); } diff --git a/src/video/haiku/SDL_bwindow.cc b/src/video/haiku/SDL_bwindow.cc index a9cc173..b79f34b 100644 --- a/src/video/haiku/SDL_bwindow.cc +++ b/src/video/haiku/SDL_bwindow.cc @@ -37,8 +37,8 @@ static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { return ((SDL_BWin*)(window->driverdata)); } -static SDL_INLINE SDL_BApp *_GetBeApp() { - return ((SDL_BApp*)be_app); +static SDL_INLINE SDL_BLooper *_GetBeLooper() { + return SDL_Looper; } static int _InitWindow(_THIS, SDL_Window *window) { @@ -71,7 +71,7 @@ static int _InitWindow(_THIS, SDL_Window *window) { return -1; window->driverdata = bwin; - int32 winID = _GetBeApp()->GetID(window); + int32 winID = _GetBeLooper()->GetID(window); bwin->SetID(winID); return 0; @@ -218,7 +218,7 @@ void HAIKU_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed) { void HAIKU_DestroyWindow(_THIS, SDL_Window * window) { _ToBeWin(window)->LockLooper(); /* This MUST be locked */ - _GetBeApp()->ClearID(_ToBeWin(window)); + _GetBeLooper()->ClearID(_ToBeWin(window)); _ToBeWin(window)->Quit(); window->driverdata = NULL; } -- 2.37.3 From f18aaee1b460e83d78531807f856d1dc0dcddada Mon Sep 17 00:00:00 2001 From: PulkoMandy Date: Thu, 13 Apr 2023 17:38:14 +0200 Subject: Don't change the current directory when starting from Terminal. diff --git a/src/main/haiku/SDL_BeApp.cc b/src/main/haiku/SDL_BeApp.cc index 5dea3a4..3dfa430 100644 --- a/src/main/haiku/SDL_BeApp.cc +++ b/src/main/haiku/SDL_BeApp.cc @@ -119,9 +119,13 @@ StartBeLooper() } while ((be_app == NULL) || be_app->IsLaunching()); } - /* Change working directory to that of executable */ + /* If started from the GUI, change working directory to that of executable. + * This matches behavior on other platforms and may be needed by some SDL software. + * Don't do it when started from terminal (TERM environment variable is set), because in that + * case, the current directory may be important, and after this there will be no way to know + * what it was. */ app_info info; - if (B_OK == be_app->GetAppInfo(&info)) { + if (NULL == getenv("TERM") && B_OK == be_app->GetAppInfo(&info)) { entry_ref ref = info.ref; BEntry entry; if (B_OK == entry.SetTo(&ref)) { -- 2.37.3