Skip to content

LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.

8.4 KB
Raw Blame
# lordos.script: the LordOS boot splash (Plymouth "script" module).
#
# The crown on a navy gradient with a soft violet glow, and a rounded progress bar that follows
# Plymouth's boot progress, smoothed so it never jumps or goes back. In the bottom right corner, the
# time since the splash started, in seconds and milliseconds (lord-sessiond logs the time from the
# kernel's start to the desktop's first frame; docs/RESULTS.md). No text messages: Esc shows
# the text console as usual. The password field appears only when a disk asks for one (LUKS).
# The images come from tools/boot/gen-boot-assets.py (1x, and @2x on 4K screens).
# See docs/brand/README.md, "Boot splash".

# ---- layout ----
scale = 1;
if (Window.GetHeight() >= 1800) scale = 2;
fun img(name) {
    if (global.scale == 2) return Image(name + "@2x.png");
    return Image(name + ".png");
}

# navy, a little lighter at the top (#12122A → #0B0B1C)
Window.SetBackgroundTopColor(0.071, 0.071, 0.165);
Window.SetBackgroundBottomColor(0.043, 0.043, 0.110);

cx = Window.GetX() + Window.GetWidth() / 2;
cy = Window.GetY() + Window.GetHeight() / 2;

crown_image = img("crown");
glow_image = img("glow");
crown_y = Math.Int(cy - crown_image.GetHeight() / 2 - 40 * scale);

glow = Sprite(glow_image);
glow.SetPosition(Math.Int(cx - glow_image.GetWidth() / 2),
                 Math.Int(crown_y + crown_image.GetHeight() / 2 - glow_image.GetHeight() / 2), 1);
crown = Sprite(crown_image);
crown.SetPosition(Math.Int(cx - crown_image.GetWidth() / 2), crown_y, 3);

# ---- the progress bar: track, a scaled gradient body and two round caps ----
track_image = img("track");
bar_w = track_image.GetWidth();
bar_h = track_image.GetHeight();
bar_x = Math.Int(cx - bar_w / 2);
bar_y = Math.Int(crown_y + crown_image.GetHeight() + 56 * scale);

track = Sprite(track_image);
track.SetPosition(bar_x, bar_y, 4);
fill_image = img("fill");
fill = Sprite();
fill.SetPosition(bar_x + bar_h / 2, bar_y, 5);
cap_start = Sprite(img("cap-start"));
cap_start.SetPosition(bar_x, bar_y, 6);
cap_end = Sprite(img("cap-end"));
cap_end.SetPosition(bar_x, bar_y, 6);

wordmark_image = img("wordmark");
wordmark = Sprite(wordmark_image);
wordmark.SetPosition(Math.Int(cx - wordmark_image.GetWidth() / 2), bar_y + bar_h + 28 * scale, 4);
wordmark.SetOpacity(0.55);

target = 0;         # what Plymouth reports (0..1)
shown = 0;          # what the bar draws, eased towards target
drawn_w = -1;
bar_visible = 1;
# shutdown and reboot have no progress: only the crown
mode = Plymouth.GetMode();
if (mode == "shutdown" || mode == "reboot") bar_visible = 0;

fun draw_bar() {
    if (!global.bar_visible) {
        track.SetOpacity(0); fill.SetOpacity(0); cap_start.SetOpacity(0); cap_end.SetOpacity(0);
        wordmark.SetOpacity(0);
        return;
    }
    track.SetOpacity(1);
    wordmark.SetOpacity(0.55);
    w = Math.Int(global.bar_w * global.shown);
    if (w == global.drawn_w) return;
    global.drawn_w = w;
    if (w < global.bar_h) {
        # not enough for both caps yet: a dot that grows into the bar
        cap_start.SetOpacity(w > 0);
        cap_end.SetOpacity(0);
        fill.SetOpacity(0);
        return;
    }
    cap_start.SetOpacity(1);
    cap_end.SetOpacity(1);
    cap_end.SetX(global.bar_x + w - global.bar_h);
    body = w - global.bar_h;
    if (body > 0) {
        fill.SetImage(global.fill_image.Scale(body, global.bar_h));
        fill.SetOpacity(1);
    } else {
        fill.SetOpacity(0);
    }
}

# ---- the boot timer, bottom right ----
timer = Sprite();
timer.SetOpacity(0);
boot_s = 0;         # Plymouth's last duration (seconds since the splash started)
since_s = 0;        # time since then, from the refresh calls (about 50 a second)
timer_shown = -1;

fun pad3(n) {
    if (n < 10) return "00" + n;
    if (n < 100) return "0" + n;
    return "" + n;
}

fun draw_timer() {
    if (!global.bar_visible) { timer.SetOpacity(0); return; }
    t = global.boot_s + global.since_s;
    ms = Math.Int(t * 1000);
    if (ms <= global.timer_shown) return;      # never backwards when Plymouth's duration catches up
    global.timer_shown = ms;
    sec = Math.Int(ms / 1000);
    text = sec + "." + pad3(ms - sec * 1000) + " s";
    img_t = Image.Text(text, 0.80, 0.78, 0.95, 0.55, global.font_timer);
    timer.SetImage(img_t);
    timer.SetPosition(Window.GetX() + Window.GetWidth() - img_t.GetWidth() - 24 * global.scale,
                      Window.GetY() + Window.GetHeight() - img_t.GetHeight() - 20 * global.scale, 20);
    timer.SetOpacity(1);
}

