aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/accelerometers.c7
-rw-r--r--src/accelerometers.h2
-rw-r--r--src/main.c27
-rw-r--r--src/mainwindow.c2
4 files changed, 24 insertions, 14 deletions
diff --git a/src/accelerometers.c b/src/accelerometers.c
index fbc749d..789e01c 100644
--- a/src/accelerometers.c
+++ b/src/accelerometers.c
@@ -132,12 +132,13 @@ void accelerometer_update(AccelHandle *accel) {
static void *accel_work(void *data) {
AccelHandle *accel;
+ int *finished = data;
int pos = 0;
accel = accelerometer_open();
audio_setup();
- while ( 1 ) {
+ while ( !(*finished) ) {
accelerometer_update(accel);
@@ -159,7 +160,7 @@ static void *accel_work(void *data) {
}
-GThread *accelerometer_start() {
- return g_thread_create(accel_work, NULL, TRUE, NULL);
+GThread *accelerometer_start(int *finished) {
+ return g_thread_create(accel_work, finished, TRUE, NULL);
}
diff --git a/src/accelerometers.h b/src/accelerometers.h
index 5f6daf2..77bf07b 100644
--- a/src/accelerometers.h
+++ b/src/accelerometers.h
@@ -35,7 +35,7 @@
extern AccelHandle *accelerometer_open(void);
extern void accelerometer_update(AccelHandle *accel);
-extern GThread *accelerometer_start(void);
+extern GThread *accelerometer_start(int *finished);
#endif /* ACCELEROMETERS_H */
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;
diff --git a/src/mainwindow.c b/src/mainwindow.c
index 93a1fd9..8b76fce 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -33,7 +33,7 @@
#include "audio.h"
static gint mainwindow_closed(GtkWidget *widget, MainWindow *mw) {
- gtk_exit(0);
+ gtk_main_quit();
return 0;
}