Merge branch 'master' of https://vcs.maemo.org/git/xscreensaver
[xscreensaver] / xscreensaver / hacks / screenhack.c
index 7d0bf87..ea2bce0 100644 (file)
@@ -92,9 +92,7 @@
 #include <X11/Shell.h>
 #include <X11/StringDefs.h>
 #include <X11/keysym.h>
-/* #include <libosso.h> */
 #include <dbus/dbus.h>
-#include <dbus/dbus-glib.h> 
 
 #ifdef __sgi
 # include <X11/SGIScheme.h>    /* for SgiUseSchemes() */
@@ -147,6 +145,7 @@ static XrmOptionDescRec default_options [] = {
   { "-window-id", ".windowID",         XrmoptionSepArg, 0 },
   { "-fps",    ".doFPS",               XrmoptionNoArg, "True" },
   { "-no-fps",  ".doFPS",              XrmoptionNoArg, "False" },
+  { "-view",  ".view",                 XrmoptionSepArg, 1 },
 
 # ifdef DEBUG_PAIR
   { "-pair",   ".pair",                XrmoptionNoArg, "True" },
@@ -523,8 +522,28 @@ run_screenhack_table (Display *dpy,
 # ifdef DEBUG_PAIR
                       Window window2,
 # endif
-                      const struct xscreensaver_function_table *ft)
+                      const struct xscreensaver_function_table *ft,
+                     int view)
 {
+#define LIVEWP_SIGNAL_INTERFACE "org.maemo.livewp"
+#define LIVEWP_PAUSE_LIVEBG_ON_VIEW1 "pause_livebg_on_view1"                                                                                                 
+#define LIVEWP_PAUSE_LIVEBG_ON_VIEW2 "pause_livebg_on_view2"                                                                                                 
+#define LIVEWP_PAUSE_LIVEBG_ON_VIEW3 "pause_livebg_on_view3"                                                                                                 
+#define LIVEWP_PAUSE_LIVEBG_ON_VIEW4 "pause_livebg_on_view4"
+#define LIVEWP_PAUSE_LIVEBG_ON_VIEW "pause_livebg_on_view"
+#define LIVEWP_PLAY_LIVEBG_ON_VIEW1 "play_livebg_on_view1"                                                                                                   
+#define LIVEWP_PLAY_LIVEBG_ON_VIEW2 "play_livebg_on_view2"                                                                                                   
+#define LIVEWP_PLAY_LIVEBG_ON_VIEW3 "play_livebg_on_view3"                                                                                                   
+#define LIVEWP_PLAY_LIVEBG_ON_VIEW4 "play_livebg_on_view4" 
+#define LIVEWP_PLAY_LIVEBG_ON_VIEW "play_livebg_on_view" 
+   DBusMessage* msg;
+   DBusConnection* conn;
+   DBusError err;
+   DBusMessageIter args;
+   int ret;
+   char pause = 0;
+   int param = 0;
+   int start_frame = 200;
 
   /* Kludge: even though the init_cb functions are declared to take 2 args,
      actually call them with 3, for the benefit of xlockmore_init() and
@@ -549,20 +568,51 @@ run_screenhack_table (Display *dpy,
     abort();
 
   if (! fps_cb) fps_cb = screenhack_do_fps;
+  /* DBUS */
+  /* initialise the error */
+  dbus_error_init(&err);
+  conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
+  if (dbus_error_is_set(&err)) { 
+         fprintf(stderr, "Connection Error (%s)\n", err.message); 
+         dbus_error_free(&err); 
+  }
+  if (NULL == conn) {
+         fprintf(stderr, "Connection Null\n"); 
+         exit(1); 
+  }
+  if (view == 1){
+       dbus_bus_add_match (conn, "type='signal', interface='org.maemo.livewp', member='pause_livebg_on_view1'", NULL);
+       dbus_bus_add_match (conn, "type='signal', interface='org.maemo.livewp', member='play_livebg_on_view1'", NULL);
+  }
+  if (view == 2){
+       dbus_bus_add_match (conn, "type='signal', interface='org.maemo.livewp', member='pause_livebg_on_view2'", NULL);
+       dbus_bus_add_match (conn, "type='signal', interface='org.maemo.livewp', member='play_livebg_on_view2'", NULL);
+  }
+  if (view == 3){
+       dbus_bus_add_match (conn, "type='signal', interface='org.maemo.livewp', member='pause_livebg_on_view3'", NULL);
+       dbus_bus_add_match (conn, "type='signal', interface='org.maemo.livewp', member='play_livebg_on_view3'", NULL);
+  }
+  if (view == 4){
+       dbus_bus_add_match (conn, "type='signal', interface='org.maemo.livewp', member='pause_livebg_on_view4'", NULL);
+       dbus_bus_add_match (conn, "type='signal', interface='org.maemo.livewp', member='play_livebg_on_view4'", NULL);
+  }
+
+  dbus_connection_flush(conn);
 
   while (1)
     {
-      unsigned long delay = ft->draw_cb (dpy, window, closure);
+      if (pause == 0){
+        unsigned long delay = ft->draw_cb (dpy, window, closure);
 #ifdef DEBUG_PAIR
-      unsigned long delay2 = 0;
-      if (window2) delay2 = ft->draw_cb (dpy, window2, closure2);
+        unsigned long delay2 = 0;
+        if (window2) delay2 = ft->draw_cb (dpy, window2, closure2);
 #endif
 
-      if (fpst) fps_cb (dpy, window, fpst, closure);
+     
+        if (fpst) fps_cb (dpy, window, fpst, closure);
 #ifdef DEBUG_PAIR
-      if (fpst2) fps_cb (dpy, window, fpst2, closure);
+        if (fpst2) fps_cb (dpy, window, fpst2, closure);
 #endif
-
       if (! usleep_and_process_events (dpy, ft,
                                        window, fpst, closure, delay
 #ifdef DEBUG_PAIR
@@ -570,6 +620,78 @@ run_screenhack_table (Display *dpy,
 #endif
                                        ))
         break;
+
+      }
+      if (start_frame > 0) {
+          start_frame--;
+          continue;
+        }
+        dbus_connection_flush(conn);
+      if (pause == 0)
+      /* non blocking read of the next available message */
+       dbus_connection_read_write(conn, 0);
+      else
+      /* blocking read of the next available message */
+       dbus_connection_read_write(conn, 20000);
+
+      msg = dbus_connection_pop_message(conn);
+
+      if (NULL == msg){  
+          continue; 
+      }
+      fprintf(stderr, "signal on view %i\n", view);
+      /* check this is a method call for the right interface & method */
+      if ((view == 1 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW1))||
+          (view == 2 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW2))||
+          (view == 3 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW3))||
+          (view == 4 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW4))){
+          /* fprintf(stderr, "Pause scene visible %i\n", view); */ 
+          pause = 1;
+          dbus_message_unref (msg);
+          continue;
+      }
+      if ((view == 1 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW1))||
+          (view == 2 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW2))||
+          (view == 3 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW3))||
+          (view == 4 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW4))){
+           /* fprintf(stderr, "Play scene visible %i\n", view); */
+          pause = 0;
+          dbus_message_unref (msg);
+          continue;
+      }
+#if 0  
+      /*  dbus_connection_steal_borrowed_message(conn, msg); */
+     /* fprintf (stderr, "APPLICATION PATH11111111111111111111 %s %s %s\n",   dbus_message_get_path(msg),   dbus_message_get_interface (msg), dbus_message_get_member (msg));*/
+        /*dbus_connection_return_message(conn, msg);*/
+      if (dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW) || 
+          dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW)){
+          if (!dbus_message_iter_init(msg, &args))
+              fprintf(stderr, "dbus message has no param\n");
+          else if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args))             
+              fprintf(stderr, "dbus message param is not int \n");
+          else{ 
+              dbus_message_iter_get_basic(&args, &param);
+              fprintf(stderr, "dbus param = %i\n", param);
+          }
+          if (param == view){
+              if (dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW)){
+                 fprintf(stderr, "dbus  Pause scene visible %i\n", param); 
+                    pause = 1;
+              }
+              if (dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW)){
+                 fprintf(stderr, "dbus   Play scene visible %i\n", param); 
+                    pause = 0;
+              }
+              /*msg = dbus_connection_pop_message(conn);*/
+              fprintf(stderr, "dbus  steal message serial = %i\n", dbus_message_get_serial(msg)); 
+              /*dbus_connection_steal_borrowed_message(conn, msg);*/
+          }else{ 
+              fprintf(stderr, "dbus  return message\n"); 
+              /*dbus_connection_return_message(conn, msg);*/
+          }
+      }    
+#endif      
+      dbus_message_unref (msg);
     }
 
   ft->free_cb (dpy, window, closure);
