fixed exec file name
[shermanaquarium] / sherman-aquarium / shermans / screensaver.c
index 8f1f57f..3a5aff9 100644 (file)
@@ -57,6 +57,13 @@ typedef struct {
 #include "soundeffects.h"
 #include "vroot.h"
 
+
+/* For Maemo */
+
+#include <libosso.h>                                                                                                                                                             
+#include <dbus/dbus.h>                                                                                                                                                             
+#include <dbus/dbus-glib.h>
+
 #ifdef DARWIN
 #include "getopt.h"
 #else
@@ -138,7 +145,10 @@ int view = 1;
 static unsigned char *original_bg;
 static AquariumData ad;
 
-
+/* For Maemo */
+static osso_context_t      *osso;
+DBusConnection      *dbus_conn_session;
+static int pause_in_view = 0;
 
 void screensaver_draw_image(int x, int y, int idx, int rev, SA_Image *image)
 {
@@ -422,6 +432,7 @@ void screensaver_main_gdk(void)
 {
     GdkEvent *event;
     int counter = 0;
+    DBusMessage* msg;
 
     while(1){
        while(gdk_events_pending()){
@@ -444,8 +455,31 @@ void screensaver_main_gdk(void)
        gdk_draw_rgb_image(window, gc, ad.xmin, ad.ymin, ad.xmax, ad.ymax,
                           GDK_RGB_DITHER_NONE, ad.rgb, ad.xmax * 3);
        gdk_flush();
+
        /* 25 fps */
        usleep(1000000/25);
+
+       if (pause_in_view == 0)
+       /* non blocking read of the next available message */
+       dbus_connection_read_write(dbus_conn_session, 0);
+       else
+             /* blocking read of the next available message */
+       dbus_connection_read_write(dbus_conn_session, 20000);
+
+       msg = dbus_connection_pop_message(dbus_conn_session);
+
+       if (NULL == msg){  
+          continue; 
+       }
+       if ( dbus_message_get_member (msg) &&
+          !strncmp( "play_livebg_on_view", dbus_message_get_member (msg),19)){
+              pause_in_view = 0; 
+       }
+       if ( dbus_message_get_member (msg) &&
+            !strncmp( "pause_livebg_on_view", dbus_message_get_member (msg),19)){
+               pause_in_view = 1;
+       }
+
     }
 
 }
@@ -497,6 +531,33 @@ void init_sdl(int sdl_flags)
     SDL_UpdateRect(screen,0,0,0,0);
 
 }
+void
+initialize_dbus(void){
+    gchar       *filter_string;
+    DBusError   error;
+
+    dbus_error_init (&error);
+    /* Add D-BUS signal handler for 'status_changed' */
+    dbus_conn_session = (DBusConnection *) osso_get_dbus_connection(osso);
+    if (dbus_conn_session){
+        filter_string =
+            g_strdup_printf("interface='org.maemo.livewp', member='pause_livebg_on_view%i'", view);
+        dbus_bus_add_match(dbus_conn_session, filter_string, &error);
+        if (dbus_error_is_set(&error)){
+             fprintf(stderr,"dbus_bus_add_match failed: %s", error.message);
+             dbus_error_free(&error);
+        }
+        g_free(filter_string);
+        filter_string =
+            g_strdup_printf("interface='org.maemo.livewp', member='play_livebg_on_view%i'", view);
+        dbus_bus_add_match(dbus_conn_session, filter_string, &error);
+        if (dbus_error_is_set(&error)){
+             fprintf(stderr,"dbus_bus_add_match failed: %s", error.message);
+             dbus_error_free(&error);
+        }
+        g_free(filter_string);
+    }
+}
 
 
 void screensaver_init()
@@ -511,13 +572,17 @@ void screensaver_init()
     screen_height = 480;
     screen_width = 800;
     
+    osso = osso_initialize("org.maemo.sherman", "3.0", TRUE, NULL);
+    initialize_dbus();
+
     if(window_id != -1){
        display = XOpenDisplay(NULL);
        XGetWindowAttributes(display, (Window)window_id, &win_attr);
        screen_height = win_attr.height;
        screen_width = win_attr.width;
        fullscreen = 0;
-       ad.proximity = 1;                       /* No sound effects */
+       //ad.proximity = 1;                     /* No sound effects */
+    ad.proximity = 0;
        window = gdk_window_foreign_new((Window)window_id);
        gdk_window_show(window);
        gc = gdk_gc_new(window);
@@ -907,6 +972,7 @@ fprintf(stderr, "1BG %i\n",bg->desktop);
 
 }
 
+
 int main(int argc, char **argv)
 {
     gdk_init(&argc, &argv);
@@ -917,12 +983,10 @@ int main(int argc, char **argv)
     screensaver_init(0);
 
     if(window_id==-1){
-       fprintf(stderr, "screensaver_main_sdl\n");
-       screensaver_main_sdl();
+           screensaver_main_sdl();
     }
     else{
-        fprintf(stderr, "screensaver_main_GDK\n");
-       screensaver_main_gdk();
+           screensaver_main_gdk();
     }
     return 0;
 }