Use libosso to prevent screen blanking
authorAlberto Mardegan <mardy@users.sourceforge.net>
Wed, 6 Jul 2011 12:00:06 +0000 (15:00 +0300)
committerAlberto Mardegan <mardy@users.sourceforge.net>
Wed, 6 Jul 2011 12:00:06 +0000 (15:00 +0300)
Makefile
ball/main.c
share/maemo.c [new file with mode: 0644]
share/maemo.h [new file with mode: 0644]

index 3b88369..e594c89 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -91,7 +91,7 @@ ifeq ($(PLATFORM),darwin)
 endif
 
 ifeq ($(PLATFORM),maemo)
-    ALL_CPPFLAGS += -D__MAEMO__
+    ALL_CPPFLAGS += -D__MAEMO__ $(shell pkg-config --cflags libosso)
 endif
 
 ALL_CPPFLAGS += $(CPPFLAGS)
@@ -153,6 +153,10 @@ ifeq ($(PLATFORM),darwin)
     BASE_LIBS += -L/opt/local/lib
 endif
 
+ifeq ($(PLATFORM),maemo)
+    BASE_LIBS += $(shell pkg-config --libs libosso)
+endif
+
 ALL_LIBS := $(SDL_LIBS) $(BASE_LIBS) $(TILT_LIBS) $(INTL_LIBS) -lSDL_ttf \
     -lvorbisfile $(OGL_LIBS)
 
@@ -322,6 +326,7 @@ BALL_OBJS += share/tilt_loop.o
 else
 ifeq ($(PLATFORM),maemo)
 BALL_OBJS += share/tilt_maemo.o
+BALL_OBJS += share/maemo.o
 else
 BALL_OBJS += share/tilt_null.o
 endif
index 40ff383..af312f6 100644 (file)
@@ -30,6 +30,9 @@
 #include "tilt.h"
 #include "fs.h"
 #include "common.h"
+#ifdef __MAEMO__
+#include "maemo.h"
+#endif
 
 #include "st_conf.h"
 #include "st_title.h"
@@ -458,7 +461,12 @@ int main(int argc, char *argv[])
 
     /* Initialize SDL. */
 
-    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == -1)
+    if (SDL_Init(SDL_INIT_VIDEO |
+                 SDL_INIT_AUDIO |
+#ifdef __MAEMO__
+                 SDL_INIT_TIMER |
+#endif
+                 SDL_INIT_JOYSTICK) == -1)
     {
         fprintf(stderr, "%s\n", SDL_GetError());
         return 1;
@@ -528,6 +536,10 @@ int main(int argc, char *argv[])
     else
         goto_state(&st_title);
 
+#ifdef __MAEMO__
+    maemo_init("neverball");
+#endif
+
     /* Run the main game loop. */
 
     t0 = SDL_GetTicks();
@@ -559,6 +571,9 @@ int main(int argc, char *argv[])
         SDL_JoystickClose(joy);
 
     tilt_free();
+#ifdef __MAEMO__
+    maemo_quit();
+#endif
     SDL_Quit();
 
     return 0;
diff --git a/share/maemo.c b/share/maemo.c
new file mode 100644 (file)
index 0000000..fa67e8a
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ *  Copyright (C) 2011  Neverball authors
+ *
+ *  This  program is  free software;  you can  redistribute  it and/or
+ *  modify it  under the  terms of the  GNU General Public  License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  This program  is distributed in the  hope that it  will be useful,
+ *  but  WITHOUT ANY WARRANTY;  without even  the implied  warranty of
+ *  MERCHANTABILITY or FITNESS FOR  A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a  copy of the GNU General Public License
+ *  along  with this  program;  if  not, write  to  the Free  Software
+ *  Foundation,  Inc.,   59  Temple  Place,  Suite   330,  Boston,  MA
+ *  02111-1307 USA
+ */
+
+#include "maemo.h"
+#include <SDL/SDL_timer.h>
+#include <libosso.h>
+
+static osso_context_t *osso_context = NULL;
+static SDL_TimerID screen_timer_id = 0;
+
+static Uint32 disable_display_blank(Uint32 interval, void *param)
+{
+    int ret;
+    ret = osso_display_blanking_pause(osso_context);
+    return interval;
+}
+
+int maemo_init(const char *program)
+{
+    osso_context = osso_initialize(program, "1.0", 0, NULL);
+    if (!osso_context) {
+        fprintf(stderr, "osso_initialize failed!\n");
+        return 0;
+    }
+
+    osso_display_blanking_pause(osso_context);
+    screen_timer_id = SDL_AddTimer(30000, disable_display_blank, NULL);
+    return 1;
+}
+
+void maemo_quit(void)
+{
+    if (osso_context)
+        osso_deinitialize(osso_context);
+
+    SDL_RemoveTimer(screen_timer_id);
+}
+
diff --git a/share/maemo.h b/share/maemo.h
new file mode 100644 (file)
index 0000000..8a5e1c5
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ *  Copyright (C) 2011  Neverball authors
+ *
+ *  This  program is  free software;  you can  redistribute  it and/or
+ *  modify it  under the  terms of the  GNU General Public  License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  This program  is distributed in the  hope that it  will be useful,
+ *  but  WITHOUT ANY WARRANTY;  without even  the implied  warranty of
+ *  MERCHANTABILITY or FITNESS FOR  A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a  copy of the GNU General Public License
+ *  along  with this  program;  if  not, write  to  the Free  Software
+ *  Foundation,  Inc.,   59  Temple  Place,  Suite   330,  Boston,  MA
+ *  02111-1307 USA
+ */
+
+int maemo_init(const char *program);
+void maemo_quit(void);
+