Redesign Plymouth theme 💄

This commit is contained in:
Daniel Thwaites 2022-10-06 11:55:30 +01:00
parent f2161fc629
commit ee248692cb
No known key found for this signature in database
GPG key ID: D8AFC4BF05670F9D
2 changed files with 118 additions and 28 deletions

View file

@ -1,5 +1,6 @@
{ config, pkgs, lib, ... }:
with lib;
with config.lib.stylix.colors;
let
@ -7,12 +8,16 @@ let
themeDir="$out/share/plymouth/themes/stylix"
mkdir -p $themeDir
cp ${./theme.script} $themeDir/stylix.script
# Convert in case the input image is not PNG
${pkgs.imagemagick}/bin/convert ${config.stylix.image} $themeDir/background.png
${pkgs.imagemagick}/bin/convert \
-background transparent \
${config.stylix.targets.plymouth.logo} \
$themeDir/logo.png
cp ${config.lib.stylix.pixel "base0B"} $themeDir/progress.png
cp ${config.lib.stylix.pixel "base00"} $themeDir/progress-background.png
cp ${config.lib.stylix.pixel "base01"} $themeDir/progress-bar.png
cp ${./theme.script} $themeDir/stylix.script
echo "
[Plymouth Theme]
@ -26,10 +31,26 @@ let
'';
in {
options.stylix.targets.plymouth.enable =
config.lib.stylix.mkEnableTarget "the Plymouth boot screen" true;
options.stylix.targets.plymouth = {
enable = config.lib.stylix.mkEnableTarget "the Plymouth boot screen" true;
config.boot.plymouth = lib.mkIf config.stylix.targets.plymouth.enable {
logo = mkOption {
description = ''
Logo to be used on the boot screen.
This defaults to the NixOS logo, but you could set it to your OEM logo
if it suits the theme.
'';
type = with types; either path package;
defaultText = literalDocBook "NixOS snowflake";
default = pkgs.fetchurl {
url = "https://raw.githubusercontent.com/NixOS/nixos-artwork/master/logo/nix-snowflake.svg";
sha256 = "SCuQlSPB14GFTq4XvExJ0QEuK2VIbrd5YYKHLRG/q5I=";
};
};
};
config.boot.plymouth = mkIf config.stylix.targets.plymouth.enable {
theme = "stylix";
themePackages = [ theme ];
};

View file

@ -1,34 +1,51 @@
### BACKGROUND ###
center_x = Window.GetWidth() / 2;
center_y = Window.GetHeight() / 2;
baseline_y = (Window.GetHeight() / 3) * 2;
background.original_image = Image("background.png");
background.ratio = Math.Max(
Window.GetWidth() / background.original_image.GetWidth(),
Window.GetHeight() / background.original_image.GetHeight()
);
background.image = background.original_image.Scale(
Math.Int(background.original_image.GetWidth() * background.ratio),
Math.Int(background.original_image.GetHeight() * background.ratio)
);
background.sprite = Sprite(background.image);
background.sprite.SetPosition(
Math.Int((Window.GetWidth() - background.image.GetWidth()) / 2),
Math.Int((Window.GetHeight() - background.image.GetHeight()) / 2),
0
### LOGO ###
logo.original_image = Image("logo.png");
if (logo.original_image.GetHeight() > 200) {
logo.ratio = logo.original_image.GetWidth() / logo.original_image.GetHeight();
logo.image = logo.original_image.Scale(Math.Int(200 * logo.ratio), 200);
} else {
logo.image = logo.original_image;
}
logo.sprite = Sprite(logo.image);
logo.sprite.SetPosition(
center_x - (logo.image.GetWidth() / 2),
center_y - (logo.image.GetHeight() / 2),
1
);
### PROGRESS ###
progress_bar.width = 0;
progress_bar.height = 4;
progress_background.width = 200;
progress_background.height = 6;
progress_background.original_image = Image("progress-background.png");
progress_background.image = progress_background.original_image.Scale(progress_background.width, progress_background.height);
progress_background.sprite = Sprite(progress_background.image);
progress_background.sprite.SetPosition(
center_x - (progress_background.width / 2),
baseline_y - (progress_background.height / 2),
1
);
progress_bar.original_image = Image("progress.png");
progress_bar.width = 0;
progress_bar.max_width = progress_background.width;
progress_bar.height = progress_background.height;
progress_bar.original_image = Image("progress-bar.png");
progress_bar.sprite = Sprite();
progress_bar.sprite.SetY(Window.GetHeight() - progress_bar.height);
progress_bar.sprite.SetZ(1);
progress_bar.sprite.SetPosition(
center_x - (progress_bar.max_width / 2),
baseline_y - (progress_bar.height / 2),
1
);
fun progress_callback (duration, progress) {
progress_bar.width = Math.Int(Window.GetWidth() * progress);
progress_bar.width = Math.Int(progress_background.width * progress);
if (progress_bar.image.GetWidth() != progress_bar.width) {
progress_bar.image = progress_bar.original_image.Scale(progress_bar.width, progress_bar.height);
@ -39,9 +56,61 @@ fun progress_callback (duration, progress) {
Plymouth.SetBootProgressFunction(progress_callback);
### PASSWORD ###
prompt = null;
bullets = null;
bullet.image = Image.Text("•", 1, 1, 1);
fun password_callback (prompt_text, bullet_count) {
progress_background.sprite.SetOpacity(0);
progress_bar.sprite.SetOpacity(0);
prompt.image = Image.Text("Enter password", 1, 1, 1);
prompt.sprite = Sprite(prompt.image);
prompt.sprite.SetPosition(
center_x - (prompt.image.GetWidth() / 2),
baseline_y - prompt.image.GetHeight(),
1
);
total_width = bullet_count * bullet.image.GetWidth();
start_x = center_x - (total_width / 2);
bullets = null;
for (i = 0; i < bullet_count; i++) {
bullets[i].sprite = Sprite(bullet.image);
bullets[i].sprite.SetPosition(
start_x + (i * bullet.image.GetWidth()),
baseline_y + bullet.image.GetHeight(),
1
);
}
}
Plymouth.SetDisplayPasswordFunction(password_callback);
### NORMAL ###
fun normal_callback() {
prompt = null;
bullets = null;
progress_background.sprite.SetOpacity(1);
progress_bar.sprite.SetOpacity(1);
}
Plymouth.SetDisplayNormalFunction(normal_callback);
### QUIT ###
fun quit_callback () {
prompt = null;
bullets = null;
progress_background.sprite.SetOpacity(0);
progress_bar.sprite.SetOpacity(0);
}