fun boot_progress(duration, progress) {
    if (duration > global.boot_s) { global.boot_s = duration; global.since_s = 0; }
    # Plymouth's progress is based on the previous boot's length; on a first boot (the live ISO, a
    # fresh card) it barely moves, so a time curve keeps the bar going: half at 8 s, two thirds at
    # 16 s, never past 95 % until Plymouth says so
    p = 0.95 * duration / (duration + 8);
    if (progress > p) p = progress;
    if (p > global.target) global.target = p;
}

fun refresh() {
    # ease out: a fraction of the remaining distance each frame (about 50 per second), never back
    if (global.shown < global.target) {
        global.shown = global.shown + (global.target - global.shown) * 0.06 + 0.0004;
        if (global.shown > global.target) global.shown = global.target;
    }
    draw_bar();
    global.since_s = global.since_s + 0.02;
    draw_timer();
}

fun quit() {
    global.shown = 1;
    global.drawn_w = -1;
    draw_bar();
}

# ---- password (encrypted disks) and questions ----
entry_image = img("entry");
entry = Sprite(entry_image);
entry_x = Math.Int(cx - entry_image.GetWidth() / 2);
entry_y = bar_y - 8 * scale;
entry.SetPosition(entry_x, entry_y, 10);
entry.SetOpacity(0);
lock_image = img("lock");
lock = Sprite(lock_image);
lock.SetPosition(Math.Int(cx - lock_image.GetWidth() / 2), entry_y - lock_image.GetHeight() - 12 * scale, 10);
lock.SetOpacity(0);
prompt = Sprite();
prompt.SetOpacity(0);
answer = Sprite();
answer.SetOpacity(0);

bullet_image = img("bullet");
bullet_step = bullet_image.GetWidth() + 8 * scale;
max_bullets = Math.Int((entry_image.GetWidth() - 36 * scale) / bullet_step);
for (i = 0; i < max_bullets; i = i + 1) {
    bullets[i] = Sprite(bullet_image);
    bullets[i].SetPosition(entry_x + 18 * scale + i * bullet_step,
                           Math.Int(entry_y + entry_image.GetHeight() / 2 - bullet_image.GetHeight() / 2), 11);
    bullets[i].SetOpacity(0);
}

# font names as literals (no number formatting in the script)
font_small = "Sans 11";
font_large = "Sans 12";
font_timer = "Sans 10";
if (scale == 2) { font_small = "Sans 22"; font_large = "Sans 24"; font_timer = "Sans 20"; }

fun set_prompt(text) {
    if (text == "") { prompt.SetOpacity(0); return; }
    t = Image.Text(text, 0.93, 0.92, 1.0, 0.8, global.font_small);
    prompt.SetImage(t);
    prompt.SetPosition(Math.Int(global.cx - t.GetWidth() / 2),
                       global.entry_y + global.entry_image.GetHeight() + 14 * global.scale, 10);
    prompt.SetOpacity(1);
}

fun show_field(on) {
    entry.SetOpacity(on);
    lock.SetOpacity(on);
    if (!on) {
        prompt.SetOpacity(0);
        answer.SetOpacity(0);
        for (i = 0; i < global.max_bullets; i = i + 1) bullets[i].SetOpacity(0);
    }
    global.bar_visible = !on;
    if (mode == "shutdown" || mode == "reboot") global.bar_visible = 0;
    global.drawn_w = -1;
    draw_bar();
}

fun display_password(text, count) {
    show_field(1);
    answer.SetOpacity(0);
    set_prompt(text);
    for (i = 0; i < global.max_bullets; i = i + 1) bullets[i].SetOpacity(i < count);
}

fun display_question(text, typed) {
    show_field(1);
    for (i = 0; i < global.max_bullets; i = i + 1) bullets[i].SetOpacity(0);
    set_prompt(text);
    t = Image.Text(typed, 1, 1, 1, 1, global.font_large);
    answer.SetImage(t);
    answer.SetPosition(global.entry_x + 18 * global.scale,
                       Math.Int(global.entry_y + global.entry_image.GetHeight() / 2 - t.GetHeight() / 2), 11);
    answer.SetOpacity(1);
}

fun display_normal() {
    show_field(0);
}

# messages are not shown (Esc shows the text console with all of them)
fun ignore_message(text) {
}

Plymouth.SetBootProgressFunction(boot_progress);
Plymouth.SetRefreshFunction(refresh);
Plymouth.SetQuitFunction(quit);
Plymouth.SetDisplayPasswordFunction(display_password);
Plymouth.SetDisplayQuestionFunction(display_question);
Plymouth.SetDisplayNormalFunction(display_normal);
Plymouth.SetMessageFunction(ignore_message);
draw_bar();