#include <linux/kd.h>
-#define CLEAR_LINE_SEQUENCE "\033[2K\r\n"
-#define BACKSPACE "\b\033[0K"
-
void ask_for_password (ply_boot_splash_plugin_t *plugin,
const char *prompt,
ply_trigger_t *answer);
+typedef void (* ply_boot_splash_plugin_window_handler_t) (ply_window_t *window, ply_boot_splash_plugin_t *, void *user_data, void *other_user_data);
ply_boot_splash_plugin_interface_t *ply_boot_splash_plugin_get_interface (void);
struct _ply_boot_splash_plugin
ply_event_loop_t *loop;
ply_trigger_t *pending_password_answer;
- ply_window_t *window;
+ ply_list_t *windows;
uint32_t keyboard_input_is_hidden : 1;
};
ply_trace ("creating plugin");
plugin = calloc (1, sizeof (ply_boot_splash_plugin_t));
+ plugin->windows = ply_list_new ();
return plugin;
}
if (plugin == NULL)
return;
+ ply_list_free (plugin->windows);
+
free (plugin);
}
ply_trace ("detaching from event loop");
}
+
+static void
+write_text_on_window (ply_window_t *window,
+ ply_boot_splash_plugin_t *plugin,
+ const char *text,
+ void *user_data);
+static void
+for_each_window (ply_boot_splash_plugin_t *plugin,
+ ply_boot_splash_plugin_window_handler_t handler,
+ void *user_data,
+ void *other_user_data)
+{
+ ply_list_node_t *node;
+
+ node = ply_list_get_first_node (plugin->windows);
+ while (node != NULL)
+ {
+ ply_list_node_t *next_node;
+ ply_window_t *window;
+
+ next_node = ply_list_get_next_node (plugin->windows, node);
+
+ window = ply_list_node_get_data (node);
+
+ handler (window, plugin, user_data, other_user_data);
+
+ node = next_node;
+ }
+}
+
+static void
+write_text_on_window (ply_window_t *window,
+ ply_boot_splash_plugin_t *plugin,
+ const char *text,
+ void *user_data)
+{
+ int fd;
+ size_t size;
+
+ size = (size_t) user_data;
+
+ fd = ply_window_get_tty_fd (window);
+
+ write (fd, text, size);
+}
+
void
on_keyboard_input (ply_boot_splash_plugin_t *plugin,
const char *keyboard_input,
size_t character_size)
{
if (plugin->keyboard_input_is_hidden)
- write (STDOUT_FILENO, "•", strlen ("•"));
+ for_each_window (plugin,
+ (ply_boot_splash_plugin_window_handler_t)
+ write_text_on_window, (void *) "*",
+ (void *) strlen ("*"));
else
- write (STDOUT_FILENO, keyboard_input, character_size);
+ for_each_window (plugin,
+ (ply_boot_splash_plugin_window_handler_t)
+ write_text_on_window, (void *) keyboard_input,
+ (void *) character_size);
}
void
on_backspace (ply_boot_splash_plugin_t *plugin)
{
- write (STDOUT_FILENO, BACKSPACE, strlen (BACKSPACE));
+ for_each_window (plugin,
+ (ply_boot_splash_plugin_window_handler_t)
+ ply_window_clear_text_character, NULL, NULL);
}
void
ply_trigger_pull (plugin->pending_password_answer, line);
plugin->keyboard_input_is_hidden = false;
plugin->pending_password_answer = NULL;
- write (STDOUT_FILENO, CLEAR_LINE_SEQUENCE, strlen (CLEAR_LINE_SEQUENCE));
+
+ for_each_window (plugin,
+ (ply_boot_splash_plugin_window_handler_t)
+ ply_window_clear_text_line, NULL, NULL);
}
}
add_window (ply_boot_splash_plugin_t *plugin,
ply_window_t *window)
{
- plugin->window = window;
+ ply_list_append_data (plugin->windows, window);
}
void
remove_window (ply_boot_splash_plugin_t *plugin,
ply_window_t *window)
{
- plugin->window = NULL;
+ ply_list_remove_data (plugin->windows, window);
+}
+
+static void
+initialize_window (ply_window_t *window,
+ ply_boot_splash_plugin_t *plugin)
+{
+ ply_boot_splash_plugin_interface_t *interface;
+
+ ply_window_set_mode (window, PLY_WINDOW_MODE_TEXT);
+
+ ply_window_set_keyboard_input_handler (window,
+ (ply_window_keyboard_input_handler_t)
+ on_keyboard_input, plugin);
+ ply_window_set_backspace_handler (window,
+ (ply_window_backspace_handler_t)
+ on_backspace, plugin);
+ ply_window_set_enter_handler (window,
+ (ply_window_enter_handler_t)
+ on_enter, plugin);
+
+ interface = ply_boot_splash_plugin_get_interface ();
+
+ interface->ask_for_password = ask_for_password;
+}
+
+static void
+uninitialize_window (ply_window_t *window,
+ ply_boot_splash_plugin_t *plugin)
+{
+ ply_window_set_keyboard_input_handler (window, NULL, NULL);
+ ply_window_set_backspace_handler (window, NULL, NULL);
+ ply_window_set_enter_handler (window, NULL, NULL);
}
bool
assert (plugin != NULL);
- if (plugin->window != NULL)
- {
- ply_boot_splash_plugin_interface_t *interface;
-
- ply_window_set_mode (plugin->window, PLY_WINDOW_MODE_TEXT);
-
- ply_window_set_keyboard_input_handler (plugin->window,
- (ply_window_keyboard_input_handler_t)
- on_keyboard_input, plugin);
- ply_window_set_backspace_handler (plugin->window,
- (ply_window_backspace_handler_t)
- on_backspace, plugin);
- ply_window_set_enter_handler (plugin->window,
- (ply_window_enter_handler_t)
- on_enter, plugin);
-
- interface = ply_boot_splash_plugin_get_interface ();
-
- interface->ask_for_password = ask_for_password;
- }
-
+ for_each_window (plugin,
+ (ply_boot_splash_plugin_window_handler_t)
+ initialize_window, NULL, NULL);
plugin->loop = loop;
ply_event_loop_watch_for_exit (loop, (ply_event_loop_exit_handler_t)
const char *output,
size_t size)
{
+ ply_trace ("writing '%s' to all windows (%d bytes)",
+ output, size);
if (size > 0)
- write (STDOUT_FILENO, output, size);
+ for_each_window (plugin,
+ (ply_boot_splash_plugin_window_handler_t)
+ write_text_on_window,
+ (void *) output, (void *) size);
}
void
ply_trace ("hiding splash screen");
+ for_each_window (plugin,
+ (ply_boot_splash_plugin_window_handler_t)
+ uninitialize_window, NULL, NULL);
+
if (plugin->pending_password_answer != NULL)
{
ply_trigger_pull (plugin->pending_password_answer, "");
plugin->keyboard_input_is_hidden = false;
}
- ply_window_set_keyboard_input_handler (plugin->window, NULL, NULL);
- ply_window_set_backspace_handler (plugin->window, NULL, NULL);
- ply_window_set_enter_handler (plugin->window, NULL, NULL);
- ply_window_clear_screen (plugin->window);
-
ply_event_loop_stop_watching_for_exit (plugin->loop,
(ply_event_loop_exit_handler_t)
detach_from_event_loop,
detach_from_event_loop (plugin);
}
-void
-ask_for_password (ply_boot_splash_plugin_t *plugin,
- const char *prompt,
- ply_trigger_t *answer)
+static void
+ask_for_password_on_window (ply_window_t *window,
+ ply_boot_splash_plugin_t *plugin,
+ const char *prompt)
{
- plugin->pending_password_answer = answer;
+ int fd;
+
+ ply_window_set_mode (window, PLY_WINDOW_MODE_TEXT);
- if (plugin->window != NULL)
- ply_window_set_mode (plugin->window, PLY_WINDOW_MODE_TEXT);
+ fd = ply_window_get_tty_fd (window);
if (prompt != NULL)
{
- write (STDOUT_FILENO, "\r\n", strlen ("\r\n"));
- write (STDOUT_FILENO, prompt, strlen (prompt));
+ write (fd, "\r\n", strlen ("\r\n"));
+ write (fd, prompt, strlen (prompt));
}
- write (STDOUT_FILENO, "\r\nPassword: ", strlen ("\r\nPassword: "));
+ write (fd, "\r\nPassword: ", strlen ("\r\nPassword: "));
plugin->keyboard_input_is_hidden = true;
}
+void
+ask_for_password (ply_boot_splash_plugin_t *plugin,
+ const char *prompt,
+ ply_trigger_t *answer)
+{
+ plugin->pending_password_answer = answer;
+
+ for_each_window (plugin,
+ (ply_boot_splash_plugin_window_handler_t)
+ ask_for_password_on_window, (void *) prompt, NULL);
+}
+
ply_boot_splash_plugin_interface_t *
ply_boot_splash_plugin_get_interface (void)
{