aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/main.c b/src/main.c
index 5944921..cac8b7f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -32,6 +32,7 @@
#include <stdio.h>
#include <glib.h>
#include <SDL.h>
+#include <unistd.h>
#include "types.h"
#include "mainwindow.h"
@@ -40,29 +41,37 @@
int main(int argc, char *argv[]) {
MainWindow *mw;
+ int graphics = 0;
GThread *accel_thread;
-
- gtk_init(&argc, &argv);
+ int finished = 0;
+
g_thread_init(NULL);
+ if ( gtk_init_check(&argc, &argv) ) {
+ graphics = 1;
+ }
+
if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {
fprintf(stderr, "Couldn't initialise SDL: %s\n", SDL_GetError());
return 1;
}
- atexit(SDL_Quit);
/* Start the accelerometer thread */
- accel_thread = accelerometer_start();
-
- /* Open the window */
- mw = mainwindow_open();
+ accel_thread = accelerometer_start(&finished);
- /* Wait "forever" */
- if ( mw != NULL ) {
+ if ( graphics ) {
+ /* Open the window */
+ mw = mainwindow_open();
gtk_main();
+ } else {
+ while ( 1 ) {
+ sleep(10);
+ }
}
+ finished = 1;
g_thread_join(accel_thread);
+ SDL_Quit();
return 0;