Atlas - SDL_BeApp.cc

Home / ext / SDL / src / core / haiku Lines: 1 | Size: 4813 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#include "SDL_internal.h" 22 23#ifdef SDL_PLATFORM_HAIKU 24 25// Handle the BeApp specific portions of the application 26 27#include <AppKit.h> 28#include <storage/AppFileInfo.h> 29#include <storage/Path.h> 30#include <storage/Entry.h> 31#include <storage/File.h> 32#include <unistd.h> 33#include <memory> 34 35#include "SDL_BApp.h" // SDL_BLooper class definition 36#include "SDL_BeApp.h" 37 38#include "../../video/haiku/SDL_BWin.h" 39 40#ifdef __cplusplus 41extern "C" { 42#endif 43 44#include "../../thread/SDL_systhread.h" 45 46// Flag to tell whether or not the Be application and looper are active or not 47static int SDL_BeAppActive = 0; 48static SDL_Thread *SDL_AppThread = NULL; 49SDL_BLooper *SDL_Looper = NULL; 50 51 52// Default application signature 53const char *SDL_signature = "application/x-SDL-executable"; 54 55 56// Create a descendant of BApplication 57class SDL_BApp : public BApplication { 58public: 59 SDL_BApp(const char *signature) : 60 BApplication(signature) { 61 } 62 63 64 virtual ~SDL_BApp() { 65 } 66 67 68 virtual void RefsReceived(BMessage *message) { 69 entry_ref entryRef; 70 for (int32 i = 0; message->FindRef("refs", i, &entryRef) == B_OK; i++) { 71 BPath referencePath = BPath(&entryRef); 72 SDL_SendDropFile(NULL, NULL, referencePath.Path()); 73 } 74 return; 75 } 76}; 77 78 79static int StartBeApp(void *unused) 80{ 81 std::unique_ptr<BApplication> App; 82 83 (void)unused; 84 // dig resources for correct signature 85 image_info info; 86 int32 cookie = 0; 87 if (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) { 88 BFile f(info.name, O_RDONLY); 89 if (f.InitCheck() == B_OK) { 90 BAppFileInfo app_info(&f); 91 if (app_info.InitCheck() == B_OK) { 92 char sig[B_MIME_TYPE_LENGTH]; 93 if (app_info.GetSignature(sig) == B_OK) { 94 SDL_signature = strndup(sig, B_MIME_TYPE_LENGTH); 95 } 96 } 97 } 98 } 99 100 App = std::unique_ptr<BApplication>(new SDL_BApp(SDL_signature)); 101 102 App->Run(); 103 return 0; 104} 105 106 107static bool StartBeLooper() 108{ 109 if (!be_app) { 110 SDL_AppThread = SDL_CreateThread(StartBeApp, "SDLApplication", NULL); 111 if (!SDL_AppThread) { 112 return SDL_SetError("Couldn't create BApplication thread"); 113 } 114 115 do { 116 SDL_Delay(10); 117 } while ((!be_app) || be_app->IsLaunching()); 118 } 119 120 SDL_Looper = new SDL_BLooper("SDLLooper"); 121 SDL_Looper->Run(); 122 return true; 123} 124 125 126// Initialize the Be Application, if it's not already started 127bool SDL_InitBeApp(void) 128{ 129 // Create the BApplication that handles appserver interaction 130 if (SDL_BeAppActive <= 0) { 131 if (!StartBeLooper()) { 132 return false; 133 } 134 135 // Mark the application active 136 SDL_BeAppActive = 0; 137 } 138 139 // Increment the application reference count 140 ++SDL_BeAppActive; 141 142 // The app is running, and we're ready to go 143 return true; 144} 145 146// Quit the Be Application, if there's nothing left to do 147void SDL_QuitBeApp(void) 148{ 149 // Decrement the application reference count 150 --SDL_BeAppActive; 151 152 // If the reference count reached zero, clean up the app 153 if (SDL_BeAppActive == 0) { 154 SDL_Looper->Lock(); 155 SDL_Looper->Quit(); 156 SDL_Looper = NULL; 157 if (SDL_AppThread) { 158 if (be_app != NULL) { // Not tested 159 be_app->PostMessage(B_QUIT_REQUESTED); 160 } 161 SDL_WaitThread(SDL_AppThread, NULL); 162 SDL_AppThread = NULL; 163 } 164 // be_app should now be NULL since be_app has quit 165 } 166} 167 168#ifdef __cplusplus 169} 170#endif 171 172// SDL_BApp functions 173void SDL_BLooper::ClearID(SDL_BWin *bwin) { 174 _SetSDLWindow(NULL, bwin->GetID()); 175 int32 i = _GetNumWindowSlots() - 1; 176 while (i >= 0 && GetSDLWindow(i) == NULL) { 177 _PopBackWindow(); 178 --i; 179 } 180} 181 182#endif // SDL_PLATFORM_HAIKU 183
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.