CI / test (push) Canceled after 0s
- Add a script-module Plymouth theme: the moon breathes over a progress bar - The bar eases towards the last boot's duration (60 s before one is recorded) - Art is SVG under boot/plymouth, rendered to PNG by render.sh (needs rsvg-convert)
94 lines
2.9 KiB
Plaintext
94 lines
2.9 KiB
Plaintext
# Chandra boot splash: the moon, and a progress bar under it while booting.
|
|
#
|
|
# Plymouth estimates the progress from how long the last boot took (/var/lib/plymouth/boot-duration;
|
|
# 60 s until it has seen one boot). The bar eases towards that estimate and never moves backwards.
|
|
|
|
Window.SetBackgroundTopColor(0.086, 0.129, 0.243); # #16213e
|
|
Window.SetBackgroundBottomColor(0.043, 0.063, 0.125); # #0b1020
|
|
|
|
center_x = Window.GetX() + Window.GetWidth() / 2;
|
|
center_y = Window.GetY() + Window.GetHeight() * 0.44;
|
|
|
|
# The art is sized for a 1080 px wide panel; scale it on anything else.
|
|
art_scale = Window.GetWidth() / 1080;
|
|
if (Window.GetHeight() < Window.GetWidth()) art_scale = Window.GetHeight() / 1080;
|
|
|
|
fun load(name) {
|
|
local.image = Image(name);
|
|
if (art_scale == 1) return image;
|
|
return image.Scale(Math.Int(image.GetWidth() * art_scale), Math.Int(image.GetHeight() * art_scale));
|
|
}
|
|
|
|
moon = load("moon.png");
|
|
moon_sprite = Sprite(moon);
|
|
moon_sprite.SetPosition(Math.Int(center_x - moon.GetWidth() / 2), Math.Int(center_y - moon.GetHeight() / 2), 1);
|
|
|
|
track = load("track.png");
|
|
fill = load("fill.png");
|
|
bar_x = Math.Int(center_x - track.GetWidth() / 2);
|
|
bar_y = Math.Int(center_y + moon.GetHeight() / 2 + 120 * art_scale);
|
|
|
|
mode = Plymouth.GetMode();
|
|
has_bar = mode == "boot";
|
|
|
|
if (has_bar) {
|
|
track_sprite = Sprite(track);
|
|
track_sprite.SetPosition(bar_x, bar_y, 1);
|
|
fill_sprite = Sprite();
|
|
fill_sprite.SetPosition(bar_x, bar_y, 2);
|
|
}
|
|
|
|
target = 0;
|
|
shown = 0;
|
|
drawn = 0;
|
|
|
|
fun draw_bar() {
|
|
if (!has_bar) return;
|
|
local.width = Math.Int(fill.GetWidth() * shown);
|
|
# Redraw only when the bar grows by a pixel; narrower than its rounded cap it isn't drawn.
|
|
if (width <= drawn || width < fill.GetHeight()) return;
|
|
global.drawn = width;
|
|
fill_sprite.SetImage(fill.Crop(0, 0, width, fill.GetHeight()));
|
|
}
|
|
|
|
fun progress_callback(duration, progress) {
|
|
if (progress > 1) progress = 1;
|
|
if (progress > target) global.target = progress;
|
|
}
|
|
Plymouth.SetBootProgressFunction(progress_callback);
|
|
|
|
phase = 0;
|
|
ticks = 0;
|
|
fun refresh_callback() {
|
|
if (shown < target) {
|
|
global.shown = shown + (target - shown) * 0.08;
|
|
draw_bar();
|
|
}
|
|
# A slow breath, 12 times a second: the panel is drawn by the CPU.
|
|
global.ticks = ticks + 1;
|
|
if (ticks >= 4) {
|
|
global.ticks = 0;
|
|
global.phase = phase + 0.10;
|
|
moon_sprite.SetOpacity(0.86 + 0.14 * Math.Cos(phase));
|
|
}
|
|
}
|
|
Plymouth.SetRefreshFunction(refresh_callback);
|
|
|
|
# The session is about to take the screen: finish the bar.
|
|
fun quit_callback() {
|
|
global.target = 1;
|
|
global.shown = 1;
|
|
draw_bar();
|
|
moon_sprite.SetOpacity(1);
|
|
}
|
|
Plymouth.SetQuitFunction(quit_callback);
|
|
|
|
# fsck, emergency mode and the like.
|
|
message_sprite = Sprite();
|
|
fun message_callback(text) {
|
|
local.image = Image.Text(text, 0.78, 0.84, 1);
|
|
message_sprite.SetImage(image);
|
|
message_sprite.SetPosition(Math.Int(center_x - image.GetWidth() / 2), bar_y + Math.Int(60 * art_scale), 3);
|
|
}
|
|
Plymouth.SetMessageFunction(message_callback);
|