]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
Create a separate window for each console
authorRay Strode <rstrode@redhat.com>
Fri, 3 Oct 2008 14:40:14 +0000 (10:40 -0400)
committerRay Strode <rstrode@redhat.com>
Wed, 8 Oct 2008 17:54:22 +0000 (13:54 -0400)
Since we may end up with multiple outputs
(if using serial console), we need to have
multiple windows one for each console line.

src/main.c
src/ply-boot-splash.c
src/ply-boot-splash.h

index 020d9e622974d6d74703c9c68f474255c93d81f6..a7895600cf14c13067e76dc90ceadf0cf9703af4 100644 (file)
@@ -37,6 +37,7 @@
 #include "ply-boot-server.h"
 #include "ply-boot-splash.h"
 #include "ply-event-loop.h"
+#include "ply-list.h"
 #include "ply-logger.h"
 #include "ply-terminal-session.h"
 #include "ply-trigger.h"
@@ -50,7 +51,7 @@ typedef struct
 {
   ply_event_loop_t *loop;
   ply_boot_server_t *boot_server;
-  ply_window_t *window;
+  ply_list_t *windows;
   ply_boot_splash_t *boot_splash;
   ply_terminal_session_t *session;
   ply_buffer_t *boot_buffer;
@@ -200,6 +201,30 @@ on_error (state_t *state)
   state->number_of_errors++;
 }
 
+static bool
+has_open_window (state_t *state)
+{
+  ply_list_node_t *node;
+
+  node = ply_list_get_first_node (state->windows);
+  while (node != NULL)
+    {
+      ply_list_node_t *next_node;
+      ply_window_t *window;
+
+      next_node = ply_list_get_next_node (state->windows, node);
+
+      window = ply_list_node_get_data (node);
+
+      if (ply_window_is_open (window))
+        return true;
+
+      node = next_node;
+    }
+
+  return false;
+}
+
 static bool
 plymouth_should_show_default_splash (state_t *state)
 {
@@ -216,7 +241,7 @@ plymouth_should_show_default_splash (state_t *state)
   if (state->console != NULL)
     return false;
 
-  if (state->window == NULL)
+  if (!has_open_window (state))
     return false;
 
   for (i = 0; strings[i] != NULL; i++)
@@ -239,11 +264,57 @@ plymouth_should_show_default_splash (state_t *state)
 }
 
 static void
-on_show_splash (state_t *state)
+open_windows (state_t *state)
 {
+  ply_list_node_t *node;
+
+  node = ply_list_get_first_node (state->windows);
+  while (node != NULL)
+    {
+      ply_list_node_t *next_node;
+      ply_window_t *window;
+
+      next_node = ply_list_get_next_node (state->windows, node);
+
+      window = ply_list_node_get_data (node);
 
-  if (state->window == NULL)
-    state->window = create_window (state, state->console);
+      if (!ply_window_is_open (window))
+        ply_window_open (window);
+
+      node = next_node;
+    }
+}
+
+static void
+close_windows (state_t *state)
+{
+  ply_list_node_t *node;
+
+  node = ply_list_get_first_node (state->windows);
+  while (node != NULL)
+    {
+      ply_list_node_t *next_node;
+      ply_window_t *window;
+
+      next_node = ply_list_get_next_node (state->windows, node);
+
+      window = ply_list_node_get_data (node);
+
+      if (ply_window_is_open (window))
+        ply_window_close (window);
+
+      ply_window_free (window);
+
+      node = next_node;
+    }
+
+  ply_list_free (state->windows);
+}
+
+static void
+on_show_splash (state_t *state)
+{
+  open_windows (state);
 
   if (plymouth_should_show_default_splash (state))
     show_default_splash (state);
@@ -263,13 +334,7 @@ on_hide_splash (state_t *state)
       state->boot_splash = NULL;
     }
 
