]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
implement become_idle interface in spinfinity
authorRay Strode <rstrode@redhat.com>
Mon, 22 Sep 2008 03:49:15 +0000 (23:49 -0400)
committerRay Strode <rstrode@redhat.com>
Tue, 23 Sep 2008 18:29:39 +0000 (14:29 -0400)
This means extending throbber to optionally take
a trigger to stop when ready.

src/libplybootsplash/ply-throbber.c
src/libplybootsplash/ply-throbber.h
src/plugins/splash/spinfinity/plugin.c

index 361a24f28589494100a617edd0bd8261a7758bed..79ab5b24a742bd2eaa5202677c556e4233c7f588 100644 (file)
@@ -65,10 +65,11 @@ struct _ply_throbber
   ply_window_t            *window;
   ply_frame_buffer_t      *frame_buffer;
   ply_frame_buffer_area_t  frame_area;
+  ply_trigger_t *stop_trigger;
 
   long x, y;
   long width, height;
-  double start_time, now;
+  double start_time, previous_time, now;
 };
 
 ply_throbber_t *
@@ -130,7 +131,7 @@ draw_background (ply_throbber_t *throbber)
                          throbber->frame_area.height);
 }
 
-static void
+static bool
 animate_at_time (ply_throbber_t *throbber,
                  double      time)
 {
@@ -138,16 +139,26 @@ animate_at_time (ply_throbber_t *throbber,
   int frame_number;
   ply_image_t * const * frames;
   uint32_t *frame_data;
+  bool should_continue;
 
   ply_window_set_mode (throbber->window, PLY_WINDOW_MODE_GRAPHICS);
 
   number_of_frames = ply_array_get_size (throbber->frames);
 
   if (number_of_frames == 0)
-    return;
+    return true;
+
+  should_continue = true;
 
   frame_number = (.5 * sin (time) + .5) * number_of_frames;
 
+  if (throbber->stop_trigger != NULL)
+    {
+      if ((time - throbber->previous_time) >= 2 * M_PI)
+        frame_number = number_of_frames - 1;
+      should_continue = false;
+    }
+
   ply_frame_buffer_pause_updates (throbber->frame_buffer);
   if (throbber->frame_area.width > 0)
     draw_background (throbber);
@@ -164,31 +175,49 @@ animate_at_time (ply_throbber_t *throbber,
                                           &throbber->frame_area, 0, 0,
                                           frame_data);
   ply_frame_buffer_unpause_updates (throbber->frame_buffer);
+
+  return should_continue;
 }
 
 static void
 on_timeout (ply_throbber_t *throbber)
 {
   double sleep_time;
+  bool should_continue;
+  throbber->previous_time = throbber->now;
   throbber->now = ply_get_timestamp ();
 
 #ifdef REAL_TIME_ANIMATION
-  animate_at_time (throbber,
-                   throbber->now - throbber->start_time);
+  should_continue = animate_at_time (throbber,
+                                 throbber->now - throbber->start_time);
 #else
   static double time = 0.0;
   time += 1.0 / FRAMES_PER_SECOND;
-  animate_at_time (throbber, time);
+  should_continue = animate_at_time (throbber, time);
 #endif
 
   sleep_time = 1.0 / FRAMES_PER_SECOND;
   sleep_time = MAX (sleep_time - (ply_get_timestamp () - throbber->now),
                     0.005);
 
-  ply_event_loop_watch_for_timeout (throbber->loop,
-                                    sleep_time,
-                                    (ply_event_loop_timeout_handler_t)
-                                    on_timeout, throbber);
+  if (!should_continue)
+    {
+
+      draw_background (throbber);
+
+      if (throbber->stop_trigger != NULL)
+        {
+          ply_trigger_pull (throbber->stop_trigger, NULL);
+          throbber->stop_trigger = NULL;
+        }
+    }
+  else
+    {
+      ply_event_loop_watch_for_timeout (throbber->loop,
+                                        sleep_time,
+                                        (ply_event_loop_timeout_handler_t)
+                                        on_timeout, throbber);
+    }
 }
 
 static bool
@@ -308,8 +337,8 @@ ply_throbber_start (ply_throbber_t         *throbber,
   return true;
 }
 
-void
-ply_throbber_stop (ply_throbber_t *throbber)
+static void
+ply_throbber_stop_now (ply_throbber_t *throbber)
 {
   if (throbber->frame_area.width > 0)
     draw_background (throbber);
@@ -326,6 +355,20 @@ ply_throbber_stop (ply_throbber_t *throbber)
     }
 }
 
