[script] Allow scripts to attach themselves to plymouth plugin callbacks

The scripts can now attach themselves to the following callbacks: refresh,
boot_progress, root_mounted, keyboard_input, update_status, display_normal,
display_password and display_question.
calculate-0.9.5
Charlie Brej 15 years ago committed by Ray Strode
parent b2e08f4968
commit a316d77674

@ -175,6 +175,7 @@ on_boot_progress (ply_boot_splash_plugin_t *plugin,
if (plugin->progress_target<0)
plugin->progress = percent_done;
plugin->progress_target = percent_done;
script_lib_plymouth_on_boot_progress(plugin->script_state, plugin->script_plymouth_lib, duration, plugin->progress);
}
@ -202,7 +203,7 @@ start_animation (ply_boot_splash_plugin_t *plugin)
plugin->script_math_lib = script_lib_math_setup(plugin->script_state);
script_return ret = script_execute(plugin->script_state, plugin->script_main_op);
if (ret.object) script_obj_unref(ret.object); // Throw anything sent back away
script_obj_unref(ret.object);
@ -256,6 +257,11 @@ on_keyboard_input (ply_boot_splash_plugin_t *plugin,
const char *keyboard_input,
size_t character_size)
{
char keyboard_string[character_size+1];
memcpy(keyboard_string, keyboard_input, character_size);
keyboard_string[character_size]='\0';
script_lib_plymouth_on_keyboard_input(plugin->script_state, plugin->script_plymouth_lib, keyboard_string);
}
void
@ -373,6 +379,7 @@ update_status (ply_boot_splash_plugin_t *plugin,
const char *status)
{
assert (plugin != NULL);
script_lib_plymouth_on_update_status(plugin->script_state, plugin->script_plymouth_lib, status);
}
void
@ -401,6 +408,7 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin,
void
on_root_mounted (ply_boot_splash_plugin_t *plugin)
{
script_lib_plymouth_on_root_mounted(plugin->script_state, plugin->script_plymouth_lib);
}
void
@ -415,6 +423,7 @@ become_idle (ply_boot_splash_plugin_t *plugin,
void display_normal (ply_boot_splash_plugin_t *plugin)
{
plugin->state = PLY_BOOT_SPLASH_DISPLAY_NORMAL;
script_lib_plymouth_on_display_normal(plugin->script_state, plugin->script_plymouth_lib);
}
void
@ -423,6 +432,7 @@ display_password (ply_boot_splash_plugin_t *plugin,
int bullets)
{
plugin->state = PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY;
script_lib_plymouth_on_display_password(plugin->script_state, plugin->script_plymouth_lib, prompt, bullets);
}
void
@ -431,6 +441,7 @@ display_question (ply_boot_splash_plugin_t *plugin,
const char *entry_text)
{
plugin->state = PLY_BOOT_SPLASH_DISPLAY_QUESTION_ENTRY;
script_lib_plymouth_on_display_question(plugin->script_state, plugin->script_plymouth_lib, prompt, entry_text);
}
ply_boot_splash_plugin_interface_t *

@ -17,13 +17,12 @@
#include "script-lib-plymouth.string"
static script_return plymouth_set_refresh (script_state* state, void* user_data)
static script_return plymouth_set_function (script_state* state, void* user_data)
{
script_obj** script_func = user_data;
script_obj* obj = script_obj_hash_get_element (state->local, "function");
script_obj_deref(&obj);
if (*script_func)
script_obj_unref(*script_func);
script_obj_unref(*script_func);
if (obj->type == SCRIPT_OBJ_TYPE_FUNCTION){
*script_func = obj;
@ -42,11 +41,25 @@ script_lib_plymouth_data_t* script_lib_plymouth_setup(script_state *state)
script_lib_plymouth_data_t* data = malloc(sizeof(script_lib_plymouth_data_t));
data->script_refresh_func = NULL;
data->script_boot_progress_func = NULL;
data->script_root_mounted_func = NULL;
data->script_keyboard_input_func = NULL;
data->script_update_status_func = NULL;
data->script_display_normal_func = NULL;
data->script_display_password_func = NULL;
data->script_display_question_func = NULL;
script_add_native_function (state->global, "PlymouthSetRefreshFunction", plymouth_set_refresh, &data->script_refresh_func, "function", NULL);
script_add_native_function (state->global, "PlymouthSetRefreshFunction", plymouth_set_function, &data->script_refresh_func, "function", NULL);
script_add_native_function (state->global, "PlymouthSetBootProgressFunction", plymouth_set_function, &data->script_boot_progress_func, "function", NULL);
script_add_native_function (state->global, "PlymouthSetRootMountedFunction", plymouth_set_function, &data->script_root_mounted_func, "function", NULL);
script_add_native_function (state->global, "PlymouthSetKeyboardInputFunction", plymouth_set_function, &data->script_keyboard_input_func, "function", NULL);
script_add_native_function (state->global, "PlymouthSetUpdateStatusFunction", plymouth_set_function, &data->script_update_status_func, "function", NULL);
script_add_native_function (state->global, "PlymouthSetDisplayNormalFunction", plymouth_set_function, &data->script_display_normal_func, "function", NULL);
script_add_native_function (state->global, "PlymouthSetDisplayPasswordFunction", plymouth_set_function, &data->script_display_password_func, "function", NULL);
script_add_native_function (state->global, "PlymouthSetDisplayQuestionFunction", plymouth_set_function, &data->script_display_question_func, "function", NULL);
data->script_main_op = script_parse_string (script_lib_plymouth_string);
script_return ret = script_execute(state, data->script_main_op);
if (ret.object) script_obj_unref(ret.object); // Throw anything sent back away
script_obj_unref(ret.object); // Throw anything sent back away
return data;
}
@ -56,18 +69,100 @@ void script_lib_plymouth_destroy(script_lib_plymouth_data_t* data)
{
script_parse_op_free (data->script_main_op);
script_obj_unref(data->script_refresh_func);
script_obj_unref(data->script_boot_progress_func);
script_obj_unref(data->script_root_mounted_func);
script_obj_unref(data->script_keyboard_input_func);
free(data);
}
void script_lib_plymouth_on_refresh(script_state* state, script_lib_plymouth_data_t* data)
{
script_obj* refresh_func_obj = data->script_refresh_func;
if (refresh_func_obj && refresh_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION){
script_return ret = script_execute_function (state, data->script_refresh_func->data.function, NULL);
if (ret.object) script_obj_unref(ret.object); // Throw anything sent back away
script_return ret = script_execute_function (state, refresh_func_obj->data.function, NULL);
script_obj_unref(ret.object); // Throw anything sent back away
}
}
void script_lib_plymouth_on_boot_progress(script_state* state, script_lib_plymouth_data_t* data, float duration, float progress)
{
script_obj* boot_progress_func_obj = data->script_boot_progress_func;
if (boot_progress_func_obj && boot_progress_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION){
script_obj* duration_obj = script_obj_new_float (duration);
script_obj* progress_obj = script_obj_new_float (progress);
script_return ret = script_execute_function (state, boot_progress_func_obj->data.function, duration_obj, progress_obj, NULL);
script_obj_unref(ret.object); // Throw anything sent back away
script_obj_unref(duration_obj);
script_obj_unref(progress_obj);
}
}
void script_lib_plymouth_on_root_mounted(script_state* state, script_lib_plymouth_data_t* data)
{
script_obj* root_mounted_func_obj = data->script_root_mounted_func;
if (root_mounted_func_obj && root_mounted_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION){
script_return ret = script_execute_function (state, root_mounted_func_obj->data.function, NULL);
script_obj_unref(ret.object);
}
}
void script_lib_plymouth_on_keyboard_input(script_state* state, script_lib_plymouth_data_t* data, const char* keyboard_input)
{
script_obj* keyboard_input_func_obj = data->script_keyboard_input_func;
if (keyboard_input_func_obj && keyboard_input_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION){
script_obj* keyboard_input_obj = script_obj_new_string (keyboard_input);
script_return ret = script_execute_function (state, keyboard_input_func_obj->data.function, keyboard_input_obj, NULL);
script_obj_unref(keyboard_input_obj);
script_obj_unref(ret.object);
}
}
void script_lib_plymouth_on_update_status(script_state* state, script_lib_plymouth_data_t* data, const char* new_status)
{
script_obj* update_status_func_obj = data->script_update_status_func;
if (update_status_func_obj && update_status_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION){
script_obj* new_status_obj = script_obj_new_string (new_status);
script_return ret = script_execute_function (state, update_status_func_obj->data.function, new_status_obj, NULL);
script_obj_unref(new_status_obj);
script_obj_unref(ret.object);
}
}
void script_lib_plymouth_on_display_normal(script_state* state, script_lib_plymouth_data_t* data)
{
script_obj* display_normal_func_obj = data->script_display_normal_func;
if (display_normal_func_obj && display_normal_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION){
script_return ret = script_execute_function (state, display_normal_func_obj->data.function, NULL);
script_obj_unref(ret.object);
}
}
void script_lib_plymouth_on_display_password(script_state* state, script_lib_plymouth_data_t* data, const char *prompt, int bullets)
{
script_obj* display_password_func_obj = data->script_display_password_func;
if (display_password_func_obj && display_password_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION){
script_obj* prompt_obj = script_obj_new_string (prompt);
script_obj* bullets_obj = script_obj_new_int (bullets);
script_return ret = script_execute_function (state, display_password_func_obj->data.function, prompt_obj, bullets_obj, NULL);
script_obj_unref(prompt_obj);
script_obj_unref(bullets_obj);
script_obj_unref(ret.object);
}
}
void script_lib_plymouth_on_display_question(script_state* state, script_lib_plymouth_data_t* data, const char *prompt, const char *entry_text)
{
script_obj* display_question_func_obj = data->script_display_question_func;
if (display_question_func_obj && display_question_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION){
script_obj* prompt_obj = script_obj_new_string (prompt);
script_obj* entry_text_obj = script_obj_new_string (entry_text);
script_return ret = script_execute_function (state, display_question_func_obj->data.function, prompt_obj, entry_text_obj, NULL);
script_obj_unref(prompt_obj);
script_obj_unref(entry_text_obj);
script_obj_unref(ret.object);
}
}

@ -7,6 +7,15 @@ typedef struct
{
script_op *script_main_op;
script_obj *script_refresh_func;
script_obj *script_boot_progress_func;
script_obj *script_root_mounted_func;
script_obj *script_keyboard_input_func;
script_obj *script_update_status_func;
script_obj *script_display_normal_func;
script_obj *script_display_password_func;
script_obj *script_display_question_func;
} script_lib_plymouth_data_t;
@ -14,5 +23,12 @@ script_lib_plymouth_data_t* script_lib_plymouth_setup(script_state *state);
void script_lib_plymouth_destroy(script_lib_plymouth_data_t* data);
void script_lib_plymouth_on_refresh(script_state* state, script_lib_plymouth_data_t* data);
void script_lib_plymouth_on_boot_progress(script_state* state, script_lib_plymouth_data_t* data, float duration, float progress);
void script_lib_plymouth_on_root_mounted(script_state* state, script_lib_plymouth_data_t* data);
void script_lib_plymouth_on_keyboard_input(script_state* state, script_lib_plymouth_data_t* data, const char* keyboard_input);
void script_lib_plymouth_on_update_status(script_state* state, script_lib_plymouth_data_t* data, const char* new_status);
void script_lib_plymouth_on_display_normal(script_state* state, script_lib_plymouth_data_t* data);
void script_lib_plymouth_on_display_password(script_state* state, script_lib_plymouth_data_t* data, const char *prompt, int bullets);
void script_lib_plymouth_on_display_question(script_state* state, script_lib_plymouth_data_t* data, const char *prompt, const char *entry_text);
#endif /* SCRIPT_LIB_PLYMOUTH */

@ -5,31 +5,32 @@ while (index<30){
if (index<10) mystring = "0" + index;
sprites[index] = SpriteNewWithImage("../spinfinity/throbber-" + mystring + ".png");
sprites[index].orig_image = sprites[index].image;
sprites[index].xd = 1 + index;
sprites[index].yd = 1 + index;
sprites[index].xd = (50 + index)/10;
sprites[index].yd = (50 + index)/10;
index = index + 1;
}
random = 1;
count = 0;
progress=0;
fun update_logo_sprite (sprite){
image_width = ImageGetWidth (sprite.image);
image_height = ImageGetHeight(sprite.image);
if (sprite.x < 0)
sprite.xd = +(global.random % 5 + 1)/0.5;
sprite.xd = +(global.random % 5 + 1);
if (sprite.y < 0)
sprite.yd = +(global.random % 5 + 1)/0.5;
sprite.yd = +(global.random % 5 + 1);
if ((sprite.x + image_width) > 800)
sprite.xd = -((global.random % 5 + 1)/0.5);
sprite.xd = -((global.random % 5 + 1));
if ((sprite.y + image_height) > 600)
sprite.yd = -((global.random % 5 + 1)/0.5);
sprite.yd = -((global.random % 5 + 1));
global.random = (1 + global.random * 7) % 101;
sprite.x = sprite.x + sprite.xd;
sprite.y = sprite.y + sprite.yd;
sprite.x = sprite.x + sprite.xd*global.progress;
sprite.y = sprite.y + sprite.yd*global.progress;
sprite.image = ImageRotate(sprite.orig_image, count*0.1);
SpriteUpdate(sprite);
}
@ -45,7 +46,33 @@ fun refresh (){
return;
}
fun on_progress (duration, progress){
global.progress = progress*300;
}
fun on_keyboard (key){
index = 0;
if (key == "a"){
while (!(index>=30)){
sprites[index].x = 0;
index++;
}
}
if (key == "b"){
while (!(index>=30)){
sprites[index].y = 0;
index++;
}
}
return;
}
// This is a comment
# As is this (both are acceptable because people do forget which to use)
/* A block comment /* with a nested sub-comment */ */
PlymouthSetRefreshFunction(refresh);
PlymouthSetKeyboardInputFunction(on_keyboard);
PlymouthSetBootProgressFunction(on_progress);
PlymouthSetUpdateStatusFunction(on_keyboard);

Loading…
Cancel
Save