-  ply_trace ("closing splash window");
-  if (state->window != NULL)
-    {
-      ply_window_close (state->window);
-      ply_window_free (state->window);
-      state->window = NULL;
-    }
+  close_windows (state);
 
   if (state->session != NULL)
     {
@@ -377,24 +442,36 @@ create_window (state_t    *state,
   ply_trace ("creating window on %s", tty_name != NULL? tty_name : "active vt");
   window = ply_window_new (tty_name);
 
-  ply_trace ("attaching window to event loop");
-  ply_window_attach_to_event_loop (window, state->loop);
+  return window;
+}
 
-  ply_trace ("opening window");
-  if (state->console == NULL && !ply_window_open (window))
+static void
+add_windows_to_boot_splash (state_t           *state,
+                            ply_boot_splash_t *splash)
+{
+  ply_list_node_t *node;
+
+  node = ply_list_get_first_node (state->windows);
+  while (node != NULL)
     {
-      ply_save_errno ();
-      ply_trace ("could not open window: %m");
-      ply_window_free (window);
-      ply_restore_errno ();
-      return NULL;
-    }
+      ply_list_node_t *next_node;
+      ply_window_t *window;
 
-  ply_trace ("listening for escape key");
-  ply_window_set_escape_handler (window, (ply_window_escape_handler_t)
-                                 on_escape_pressed, state);
+      next_node = ply_list_get_next_node (state->windows, node);
 
-  return window;
+      window = ply_list_node_get_data (node);
+
+      if (ply_window_is_open (window))
+        {
+          ply_trace ("adding window to boot splash");
+          ply_boot_splash_add_window (splash, window);
+        }
+
+      ply_trace ("listening for escape key");
+      ply_window_set_escape_handler (window, (ply_window_escape_handler_t)
+                                     on_escape_pressed, state);
+      node = next_node;
+    }
 }
 
 static ply_boot_splash_t *
@@ -405,11 +482,23 @@ start_boot_splash (state_t    *state,
 
   ply_trace ("Loading boot splash plugin '%s'",
              module_path);
-  splash = ply_boot_splash_new (module_path, state->window, state->boot_buffer);
+
+  splash = ply_boot_splash_new (module_path, state->boot_buffer);
+
+  if (!ply_boot_splash_load (splash))
+    {
+      ply_save_errno ();
+      ply_boot_splash_free (splash);
+      ply_restore_errno ();
+      return NULL;
+    }
 
   ply_trace ("attaching plugin to event loop");
   ply_boot_splash_attach_to_event_loop (splash, state->loop);
 
+  ply_trace ("adding windows to boot splash");
+  add_windows_to_boot_splash (state, splash);
+
   ply_trace ("showing plugin");
   if (!ply_boot_splash_show (splash))
     {
@@ -498,7 +587,7 @@ check_verbosity (state_t *state)
 }
 
 static void
-check_for_serial_console (state_t *state)
+check_for_consoles (state_t *state)
 {
   char *console_key;
   char *remaining_command_line;
@@ -523,7 +612,12 @@ check_for_serial_console (state_t *state)
           *end = '\0';
           remaining_command_line += end - state->console;
         }
+
+      ply_list_append_data (state->windows, create_window (state, state->console));
     }
+
+    if (ply_list_get_length (state->windows) == 0)
+      ply_list_append_data (state->windows, ply_window_new ("tty1"));
 }
 
 static bool
@@ -562,7 +656,9 @@ initialize_environment (state_t *state)
     return false;
 
   check_verbosity (state);
-  check_for_serial_console (state);
+
+  state->windows = ply_list_new ();
+  check_for_consoles (state);
 
   if (state->console != NULL)
     redirect_standard_io_to_device (state->console);
@@ -691,8 +787,7 @@ main (int    argc,
   ply_boot_splash_free (state.boot_splash);
   state.boot_splash = NULL;
 
-  ply_window_free (state.window);
-  state.window = NULL;
+  ply_list_free (state.windows);
 
   ply_boot_server_free (state.boot_server);
   state.boot_server = NULL;
index 59b7dcda72b34b5258991983a9d3c9c6a510db28..b538535c5f18ca4c95caa71012790cd3f6d60970 100644 (file)
@@ -56,7 +56,6 @@ struct _ply_boot_splash
   ply_module_handle_t *module_handle;
   const ply_boot_splash_plugin_interface_t *plugin_interface;
   ply_boot_splash_plugin_t *plugin;
-  ply_window_t *window;
   ply_buffer_t *boot_buffer;
   ply_trigger_t *idle_trigger;
 
@@ -67,6 +66,7 @@ struct _ply_boot_splash
   double start_time;
   double wait_time;
 
+  uint32_t is_loaded : 1;
   uint32_t is_shown : 1;
 };
 
