From e111ba8bafaa41fced0824e6fbccc20372917a3d Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Wed, 9 Jan 2019 11:31:06 +0100 Subject: [PATCH 1/5] libply: Add ply_key_file_get_bool function Add a function to read a boolean value from a ply-key-file. This function will return true if the key exists and it has a value of "1", "y", "yes" or "true" (case-insensitive). In all other cases it returns false. Signed-off-by: Hans de Goede --- src/libply/ply-key-file.c | 33 +++++++++++++++++++++++++++++++++ src/libply/ply-key-file.h | 4 ++++ 2 files changed, 37 insertions(+) diff --git a/src/libply/ply-key-file.c b/src/libply/ply-key-file.c index 862d6d59..1c05766a 100644 --- a/src/libply/ply-key-file.c +++ b/src/libply/ply-key-file.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -356,6 +357,38 @@ ply_key_file_get_value (ply_key_file_t *key_file, return strdup (entry->value); } +bool +ply_key_file_get_bool (ply_key_file_t *key_file, + const char *group_name, + const char *key) +{ + ply_key_file_group_t *group; + ply_key_file_entry_t *entry; + + group = ply_key_file_find_group (key_file, group_name); + + if (group == NULL) { + ply_trace ("key file does not have group '%s'", group_name); + return false; + } + + entry = ply_key_file_find_entry (key_file, group, key); + + if (entry == NULL) { + ply_trace ("key file does not have entry for key '%s'", key); + return false; + } + + /* We treat "1", "y" and "yes" and "true" as true, all else is false */ + if (strcasecmp (entry->value, "1") == 0 || + strcasecmp (entry->value, "y") == 0 || + strcasecmp (entry->value, "yes") == 0 || + strcasecmp (entry->value, "true") == 0) + return true; + + return false; +} + static void ply_key_file_foreach_entry_entries (void *key, void *data, diff --git a/src/libply/ply-key-file.h b/src/libply/ply-key-file.h index e69d14a8..ef7124b5 100644 --- a/src/libply/ply-key-file.h +++ b/src/libply/ply-key-file.h @@ -42,6 +42,10 @@ bool ply_key_file_has_key (ply_key_file_t *key_file, char *ply_key_file_get_value (ply_key_file_t *key_file, const char *group_name, const char *key); +/* Note this returns false for non existing keys */ +bool ply_key_file_get_bool (ply_key_file_t *key_file, + const char *group_name, + const char *key); void ply_key_file_foreach_entry (ply_key_file_t *key_file, ply_key_file_foreach_func_t func, void *user_data); From 6cf1bb3e37df6b69d3b0e17eee394ad8c6e57e75 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Thu, 20 Dec 2018 12:47:39 +0100 Subject: [PATCH 2/5] two-step: Rename UseBGRT to UseFirmwareBackground Rename the UseBGRT theme configfile option to UseFirmwareBackground, to make it clear what this does using language which most users will be able to understand, rather then using the cryptic BGRT ACPI table reference. While at it also switch to using the new ply_key_file_get_bool function, so that users can edit an existing configfile with "UseFirmwareBackground=true" in there and change it to "=false" and actually have that work as expected. The switch to ply_key_file_get_bool also fixes a memleak as ply_key_file_get_value returns a strdup-ed value which we were not free-ing. Signed-off-by: Hans de Goede --- src/plugins/splash/two-step/plugin.c | 3 +-- themes/bgrt/bgrt.plymouth.in | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/plugins/splash/two-step/plugin.c b/src/plugins/splash/two-step/plugin.c index c1e75a8e..8f1ad584 100644 --- a/src/plugins/splash/two-step/plugin.c +++ b/src/plugins/splash/two-step/plugin.c @@ -813,8 +813,7 @@ create_plugin (ply_key_file_t *key_file) free (color); - /* Boolean option, true if the key is present */ - if (ply_key_file_get_value (key_file, "two-step", "UseBGRT")) + if (ply_key_file_get_bool (key_file, "two-step", "UseFirmwareBackground")) plugin->background_bgrt_image = ply_image_new ("/sys/firmware/acpi/bgrt/image"); progress_function = ply_key_file_get_value (key_file, "two-step", "ProgressFunction"); diff --git a/themes/bgrt/bgrt.plymouth.in b/themes/bgrt/bgrt.plymouth.in index b5cc8432..dc5eaf5c 100644 --- a/themes/bgrt/bgrt.plymouth.in +++ b/themes/bgrt/bgrt.plymouth.in @@ -13,4 +13,4 @@ Transition=none TransitionDuration=0.0 BackgroundStartColor=0x202020 BackgroundEndColor=0x202020 -UseBGRT=true +UseFirmwareBackground=true From 410ba63c81f49b08ab674d359239869b23bdd80e Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Wed, 19 Dec 2018 11:52:03 +0100 Subject: [PATCH 3/5] two-step: Make the box image surrounding the unlock dialog optional In some themes we want a simple style text entry without a dialog like box around it. Signed-off-by: Hans de Goede --- src/plugins/splash/two-step/plugin.c | 50 ++++++++++++++++++---------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/plugins/splash/two-step/plugin.c b/src/plugins/splash/two-step/plugin.c index 8f1ad584..c6e9be4b 100644 --- a/src/plugins/splash/two-step/plugin.c +++ b/src/plugins/splash/two-step/plugin.c @@ -91,7 +91,7 @@ typedef struct ply_throbber_t *throbber; ply_label_t *label; ply_label_t *message_label; - ply_rectangle_t box_area, lock_area, watermark_area; + ply_rectangle_t box_area, lock_area, watermark_area, dialog_area; ply_trigger_t *end_trigger; ply_pixel_buffer_t *background_buffer; bool background_is_bgrt; @@ -648,9 +648,8 @@ view_show_prompt (view_t *view, const char *prompt) { ply_boot_splash_plugin_t *plugin; + unsigned long screen_width, screen_height, entry_width, entry_height; int x, y; - int entry_width, entry_height; - unsigned long screen_width, screen_height; assert (view != NULL); @@ -660,17 +659,25 @@ view_show_prompt (view_t *view, screen_height = ply_pixel_display_get_height (view->display); if (ply_entry_is_hidden (view->entry)) { - view->box_area.width = ply_image_get_width (plugin->box_image); - view->box_area.height = ply_image_get_height (plugin->box_image); - view->box_area.x = screen_width / 2.0 - view->box_area.width / 2.0; - view->box_area.y = screen_height / 2.0 - view->box_area.height / 2.0; - view->lock_area.width = ply_image_get_width (plugin->lock_image); view->lock_area.height = ply_image_get_height (plugin->lock_image); entry_width = ply_entry_get_width (view->entry); entry_height = ply_entry_get_height (view->entry); + if (plugin->box_image) { + view->box_area.width = ply_image_get_width (plugin->box_image); + view->box_area.height = ply_image_get_height (plugin->box_image); + view->box_area.x = (screen_width - view->box_area.width) * 0.5; + view->box_area.y = (screen_height - view->box_area.height) * 0.5; + view->dialog_area = view->box_area; + } else { + view->dialog_area.width = view->lock_area.width + entry_width; + view->dialog_area.height = MAX(view->lock_area.height, entry_height); + view->dialog_area.x = (screen_width - view->dialog_area.width) * 0.5; + view->dialog_area.y = (screen_height - view->dialog_area.height) * 0.5; + } + x = screen_width / 2.0 - (view->lock_area.width + entry_width) / 2.0 + view->lock_area.width; y = screen_height / 2.0 - entry_height / 2.0; @@ -689,7 +696,7 @@ view_show_prompt (view_t *view, ply_label_set_width (view->label, label_width); x = (screen_width - label_width) / 2; - y = view->box_area.y + view->box_area.height; + y = view->dialog_area.y + view->dialog_area.height; ply_label_show (view->label, view->display, x, y); } @@ -881,9 +888,11 @@ destroy_plugin (ply_boot_splash_plugin_t *plugin) detach_from_event_loop (plugin); } - ply_image_free (plugin->box_image); ply_image_free (plugin->lock_image); + if (plugin->box_image != NULL) + ply_image_free (plugin->box_image); + if (plugin->corner_image != NULL) ply_image_free (plugin->corner_image); @@ -1091,10 +1100,12 @@ on_draw (view_t *view, plugin->state == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) { uint32_t *box_data, *lock_data; - box_data = ply_image_get_data (plugin->box_image); - ply_pixel_buffer_fill_with_argb32_data (pixel_buffer, - &view->box_area, - box_data); + if (plugin->box_image) { + box_data = ply_image_get_data (plugin->box_image); + ply_pixel_buffer_fill_with_argb32_data (pixel_buffer, + &view->box_area, + box_data); + } ply_entry_draw_area (view->entry, pixel_buffer, @@ -1223,9 +1234,14 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin, if (!ply_image_load (plugin->lock_image)) return false; - ply_trace ("loading box image"); - if (!ply_image_load (plugin->box_image)) - return false; + if (plugin->box_image != NULL) { + ply_trace ("loading box image"); + + if (!ply_image_load (plugin->box_image)) { + ply_image_free (plugin->box_image); + plugin->box_image = NULL; + } + } if (plugin->corner_image != NULL) { ply_trace ("loading corner image"); From 27e671bff7df6310e32e640b7db91642ab31e84b Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Wed, 19 Dec 2018 13:28:28 +0100 Subject: [PATCH 4/5] two-step: Add support for non center alignment of the (diskcrypt) dialog Add DialogHorizontalAlignment and DialogVerticalAlignment options which allow placing the (diskcrypt) dialog aligned at another place then the center of the screen. Signed-off-by: Hans de Goede --- src/plugins/splash/two-step/plugin.c | 39 ++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/plugins/splash/two-step/plugin.c b/src/plugins/splash/two-step/plugin.c index c6e9be4b..0f79795b 100644 --- a/src/plugins/splash/two-step/plugin.c +++ b/src/plugins/splash/two-step/plugin.c @@ -112,6 +112,9 @@ struct _ply_boot_splash_plugin ply_boot_splash_display_type_t state; + double dialog_horizontal_alignment; + double dialog_vertical_alignment; + double watermark_horizontal_alignment; double watermark_vertical_alignment; @@ -668,21 +671,27 @@ view_show_prompt (view_t *view, if (plugin->box_image) { view->box_area.width = ply_image_get_width (plugin->box_image); view->box_area.height = ply_image_get_height (plugin->box_image); - view->box_area.x = (screen_width - view->box_area.width) * 0.5; - view->box_area.y = (screen_height - view->box_area.height) * 0.5; + view->box_area.x = (screen_width - view->box_area.width) * plugin->dialog_horizontal_alignment; + view->box_area.y = (screen_height - view->box_area.height) * plugin->dialog_vertical_alignment; view->dialog_area = view->box_area; } else { view->dialog_area.width = view->lock_area.width + entry_width; view->dialog_area.height = MAX(view->lock_area.height, entry_height); - view->dialog_area.x = (screen_width - view->dialog_area.width) * 0.5; - view->dialog_area.y = (screen_height - view->dialog_area.height) * 0.5; + view->dialog_area.x = (screen_width - view->dialog_area.width) * plugin->dialog_horizontal_alignment; + view->dialog_area.y = (screen_height - view->dialog_area.height) * plugin->dialog_vertical_alignment; } - x = screen_width / 2.0 - (view->lock_area.width + entry_width) / 2.0 + view->lock_area.width; - y = screen_height / 2.0 - entry_height / 2.0; + view->lock_area.x = + view->dialog_area.x + + (view->dialog_area.width - + (view->lock_area.width + entry_width)) / 2.0; + view->lock_area.y = + view->dialog_area.y + + (view->dialog_area.height - view->lock_area.height) / 2.0; - view->lock_area.x = screen_width / 2.0 - (view->lock_area.width + entry_width) / 2.0; - view->lock_area.y = screen_height / 2.0 - view->lock_area.height / 2.0; + x = view->lock_area.x + view->lock_area.width; + y = view->dialog_area.y + + (view->dialog_area.height - entry_height) / 2.0; ply_entry_show (view->entry, plugin->loop, view->display, x, y); } @@ -783,6 +792,20 @@ create_plugin (ply_key_file_t *key_file) plugin->watermark_vertical_alignment = .5; free (alignment); + alignment = ply_key_file_get_value (key_file, "two-step", "DialogHorizontalAlignment"); + if (alignment != NULL) + plugin->dialog_horizontal_alignment = ply_strtod (alignment); + else + plugin->dialog_horizontal_alignment = .5; + free (alignment); + + alignment = ply_key_file_get_value (key_file, "two-step", "DialogVerticalAlignment"); + if (alignment != NULL) + plugin->dialog_vertical_alignment = ply_strtod (alignment); + else + plugin->dialog_vertical_alignment = .5; + free (alignment); + plugin->transition = PLY_PROGRESS_ANIMATION_TRANSITION_NONE; transition = ply_key_file_get_value (key_file, "two-step", "Transition"); if (transition != NULL) { From d62be07815fc4830c5630c9b52a5b7ec08c62637 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Wed, 19 Dec 2018 13:33:08 +0100 Subject: [PATCH 5/5] two-step: Make clearing the dialog-background when using the firmware background optional Since the ask-for-password or ask-question dialog and the firmware background may intersect so far we've been clearing the screen to black when showing a dialog and using the firmware background. This is not always desirable, this commit adds a new "DialogClearsFirmwareBackground" option to the two-step based theme config file, which enables this behavior when set. The new default is to keep using the initial (firmware) background when showing a dialog, which matches the non firmware-background paths. Also update the bgrt theme to use the "DialogClearsFirmwareBackground" option, keeping the current behavior for that theme. Signed-off-by: Hans de Goede --- src/plugins/splash/two-step/plugin.c | 10 +++++++--- themes/bgrt/bgrt.plymouth.in | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/plugins/splash/two-step/plugin.c b/src/plugins/splash/two-step/plugin.c index 0f79795b..53f19ee4 100644 --- a/src/plugins/splash/two-step/plugin.c +++ b/src/plugins/splash/two-step/plugin.c @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2009 Red Hat, Inc. + * Copyright (C) 2009-2019 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * - * Written by: William Jon McCann + * Written by: William Jon McCann, Hans de Goede * */ #include "config.h" @@ -138,6 +138,7 @@ struct _ply_boot_splash_plugin uint32_t is_visible : 1; uint32_t is_animating : 1; uint32_t is_idle : 1; + uint32_t dialog_clears_firmware_background : 1; }; ply_boot_splash_plugin_interface_t *ply_boot_splash_plugin_get_interface (void); @@ -846,6 +847,9 @@ create_plugin (ply_key_file_t *key_file) if (ply_key_file_get_bool (key_file, "two-step", "UseFirmwareBackground")) plugin->background_bgrt_image = ply_image_new ("/sys/firmware/acpi/bgrt/image"); + plugin->dialog_clears_firmware_background = + ply_key_file_get_bool (key_file, "two-step", "DialogClearsFirmwareBackground"); + progress_function = ply_key_file_get_value (key_file, "two-step", "ProgressFunction"); if (progress_function != NULL) { @@ -1081,7 +1085,7 @@ draw_background (view_t *view, */ if ((plugin->state == PLY_BOOT_SPLASH_DISPLAY_QUESTION_ENTRY || plugin->state == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) && - view->background_is_bgrt) + view->background_is_bgrt && plugin->dialog_clears_firmware_background) ply_pixel_buffer_fill_with_hex_color (pixel_buffer, &area, 0); else if (view->background_buffer != NULL) ply_pixel_buffer_fill_with_buffer (pixel_buffer, view->background_buffer, 0, 0); diff --git a/themes/bgrt/bgrt.plymouth.in b/themes/bgrt/bgrt.plymouth.in index dc5eaf5c..86c26229 100644 --- a/themes/bgrt/bgrt.plymouth.in +++ b/themes/bgrt/bgrt.plymouth.in @@ -14,3 +14,4 @@ TransitionDuration=0.0 BackgroundStartColor=0x202020 BackgroundEndColor=0x202020 UseFirmwareBackground=true +DialogClearsFirmwareBackground=true