+void
+ply_throbber_stop (ply_throbber_t *throbber,
+                   ply_trigger_t  *stop_trigger)
+{
+
+  if (stop_trigger == NULL)
+    {
+      ply_throbber_stop_now (throbber);
+      return;
+    }
+
+  throbber->stop_trigger = stop_trigger;
+}
+
 long
 ply_throbber_get_width (ply_throbber_t *throbber)
 {
index 21ff17eebc4d43f07c9ea431c0f34b462c4ac0a4..83f6b43eea7637b5acedc789a98e79b352f569a6 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "ply-event-loop.h"
 #include "ply-frame-buffer.h"
+#include "ply-trigger.h"
 #include "ply-window.h"
 
 typedef struct _ply_throbber ply_throbber_t;
@@ -43,7 +44,8 @@ bool ply_throbber_start (ply_throbber_t         *throbber,
                          ply_window_t       *window,
                          long                x,
                          long                y);
-void ply_throbber_stop (ply_throbber_t *throbber);
+void ply_throbber_stop (ply_throbber_t *throbber,
+                        ply_trigger_t  *stop_trigger);
 
 long ply_throbber_get_width (ply_throbber_t *throbber);
 long ply_throbber_get_height (ply_throbber_t *throbber);
index ec8176c0a0049268a33a768a24f1dfa2bfe18831..df32442b49e4c1bd59567069aff32e6512182925 100644 (file)
@@ -75,6 +75,7 @@ struct _ply_boot_splash_plugin
   ply_label_t *label;
 
   ply_answer_t *pending_password_answer;
+  ply_trigger_t *idle_trigger;
 
   uint32_t root_is_mounted : 1;
   uint32_t is_visible : 1;
@@ -205,14 +206,15 @@ start_animation (ply_boot_splash_plugin_t *plugin)
 }
 
 static void
-stop_animation (ply_boot_splash_plugin_t *plugin)
+stop_animation (ply_boot_splash_plugin_t *plugin,
+                ply_trigger_t            *trigger)
 {
   int i;
 
   assert (plugin != NULL);
   assert (plugin->loop != NULL);
 
-  ply_throbber_stop (plugin->throbber);
+  ply_throbber_stop (plugin->throbber, trigger);
 
 #ifdef ENABLE_FADE_OUT
   for (i = 0; i < 10; i++)
@@ -240,7 +242,7 @@ static void
 on_interrupt (ply_boot_splash_plugin_t *plugin)
 {
   ply_event_loop_exit (plugin->loop, 1);
-  stop_animation (plugin);
+  stop_animation (plugin, NULL);
   ply_window_set_mode (plugin->window, PLY_WINDOW_MODE_TEXT);
 }
 
@@ -440,7 +442,7 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin,
 
   if (plugin->loop != NULL)
     {
-      stop_animation (plugin);
+      stop_animation (plugin, NULL);
 
       ply_event_loop_stop_watching_for_exit (plugin->loop, (ply_event_loop_exit_handler_t)
                                              detach_from_event_loop,
@@ -521,7 +523,7 @@ ask_for_password (ply_boot_splash_plugin_t *plugin,
 
   if (ply_entry_is_hidden (plugin->entry))
     {
-      stop_animation (plugin);
+      stop_animation (plugin, NULL);
       show_password_prompt (plugin, prompt);
     }
   else
@@ -537,6 +539,13 @@ on_root_mounted (ply_boot_splash_plugin_t *plugin)
   plugin->root_is_mounted = true;
 }
 
+void
+become_idle (ply_boot_splash_plugin_t *plugin,
+             ply_trigger_t            *idle_trigger)
+{
+  stop_animation (plugin, idle_trigger);
+}
+
 ply_boot_splash_plugin_interface_t *
 ply_boot_splash_plugin_get_interface (void)
 {
@@ -550,7 +559,8 @@ ply_boot_splash_plugin_get_interface (void)
       .update_status = update_status,
       .hide_splash_screen = hide_splash_screen,
       .ask_for_password = ask_for_password,
-      .on_root_mounted = on_root_mounted
+      .on_root_mounted = on_root_mounted,
+      .become_idle = become_idle
     };
 
   return &plugin_interface;