diff options
Diffstat (limited to 'src/haiku_support.cc')
-rw-r--r-- | src/haiku_support.cc | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/src/haiku_support.cc b/src/haiku_support.cc index f0db852e26e..0642dbacff7 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -89,6 +89,7 @@ enum CANCEL_DROP = 3003, SHOW_MENU_BAR = 3004, BE_MENU_BAR_OPEN = 3005, + QUIT_APPLICATION = 3006, }; static color_space dpy_color_space = B_NO_COLOR_SPACE; @@ -418,6 +419,15 @@ public: haiku_write (APP_QUIT_REQUESTED_EVENT, &rq); return 0; } + + void + MessageReceived (BMessage *msg) + { + if (msg->what == QUIT_APPLICATION) + Quit (); + else + BApplication::MessageReceived (msg); + } }; class EmacsWindow : public BWindow @@ -2328,13 +2338,15 @@ public: static int32 start_running_application (void *data) { + Emacs *app = (Emacs *) data; + haiku_io_init_in_app_thread (); - if (!((Emacs *) data)->Lock ()) + if (!app->Lock ()) gui_abort ("Failed to lock application"); - ((Emacs *) data)->Run (); - ((Emacs *) data)->Unlock (); + app->Run (); + app->Unlock (); return 0; } @@ -2404,25 +2416,37 @@ BBitmap_dimensions (void *bitmap, int *left, int *top, *mono_p = (((BBitmap *) bitmap)->ColorSpace () == B_GRAY1); } +static void +wait_for_exit_of_app_thread (void) +{ + status_t ret; + + be_app->PostMessage (QUIT_APPLICATION); + wait_for_thread (app_thread, &ret); +} + /* Set up an application and return it. If starting the application thread fails, abort Emacs. */ void * BApplication_setup (void) { - if (be_app) - return be_app; thread_id id; Emacs *app; + if (be_app) + return be_app; + app = new Emacs; app->Unlock (); + if ((id = spawn_thread (start_running_application, "Emacs app thread", B_DEFAULT_MEDIA_PRIORITY, app)) < 0) gui_abort ("spawn_thread failed"); resume_thread (id); - app_thread = id; + + atexit (wait_for_exit_of_app_thread); return app; } @@ -3772,16 +3796,6 @@ be_popup_file_dialog (int open_p, const char *default_dir, int must_match_p, int } } -void -be_app_quit (void) -{ - if (be_app) - { - while (!be_app->Lock ()); - be_app->Quit (); - } -} - /* Zoom WINDOW. */ void BWindow_zoom (void *window) |