Re-center the Plymouth prompt when a display appears late (#11641)
The theme laid out the logo, password entry and progress bar once, when the script first ran. Plymouth sizes its window to the largest display present, so a monitor that comes up after plymouthd starts (a Thunderbolt display whose DisplayPort tunnel is established about a second after the kernel's display driver loads, a dock, an MST hub) got the prompt drawn at the internal panel's coordinates: off-center on the external display and partly off-screen on the panel. With the lid closed the passphrase box was effectively invisible. Move the layout into a function and re-run it from the refresh callback whenever Window.GetWidth/GetHeight change, which is how Plymouth's script plugin exposes a display being added or removed. Existing bullets are repositioned too. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
31bd80daa4
commit
1b001a69d3
1 file changed
+53
-26
@@ -5,8 +5,6 @@ Window.SetBackgroundBottomColor(0.101, 0.105, 0.149);
|
||||
|
||||
logo.image = Image("logo.png");
|
||||
logo.sprite = Sprite(logo.image);
|
||||
logo.sprite.SetX(Window.GetWidth() / 2 - logo.image.GetWidth() / 2);
|
||||
logo.sprite.SetY(Window.GetHeight() / 2 - logo.image.GetHeight() / 2);
|
||||
logo.sprite.SetOpacity(1);
|
||||
|
||||
# Use these to adjust the progress bar timing
|
||||
@@ -22,7 +20,18 @@ global.fake_progress_start_time = 0.0; # Track when fake progress started
|
||||
global.password_shown = 0; # Track if password dialog has been shown
|
||||
global.max_progress = 0.0; # Track the maximum progress reached to prevent backwards movement
|
||||
|
||||
# Window size the sprites were last laid out for
|
||||
global.layout_width = 0;
|
||||
global.layout_height = 0;
|
||||
|
||||
fun refresh_callback() {
|
||||
# Displays can show up after this script ran, e.g. a Thunderbolt monitor
|
||||
# whose DisplayPort tunnel comes up after plymouthd started. The window
|
||||
# grows to the largest display, so re-center everything when it changes.
|
||||
if (Window.GetWidth() != global.layout_width || Window.GetHeight() != global.layout_height) {
|
||||
layout();
|
||||
}
|
||||
|
||||
global.animation_frame++;
|
||||
|
||||
# Animate fake progress to limit over time with easing
|
||||
@@ -108,27 +117,23 @@ entry.image = Image("entry.png");
|
||||
bullet.image = Image("bullet.png");
|
||||
|
||||
entry.sprite = Sprite(entry.image);
|
||||
entry.x = Window.GetWidth() / 2 - entry.image.GetWidth() / 2;
|
||||
entry.y = logo.sprite.GetY() + logo.image.GetHeight() + 40;
|
||||
entry.sprite.SetPosition(entry.x, entry.y, 10001);
|
||||
entry.sprite.SetOpacity(0);
|
||||
|
||||
# Scale lock to be slightly shorter than entry field height
|
||||
# Original lock is 84x96, entry height determines scale
|
||||
lock_height = entry.image.GetHeight() * 0.8;
|
||||
lock_scale = lock_height / 96;
|
||||
lock_width = 84 * lock_scale;
|
||||
lock.height = entry.image.GetHeight() * 0.8;
|
||||
lock.width = 84 * (lock.height / 96);
|
||||
|
||||
scaled_lock = lock.image.Scale(lock_width, lock_height);
|
||||
lock.sprite = Sprite(scaled_lock);
|
||||
lock.x = entry.x - lock_width - 15;
|
||||
lock.y = entry.y + entry.image.GetHeight() / 2 - lock_height / 2;
|
||||
lock.sprite.SetPosition(lock.x, lock.y, 10001);
|
||||
lock.sprite = Sprite(lock.image.Scale(lock.width, lock.height));
|
||||
lock.sprite.SetOpacity(0);
|
||||
|
||||
# Bullet array
|
||||
bullet.sprites = [];
|
||||
|
||||
fun position_bullet(index) {
|
||||
bullet.sprites[index].SetPosition(entry.x + 20 + index * (7 + 5), entry.y + entry.image.GetHeight() / 2 - 3.5, 10002);
|
||||
}
|
||||
|
||||
fun display_normal_callback() {
|
||||
hide_password_dialog();
|
||||
|
||||
@@ -165,11 +170,8 @@ fun display_password_callback(prompt, bullets) {
|
||||
for (index = 0; index < bullets_to_show; index++) {
|
||||
if (!bullet.sprites[index]) {
|
||||
# Scale bullet image to 7x7 pixels
|
||||
scaled_bullet = bullet.image.Scale(7, 7);
|
||||
bullet.sprites[index] = Sprite(scaled_bullet);
|
||||
bullet.x = entry.x + 20 + index * (7 + 5);
|
||||
bullet.y = entry.y + entry.image.GetHeight() / 2 - 3.5;
|
||||
bullet.sprites[index].SetPosition(bullet.x, bullet.y, 10002);
|
||||
bullet.sprites[index] = Sprite(bullet.image.Scale(7, 7));
|
||||
position_bullet(index);
|
||||
}
|
||||
|
||||
bullet.sprites[index].SetOpacity(1);
|
||||
@@ -183,19 +185,11 @@ Plymouth.SetDisplayPasswordFunction(display_password_callback);
|
||||
|
||||
progress_box.image = Image("progress_box.png");
|
||||
progress_box.sprite = Sprite(progress_box.image);
|
||||
|
||||
progress_box.x = Window.GetWidth() / 2 - progress_box.image.GetWidth() / 2;
|
||||
progress_box.y = entry.y + entry.image.GetHeight() / 2 - progress_box.image.GetHeight() / 2;
|
||||
progress_box.sprite.SetPosition(progress_box.x, progress_box.y, 0);
|
||||
progress_box.sprite.SetOpacity(0);
|
||||
|
||||
progress_bar.original_image = Image("progress_bar.png");
|
||||
progress_bar.sprite = Sprite();
|
||||
progress_bar.image = progress_bar.original_image.Scale(1, progress_bar.original_image.GetHeight());
|
||||
|
||||
progress_bar.x = Window.GetWidth() / 2 - progress_bar.original_image.GetWidth() / 2;
|
||||
progress_bar.y = progress_box.y + (progress_box.image.GetHeight() - progress_bar.original_image.GetHeight()) / 2;
|
||||
progress_bar.sprite.SetPosition(progress_bar.x, progress_bar.y, 1);
|
||||
progress_bar.sprite.SetOpacity(0);
|
||||
|
||||
fun progress_callback(duration, progress) {
|
||||
@@ -216,6 +210,39 @@ fun progress_callback(duration, progress) {
|
||||
|
||||
Plymouth.SetBootProgressFunction(progress_callback);
|
||||
|
||||
#----------------------------------------- Layout --------------------------------
|
||||
|
||||
# Center the logo, dialogue and progress bar for the current window size
|
||||
fun layout() {
|
||||
global.layout_width = Window.GetWidth();
|
||||
global.layout_height = Window.GetHeight();
|
||||
|
||||
logo.sprite.SetX(global.layout_width / 2 - logo.image.GetWidth() / 2);
|
||||
logo.sprite.SetY(global.layout_height / 2 - logo.image.GetHeight() / 2);
|
||||
|
||||
entry.x = global.layout_width / 2 - entry.image.GetWidth() / 2;
|
||||
entry.y = logo.sprite.GetY() + logo.image.GetHeight() + 40;
|
||||
entry.sprite.SetPosition(entry.x, entry.y, 10001);
|
||||
|
||||
lock.x = entry.x - lock.width - 15;
|
||||
lock.y = entry.y + entry.image.GetHeight() / 2 - lock.height / 2;
|
||||
lock.sprite.SetPosition(lock.x, lock.y, 10001);
|
||||
|
||||
for (index = 0; bullet.sprites[index]; index++) {
|
||||
position_bullet(index);
|
||||
}
|
||||
|
||||
progress_box.x = global.layout_width / 2 - progress_box.image.GetWidth() / 2;
|
||||
progress_box.y = entry.y + entry.image.GetHeight() / 2 - progress_box.image.GetHeight() / 2;
|
||||
progress_box.sprite.SetPosition(progress_box.x, progress_box.y, 0);
|
||||
|
||||
progress_bar.x = global.layout_width / 2 - progress_bar.original_image.GetWidth() / 2;
|
||||
progress_bar.y = progress_box.y + (progress_box.image.GetHeight() - progress_bar.original_image.GetHeight()) / 2;
|
||||
progress_bar.sprite.SetPosition(progress_bar.x, progress_bar.y, 1);
|
||||
}
|
||||
|
||||
layout();
|
||||
|
||||
#----------------------------------------- Message --------------------------------
|
||||
|
||||
message_sprite = Sprite();
|
||||
|
||||
Reference in new issue
Block a user