]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
add new ply_window_t type to manage text versus graphics mode,
authorRay Strode <rstrode@redhat.com>
Thu, 15 May 2008 19:52:19 +0000 (15:52 -0400)
committerRay Strode <rstrode@redhat.com>
Sat, 17 May 2008 06:16:22 +0000 (02:16 -0400)
and eventually key events

12 files changed:
src/Makefile.am
src/main.c
src/ply-boot-splash-plugin.h
src/ply-boot-splash.c
src/ply-window.c [new file with mode: 0644]
src/ply-window.h [new file with mode: 0644]
src/splash-plugins/fedora-fade-in/Makefile.am
src/splash-plugins/fedora-fade-in/fedora-fade-in.c
src/splash-plugins/text/text.c
src/tests/Makefile.am
src/tests/ply-boot-splash-test.am
src/tests/ply-window-test.am [new file with mode: 0644]

index 540bf19584a22bd935be8a25a2fe7a75efc163a7..3baee74545b0ec23f2f72fa63177735cc2dac379 100644 (file)
@@ -3,7 +3,7 @@ INCLUDES = -I$(top_srcdir)                                                    \
            -I$(srcdir)/libply                                                 \
            -I$(srcdir)
 plymouthbindir = $(libexecdir)/plymouth
-plymouthbin_PROGRAMS = plymouth 
+plymouthbin_PROGRAMS = plymouth
 
 plymouth_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLYMOUTH_PLUGIN_PATH=\"$(libdir)/plymouth/\"
 plymouth_LDADD = $(PLYMOUTH_LIBS) libply/libply.la
index 0f6ba0bdebdb87e0374e05d4d771b099da64073c..0acfc6ba6a94a0090f5874f0bab7a49c6451bbbf 100644 (file)
@@ -421,7 +421,7 @@ main (int    argc,
       return EX_UNAVAILABLE;
     }
 
-  state.boot_server = start_boot_server (&state); 
+  state.boot_server = start_boot_server (&state);
 
   if (state.boot_server == NULL)
     {
index 3b54dfa9f3a56ffa8fa420a24cc78ae7475a6ebd..789c4781962c81345ea1d36f5fda5a241c19741a 100644 (file)
@@ -27,6 +27,7 @@
 #include <unistd.h>
 
 #include "ply-event-loop.h"
+#include "ply-window.h"
 
 typedef struct _ply_boot_splash_plugin ply_boot_splash_plugin_t;
 
@@ -35,10 +36,12 @@ typedef struct
   ply_boot_splash_plugin_t * (* create_plugin) (void);
   void (* destroy_plugin) (ply_boot_splash_plugin_t *plugin);
 
-  bool (* show_splash_screen) (ply_boot_splash_plugin_t *plugin);
+  bool (* show_splash_screen) (ply_boot_splash_plugin_t *plugin,
+                               ply_window_t             *window);
   void (* update_status) (ply_boot_splash_plugin_t *plugin,
                           const char               *status);
-  void (* hide_splash_screen) (ply_boot_splash_plugin_t *plugin);
+  void (* hide_splash_screen) (ply_boot_splash_plugin_t *plugin,
+                               ply_window_t             *window);
   void (* attach_to_event_loop) (ply_boot_splash_plugin_t *plugin,
                                  ply_event_loop_t         *loop);
 
index 86e806b388bd5311e4a717262e8204b67da772ce..4a1f93c0785f4976df1a3b2c1ca1d020e8a52b6e 100644 (file)
@@ -43,6 +43,7 @@ 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;
 
   char *module_name;
   char *status;
@@ -101,8 +102,10 @@ ply_boot_splash_load_plugin (ply_boot_splash_t *splash)
 
   if (get_boot_splash_plugin_interface == NULL)
     {
+      ply_save_errno ();
       ply_close_module (splash->module_handle);
       splash->module_handle = NULL;
+      ply_restore_errno ();
       return false;
     }
 
@@ -110,8 +113,10 @@ ply_boot_splash_load_plugin (ply_boot_splash_t *splash)
 
   if (splash->plugin_interface == NULL)
     {
+      ply_save_errno ();
       ply_close_module (splash->module_handle);
       splash->module_handle = NULL;
+      ply_restore_errno ();
       return false;
     }
 
@@ -138,6 +143,23 @@ ply_boot_splash_unload_plugin (ply_boot_splash_t *splash)
   splash->module_handle = NULL;
 }
 
