diff --git a/src/main.c b/src/main.c index 0acfc6ba..f6c02852 100644 --- a/src/main.c +++ b/src/main.c @@ -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); diff --git a/src/ply-boot-splash.c b/src/ply-boot-splash.c index e17f204d..51e78880 100644 --- a/src/ply-boot-splash.c +++ b/src/ply-boot-splash.c @@ -30,6 +30,7 @@ #include #include #include +#include #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)) diff --git a/src/ply-boot-splash.h b/src/ply-boot-splash.h index 79b09b04..c89636d5 100644 --- a/src/ply-boot-splash.h +++ b/src/ply-boot-splash.h @@ -30,8 +30,13 @@ 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,