From a86294645b046f708448c87aa8cf4e226767edd8 Mon Sep 17 00:00:00 2001 From: atagen Date: Wed, 7 May 2025 16:31:37 +1000 Subject: [PATCH] init s --- package.nix | 63 ++++++++++++++++++++++++++++++++++++ template.plymouth | 8 +++++ template.script | 82 +++++++++++++++++++++++++++++++++++++++++++++++ themes.nix | 6 ++++ 4 files changed, 159 insertions(+) create mode 100644 package.nix create mode 100644 template.plymouth create mode 100644 template.script create mode 100644 themes.nix diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..ff97b9e --- /dev/null +++ b/package.nix @@ -0,0 +1,63 @@ +{ + stdenvNoCC, + fetchFromGitea, + lib, + selectedTheme ? "starship", + screenNumber ? 0, +}: +let + themeDetails = import ./themes.nix; + validThemes = builtins.attrNames themeDetails; + themeName = lib.checkListOfEnum "plymouth theme" validThemes selectedTheme; + theme = themeDetails.${themeName}; +in +stdenvNoCC.mkDerivation { + pname = "hudcore-plymouth"; + version = themeName; + + src = fetchFromGitea { + domain = "git.atagen.co"; + owner = "atagen"; + repo = "hudcore-plymouth"; + rev = themeName; + hash = theme.hash; + }; + + installPhase = + let + templateScript = ./template.script; + templatePlymouth = ./template.plymouth; + themeScript = "${themeName}.script"; + themePlymouth = "${themeName}.plymouth"; + in + '' + cp ${templateScript} ${themeScript} + sed -i 's/%SCREEN_NUMBER%/${screenNumber}/g' ${themeScript} + sed -i 's/%FRAME_COUNT%/${theme.frameCount}/g' ${themeScript} + + cp ${templatePlymouth} ${themePlymouth} + sed -i 's/%NAME%/${themeName}/g' ${themePlymouth} + + mkdir -p $out/share/plymouth/themes/${themeName} + cp -r * $out/share/plymouth/themes/${themeName} + ''; + + passthru.updateScript = { }; + + meta = { + description = "Fantasy HUD Plymouth themes"; + longDescription = '' + A set of mostly HUD-inspired plymouth boot screens. + Default is `starship`. + Override `selectedTheme` in order to pick a different one. + Currently available: + `nixdrop` + `starship` + `containment` + ''; + homepage = "https://git.atagen.co/atagen/hudcore-plymouth"; + license = lib.licenses.gpl3; + platforms = lib.platforms.linux; + maintainers = [ lib.maintainers.atagen ]; + }; +} diff --git a/template.plymouth b/template.plymouth new file mode 100644 index 0000000..1605e84 --- /dev/null +++ b/template.plymouth @@ -0,0 +1,8 @@ +[Plymouth Theme] +Name=%NAME% +Description=A theme from the atagen/hudcore-plymouth pack. +ModuleName=script + +[script] +ImageDir=/usr/share/plymouth/themes/%NAME% +ScriptFile=/usr/share/plymouth/themes/%NAME%/%NAME%.script diff --git a/template.script b/template.script new file mode 100644 index 0000000..e100cd0 --- /dev/null +++ b/template.script @@ -0,0 +1,82 @@ +// based on work by Aditya Shakya (adi1090x@gmail.com) + +screen.w = Window.GetWidth(%SCREEN_NUMBER%); +screen.h = Window.GetHeight(%SCREEN_NUMBER%); +screen.hw = screen.w / 2; +screen.hh = screen.h / 2; +cur_frame = 0; + +for (i = 0; i < max_frames; i++) { + images.img[i] = Image(i + ".png"); +} +images.w = images[0].GetWidth() +images.h = images[0].GetHeight() +images.hw = images.w / 2 +images.hh = images.h / 2 + +draw = Sprite(); +draw.SetX(Window.GetX() + (screen.hw - images.hw)); +draw.SetY(Window.GetY() + (screen.hh - images.hh)); + +fun refresh () { + image.SetImage(images.img[cur_frame]); + cur_frame = (cur_frame + 1) % %FRAME_COUNT%; +} +Plymouth.SetRefreshFunction(refresh); + +fun DisplayQuestionCallback(prompt, entry) { + question = null; + answer = null; + + if (entry == "") + entry = ""; + + question.image = Image.Text(prompt, 1, 1, 1); + question.sprite = Sprite(question.image); + question.sprite.SetX(screen.half.w - question.image.GetWidth() / 2); + question.sprite.SetY(screen.h - 4 * question.image.GetHeight()); + + answer.image = Image.Text(entry, 1, 1, 1); + answer.sprite = Sprite(answer.image); + answer.sprite.SetX(screen.half.w - answer.image.GetWidth() / 2); + answer.sprite.SetY(screen.h - 2 * answer.image.GetHeight()); +} +Plymouth.SetDisplayQuestionFunction(DisplayQuestionCallback); + + +fun DisplayPasswordCallback(nil, bulletCount) { + state.status = "pause"; + totalWidth = bulletCount * bullet.image.GetWidth(); + startPos = screen.half.w - totalWidth / 2; + + prompt.image = Image.Text("Enter Password", 1, 1, 1); + prompt.sprite = Sprite(prompt.image); + prompt.sprite.SetX(screen.half.w - prompt.image.GetWidth() / 2); + prompt.sprite.SetY(screen.h - 4 * prompt.image.GetHeight()); + + // Clear all bullets (user might hit backspace) + bullets = null; + for (i = 0; i < bulletCount; i++) { + bullets[i].sprite = Sprite(bullet.image); + bullets[i].sprite.SetX(startPos + i * bullet.image.GetWidth()); + bullets[i].sprite.SetY(screen.h - 2 * bullet.image.GetHeight()); + } +} +Plymouth.SetDisplayPasswordFunction(DisplayPasswordCallback); + +fun DisplayNormalCallback() { + state.status = "play"; + bullets = null; + prompt = null; + message = null; + question = null; + answer = null; +} +Plymouth.SetDisplayNormalFunction(DisplayNormalCallback); + +fun MessageCallback(text) { + message.image = Image.Text(text, 1, 1, 1); + message.sprite = Sprite(message.image); + message.sprite.SetPosition(screen.half.w - message.image.GetWidth() / 2, message.image.GetHeight()); +} +Plymouth.SetMessageFunction(MessageCallback); diff --git a/themes.nix b/themes.nix new file mode 100644 index 0000000..a19e374 --- /dev/null +++ b/themes.nix @@ -0,0 +1,6 @@ +{ + starship = { + frameCount = 450; + hash = "0"; + }; +}