]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
Intercept escape key before passing keyboard input to splash plugin
authorRay Strode <rstrode@redhat.com>
Mon, 19 May 2008 03:34:25 +0000 (23:34 -0400)
committerRay Strode <rstrode@redhat.com>
Mon, 19 May 2008 04:05:46 +0000 (00:05 -0400)
We want to pass escape to the layer that created the boot splash, so
that it can tear down the curren splash plugin and put up the
details view

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

index 0acfc6ba6a94a0090f5874f0bab7a49c6451bbbf..f6c028528b30b1516a64d3f6a43da3dd71cbfec7 100644 (file)
@@ -150,7 +150,7 @@ start_boot_splash (state_t    *state,
 
   ply_trace ("Loading boot splash plugin '%s'",
              module_path);
-  splash = ply_boot_splash_new (module_path);
+  splash = ply_boot_splash_new (module_path, NULL, NULL);
 
   ply_trace ("attaching plugin to event loop");
   ply_boot_splash_attach_to_event_loop (splash, state->loop);
index e17f204d870babfda72043871e0f53e090e5a766..51e788809f1fbbf7a7a396708631116b68575686 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <wchar.h>
 
 #include "ply-boot-splash-plugin.h"
 #include "ply-event-loop.h"
@@ -37,6 +38,8 @@
 #include "ply-logger.h"
 #include "ply-utils.h"
 
+#define KEY_ESCAPE '\033'
+
 struct _ply_boot_splash
 {
   ply_event_loop_t *loop;
@@ -45,6 +48,9 @@ struct _ply_boot_splash
   ply_boot_splash_plugin_t *plugin;
   ply_window_t *window;
 
+  ply_boot_splash_escape_handler_t escape_handler;
+  void *escape_handler_user_data;
+
   char *module_name;
   char *status;
 
@@ -55,7 +61,9 @@ typedef const ply_boot_splash_plugin_interface_t *
         (* get_plugin_interface_function_t) (void);
 
 ply_boot_splash_t *
-ply_boot_splash_new (const char *module_name)
+ply_boot_splash_new (const char *module_name,
+                     ply_boot_splash_escape_handler_t escape_handler,
+                     void *user_data)
 {
   ply_boot_splash_t *splash;
 
@@ -67,6 +75,9 @@ ply_boot_splash_new (const char *module_name)
   splash->module_handle = NULL;
   splash->is_shown = false;
 
+  splash->escape_handler = escape_handler;
+  splash->escape_handler_user_data = user_data;
+
   return splash;
 }
 
@@ -143,12 +154,36 @@ ply_boot_splash_unload_plugin (ply_boot_splash_t *splash)
   splash->module_handle = NULL;
 }
 
+static bool
+ply_boot_splash_process_keyboard_input (ply_boot_splash_t *splash,
+                                        const char        *keyboard_input)
+{
+  wchar_t key;
+
+  if (mbrtowc (&key, keyboard_input, 1, NULL) > 0)
+    {
+      if (key == KEY_ESCAPE)
+        {
+          if (splash->escape_handler != NULL)
+            splash->escape_handler (splash->escape_handler_user_data);
+
+          return true;
+        }
+    }
+
+  return false;
+}
+
 static void
 on_keyboard_input (ply_boot_splash_t *splash,
-                   const char        *key)
+                   const char        *keyboard_input)
 {
+
+  if (ply_boot_splash_process_keyboard_input (splash, keyboard_input))
+    return;
+
   if (splash->plugin_interface->on_keyboard_input != NULL)
-    splash->plugin_interface->on_keyboard_input (splash->plugin, key);
+    splash->plugin_interface->on_keyboard_input (splash->plugin, keyboard_input);
 }
 
 static bool
@@ -158,6 +193,8 @@ ply_boot_splash_create_window (ply_boot_splash_t *splash)
                                    (ply_window_keyboard_input_handler_t)
                                    on_keyboard_input, splash);
 
+  ply_window_attach_to_event_loop (splash->window, splash->loop);
+
   if (!ply_window_open (splash->window))
     {
       ply_save_errno ();
@@ -313,7 +350,7 @@ main (int    argc,
   else
     module_name = "../splash-plugins/fedora-fade-in/.libs/fedora-fade-in.so";
 
-  splash = ply_boot_splash_new (module_name);
+  splash = ply_boot_splash_new (module_name, NULL, NULL);
   ply_boot_splash_attach_to_event_loop (splash, loop);
 
   if (!ply_boot_splash_show (splash))
index 79b09b041492e49f0bcf05f58e6c7b76aad41a3c..c89636d5b46228f4d825f87384f31a1dd33bbb58 100644 (file)
 
 typedef struct _ply_boot_splash ply_boot_splash_t;
 
+typedef void (* ply_boot_splash_escape_handler_t) (void *user_data);
+
+
 #ifndef PLY_HIDE_FUNCTION_DECLARATIONS
-ply_boot_splash_t *ply_boot_splash_new (const char *module_name);
+ply_boot_splash_t *ply_boot_splash_new (const char *module_name,
+                                        ply_boot_splash_escape_handler_t escape_handler,
+                                        void *user_data);
 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,