fix(plymouth): #137 splash follows the canvas; #145 keyboard hint on the LUKS prompt
All checks were successful
Check / eval (push) Successful in 3m59s

The logo was off-centre on the external when booting/shutting down docked.
Both earlier diagnoses in this repo were WRONG, and that is the part worth
keeping: Window.GetWidth() returns max_width (not head 0), and per-head
sprites would have DUPLICATED the logo — the script plugin already builds
one max_width x max_height canvas, centres every display inside it
(script-lib-sprite.c:536) and draws sprites at (sprite.x - display.x), so a
canvas-centred sprite is centred on every head. The arithmetic was right.

The bug was TIME: every position was a top-level statement evaluated once
at parse time. A head arriving/leaving mid-splash resizes the canvas, the
plugin re-centres the displays, and frozen sprites end up off by
(new_max - old_max)/2 on every head. One monitor never resizes the canvas —
hence "only when docked". Fix: one layout(), re-run from the existing
refresh callback on canvas change.

The trap that cost two attempts (now a comment): in plymouth script a bare
assignment inside a function writes the GLOBAL if that name already exists
globally. So `canvas_width = Window.GetWidth()` updated global.canvas_width
BEFORE the guard compared against it — always false, body never ran, splash
rendered as a bare background, NO error logged. Isolated with a 20-line
probe. Hence cw/ch.

#145 rides along: a VT loads one keymap and knows nothing of per-device
layouts, so the passphrase box types with the console layout — worth saying
before three wrong tries on a disk you cannot read (same gap as #114, one
step earlier). Fedora's mechanism does not port: ply_keymap_icon is a C
widget in the two-step plugin (the script plugin has no keyboard API), fed
from XKBLAYOUT in /etc/vconsole.conf, which NixOS never writes (plymouth's
trace says `XKBLAYOUT: (null)`). So @LAYOUT@ is baked from
services.xserver.xkb.layout like the palette — the FIRST of a comma list,
since that is what the VT loads. Icon is plymouth's own keyboard.png (the
same glyph Fedora shows), copied at build time so no GPL bytes enter the
repo, recoloured to subtext.

chmod +w after that copy: store files are 444 and recolor rewrites in
place. Without it magick fails, the phase aborts, and EVERY LATER SED
SILENTLY DOES NOT RUN — the theme shipped with @BG_R@ literals and I only
caught it by reading the build log.

Verified by render (tools/plymouth-preview.sh, real built theme): both
heads centred, password dialog showing padlock + entry + keyboard icon and
"us". V3 queued — only a real docked boot can resize a canvas.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-16 13:14:05 +01:00
parent 121b91f69c
commit ff0f9d6359
6 changed files with 247 additions and 166 deletions

View File

