From 2b0d1855464469853dbb1d09182a3c4bea6dd198 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 9 Mar 2009 12:16:10 -0400 Subject: [PATCH] Factor handler registration code out into separate functions in plugins This will make it easier to unregister the handlers from both hide and destroy --- src/plugins/splash/fade-in/plugin.c | 60 +++++++++++++++---------- src/plugins/splash/glow/plugin.c | 61 ++++++++++++++++---------- src/plugins/splash/pulser/plugin.c | 56 ++++++++++++++--------- src/plugins/splash/solar/plugin.c | 60 +++++++++++++++---------- src/plugins/splash/spinfinity/plugin.c | 61 ++++++++++++++++---------- src/plugins/splash/text/plugin.c | 57 +++++++++++++++--------- 6 files changed, 224 insertions(+), 131 deletions(-) diff --git a/src/plugins/splash/fade-in/plugin.c b/src/plugins/splash/fade-in/plugin.c index 71411d50..598bc08a 100644 --- a/src/plugins/splash/fade-in/plugin.c +++ b/src/plugins/splash/fade-in/plugin.c @@ -156,6 +156,9 @@ free_stars (ply_boot_splash_plugin_t *plugin) plugin->stars = NULL; } +static void add_handlers (ply_boot_splash_plugin_t *plugin); +static void remove_handlers (ply_boot_splash_plugin_t *plugin); + static void detach_from_event_loop (ply_boot_splash_plugin_t *plugin); void @@ -440,6 +443,39 @@ on_erase (ply_boot_splash_plugin_t *plugin, PLYMOUTH_BACKGROUND_END_COLOR); } +static void +add_handlers (ply_boot_splash_plugin_t *plugin) +{ + ply_window_add_keyboard_input_handler (plugin->window, + (ply_window_keyboard_input_handler_t) + on_keyboard_input, plugin); + ply_window_add_backspace_handler (plugin->window, + (ply_window_backspace_handler_t) + on_backspace, plugin); + ply_window_add_enter_handler (plugin->window, + (ply_window_enter_handler_t) + on_enter, plugin); + + ply_window_set_draw_handler (plugin->window, + (ply_window_draw_handler_t) + on_draw, plugin); + + ply_window_set_erase_handler (plugin->window, + (ply_window_erase_handler_t) + on_erase, plugin); +} + +static void +remove_handlers (ply_boot_splash_plugin_t *plugin) +{ + + ply_window_remove_keyboard_input_handler (plugin->window, (ply_window_keyboard_input_handler_t) on_keyboard_input); + ply_window_remove_backspace_handler (plugin->window, (ply_window_backspace_handler_t) on_backspace); + ply_window_remove_enter_handler (plugin->window, (ply_window_enter_handler_t) on_enter); + ply_window_set_draw_handler (plugin->window, NULL, NULL); + ply_window_set_erase_handler (plugin->window, NULL, NULL); +} + void add_window (ply_boot_splash_plugin_t *plugin, ply_window_t *window) @@ -462,23 +498,7 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin, assert (plugin != NULL); assert (plugin->logo_image != NULL); - ply_window_add_keyboard_input_handler (plugin->window, - (ply_window_keyboard_input_handler_t) - on_keyboard_input, plugin); - ply_window_add_backspace_handler (plugin->window, - (ply_window_backspace_handler_t) - on_backspace, plugin); - ply_window_add_enter_handler (plugin->window, - (ply_window_enter_handler_t) - on_enter, plugin); - - ply_window_set_draw_handler (plugin->window, - (ply_window_draw_handler_t) - on_draw, plugin); - - ply_window_set_erase_handler (plugin->window, - (ply_window_erase_handler_t) - on_erase, plugin); + add_handlers (plugin); plugin->loop = loop; @@ -605,11 +625,7 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, { assert (plugin != NULL); - ply_window_remove_keyboard_input_handler (plugin->window, (ply_window_keyboard_input_handler_t) on_keyboard_input); - ply_window_remove_backspace_handler (plugin->window, (ply_window_backspace_handler_t) on_backspace); - ply_window_remove_enter_handler (plugin->window, (ply_window_enter_handler_t) on_enter); - ply_window_set_draw_handler (plugin->window, NULL, NULL); - ply_window_set_erase_handler (plugin->window, NULL, NULL); + remove_handlers (plugin); if (plugin->loop != NULL) { diff --git a/src/plugins/splash/glow/plugin.c b/src/plugins/splash/glow/plugin.c index 113ec869..c81c9215 100644 --- a/src/plugins/splash/glow/plugin.c +++ b/src/plugins/splash/glow/plugin.c @@ -94,6 +94,9 @@ struct _ply_boot_splash_plugin uint32_t is_animating : 1; }; +static void add_handlers (ply_boot_splash_plugin_t *plugin); +static void remove_handlers (ply_boot_splash_plugin_t *plugin); + static void detach_from_event_loop (ply_boot_splash_plugin_t *plugin); ply_boot_splash_plugin_t * create_plugin (void) @@ -317,6 +320,39 @@ on_erase (ply_boot_splash_plugin_t *plugin, PLYMOUTH_BACKGROUND_END_COLOR); } +static void +add_handlers (ply_boot_splash_plugin_t *plugin) +{ + ply_window_add_keyboard_input_handler (plugin->window, + (ply_window_keyboard_input_handler_t) + on_keyboard_input, plugin); + ply_window_add_backspace_handler (plugin->window, + (ply_window_backspace_handler_t) + on_backspace, plugin); + ply_window_add_enter_handler (plugin->window, + (ply_window_enter_handler_t) + on_enter, plugin); + + ply_window_set_draw_handler (plugin->window, + (ply_window_draw_handler_t) + on_draw, plugin); + + ply_window_set_erase_handler (plugin->window, + (ply_window_erase_handler_t) + on_erase, plugin); +} + +static void +remove_handlers (ply_boot_splash_plugin_t *plugin) +{ + + ply_window_remove_keyboard_input_handler (plugin->window, (ply_window_keyboard_input_handler_t) on_keyboard_input); + ply_window_remove_backspace_handler (plugin->window, (ply_window_backspace_handler_t) on_backspace); + ply_window_remove_enter_handler (plugin->window, (ply_window_enter_handler_t) on_enter); + ply_window_set_draw_handler (plugin->window, NULL, NULL); + ply_window_set_erase_handler (plugin->window, NULL, NULL); +} + void add_window (ply_boot_splash_plugin_t *plugin, ply_window_t *window) @@ -338,23 +374,7 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin, { assert (plugin != NULL); - ply_window_add_keyboard_input_handler (plugin->window, - (ply_window_keyboard_input_handler_t) - on_keyboard_input, plugin); - ply_window_add_backspace_handler (plugin->window, - (ply_window_backspace_handler_t) - on_backspace, plugin); - ply_window_add_enter_handler (plugin->window, - (ply_window_enter_handler_t) - on_enter, plugin); - - ply_window_set_draw_handler (plugin->window, - (ply_window_draw_handler_t) - on_draw, plugin); - - ply_window_set_erase_handler (plugin->window, - (ply_window_erase_handler_t) - on_erase, plugin); + add_handlers (plugin); plugin->loop = loop; @@ -451,12 +471,7 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, { assert (plugin != NULL); - - ply_window_remove_keyboard_input_handler (plugin->window, (ply_window_keyboard_input_handler_t) on_keyboard_input); - ply_window_remove_backspace_handler (plugin->window, (ply_window_backspace_handler_t) on_backspace); - ply_window_remove_enter_handler (plugin->window, (ply_window_enter_handler_t) on_enter); - ply_window_set_draw_handler (plugin->window, NULL, NULL); - ply_window_set_erase_handler (plugin->window, NULL, NULL); + remove_handlers (plugin); if (plugin->loop != NULL) { diff --git a/src/plugins/splash/pulser/plugin.c b/src/plugins/splash/pulser/plugin.c index 82a25c18..122139ed 100644 --- a/src/plugins/splash/pulser/plugin.c +++ b/src/plugins/splash/pulser/plugin.c @@ -70,6 +70,8 @@ struct _ply_boot_splash_plugin }; void hide_splash_screen (ply_boot_splash_plugin_t *plugin, ply_event_loop_t *loop); +static void add_handlers (ply_boot_splash_plugin_t *plugin); +static void remove_handlers (ply_boot_splash_plugin_t *plugin); ply_boot_splash_plugin_t * create_plugin (void) @@ -203,6 +205,37 @@ on_erase (ply_boot_splash_plugin_t *plugin, ply_window_clear_screen (plugin->window); } +static void +add_handlers (ply_boot_splash_plugin_t *plugin) +{ + ply_window_add_keyboard_input_handler (plugin->window, + (ply_window_keyboard_input_handler_t) + on_keyboard_input, plugin); + ply_window_add_backspace_handler (plugin->window, + (ply_window_backspace_handler_t) + on_backspace, plugin); + ply_window_add_enter_handler (plugin->window, + (ply_window_enter_handler_t) + on_enter, plugin); + ply_window_set_draw_handler (plugin->window, + (ply_window_draw_handler_t) + on_draw, plugin); + ply_window_set_erase_handler (plugin->window, + (ply_window_erase_handler_t) + on_erase, plugin); +} + +static void +remove_handlers (ply_boot_splash_plugin_t *plugin) +{ + + ply_window_remove_keyboard_input_handler (plugin->window, (ply_window_keyboard_input_handler_t) on_keyboard_input); + ply_window_remove_backspace_handler (plugin->window, (ply_window_backspace_handler_t) on_backspace); + ply_window_remove_enter_handler (plugin->window, (ply_window_enter_handler_t) on_enter); + ply_window_set_draw_handler (plugin->window, NULL, NULL); + ply_window_set_erase_handler (plugin->window, NULL, NULL); +} + void add_window (ply_boot_splash_plugin_t *plugin, ply_window_t *window) @@ -224,24 +257,9 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin, { assert (plugin != NULL); + add_handlers (plugin); ply_show_new_kernel_messages (false); - ply_window_add_keyboard_input_handler (plugin->window, - (ply_window_keyboard_input_handler_t) - on_keyboard_input, plugin); - ply_window_add_backspace_handler (plugin->window, - (ply_window_backspace_handler_t) - on_backspace, plugin); - ply_window_add_enter_handler (plugin->window, - (ply_window_enter_handler_t) - on_enter, plugin); - ply_window_set_draw_handler (plugin->window, - (ply_window_draw_handler_t) - on_draw, plugin); - ply_window_set_erase_handler (plugin->window, - (ply_window_erase_handler_t) - on_erase, plugin); - plugin->loop = loop; ply_event_loop_watch_for_exit (loop, (ply_event_loop_exit_handler_t) detach_from_event_loop, @@ -282,11 +300,7 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, if (plugin->window != NULL) { - ply_window_remove_keyboard_input_handler (plugin->window, (ply_window_keyboard_input_handler_t) on_keyboard_input); - ply_window_remove_backspace_handler (plugin->window, (ply_window_backspace_handler_t) on_backspace); - ply_window_remove_enter_handler (plugin->window, (ply_window_enter_handler_t) on_enter); - ply_window_set_draw_handler (plugin->window, NULL, NULL); - ply_window_set_erase_handler (plugin->window, NULL, NULL); + remove_handlers (plugin); ply_window_set_background_color (plugin->window, PLY_WINDOW_COLOR_DEFAULT); ply_window_clear_screen (plugin->window); diff --git a/src/plugins/splash/solar/plugin.c b/src/plugins/splash/solar/plugin.c index 1c3b6a5d..d80d97f9 100644 --- a/src/plugins/splash/solar/plugin.c +++ b/src/plugins/splash/solar/plugin.c @@ -200,6 +200,9 @@ struct _ply_boot_splash_plugin uint32_t is_animating : 1; }; +static void add_handlers (ply_boot_splash_plugin_t *plugin); +static void remove_handlers (ply_boot_splash_plugin_t *plugin); + static void detach_from_event_loop (ply_boot_splash_plugin_t *plugin); @@ -1108,6 +1111,39 @@ on_erase (ply_boot_splash_plugin_t *plugin, ply_image_get_data (plugin->logo_image)); } +static void +add_handlers (ply_boot_splash_plugin_t *plugin) +{ + ply_window_add_keyboard_input_handler (plugin->window, + (ply_window_keyboard_input_handler_t) + on_keyboard_input, plugin); + ply_window_add_backspace_handler (plugin->window, + (ply_window_backspace_handler_t) + on_backspace, plugin); + ply_window_add_enter_handler (plugin->window, + (ply_window_enter_handler_t) + on_enter, plugin); + + ply_window_set_draw_handler (plugin->window, + (ply_window_draw_handler_t) + on_draw, plugin); + + ply_window_set_erase_handler (plugin->window, + (ply_window_erase_handler_t) + on_erase, plugin); +} + +static void +remove_handlers (ply_boot_splash_plugin_t *plugin) +{ + + ply_window_remove_keyboard_input_handler (plugin->window, (ply_window_keyboard_input_handler_t) on_keyboard_input); + ply_window_remove_backspace_handler (plugin->window, (ply_window_backspace_handler_t) on_backspace); + ply_window_remove_enter_handler (plugin->window, (ply_window_enter_handler_t) on_enter); + ply_window_set_draw_handler (plugin->window, NULL, NULL); + ply_window_set_erase_handler (plugin->window, NULL, NULL); +} + void add_window (ply_boot_splash_plugin_t *plugin, ply_window_t *window) @@ -1338,23 +1374,7 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin, assert (plugin != NULL); assert (plugin->logo_image != NULL); - ply_window_add_keyboard_input_handler (plugin->window, - (ply_window_keyboard_input_handler_t) - on_keyboard_input, plugin); - ply_window_add_backspace_handler (plugin->window, - (ply_window_backspace_handler_t) - on_backspace, plugin); - ply_window_add_enter_handler (plugin->window, - (ply_window_enter_handler_t) - on_enter, plugin); - - ply_window_set_draw_handler (plugin->window, - (ply_window_draw_handler_t) - on_draw, plugin); - - ply_window_set_erase_handler (plugin->window, - (ply_window_erase_handler_t) - on_erase, plugin); + add_handlers (plugin); plugin->loop = loop; @@ -1436,11 +1456,7 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, { assert (plugin != NULL); - ply_window_remove_keyboard_input_handler (plugin->window, (ply_window_keyboard_input_handler_t) on_keyboard_input); - ply_window_remove_backspace_handler (plugin->window, (ply_window_backspace_handler_t) on_backspace); - ply_window_remove_enter_handler (plugin->window, (ply_window_enter_handler_t) on_enter); - ply_window_set_draw_handler (plugin->window, NULL, NULL); - ply_window_set_erase_handler (plugin->window, NULL, NULL); + remove_handlers (plugin); if (plugin->loop != NULL) { diff --git a/src/plugins/splash/spinfinity/plugin.c b/src/plugins/splash/spinfinity/plugin.c index ebf0bb73..07460f1b 100644 --- a/src/plugins/splash/spinfinity/plugin.c +++ b/src/plugins/splash/spinfinity/plugin.c @@ -95,6 +95,9 @@ struct _ply_boot_splash_plugin uint32_t is_animating : 1; }; +static void add_handlers (ply_boot_splash_plugin_t *plugin); +static void remove_handlers (ply_boot_splash_plugin_t *plugin); + static void detach_from_event_loop (ply_boot_splash_plugin_t *plugin); ply_boot_splash_plugin_t * create_plugin (void) @@ -332,6 +335,39 @@ on_erase (ply_boot_splash_plugin_t *plugin, PLYMOUTH_BACKGROUND_END_COLOR); } +static void +add_handlers (ply_boot_splash_plugin_t *plugin) +{ + ply_window_add_keyboard_input_handler (plugin->window, + (ply_window_keyboard_input_handler_t) + on_keyboard_input, plugin); + ply_window_add_backspace_handler (plugin->window, + (ply_window_backspace_handler_t) + on_backspace, plugin); + ply_window_add_enter_handler (plugin->window, + (ply_window_enter_handler_t) + on_enter, plugin); + + ply_window_set_draw_handler (plugin->window, + (ply_window_draw_handler_t) + on_draw, plugin); + + ply_window_set_erase_handler (plugin->window, + (ply_window_erase_handler_t) + on_erase, plugin); +} + +static void +remove_handlers (ply_boot_splash_plugin_t *plugin) +{ + + ply_window_remove_keyboard_input_handler (plugin->window, (ply_window_keyboard_input_handler_t) on_keyboard_input); + ply_window_remove_backspace_handler (plugin->window, (ply_window_backspace_handler_t) on_backspace); + ply_window_remove_enter_handler (plugin->window, (ply_window_enter_handler_t) on_enter); + ply_window_set_draw_handler (plugin->window, NULL, NULL); + ply_window_set_erase_handler (plugin->window, NULL, NULL); +} + void add_window (ply_boot_splash_plugin_t *plugin, ply_window_t *window) @@ -354,23 +390,7 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin, assert (plugin != NULL); assert (plugin->logo_image != NULL); - ply_window_add_keyboard_input_handler (plugin->window, - (ply_window_keyboard_input_handler_t) - on_keyboard_input, plugin); - ply_window_add_backspace_handler (plugin->window, - (ply_window_backspace_handler_t) - on_backspace, plugin); - ply_window_add_enter_handler (plugin->window, - (ply_window_enter_handler_t) - on_enter, plugin); - - ply_window_set_draw_handler (plugin->window, - (ply_window_draw_handler_t) - on_draw, plugin); - - ply_window_set_erase_handler (plugin->window, - (ply_window_erase_handler_t) - on_erase, plugin); + add_handlers (plugin); plugin->loop = loop; @@ -450,12 +470,7 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, { assert (plugin != NULL); - - ply_window_remove_keyboard_input_handler (plugin->window, (ply_window_keyboard_input_handler_t) on_keyboard_input); - ply_window_remove_backspace_handler (plugin->window, (ply_window_backspace_handler_t) on_backspace); - ply_window_remove_enter_handler (plugin->window, (ply_window_enter_handler_t) on_enter); - ply_window_set_draw_handler (plugin->window, NULL, NULL); - ply_window_set_erase_handler (plugin->window, NULL, NULL); + remove_handlers (plugin); if (plugin->loop != NULL) { diff --git a/src/plugins/splash/text/plugin.c b/src/plugins/splash/text/plugin.c index e87cece7..bbc5a3b7 100644 --- a/src/plugins/splash/text/plugin.c +++ b/src/plugins/splash/text/plugin.c @@ -74,6 +74,9 @@ struct _ply_boot_splash_plugin void hide_splash_screen (ply_boot_splash_plugin_t *plugin, ply_event_loop_t *loop); +static void add_handlers (ply_boot_splash_plugin_t *plugin); +static void remove_handlers (ply_boot_splash_plugin_t *plugin); + ply_boot_splash_plugin_t * create_plugin (void) { @@ -234,6 +237,38 @@ on_erase (ply_boot_splash_plugin_t *plugin, ply_window_clear_screen (plugin->window); } +static void +add_handlers (ply_boot_splash_plugin_t *plugin) +{ + ply_window_add_keyboard_input_handler (plugin->window, + (ply_window_keyboard_input_handler_t) + on_keyboard_input, plugin); + ply_window_add_backspace_handler (plugin->window, + (ply_window_backspace_handler_t) + on_backspace, plugin); + ply_window_add_enter_handler (plugin->window, + (ply_window_enter_handler_t) + on_enter, plugin); + ply_window_set_draw_handler (plugin->window, + (ply_window_draw_handler_t) + on_draw, plugin); + ply_window_set_erase_handler (plugin->window, + (ply_window_erase_handler_t) + on_erase, plugin); +} + +static void +remove_handlers (ply_boot_splash_plugin_t *plugin) +{ + + ply_window_remove_keyboard_input_handler (plugin->window, (ply_window_keyboard_input_handler_t) on_keyboard_input); + ply_window_remove_backspace_handler (plugin->window, (ply_window_backspace_handler_t) on_backspace); + ply_window_remove_enter_handler (plugin->window, (ply_window_enter_handler_t) on_enter); + ply_window_set_draw_handler (plugin->window, NULL, NULL); + ply_window_set_erase_handler (plugin->window, NULL, NULL); + +} + void add_window (ply_boot_splash_plugin_t *plugin, ply_window_t *window) @@ -255,21 +290,7 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin, { assert (plugin != NULL); - ply_window_add_keyboard_input_handler (plugin->window, - (ply_window_keyboard_input_handler_t) - on_keyboard_input, plugin); - ply_window_add_backspace_handler (plugin->window, - (ply_window_backspace_handler_t) - on_backspace, plugin); - ply_window_add_enter_handler (plugin->window, - (ply_window_enter_handler_t) - on_enter, plugin); - ply_window_set_draw_handler (plugin->window, - (ply_window_draw_handler_t) - on_draw, plugin); - ply_window_set_erase_handler (plugin->window, - (ply_window_erase_handler_t) - on_erase, plugin); + add_handlers (plugin); ply_window_hide_text_cursor (plugin->window); ply_window_set_text_cursor_position (plugin->window, 0, 0); @@ -331,11 +352,7 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, if (plugin->window != NULL) { - ply_window_remove_keyboard_input_handler (plugin->window, (ply_window_keyboard_input_handler_t) on_keyboard_input); - ply_window_remove_backspace_handler (plugin->window, (ply_window_backspace_handler_t) on_backspace); - ply_window_remove_enter_handler (plugin->window, (ply_window_enter_handler_t) on_enter); - ply_window_set_draw_handler (plugin->window, NULL, NULL); - ply_window_set_erase_handler (plugin->window, NULL, NULL); + remove_handlers (plugin); ply_window_set_background_color (plugin->window, PLY_WINDOW_COLOR_DEFAULT); ply_window_clear_screen (plugin->window); -- 2.47.3