+static bool
+ply_boot_splash_create_window (ply_boot_splash_t *splash)
+{
+  splash->window = ply_window_new ("/dev/tty1");
+
+  if (!ply_window_open (splash->window))
+    {
+      ply_save_errno ();
+      ply_window_free (splash->window);
+      splash->window = NULL;
+      ply_restore_errno ();
+      return false;
+    }
+
+  return true;
+}
+
 bool
 ply_boot_splash_show (ply_boot_splash_t *splash)
 {
@@ -145,8 +167,14 @@ ply_boot_splash_show (ply_boot_splash_t *splash)
   assert (splash->module_name != NULL);
   assert (splash->loop != NULL);
 
+  ply_trace ("trying to load %s", splash->module_name);
   if (!ply_boot_splash_load_plugin (splash))
-    return false;
+    {
+      ply_save_errno ();
+      ply_trace ("can't load plugin: %m");
+      ply_restore_errno ();
+      return false;
+    }
 
   assert (splash->plugin_interface != NULL);
   assert (splash->plugin != NULL);
@@ -155,9 +183,22 @@ ply_boot_splash_show (ply_boot_splash_t *splash)
 
   splash->plugin_interface->attach_to_event_loop (splash->plugin,
                                                   splash->loop);
-  if (!splash->plugin_interface->show_splash_screen (splash->plugin))
+
+  if (!ply_boot_splash_create_window (splash))
     return false;
 
+  assert (splash->window != NULL);
+
+  if (!splash->plugin_interface->show_splash_screen (splash->plugin,
+                                                     splash->window))
+    {
+
+      ply_save_errno ();
+      ply_trace ("can't show splash: %m");
+      ply_restore_errno ();
+      return false;
+    }
+
   splash->is_shown = true;
   return true;
 }
@@ -197,7 +238,8 @@ ply_boot_splash_hide (ply_boot_splash_t *splash)
   assert (splash->plugin != NULL);
   assert (splash->plugin_interface->hide_splash_screen != NULL);
 
-  splash->plugin_interface->hide_splash_screen (splash->plugin);
+  splash->plugin_interface->hide_splash_screen (splash->plugin,
+                                                splash->window);
 
   ply_boot_splash_unload_plugin (splash);
   splash->is_shown = false;