@@ -24,8 +24,20 @@ let
text = colorOf "text" "#D3DAE0";
surface = colorOf "surface" "#303A46";
accent = colorOf "accent" "#B79BE8";
# The keyboard hint is a footnote, not a headline: subtext, like the rest of
# the palette's secondary text (#145).
subtext = colorOf "subtext" "#97A3B2";
magick = lib.getExe' pkgs.imagemagick "magick";
# What the passphrase prompt actually types with. `services.xserver.xkb.layout`
# is this distro's single source for the layout, bridged to the console (and
# so to the initrd prompt) by console.useXkbConfig — see modules/nixos/default.nix.
# A VT loads exactly ONE keymap, so a comma list ("us,gb") means the FIRST:
# printing the raw string would lie in precisely the multi-layout case the
# label exists for.
kbdLayout = lib.head
(lib.splitString "," (config.services.xserver.xkb.layout or "us"));
# Plymouth's Window.SetBackgroundTopColor takes three floats in
# 0.01.0; the .plymouth metadata's ConsoleLogBackgroundColor takes a
# 0xRRGGBB hex. Nix has no float math: multiply, integer-divide, pad.
@@ -38,7 +50,9 @@ let
else if lib.stringLength s == 2 then "0${s}"
else s;
in "0.${padded}";
channel = off: byteToFloat (lib.fromHexString (lib.substring off 2 base));
channelOf = hex: off: byteToFloat (lib.fromHexString (lib.substring off 2 hex));
channel = channelOf base; # Window.SetBackground* (the splash base)
fgChannel = channelOf subtext; # Image.Text needs the same 0.0-1.0 floats
nomarchy-plymouth = pkgs.stdenv.mkDerivation {
pname = "nomarchy-plymouth";
@@ -53,6 +67,17 @@ let
mkdir -p "$themedir"
cp * "$themedir/"
# The keyboard glyph for the passphrase hint (#145) is plymouth's own
# literally the icon Fedora shows, since its keymap widget loads this same
# asset. Copied at build time rather than vendored: the bytes stay in
# nixpkgs' (GPL) plymouth and never enter this repo, and it cannot drift
# from the plymouth we actually run.
# chmod: store files are read-only (444) and `recolor` rewrites in place.
# unpackPhase makes the *source* writable, which is why the art below
# needs no such thing a file copied straight from the store does.
cp ${pkgs.plymouth}/share/plymouth/themes/spinner/keyboard.png "$themedir/keyboard.png"
chmod +w "$themedir/keyboard.png"
# Recolor the splash art from the palette (flat fill, alpha kept) so
# it reads on any base instead of the shipped fixed navy.
recolor() { ${magick} "$themedir/$1" -fill "#$2" -colorize 100 "$themedir/$1"; }
@@ -62,6 +87,7 @@ let
recolor entry.png ${surface} # password field box
recolor progress_box.png ${surface} # progress track
recolor progress_bar.png ${accent} # progress fill
recolor keyboard.png ${subtext} # passphrase keyboard-layout hint
# Point the .plymouth metadata into the store
sed -i "s|/usr/share/plymouth/themes/nomarchy|$themedir|g" \
@@ -73,6 +99,10 @@ let
-e 's|@BG_R@|${channel 0}|g' \
-e 's|@BG_G@|${channel 2}|g' \
-e 's|@BG_B@|${channel 4}|g' \
-e 's|@FG_R@|${fgChannel 0}|g' \
-e 's|@FG_G@|${fgChannel 2}|g' \
-e 's|@FG_B@|${fgChannel 4}|g' \
-e 's|@LAYOUT@|${kbdLayout}|g' \
"$themedir/nomarchy.script"
sed -i 's|@BG_HEX@|${base}|g' \
"$themedir/nomarchy.plymouth"

View File

@@ -3,18 +3,125 @@
Window.SetBackgroundTopColor(@BG_R@, @BG_G@, @BG_B@);
Window.SetBackgroundBottomColor(@BG_R@, @BG_G@, @BG_B@);
logo.image = Image("logo.png");
# Everything is placed by layout(), which runs on every canvas change — never
# once at parse time (#137).
#
# How the canvas works, because it is not obvious and the old code read as
# correct: the script plugin lays all heads out in ONE virtual canvas of
# max_width x max_height (the largest head), centres each display inside it
# (display->x = (max_width - width) / 2) and draws each sprite at
# (sprite.x - display.x). So Window.GetWidth() is the CANVAS width — the
# widest head, NOT head 0 — and a canvas-centred sprite lands centred on every
# head. The arithmetic below is unchanged from the original and it was always
# right. What it was not is permanent: when a head arrives or leaves the
# canvas resizes, the plugin re-centres each display, and sprites keep the
# coordinates they were given — so positions frozen at parse time end up off by
# (new_max - old_max) / 2 on EVERY head. Booting or shutting down with an
# external attached is exactly that. One monitor never resizes the canvas,
# which is why this only ever showed docked.
#
# TRAP — read before editing layout(). In plymouth script a bare assignment
# inside a function writes the GLOBAL if that name already exists globally
# (`global.foo` and a bare `foo` are the same variable; it only becomes a local
# when no global of that name exists). So a local named after the global it
# guards on silently updates that global *before* the comparison, the guard is
# then always false, and the body never runs — the whole splash renders as a
# bare background, with no error logged anywhere. Hence `cw`/`ch` below, and
# never `canvas_width = Window.GetWidth()`.
logo.original_image = Image("logo.png");
lock.image = Image("lock.png");
entry.image = Image("entry.png");
bullet.image = Image("bullet.png");
# The keyboard hint for the passphrase prompt (#145): a VT loads ONE keymap and
# knows nothing of per-device layouts, so what you type here is the console
# layout — which is worth saying out loud before three wrong tries on a disk
# nobody can read yet. Both are baked at build time by plymouth.nix.
kbd.icon_image = Image("keyboard.png");
kbd.text_image = Image.Text("@LAYOUT@", @FG_R@, @FG_G@, @FG_B@);
# Calculate scale factor to make logo ~15% of screen height
logo_scale_factor = (Window.GetHeight() * 0.15) / logo.image.GetHeight();
logo_width = logo.image.GetWidth() * logo_scale_factor;
logo_height = logo.image.GetHeight() * logo_scale_factor;
logo.image = logo.image.Scale(logo_width, logo_height);
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 = Sprite();
logo.sprite.SetOpacity (1);
entry.sprite = Sprite(entry.image);
entry.sprite.SetOpacity (0);
lock.sprite = Sprite();
lock.sprite.SetOpacity (0);
kbd.icon_sprite = Sprite();
kbd.icon_sprite.SetOpacity (0);
kbd.text_sprite = Sprite();
kbd.text_sprite.SetOpacity (0);
global.canvas_width = 0;
global.canvas_height = 0;
global.bullet_size = 7;
global.bullet_gap = 5;
fun layout ()
{
cw = Window.GetWidth();
ch = Window.GetHeight();
if (cw != global.canvas_width || ch != global.canvas_height)
{
global.canvas_width = cw;
global.canvas_height = ch;
# Logo: ~15% of canvas height, centred.
logo_scale = (ch * 0.15) / logo.original_image.GetHeight();
logo.image = logo.original_image.Scale(
logo.original_image.GetWidth() * logo_scale,
logo.original_image.GetHeight() * logo_scale);
logo.sprite.SetImage(logo.image);
logo.sprite.SetX(cw / 2 - logo.image.GetWidth() / 2);
logo.sprite.SetY(ch / 2 - logo.image.GetHeight() / 2);
# Password entry, under the logo.
entry.x = cw / 2 - entry.image.GetWidth() / 2;
entry.y = logo.sprite.GetY() + logo.image.GetHeight() + 40;
entry.sprite.SetPosition(entry.x, entry.y, 10001);
# Lock, slightly shorter than the entry, to its left.
# (source lock.png is 84x96)
lock_h = entry.image.GetHeight() * 0.8;
lock_w = 84 * (lock_h / 96);
lock.sprite.SetImage(lock.image.Scale(lock_w, lock_h));
lock.sprite.SetPosition(entry.x - lock_w - 15,
entry.y + entry.image.GetHeight() / 2 - lock_h / 2,
10001);
# Keyboard hint, centred as one icon+text group under the entry.
kbd_gap = 8;
kbd_x = cw / 2 - (kbd.icon_image.GetWidth() + kbd_gap
+ kbd.text_image.GetWidth()) / 2;
kbd_y = entry.y + entry.image.GetHeight() + 18;
kbd.icon_sprite.SetImage(kbd.icon_image);
kbd.icon_sprite.SetPosition(kbd_x, kbd_y, 10001);
kbd.text_sprite.SetImage(kbd.text_image);
kbd.text_sprite.SetPosition(
kbd_x + kbd.icon_image.GetWidth() + kbd_gap,
kbd_y + kbd.icon_image.GetHeight() / 2 - kbd.text_image.GetHeight() / 2,
10001);
# Bullets already on screen belong to the old canvas.
for (index = 0; bullet.sprites[index]; index++)
{
bullet.sprites[index].SetPosition(
entry.x + 20 + index * (global.bullet_size + global.bullet_gap),
entry.y + entry.image.GetHeight() / 2 - global.bullet_size / 2,
10002);
}
# Progress box + bar share the entry's line.
progress_box.sprite.SetPosition(
cw / 2 - progress_box.image.GetWidth() / 2,
entry.y + entry.image.GetHeight() / 2 - progress_box.image.GetHeight() / 2,
0);
progress_bar.sprite.SetPosition(
cw / 2 - progress_bar.original_image.GetWidth() / 2,
entry.y + entry.image.GetHeight() / 2
- progress_bar.original_image.GetHeight() / 2,
1);
}
}
# Use these to adjust the progress bar timing
global.fake_progress_limit = 0.7; # Target percentage for fake progress (0.0 to 1.0)
@@ -31,6 +138,10 @@ global.max_progress = 0.0; # Track the maximum progress reached to prevent back
fun refresh_callback ()
{
# Cheap: two Window.Get*() reads; layout() returns at once unless the canvas
# actually resized (a head arrived or left).
layout();
global.animation_frame++;
# Animate fake progress to limit over time with easing
@@ -91,12 +202,18 @@ fun show_password_dialog()
{
lock.sprite.SetOpacity(1);
entry.sprite.SetOpacity(1);
# The keyboard hint belongs to the prompt: it is only ever the answer to
# "what am I typing with?", so it appears and leaves with the box (#145).
kbd.icon_sprite.SetOpacity(1);
kbd.text_sprite.SetOpacity(1);
}
fun hide_password_dialog()
{
lock.sprite.SetOpacity(0);
entry.sprite.SetOpacity(0);
kbd.icon_sprite.SetOpacity(0);
kbd.text_sprite.SetOpacity(0);
for (index = 0; bullet.sprites[index]; index++)
bullet.sprites[index].SetOpacity(0);
}
@@ -121,30 +238,7 @@ fun stop_fake_progress()
#----------------------------------------- Dialogue --------------------------------
lock.image = Image("lock.png");
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;
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.SetOpacity(0);
# Bullet array
# Images and sprites are created at the top; every position lives in layout().
bullet.sprites = [];
fun display_normal_callback ()
@@ -206,21 +300,18 @@ 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);
# First placement: everything layout() reads now exists. The refresh callback
# re-runs it, so a head arriving or leaving mid-splash moves the splash with it
# instead of stranding it against a canvas that is gone.
layout();
fun progress_callback (duration, progress)
{
global.real_progress = progress;