Haiku: use a BLooper for events, only create a BApplication when it doesn't already exist. (#7555)
This commit is contained in:
@@ -47,6 +47,7 @@ extern "C" {
|
||||
#include <vector>
|
||||
|
||||
/* Forward declarations */
|
||||
class SDL_BLooper;
|
||||
class SDL_BWin;
|
||||
|
||||
/* Message constants */
|
||||
@@ -72,32 +73,25 @@ enum ToSDL
|
||||
BAPP_SCREEN_CHANGED
|
||||
};
|
||||
|
||||
/* Create a descendant of BApplication */
|
||||
class SDL_BApp : public BApplication
|
||||
|
||||
extern "C" SDL_BLooper *SDL_Looper;
|
||||
|
||||
|
||||
/* 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)
|
||||
{
|
||||
#ifdef 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)
|
||||
{
|
||||
@@ -168,7 +162,7 @@ class SDL_BApp : public BApplication
|
||||
break;
|
||||
|
||||
default:
|
||||
BApplication::MessageReceived(message);
|
||||
BLooper::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -221,7 +215,7 @@ class SDL_BApp : public BApplication
|
||||
|
||||
private:
|
||||
/* Event management */
|
||||
void _HandleBasicWindowEvent(BMessage *msg, int32 sdlEventType)
|
||||
void _HandleBasicWindowEvent(BMessage *msg, SDL_EventType sdlEventType)
|
||||
{
|
||||
SDL_Window *win;
|
||||
int32 winID;
|
||||
|
||||
@@ -124,8 +124,8 @@ class SDL_BWin : public BWindow
|
||||
|
||||
#ifdef 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;
|
||||
@@ -208,8 +208,8 @@ class SDL_BWin : public BWindow
|
||||
{
|
||||
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
|
||||
@@ -571,7 +571,7 @@ class SDL_BWin : public BWindow
|
||||
if (keyUtf8 != NULL) {
|
||||
msg.AddData("key-utf8", B_INT8_TYPE, (const void *)keyUtf8, len);
|
||||
}
|
||||
be_app->PostMessage(&msg);
|
||||
SDL_Looper->PostMessage(&msg);
|
||||
}
|
||||
|
||||
void _RepaintEvent()
|
||||
@@ -583,7 +583,7 @@ class SDL_BWin : public BWindow
|
||||
void _PostWindowEvent(BMessage &msg)
|
||||
{
|
||||
msg.AddInt32("window-id", _id);
|
||||
be_app->PostMessage(&msg);
|
||||
SDL_Looper->PostMessage(&msg);
|
||||
}
|
||||
|
||||
/* Command methods (functions called upon by SDL) */
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -358,7 +358,7 @@ HAIKU_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
||||
// "2 BApplication objects were created. Only one is allowed."
|
||||
std::unique_ptr<BApplication> application;
|
||||
if (be_app == NULL) {
|
||||
application = std::unique_ptr<BApplication>(new(std::nothrow) BApplication(signature));
|
||||
application = std::unique_ptr<BApplication>(new(std::nothrow) BApplication(SDL_signature));
|
||||
if (application == NULL) {
|
||||
return SDL_SetError("Cannot create the BApplication object. Lack of memory?");
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
@@ -72,7 +72,7 @@ static int _InitWindow(_THIS, SDL_Window *window) {
|
||||
}
|
||||
|
||||
window->driverdata = (SDL_WindowData *)bwin;
|
||||
int32 winID = _GetBeApp()->GetID(window);
|
||||
int32 winID = _GetBeLooper()->GetID(window);
|
||||
bwin->SetID(winID);
|
||||
|
||||
return 0;
|
||||
@@ -206,7 +206,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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user