diff --git a/src/ply-window.c b/src/ply-window.c
new file mode 100644 (file)
index 0000000..bc0bfec
--- /dev/null
@@ -0,0 +1,218 @@
+/* ply-window.h - APIs for putting up a window screen
+ *
+ * Copyright (C) 2007 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by: Ray Strode <rstrode@redhat.com>
+ */
+#include "config.h"
+#include "ply-window.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <linux/kd.h>
+
+#include "ply-event-loop.h"
+#include "ply-logger.h"
+#include "ply-utils.h"
+
+struct _ply_window
+{
+  ply_event_loop_t *loop;
+
+  char *tty_name;
+  int   tty_fd;
+
+  ply_window_mode_t mode;
+};
+
+
+ply_window_t *
+ply_window_new (const char *tty_name)
+{
+  ply_window_t *window;
+
+  assert (tty_name != NULL);
+
+  window = calloc (1, sizeof (ply_window_t));
+  window->loop = NULL;
+  window->tty_name = strdup (tty_name);
+  window->tty_fd = -1;
+
+  return window;
+}
+
+bool
+ply_window_open (ply_window_t *window)
+{
+  assert (window != NULL);
+  assert (window->tty_name != NULL);
+  assert (window->tty_fd < 0);
+
+  window->tty_fd = open (window->tty_name, O_RDWR | O_NOCTTY);
+
+  if (window->tty_fd < 0)
+    return false;
+
+  if (!ply_window_set_mode (window, PLY_WINDOW_MODE_TEXT))
+    return false;
+
+  return true;
+}
+
+void
+ply_window_close (ply_window_t *window)
+{
+  ply_window_set_mode (window, PLY_WINDOW_MODE_TEXT);
+
+  close (window->tty_fd);
+  window->tty_fd = -1;
+}
+
+bool
+ply_window_set_mode (ply_window_t      *window,
+                     ply_window_mode_t  mode)
+{
+  assert (window != NULL);
+  assert (mode == PLY_WINDOW_MODE_TEXT || mode == PLY_WINDOW_MODE_GRAPHICS);
+
+  switch (mode)
+    {
+      case PLY_WINDOW_MODE_TEXT:
+        if (ioctl (window->tty_fd, KDSETMODE, KD_TEXT) < 0)
+          return false;
+        break;
+
+      case PLY_WINDOW_MODE_GRAPHICS:
+        if (ioctl (window->tty_fd, KDSETMODE, KD_GRAPHICS) < 0)
+          return false;
+        break;
+    }
+
+  window->mode = mode;
+  return true;
+}
+
+void
+ply_window_free (ply_window_t *window)
+{
+  if (window == NULL)
+    return;
+
+  ply_window_set_mode (window, PLY_WINDOW_MODE_TEXT);
+  ply_window_close (window);
+
+  free (window);
+}
+
+static void
+ply_window_detach_from_event_loop (ply_window_t *window)
+{
+  assert (window != NULL);
+  window->loop = NULL;
+}
+
+void
+ply_window_attach_to_event_loop (ply_window_t *window,
+                                      ply_event_loop_t  *loop)
+{
+  assert (window != NULL);
+  assert (loop != NULL);
+  assert (window->loop == NULL);
+
+  window->loop = loop;
+
+  ply_event_loop_watch_for_exit (loop, (ply_event_loop_exit_handler_t)
+                                 ply_window_detach_from_event_loop,
+                                 window);
+}
+
+#ifdef PLY_WINDOW_ENABLE_TEST
+
+#include <stdio.h>
+
+#include "ply-event-loop.h"
+#include "ply-window.h"
+
+static void
+on_timeout (ply_window_t     *window,
+            ply_event_loop_t *loop)
+{
+  ply_event_loop_exit (loop, 0);
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+  ply_event_loop_t *loop;
+  ply_window_t *window;
+  int exit_code;
+  const char *tty_name;
+
+  exit_code = 0;
+
+  loop = ply_event_loop_new ();
+
+  if (argc > 1)
+    tty_name = argv[1];
+  else
+    tty_name = "/dev/tty1";
+
+  window = ply_window_new (tty_name);
+  ply_window_attach_to_event_loop (window, loop);
+
+  if (!ply_window_open (window))
+    {
+      ply_save_errno ();
+      perror ("could not open window");
+      ply_restore_errno ();
+      return errno;
+    }
+
+  if (!ply_window_set_mode (window, PLY_WINDOW_MODE_GRAPHICS))
+    {
+      ply_save_errno ();
+      perror ("could not set window for graphics mode");
+      ply_restore_errno ();
+    }
+
+  ply_event_loop_watch_for_timeout (loop,
+                                    1.0,
+                                   (ply_event_loop_timeout_handler_t)
+                                   on_timeout,
+                                   window);
+  exit_code = ply_event_loop_run (loop);
+
+  ply_window_close (window);
+  ply_window_free (window);
+
+  return exit_code;
+}
+
+#endif /* PLY_WINDOW_ENABLE_TEST */
+/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
diff --git a/src/ply-window.h b/src/ply-window.h
new file mode 100644 (file)
index 0000000..da03238
--- /dev/null
@@ -0,0 +1,54 @@
+/* ply-window.h - APIs for putting up a splash screen
+ *
+ * Copyright (C) 2008 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written By: Ray Strode <rstrode@redhat.com>
+ */
+#ifndef PLY_WINDOW_H
+#define PLY_WINDOW_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include "ply-event-loop.h"
+
+typedef struct _ply_window ply_window_t;
+
+typedef enum
+{
+  PLY_WINDOW_MODE_TEXT,
+  PLY_WINDOW_MODE_GRAPHICS
+} ply_window_mode_t;
+
+#ifndef PLY_HIDE_FUNCTION_DECLARATIONS
+ply_window_t *ply_window_new (const char *tty_name);
+void ply_window_free (ply_window_t *window);
+
+bool ply_window_open (ply_window_t *window);
+void ply_window_close (ply_window_t *window);
+bool ply_window_set_mode (ply_window_t      *window,
+                          ply_window_mode_t  mode);
+
+void ply_window_attach_to_event_loop (ply_window_t     *window,
+                                      ply_event_loop_t *loop);
+
+#endif
+
+#endif /* PLY_WINDOW_H */
+/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
index 8d6b7d08e8e96b1c9ab88bc47bff0be52b3b4a2d..29ec948a6f509592bc46e4271416a7b06007cda9 100644 (file)
@@ -11,6 +11,8 @@ fedora_fade_in_la_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLYMOUTH_IMAGE_DIR=\"$(datadir)/
 fedora_fade_in_la_LDFLAGS = -module -avoid-version -export-dynamic
 fedora_fade_in_la_LIBADD = $(PLYMOUTH_LIBS) ../../libply/libply.la
 fedora_fade_in_la_SOURCES = $(srcdir)/../../ply-boot-splash-plugin.h         \
