[Splashy-devel] 2/6 Make simple interface for splashy_video.h

Tim Dijkstra newsuser at famdijkstra.org
Sat Aug 12 21:36:42 UTC 2006


Move access to directfb structure to splashy_video.c. That way
we can in the end have only splashy_video.c include directfb.h. 


diff -u splashy_functions.c splashy_functions.c
--- splashy_functions.c	2006-08-12 13:22:31.000000000 +0200
+++ splashy_functions.c	2006-08-12 13:16:40.000000000 +0200
@@ -64,6 +64,8 @@
 #include <linux/vt.h>           /* VT_* */
 #endif
 
+#include <directfb_keyboard.h>  /* DIKI_F2 etc */
+
 #include "common_macros.h"
 #include "common_functions.h"
 #include "xml_parser.h"
@@ -174,15 +176,7 @@
 
         DEBUG_PRINT ("cmd_exit releasing memory %s", "");
 
-        /*
-         * free up memory 
-         */
-        video.ev_buffer->Release (video.ev_buffer);     /* input buffer */
-        video.keyboard->Release (video.keyboard);       /* keyevents gone */
-        video.primary_surface->Release (video.primary_surface); /* pix holder 
-                                                                 */
-        video.primary_window->Release (video.primary_window);
-        video.dfb->Release (video.dfb); /* kill it ! */
+        video_stop_splash (&video);
 
         exit (0);
         return 0;               /* we never reach this */
@@ -949,7 +943,7 @@
         /*
          * setup an event interface 
          */
-        DFBInputEvent event;
+        int key;
 
         /*
          * set the cancellation parameters -- - Enable thread cancellation - 
@@ -968,27 +962,23 @@
                 /*
                  * sub-parent (we are a fork after all). init is our parent 
                  */
-                DFBCHECK (video.ev_buffer->WaitForEvent (video.ev_buffer));
+                video_wait_for_event(&video);
+
                 /*
                  * get all events from our event buffer (fifo style) and
                  * process them. 
                  */
-                while (video.ev_buffer->HasEvent (video.ev_buffer) == DFB_OK
-                       && video.ev_buffer->GetEvent (video.ev_buffer,
-                                                     DFB_EVENT (&event)) ==
-                       DFB_OK)
+                while (video_get_key_event (&video, &key))
                 {
                         /*
                          * exit if ESC or F2 is pressed also kill our
                          * sub_child while at it 
                          */
-                        if (event.type == DIET_KEYPRESS)
-                        {
-                                if (event.key_id == DIKI_ESCAPE)
+                                if (key == DIKI_ESCAPE)
                                 {
                                         splashy_child_exit ();
                                 }
-                                else if (event.key_id == DIKI_F2)
+                                else if (key == DIKI_F2)
                                 {
                                         /*
                                          * when F2 is pressed we display a
@@ -1018,7 +1008,6 @@
                                                                      _current_background);
                                         }
                                 }
-                        }
                 }               /* ends while ev_buffer */
                 /*
                  * every 100 tries check to see if the thread has been
@@ -1205,22 +1194,9 @@
          */
         video_start_text_area (&video);
 
-        /*
-         * setup our main input: keyboard 
-         */
-        /*
-         * TODO would we leak if we don't check if video.keyboard is not NULL 
-         * ? We should make sure splashy can't be launched twice from this
-         * same thread 
-         */
-        DFBCHECK (video.dfb->
-                  GetInputDevice (video.dfb, DIDID_KEYBOARD,
-                                  &video.keyboard));
-        /*
-         * create event buffer for the keyboard: to listen for events 
-         */
-        DFBCHECK (video.keyboard->
-                  CreateEventBuffer (video.keyboard, &video.ev_buffer));
+        /* Maybe this can be moved to video_start_splash? */
+        video_create_event_buffer(&video);
+
         /*
          * here is where the magic happens: because WaitForEvent*() waits idle
          * for events, we need to fork and handle this in separate threads
diff -u splashy_video.c splashy_video.c
--- splashy_video.c	2006-08-12 13:22:31.000000000 +0200
+++ splashy_video.c	2006-08-12 13:28:57.000000000 +0200
@@ -812,6 +812,68 @@
 }
 
 void
+video_stop_splash (splashy_video_t * video)
+{
+        /*
+         * free up memory 
+         */
+        /* TODO Do we need to check if keyboard and ev_buffer were init'd ?*/
+        video->ev_buffer->Release (video->ev_buffer);     /* input buffer */
+        video->keyboard->Release (video->keyboard);       /* keyevents gone */
+        video->primary_surface->Release (video->primary_surface); /* pix holder 
+                                                                 */
+        video->primary_window->Release (video->primary_window);
+        video->dfb->Release (video->dfb); /* kill it ! */
+}
+
+void
+video_create_event_buffer (splashy_video_t * video)
+{
+        /*
+         * setup our main input: keyboard 
+         */
+        /*
+         * TODO would we leak if we don't check if video.keyboard is not NULL 
+         * ? We should make sure splashy can't be launched twice from this
+         * same thread 
+         */
+        DFBCHECK (video->dfb->
+                  GetInputDevice (video->dfb, DIDID_KEYBOARD,
+                                  &video->keyboard));
+        /*
+         * create event buffer for the keyboard: to listen for events 
+         */
+        DFBCHECK (video->keyboard->
+                  CreateEventBuffer (video->keyboard, &video->ev_buffer));
+}
+
+void
+video_wait_for_event (splashy_video_t * video)
+{
+        /* TODO Do some checks here first? */
+        DFBCHECK (video->ev_buffer->WaitForEvent (video->ev_buffer));
+}
+
+int
+video_get_key_event (splashy_video_t * video, int *key_id)
+{
+        DFBInputEvent DFBevent;
+        
+        while (video->ev_buffer->HasEvent (video->ev_buffer) == DFB_OK
+                       && video->ev_buffer->GetEvent (video->ev_buffer,
+                                                     DFB_EVENT (&DFBevent)) ==
+                       DFB_OK) 
+        {
+            if (DFBevent.type != DIET_KEYPRESS) continue;
+
+            *key_id = DFBevent.key_id;
+            return TRUE;
+        }
+
+        return FALSE;
+}
+
+void
 video_change_splash (splashy_video_t * video,
                      const gchar * newimage)
 {
diff -u splashy_video.h splashy_video.h
--- splashy_video.h	2006-08-12 13:22:31.000000000 +0200
+++ splashy_video.h	2006-08-12 13:28:25.000000000 +0200
@@ -95,4 +95,10 @@
 void video_fade_in (splashy_video_t * video);
 void video_fade_out (splashy_video_t * video);
 
+void video_stop_splash (splashy_video_t * video);
+
+void video_create_event_buffer (splashy_video_t * video);
+void video_wait_for_event (splashy_video_t * video);
+int video_get_key_event (splashy_video_t * video, int * key_id);
+
 #endif

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.alioth.debian.org/pipermail/splashy-devel/attachments/20060812/b9c12543/signature.pgp


More information about the Splashy-devel mailing list