32
32
#include < unistd.h>
33
33
#include < memory>
34
34
35
- #include " SDL_BApp.h" /* SDL_BApp class definition */
35
+ #include " SDL_BApp.h" /* SDL_BLooper class definition */
36
36
#include " SDL_BeApp.h"
37
37
38
38
#include " ../../video/haiku/SDL_BWin.h"
@@ -43,12 +43,38 @@ extern "C" {
43
43
44
44
#include " ../../thread/SDL_systhread.h"
45
45
46
- /* Flag to tell whether or not the Be application is active or not */
46
+ /* Flag to tell whether or not the Be application and looper are active or not */
47
47
static int SDL_BeAppActive = 0 ;
48
48
static SDL_Thread *SDL_AppThread = NULL ;
49
+ SDL_BLooper *SDL_Looper = NULL ;
50
+
49
51
50
52
/* Default application signature */
51
- const char *signature = " application/x-SDL-executable" ;
53
+ const char *SDL_signature = " application/x-SDL-executable" ;
54
+
55
+
56
+ /* Create a descendant of BApplication */
57
+ class SDL_BApp : public BApplication {
58
+ public:
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 , referencePath.Path ());
73
+ }
74
+ return ;
75
+ }
76
+ };
77
+
52
78
53
79
static int StartBeApp (void *unused)
54
80
{
@@ -65,47 +91,61 @@ static int StartBeApp(void *unused)
65
91
if (app_info.InitCheck () == B_OK) {
66
92
char sig[B_MIME_TYPE_LENGTH];
67
93
if (app_info.GetSignature (sig) == B_OK) {
68
- signature = strndup (sig, B_MIME_TYPE_LENGTH);
94
+ SDL_signature = strndup (sig, B_MIME_TYPE_LENGTH);
69
95
}
70
96
}
71
97
}
72
98
}
73
99
74
- App = std::unique_ptr<BApplication>(new SDL_BApp (signature ));
100
+ App = std::unique_ptr<BApplication>(new SDL_BApp (SDL_signature ));
75
101
76
102
App->Run ();
77
103
return 0 ;
78
104
}
79
105
80
- /* Initialize the Be Application, if it's not already started */
81
- int
82
- SDL_InitBeApp ( void )
106
+
107
+ static int
108
+ StartBeLooper ( )
83
109
{
84
- /* Create the BApplication that handles appserver interaction */
85
- if (SDL_BeAppActive <= 0 ) {
110
+ if (!be_app) {
86
111
SDL_AppThread = SDL_CreateThreadInternal (StartBeApp, " SDLApplication" , 0 , NULL );
87
112
if (SDL_AppThread == NULL ) {
88
113
return SDL_SetError (" Couldn't create BApplication thread" );
89
114
}
90
115
91
- /* Change working directory to that of executable */
92
- app_info info;
93
- if (B_OK == be_app->GetAppInfo (&info)) {
94
- entry_ref ref = info.ref ;
95
- BEntry entry;
96
- if (B_OK == entry.SetTo (&ref)) {
97
- BPath path;
98
- if (B_OK == path.SetTo (&entry)) {
99
- if (B_OK == path.GetParent (&path)) {
100
- chdir (path.Path ());
101
- }
116
+ do {
117
+ SDL_Delay (10 );
118
+ } while ((be_app == NULL ) || be_app->IsLaunching ());
119
+ }
120
+
121
+ /* Change working directory to that of executable */
122
+ app_info info;
123
+ if (B_OK == be_app->GetAppInfo (&info)) {
124
+ entry_ref ref = info.ref ;
125
+ BEntry entry;
126
+ if (B_OK == entry.SetTo (&ref)) {
127
+ BPath path;
128
+ if (B_OK == path.SetTo (&entry)) {
129
+ if (B_OK == path.GetParent (&path)) {
130
+ chdir (path.Path ());
102
131
}
103
132
}
104
133
}
134
+ }
105
135
106
- do {
107
- SDL_Delay (10 );
108
- } while ((be_app == NULL ) || be_app->IsLaunching ());
136
+ SDL_Looper = new SDL_BLooper (" SDLLooper" );
137
+ SDL_Looper->Run ();
138
+ return (0 );
139
+ }
140
+
141
+
142
+ /* Initialize the Be Application, if it's not already started */
143
+ int
144
+ SDL_InitBeApp (void )
145
+ {
146
+ /* Create the BApplication that handles appserver interaction */
147
+ if (SDL_BeAppActive <= 0 ) {
148
+ StartBeLooper ();
109
149
110
150
/* Mark the application active */
111
151
SDL_BeAppActive = 0 ;
@@ -127,6 +167,9 @@ SDL_QuitBeApp(void)
127
167
128
168
/* If the reference count reached zero, clean up the app */
129
169
if (SDL_BeAppActive == 0 ) {
170
+ SDL_Looper->Lock ();
171
+ SDL_Looper->Quit ();
172
+ SDL_Looper = NULL ;
130
173
if (SDL_AppThread != NULL ) {
131
174
if (be_app != NULL ) { /* Not tested */
132
175
be_app->PostMessage (B_QUIT_REQUESTED);
@@ -143,7 +186,7 @@ SDL_QuitBeApp(void)
143
186
#endif
144
187
145
188
/* SDL_BApp functions */
146
- void SDL_BApp ::ClearID (SDL_BWin *bwin) {
189
+ void SDL_BLooper ::ClearID (SDL_BWin *bwin) {
147
190
_SetSDLWindow (NULL , bwin->GetID ());
148
191
int32 i = _GetNumWindowSlots () - 1 ;
149
192
while (i >= 0 && GetSDLWindow (i) == NULL ) {
0 commit comments