+                            $(srcdir)/../../ply-window.h                     \
+                            $(srcdir)/../../ply-window.c                     \
                             $(srcdir)/fedora-fade-in.c
 
 plymouthdir = $(datadir)/plymouth
index 0d6b926219469408330f9a200cef73d204119fc7..25c675e256949b0fca5bf0406872bb7e5e77a755 100644 (file)
@@ -45,7 +45,7 @@
 #include "ply-frame-buffer.h"
 #include "ply-image.h"
 #include "ply-utils.h"
-
+#include "ply-window.h"
 
 #include <linux/kd.h>
 
@@ -68,8 +68,8 @@ struct _ply_boot_splash_plugin
   ply_image_t *logo_image;
   ply_image_t *star_image;
   ply_list_t *stars;
+  ply_window_t *window;
 
-  int console_fd;
   double start_time;
   double now;
 };
@@ -81,7 +81,6 @@ create_plugin (void)
 
   srand ((int) ply_get_timestamp ());
   plugin = calloc (1, sizeof (ply_boot_splash_plugin_t));
-  plugin->console_fd = -1;
   plugin->start_time = 0.0;
 
   plugin->frame_buffer = ply_frame_buffer_new (NULL);
@@ -152,45 +151,6 @@ destroy_plugin (ply_boot_splash_plugin_t *plugin)
   free (plugin);
 }
 
-static bool
-set_graphics_mode (ply_boot_splash_plugin_t *plugin)
-{
-  assert (plugin != NULL);
-
-  if (ioctl (plugin->console_fd, KDSETMODE, KD_GRAPHICS) < 0)
-    return false;
-
-  return true;
-}
-
-static void
-set_text_mode (ply_boot_splash_plugin_t *plugin)
-{
-  assert (plugin != NULL);
-
-  ioctl (plugin->console_fd, KDSETMODE, KD_TEXT);
-}
-
-static bool
-open_console (ply_boot_splash_plugin_t *plugin)
-{
-  assert (plugin != NULL);
-
-  plugin->console_fd = open ("/dev/tty0", O_RDWR);
-
-  if (plugin->console_fd < 0)
-    return false;
-
-  return true;
-}
-
-static void
-close_console (ply_boot_splash_plugin_t *plugin)
-{
-  close (plugin->console_fd);
-  plugin->console_fd = -1;
-}
-
 static void
 animate_at_time (ply_boot_splash_plugin_t *plugin,
                  double                    time)
@@ -265,7 +225,7 @@ on_timeout (ply_boot_splash_plugin_t *plugin)
 {
   double sleep_time;
 
-  set_graphics_mode (plugin);
+  ply_window_set_mode (plugin->window, PLY_WINDOW_MODE_GRAPHICS);
   plugin->now = ply_get_timestamp ();
 
 
@@ -342,7 +302,7 @@ stop_animation (ply_boot_splash_plugin_t *plugin)
   ply_frame_buffer_fill_with_color (plugin->frame_buffer, NULL,
                                     0.0, 0.0, 0.0, 1.0);
 
-  set_text_mode (plugin);
+  ply_window_set_mode (plugin->window, PLY_WINDOW_MODE_TEXT);
 }
 
 static void