@@ -579,6 +701,8 @@ run_screenhack_table (Display *dpy,
   if (window2) ft->free_cb (dpy, window2, closure2);
   if (window2) fps_free (fpst2);
 #endif
+  /* close the connection */
+  dbus_connection_close(conn);
 }
 
 
@@ -687,6 +811,7 @@ main (int argc, char **argv)
   XEvent event;
   Boolean dont_clear;
   char version[255];
+  int view;
 
   fix_fds();
 
@@ -837,19 +962,9 @@ main (int argc, char **argv)
       on_window = get_integer_resource (dpy, "windowID", "WindowID");
     if (s) free (s);
   }
-  /* OSSO initialize */
-/*  osso = osso_initialize("org.maemo.xscreensaver", "0.5.11", TRUE, NULL); */
-  
-   DBusGConnection *connection;
-   GError *error;
-   DBusGProxy *proxy;
-
-   g_type_init ();
-   error = NULL;
-   connection = dbus_g_bus_get (DBUS_BUS_SESSION,  &error);
-
-
 
+  view = get_integer_resource (dpy, "view", "view");
+  fprintf(stderr, "View %i\n", view);
   if (on_window)
     {
       window = (Window) on_window;
@@ -938,7 +1053,7 @@ main (int argc, char **argv)
 # ifdef DEBUG_PAIR
                         window2,
 # endif
-                        ft);
+                        ft, view);
 
   XtDestroyWidget (toplevel);
   XtDestroyApplicationContext (app);