]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/android/mainthread.cpp
Expose window flags and set fullscreen mode by default
[libs/core.git] / source / core / android / mainthread.cpp
index e07c837bcfdb15706f33e62baa98eeb1b82b26db..255eaa3260b892f43ae5d69eb670340b6a487120 100644 (file)
@@ -1,5 +1,9 @@
 #include <cstring>
+#include <cstdlib>
+#include <android/window.h>
+#include <msp/fs/dir.h>
 #include <msp/fs/path.h>
+#include <msp/fs/utils.h>
 #include "application.h"
 #include "errorlogger.h"
 #include "mainthread.h"
@@ -10,9 +14,19 @@ namespace Msp {
 namespace Android {
 
 MainThread::MainThread(ANativeActivity *a):
-       activity(a),
+       asset_manager(a->assetManager),
+       int_data_path(a->internalDataPath),
        starting_up(true)
 {
+       attach_to_activity(a);
+       startup_mutex.lock();
+       launch();
+}
+
+void MainThread::attach_to_activity(ANativeActivity *a)
+{
+       activity = a;
+       activity->callbacks->onDestroy = &activity_destroyed;
        activity->callbacks->onNativeWindowCreated = &native_window_created;
        activity->callbacks->onNativeWindowResized = &native_window_resized;
        activity->callbacks->onNativeWindowDestroyed = &native_window_destroyed;
@@ -20,9 +34,7 @@ MainThread::MainThread(ANativeActivity *a):
        activity->callbacks->onInputQueueDestroyed = &input_queue_destroyed;
        activity->instance = this;
 
-       startup_mutex.lock();
-
-       launch();
+       set_window_flags(AWINDOW_FLAG_FULLSCREEN, 0);
 }
 
 void MainThread::wait_for_app_created()
@@ -39,16 +51,28 @@ void MainThread::resume_startup()
        }
 }
 
+void MainThread::set_window_flags(unsigned set, unsigned clear)
+{
+       ANativeActivity_setWindowFlags(activity, set, clear);
+}
+
 void MainThread::main()
 {
        /* I have no idea how dependable this is, but it seems to be the only way
        to get the package name aside from making a Java call through JNI */
-       char *appname = strdup(FS::Path(activity->internalDataPath)[-2].c_str());
+       char *appname = strdup(int_data_path[-2].c_str());
        char *argv[] = { appname, 0 };
        Msp::Android::ErrorLogger err_logger;
+       FS::chdir(FS::dirname(int_data_path));
        Msp::Application::run(1, argv, this, &app_created);
        free(appname);
-       ANativeActivity_finish(activity);
+       if(activity)
+       {
+               activity->callbacks->onDestroy = &end_process;
+               ANativeActivity_finish(activity);
+       }
+       else
+               end_process(0);
 }
 
 void MainThread::app_created(void *data)
@@ -56,6 +80,11 @@ void MainThread::app_created(void *data)
        reinterpret_cast<MainThread *>(data)->resume_startup();
 }
 
+void MainThread::activity_destroyed(ANativeActivity *activity)
+{
+       reinterpret_cast<MainThread *>(activity->instance)->activity = 0;
+}
+
 void MainThread::native_window_created(ANativeActivity *activity, ANativeWindow *window)
 {
        reinterpret_cast<MainThread *>(activity->instance)->signal_native_window_created.emit(window);
@@ -81,5 +110,10 @@ void MainThread::input_queue_destroyed(ANativeActivity *activity, AInputQueue *q
        reinterpret_cast<MainThread *>(activity->instance)->signal_input_queue_destroyed.emit(queue);
 }
 
+void MainThread::end_process(ANativeActivity *)
+{
+       exit(0);
+}
+
 } // namespace Android
 } // namespace Msp