mirror of
https://github.com/danth/stylix
synced 2024-11-10 06:34:15 +00:00
Add option to disable animation in Plymouth ✨
This allows the use of logos which don't have rotational symmetry.
This commit is contained in:
parent
bd1b970115
commit
76a8050ab2
2 changed files with 99 additions and 14 deletions
|
@ -4,22 +4,30 @@ with lib;
|
|||
with config.lib.stylix.colors;
|
||||
|
||||
let
|
||||
cfg = config.stylix.targets.plymouth;
|
||||
|
||||
theme = pkgs.runCommand "stylix-plymouth" { } ''
|
||||
themeDir="$out/share/plymouth/themes/stylix"
|
||||
mkdir -p $themeDir
|
||||
|
||||
# Convert in case the input image is not PNG
|
||||
# A transparent border of 42% ensures that the image is not clipped when rotated
|
||||
${pkgs.imagemagick}/bin/convert \
|
||||
-background transparent \
|
||||
-bordercolor transparent \
|
||||
-border 42% \
|
||||
${config.stylix.targets.plymouth.logo} \
|
||||
${
|
||||
# A transparent border ensures the image is not clipped when rotated
|
||||
optionalString cfg.logoAnimated "-border 42%"
|
||||
} \
|
||||
${cfg.logo} \
|
||||
$themeDir/logo.png
|
||||
|
||||
cp ${./theme.script} $themeDir/stylix.script
|
||||
${
|
||||
if config.stylix.targets.plymouth.blackBackground
|
||||
if cfg.logoAnimated
|
||||
then "cp ${./theme.script} $themeDir/stylix.script"
|
||||
else "cp ${./theme_still.script} $themeDir/stylix.script"
|
||||
}
|
||||
|
||||
${
|
||||
if cfg.blackBackground
|
||||
then ''
|
||||
substituteInPlace $themeDir/stylix.script \
|
||||
--replace "%BASE00%" "0, 0, 0" \
|
||||
|
@ -48,14 +56,9 @@ in {
|
|||
enable = config.lib.stylix.mkEnableTarget "the Plymouth boot screen" true;
|
||||
|
||||
logo = mkOption {
|
||||
description = mdDoc ''
|
||||
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.
|
||||
'';
|
||||
description = mdDoc "Logo to be used on the boot screen.";
|
||||
type = with types; either path package;
|
||||
defaultText = literalMD "NixOS snowflake";
|
||||
defaultText = literalMD "NixOS logo";
|
||||
default = pkgs.fetchurl {
|
||||
url = "https://raw.githubusercontent.com/NixOS/nixos-artwork/master/logo/nix-snowflake.svg";
|
||||
# Reduce size
|
||||
|
@ -68,6 +71,17 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
logoAnimated = mkOption {
|
||||
description = mdDoc ''
|
||||
Whether to apply a spinning animation to the logo.
|
||||
|
||||
Disabling this allows the use of logos which don't have rotational
|
||||
symmetry.
|
||||
'';
|
||||
type = types.bool;
|
||||
default = true;
|
||||
};
|
||||
|
||||
blackBackground = mkOption {
|
||||
description = mdDoc ''
|
||||
Whether to use a black background rather than a theme colour.
|
||||
|
@ -81,7 +95,7 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
config.boot.plymouth = mkIf config.stylix.targets.plymouth.enable {
|
||||
config.boot.plymouth = mkIf cfg.enable {
|
||||
theme = "stylix";
|
||||
themePackages = [ theme ];
|
||||
};
|
||||
|
|
71
modules/plymouth/theme_still.script
Normal file
71
modules/plymouth/theme_still.script
Normal file
|
@ -0,0 +1,71 @@
|
|||
center_x = Window.GetWidth() / 2;
|
||||
center_y = Window.GetHeight() / 2;
|
||||
baseline_y = Window.GetHeight() * 0.9;
|
||||
|
||||
|
||||
### BACKGROUND ###
|
||||
|
||||
Window.SetBackgroundTopColor(%BASE00%);
|
||||
Window.SetBackgroundBottomColor(%BASE00%);
|
||||
|
||||
|
||||
### LOGO ###
|
||||
|
||||
logo.image = Image("logo.png");
|
||||
logo.sprite = Sprite(logo.image);
|
||||
logo.sprite.SetPosition(
|
||||
center_x - (logo.image.GetWidth() / 2),
|
||||
center_y - (logo.image.GetHeight() / 2),
|
||||
1
|
||||
);
|
||||
|
||||
### PASSWORD ###
|
||||
|
||||
prompt = null;
|
||||
bullets = null;
|
||||
bullet.image = Image.Text("•", %BASE05%);
|
||||
|
||||
fun password_callback (prompt_text, bullet_count) {
|
||||
prompt.image = Image.Text("Enter password", %BASE05%);
|
||||
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;
|
||||
}
|
||||
|
||||
Plymouth.SetDisplayNormalFunction(normal_callback);
|
||||
|
||||
|
||||
### QUIT ###
|
||||
|
||||
fun quit_callback() {
|
||||
prompt = null;
|
||||
bullets = null;
|
||||
}
|
||||
|
||||
Plymouth.SetQuitFunction(quit_callback);
|
Loading…
Reference in a new issue