@@ -75,7 +75,6 @@ typedef const ply_boot_splash_plugin_interface_t *
 
 ply_boot_splash_t *
 ply_boot_splash_new (const char   *module_name,
-                     ply_window_t *window,
                      ply_buffer_t *boot_buffer)
 {
   ply_boot_splash_t *splash;
@@ -88,14 +87,27 @@ ply_boot_splash_new (const char   *module_name,
   splash->module_handle = NULL;
   splash->is_shown = false;
 
-  splash->window = window;
   splash->boot_buffer = boot_buffer;
 
   return splash;
 }
 
-static bool
-ply_boot_splash_load_plugin (ply_boot_splash_t *splash)
+void
+ply_boot_splash_add_window (ply_boot_splash_t *splash,
+                            ply_window_t      *window)
+{
+  splash->plugin_interface->add_window (splash->plugin, window);
+}
+
+void
+ply_boot_splash_remove_window (ply_boot_splash_t *splash,
+                               ply_window_t      *window)
+{
+  splash->plugin_interface->remove_window (splash->plugin, window);
+}
+
+bool
+ply_boot_splash_load (ply_boot_splash_t *splash)
 {
   assert (splash != NULL);
   assert (splash->module_name != NULL);
@@ -135,6 +147,8 @@ ply_boot_splash_load_plugin (ply_boot_splash_t *splash)
 
   assert (splash->plugin != NULL);
 
+  splash->is_loaded = true;
+
   return true;
 }
 
@@ -171,8 +185,8 @@ save_boot_duration (ply_boot_splash_t *splash)
     }
 }
 
-static void
-ply_boot_splash_unload_plugin (ply_boot_splash_t *splash)
+void
+ply_boot_splash_unload (ply_boot_splash_t *splash)
 {
   assert (splash != NULL);
   assert (splash->plugin != NULL);
@@ -187,6 +201,8 @@ ply_boot_splash_unload_plugin (ply_boot_splash_t *splash)
   splash->module_handle = NULL;
 
   save_boot_duration (splash);
+
+  splash->is_loaded = false;
 }
 
 void
@@ -196,7 +212,7 @@ ply_boot_splash_free (ply_boot_splash_t *splash)
     return;
 
   if (splash->module_handle != NULL)
-    ply_boot_splash_unload_plugin (splash);
+    ply_boot_splash_unload (splash);
 
   free (splash->module_name);
   free (splash);
@@ -251,21 +267,10 @@ ply_boot_splash_show (ply_boot_splash_t *splash)
   splash->start_time = ply_get_timestamp ();
   splash->boot_duration = DEFAULT_BOOT_DURATION;
 
-  ply_trace ("trying to load %s", splash->module_name);
-  if (!ply_boot_splash_load_plugin (splash))
-    {
-      ply_save_errno ();
-      ply_trace ("can't load plugin: %m");
-      ply_restore_errno ();
-      return false;
-    }
-
   assert (splash->plugin_interface != NULL);
   assert (splash->plugin != NULL);
   assert (splash->plugin_interface->show_splash_screen != NULL);
 
-  splash->plugin_interface->add_window (splash->plugin, splash->window);
-
   ply_trace ("showing splash screen\n");
   if (!splash->plugin_interface->show_splash_screen (splash->plugin,
                                                      splash->loop,
@@ -379,8 +384,6 @@ ply_boot_splash_hide (ply_boot_splash_t *splash)
   splash->plugin_interface->hide_splash_screen (splash->plugin,
                                                 splash->loop);
 
-  splash->plugin_interface->remove_window (splash->plugin, splash->window);
-
   splash->is_shown = false;
 
   if (splash->loop != NULL)
@@ -497,7 +500,14 @@ main (int    argc,
                                  (ply_window_escape_handler_t) on_quit, &state);
 
   state.buffer = ply_buffer_new ();
-  state.splash = ply_boot_splash_new (module_name, state.window, state.buffer);
+  state.splash = ply_boot_splash_new (module_name, state.buffer);
+  if (!ply_boot_splash_load_plugin (state.spalsh))
+    {
+      perror ("could not load splash screen");
+      return errno;
+    }
+
+  ply_boot_splash_add_window (state.window);
   ply_boot_splash_attach_to_event_loop (state.splash, state.loop);
 
   if (!ply_boot_splash_show (state.splash))
index 057e626d5e1efada8bb56b3d5c8349801340dae0..1d7a2df1b7e410b4a5fda45f1a0b28bfdf4c538d 100644 (file)
@@ -37,8 +37,13 @@ typedef void (* ply_boot_splash_on_idle_handler_t) (void *user_data);
 
 #ifndef PLY_HIDE_FUNCTION_DECLARATIONS
 ply_boot_splash_t *ply_boot_splash_new (const char *module_name,
-                                        ply_window_t *window,
                                         ply_buffer_t *boot_buffer);
+bool ply_boot_splash_load (ply_boot_splash_t *splash);
+void ply_boot_splash_unload (ply_boot_splash_t *splash);
+void ply_boot_splash_add_window (ply_boot_splash_t *splash,
+                                 ply_window_t      *window);
+void ply_boot_splash_remove_window (ply_boot_splash_t *splash,
+                                    ply_window_t      *window);
 void ply_boot_splash_free (ply_boot_splash_t *splash);
 bool ply_boot_splash_show (ply_boot_splash_t *splash);
 void ply_boot_splash_update_status (ply_boot_splash_t *splash,