diff options
| author | Ray Strode <rstrode@redhat.com> | 2008-05-23 01:00:28 -0400 |
|---|---|---|
| committer | Ray Strode <rstrode@redhat.com> | 2008-05-23 01:00:28 -0400 |
| commit | 7e14cb94526e222061774e5ed3adfc9751a53928 (patch) | |
| tree | e585db9a149d546bac278196faaf434d27ad032f /src/splash-plugins | |
| parent | d2b4a3ef73738f5a5a131f630a33e3a0b6e5d6de (diff) | |
| download | plymouth-7e14cb94526e222061774e5ed3adfc9751a53928.tar.gz plymouth-7e14cb94526e222061774e5ed3adfc9751a53928.tar.xz plymouth-7e14cb94526e222061774e5ed3adfc9751a53928.zip | |
Move keyboard handling to window so we can do line editing
The logic for line editing is a little complicated, so it's
best not to duplicate it across all the plugins. Now we
manage it all from the window. The plugins now access the
various editing events via there vtable, but that's an
extra layer of indirection that doesn't matter given that
we pass the window to the plugins anyway. We should drop
that and just have the plugins register for edit events
directly.
Diffstat (limited to 'src/splash-plugins')
| -rw-r--r-- | src/splash-plugins/details/details.c | 49 | ||||
| -rw-r--r-- | src/splash-plugins/fedora-fade-in/fedora-fade-in.c | 41 | ||||
| -rw-r--r-- | src/splash-plugins/text/text.c | 48 |
3 files changed, 71 insertions, 67 deletions
diff --git a/src/splash-plugins/details/details.c b/src/splash-plugins/details/details.c index b8afb37..eb16331 100644 --- a/src/splash-plugins/details/details.c +++ b/src/splash-plugins/details/details.c @@ -52,7 +52,8 @@ #include <linux/kd.h> -#define CLEAR_LINE_SEQUENCE "\033[2K" +#define CLEAR_LINE_SEQUENCE "\033[2K\r\n" +#define BACKSPACE "\b\033[0K" struct _ply_boot_splash_plugin { @@ -61,7 +62,6 @@ struct _ply_boot_splash_plugin ply_boot_splash_password_answer_handler_t password_answer_handler; void *password_answer_data; - ply_buffer_t *keyboard_input_buffer; uint32_t keyboard_input_is_hidden : 1; }; @@ -73,7 +73,6 @@ create_plugin (void) ply_trace ("creating plugin"); plugin = calloc (1, sizeof (ply_boot_splash_plugin_t)); - plugin->keyboard_input_buffer = ply_buffer_new (); return plugin; } @@ -86,8 +85,6 @@ destroy_plugin (ply_boot_splash_plugin_t *plugin) if (plugin == NULL) return; - ply_buffer_free (plugin->keyboard_input_buffer); - free (plugin); } @@ -176,29 +173,33 @@ on_keyboard_input (ply_boot_splash_plugin_t *plugin, const char *keyboard_input, size_t character_size) { - if (plugin->password_answer_handler != NULL) - { - if (character_size == 1 && keyboard_input[0] == '\r') - { - plugin->password_answer_handler (plugin->password_answer_data, - ply_buffer_get_bytes (plugin->keyboard_input_buffer)); - plugin->keyboard_input_is_hidden = false; - ply_buffer_clear (plugin->keyboard_input_buffer); - plugin->password_answer_handler = NULL; - write (STDOUT_FILENO, CLEAR_LINE_SEQUENCE, strlen (CLEAR_LINE_SEQUENCE)); - return; - } - } - - ply_buffer_append_bytes (plugin->keyboard_input_buffer, - keyboard_input, character_size); - if (plugin->keyboard_input_is_hidden) write (STDOUT_FILENO, "•", strlen ("•")); else write (STDOUT_FILENO, keyboard_input, character_size); } +void +on_backspace (ply_boot_splash_plugin_t *plugin) +{ + write (STDOUT_FILENO, BACKSPACE, strlen (BACKSPACE)); +} + +void +on_enter (ply_boot_splash_plugin_t *plugin, + const char *line) +{ + if (plugin->password_answer_handler != NULL) + { + plugin->password_answer_handler (plugin->password_answer_data, + line); + plugin->keyboard_input_is_hidden = false; + plugin->password_answer_handler = NULL; + write (STDOUT_FILENO, CLEAR_LINE_SEQUENCE, strlen (CLEAR_LINE_SEQUENCE)); + } +} + + ply_boot_splash_plugin_interface_t * ply_boot_splash_plugin_get_interface (void) { @@ -211,7 +212,9 @@ ply_boot_splash_plugin_get_interface (void) .on_boot_output = on_boot_output, .hide_splash_screen = hide_splash_screen, .ask_for_password = ask_for_password, - .on_keyboard_input = on_keyboard_input + .on_keyboard_input = on_keyboard_input, + .on_backspace = on_backspace, + .on_enter = on_enter }; return &plugin_interface; diff --git a/src/splash-plugins/fedora-fade-in/fedora-fade-in.c b/src/splash-plugins/fedora-fade-in/fedora-fade-in.c index b599f80..88dd43f 100644 --- a/src/splash-plugins/fedora-fade-in/fedora-fade-in.c +++ b/src/splash-plugins/fedora-fade-in/fedora-fade-in.c @@ -87,8 +87,6 @@ struct _ply_boot_splash_plugin ply_boot_splash_password_answer_handler_t password_answer_handler; void *password_answer_data; - ply_buffer_t *keyboard_input_buffer; - double start_time; double now; }; @@ -102,8 +100,6 @@ create_plugin (void) plugin = calloc (1, sizeof (ply_boot_splash_plugin_t)); plugin->start_time = 0.0; - plugin->keyboard_input_buffer = ply_buffer_new (); - plugin->frame_buffer = ply_frame_buffer_new (NULL); plugin->logo_image = ply_image_new (PLYMOUTH_IMAGE_DIR "fedora-logo.png"); plugin->star_image = ply_image_new (PLYMOUTH_IMAGE_DIR "star.png"); @@ -190,8 +186,6 @@ destroy_plugin (ply_boot_splash_plugin_t *plugin) if (plugin == NULL) return; - ply_buffer_free (plugin->keyboard_input_buffer); - free_stars (plugin); ply_image_free (plugin->logo_image); ply_image_free (plugin->star_image); @@ -629,24 +623,27 @@ on_keyboard_input (ply_boot_splash_plugin_t *plugin, if (plugin->password_answer_handler == NULL) return; - if (character_size == 1 && keyboard_input[0] == '\r') - { - plugin->password_answer_handler (plugin->password_answer_data, - ply_buffer_get_bytes (plugin->keyboard_input_buffer)); - ply_buffer_clear (plugin->keyboard_input_buffer); - plugin->password_answer_handler = NULL; - - start_animation (plugin); - return; - } - - ply_buffer_append_bytes (plugin->keyboard_input_buffer, - keyboard_input, character_size); - plugin->entry->number_of_bullets++; draw_password_entry (plugin); } +void +on_backspace (ply_boot_splash_plugin_t *plugin) +{ + plugin->entry->number_of_bullets--; + draw_password_entry (plugin); +} + +void +on_enter (ply_boot_splash_plugin_t *plugin, + const char *text) +{ + plugin->password_answer_handler (plugin->password_answer_data, + text); + plugin->entry->number_of_bullets = 0; + start_animation (plugin); +} + ply_boot_splash_plugin_interface_t * ply_boot_splash_plugin_get_interface (void) { @@ -658,7 +655,9 @@ ply_boot_splash_plugin_get_interface (void) .update_status = update_status, .hide_splash_screen = hide_splash_screen, .ask_for_password = ask_for_password, - .on_keyboard_input = on_keyboard_input + .on_keyboard_input = on_keyboard_input, + .on_backspace = on_backspace, + .on_enter = on_enter }; return &plugin_interface; diff --git a/src/splash-plugins/text/text.c b/src/splash-plugins/text/text.c index 5198e93..bfa591a 100644 --- a/src/splash-plugins/text/text.c +++ b/src/splash-plugins/text/text.c @@ -52,7 +52,8 @@ #include <linux/kd.h> -#define CLEAR_LINE_SEQUENCE "\033[2K" +#define CLEAR_LINE_SEQUENCE "\033[2K\r\n" +#define BACKSPACE "\b\033[0K" struct _ply_boot_splash_plugin { @@ -62,7 +63,6 @@ struct _ply_boot_splash_plugin ply_boot_splash_password_answer_handler_t password_answer_handler; void *password_answer_data; - ply_buffer_t *keyboard_input_buffer; uint32_t keyboard_input_is_hidden : 1; }; @@ -74,7 +74,6 @@ create_plugin (void) ply_trace ("creating plugin"); plugin = calloc (1, sizeof (ply_boot_splash_plugin_t)); - plugin->keyboard_input_buffer = ply_buffer_new (); plugin->console_fd = -1; return plugin; @@ -88,8 +87,6 @@ destroy_plugin (ply_boot_splash_plugin_t *plugin) if (plugin == NULL) return; - ply_buffer_free (plugin->keyboard_input_buffer); - free (plugin); } @@ -180,29 +177,32 @@ on_keyboard_input (ply_boot_splash_plugin_t *plugin, const char *keyboard_input, size_t character_size) { - if (plugin->password_answer_handler != NULL) - { - if (character_size == 1 && keyboard_input[0] == '\r') - { - plugin->password_answer_handler (plugin->password_answer_data, - ply_buffer_get_bytes (plugin->keyboard_input_buffer)); - plugin->keyboard_input_is_hidden = false; - ply_buffer_clear (plugin->keyboard_input_buffer); - plugin->password_answer_handler = NULL; - write (STDOUT_FILENO, CLEAR_LINE_SEQUENCE, strlen (CLEAR_LINE_SEQUENCE)); - return; - } - } - - ply_buffer_append_bytes (plugin->keyboard_input_buffer, - keyboard_input, character_size); - if (plugin->keyboard_input_is_hidden) write (STDOUT_FILENO, "•", strlen ("•")); else write (STDOUT_FILENO, keyboard_input, character_size); } +void +on_backspace (ply_boot_splash_plugin_t *plugin) +{ + write (STDOUT_FILENO, BACKSPACE, strlen (BACKSPACE)); +} + +void +on_enter (ply_boot_splash_plugin_t *plugin, + const char *line) +{ + if (plugin->password_answer_handler != NULL) + { + plugin->password_answer_handler (plugin->password_answer_data, + line); + plugin->keyboard_input_is_hidden = false; + plugin->password_answer_handler = NULL; + write (STDOUT_FILENO, CLEAR_LINE_SEQUENCE, strlen (CLEAR_LINE_SEQUENCE)); + } +} + ply_boot_splash_plugin_interface_t * ply_boot_splash_plugin_get_interface (void) { @@ -214,7 +214,9 @@ ply_boot_splash_plugin_get_interface (void) .update_status = update_status, .hide_splash_screen = hide_splash_screen, .ask_for_password = ask_for_password, - .on_keyboard_input = on_keyboard_input + .on_keyboard_input = on_keyboard_input, + .on_backspace = on_backspace, + .on_enter = on_enter }; return &plugin_interface; |