@@ -353,7 +313,8 @@ on_interrupt (ply_boot_splash_plugin_t *plugin)
 }
 
 bool
-show_splash_screen (ply_boot_splash_plugin_t *plugin)
+show_splash_screen (ply_boot_splash_plugin_t *plugin,
+                    ply_window_t             *window)
 {
   assert (plugin != NULL);
   assert (plugin->logo_image != NULL);
@@ -371,18 +332,10 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin)
   if (!ply_frame_buffer_open (plugin->frame_buffer))
     return false;
 
-  ply_trace ("opening console");
-  if (!open_console (plugin))
-    return false;
+  plugin->window = window;
 
-  ply_trace ("settings graphics mode");
-  if (!set_graphics_mode (plugin))
-    {
-      ply_save_errno ();
-      close_console (plugin);
-      ply_restore_errno ();
-      return false;
-    }
+  if (!ply_window_set_mode (plugin->window, PLY_WINDOW_MODE_GRAPHICS))
+    return false;
 
   ply_event_loop_watch_signal (plugin->loop,
                                SIGINT,
@@ -478,11 +431,12 @@ detach_from_event_loop (ply_boot_splash_plugin_t *plugin)
 {
   plugin->loop = NULL;
 
-  set_text_mode (plugin);
+  ply_window_set_mode (plugin->window, PLY_WINDOW_MODE_TEXT);
 }
 
 void
-hide_splash_screen (ply_boot_splash_plugin_t *plugin)
+hide_splash_screen (ply_boot_splash_plugin_t *plugin,
+                    ply_window_t             *window)
 {
   assert (plugin != NULL);
 
index d2f9b99244f2b6cbcc7b864c7041f2b6b6b9d481..014885aea97ab54bbac71937dfc323779ced2921 100644 (file)
@@ -46,7 +46,7 @@
 #include "ply-frame-buffer.h"
 #include "ply-image.h"
 #include "ply-utils.h"
-
+#include "ply-window.h"
 
 #include <linux/kd.h>
 
@@ -94,16 +94,9 @@ open_console (ply_boot_splash_plugin_t *plugin)
   return true;
 }
 
-static void
-close_console (ply_boot_splash_plugin_t *plugin)
-{
-  ply_trace ("closing console");
-  close (plugin->console_fd);
-  plugin->console_fd = -1;
-}
-
 bool
-show_splash_screen (ply_boot_splash_plugin_t *plugin)
+show_splash_screen (ply_boot_splash_plugin_t *plugin,
+                    ply_window_t             *window)
 {
   assert (plugin != NULL);
 
index 7fc5eef6ad581691428df474c83a8918c18a7d1e..96279eb2845a4c4d064cee7212d0ff93d18cffef 100644 (file)
@@ -7,6 +7,7 @@ TESTS =
 
 include $(srcdir)/ply-boot-server-test.am
 include $(srcdir)/ply-boot-splash-test.am
+include $(srcdir)/ply-window-test.am
 
 noinst_PROGRAMS = $(TESTS)
 MAINTAINERCLEANFILES = Makefile.in
index d95d0123138090158520dfa535ed9d3927e2d33a..af67aad48bd9a62b147936b2d872df6b740c46d6 100644 (file)
@@ -5,5 +5,7 @@ ply_boot_splash_test_LDADD = $(PLYMOUTH_LIBS) ../libply/libply.la
 
 ply_boot_splash_test_SOURCES =                                                \
                           $(srcdir)/../ply-boot-splash-plugin.h               \
+                          $(srcdir)/../ply-window.h                           \
+                          $(srcdir)/../ply-window.c                           \
                           $(srcdir)/../ply-boot-splash.h                      \
                           $(srcdir)/../ply-boot-splash.c
diff --git a/src/tests/ply-window-test.am b/src/tests/ply-window-test.am
new file mode 100644 (file)
index 0000000..09a5644
--- /dev/null
@@ -0,0 +1,8 @@
+TESTS += ply-window-test
+
+ply_window_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_WINDOW_ENABLE_TEST
+ply_window_test_LDADD = $(PLYMOUTH_LIBS) ../libply/libply.la
+
+ply_window_test_SOURCES =                                                \
+                          $(srcdir)/../ply-window.h                      \
+                          $(srcdir)/../ply-window.c