diff --git a/apps/hyprlock/default.nix b/apps/hyprlock/default.nix index ecefc42..1b5e949 100644 --- a/apps/hyprlock/default.nix +++ b/apps/hyprlock/default.nix @@ -6,6 +6,9 @@ cacheWallpaper = "${config.home.homeDirectory}/.cache/current_wallpaper"; clockFont = "JetBrains Mono"; in { + imports = [ + ./scripts/typewriter.nix + ]; programs.hyprlock = { enable = true; extraConfig = '' @@ -26,17 +29,6 @@ in { vibrancy = 0.2 } - # Typewriter greeting (above clock) - label { - monitor = - text = Hello World! - color = $on_surface_variant - font_size = 24 - font_family = ${clockFont} Bold - position = 0, 200 - halign = center - valign = center - } # Hours (top) label { @@ -111,6 +103,19 @@ in { fail_timeout = 2000 fail_transition = 300 } + + # Typewriter greeting (above clock) + label { + monitor = + text = cmd[update:50] hakase-hyprlock-typewriter 'They do be like that, huh?' + color = $on_surface_variant + font_size = 24 + font_family = ${clockFont} Bold + position = 0, 200 + halign = center + valign = center + } + ''; }; } diff --git a/apps/hyprlock/scripts/random-text.nix b/apps/hyprlock/scripts/random-text.nix new file mode 100644 index 0000000..1f558d7 --- /dev/null +++ b/apps/hyprlock/scripts/random-text.nix @@ -0,0 +1,8 @@ +{pkgs, ...}: let + hakase-hyprlock-text-generator = pkgs.writeShellScriptBin "hakase-hyprlock-text-generator" '' + + ''; +in { + home.packages = [ + ]; +} diff --git a/apps/hyprlock/scripts/typewriter.nix b/apps/hyprlock/scripts/typewriter.nix index 6885199..ec4ce6f 100644 --- a/apps/hyprlock/scripts/typewriter.nix +++ b/apps/hyprlock/scripts/typewriter.nix @@ -1,3 +1,60 @@ {pkgs, ...}: let + hakase-hyprlock-typewriter = pkgs.writeShellScriptBin "hakase-hyprlock-typewriter" '' + text="$1" + if [[ -z "$text" ]]; then + echo "Usage: $(basename "$0") [text]" + exit 1 + fi + state_file="''${XDG_RUNTIME_DIR:-/tmp}/typewriter_pos" + blink_file="''${XDG_RUNTIME_DIR:-/tmp}/typewriter_blink" + pid_file="''${XDG_RUNTIME_DIR:-/tmp}/typewriter_pid" + + current_pid=$(pgrep -x hyprlock | head -1) + + if [[ -f $pid_file ]]; then + old_pid=$(cat $pid_file) + if [[ "''${old_pid}" != "''${current_pid}" ]]; then + rm -f "$state_file" "$blink_file" + fi + fi + echo "$current_pid" >"$pid_file" + + if [[ ! -f $state_file ]]; then + echo 0 >"$state_file" + fi + + if [[ ! -f $blink_file ]]; then + echo 0 >"$blink_file" + fi + + len=''${#text} + letter=$(cat "$state_file") + blink=$(cat "$blink_file") + + if [[ $letter -lt $len ]]; then + letter=$((letter + 1)) + echo "$letter" >"$state_file" + echo "''${text:0:$letter}_" + else + # Toggle every 4 calls (at 200ms update = ~800ms blink) + if (((blink / 20) % 2 == 0)); then + echo "''${text}_" + else + echo "''${text}_" + fi + fi + + blink=$((blink + 1)) + echo "$blink" >"$blink_file" + ''; + hakase-test-hyprlock-typewriter = pkgs.writeShellScriptBin "hakase-test-hyprlock-typewriter" '' + for i in {1..10}; do + hakase-hyprlock-typewriter + done + ''; in { + home.packages = [ + hakase-hyprlock-typewriter + hakase-test-hyprlock-typewriter + ]; } diff --git a/test/hakase-animation-typewriter.sh b/test/hakase-animation-typewriter.sh new file mode 100755 index 0000000..c318295 --- /dev/null +++ b/test/hakase-animation-typewriter.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# flow +# REPEATS via cmd[]. DESIGNED FOR HYPRLOCK SCRIPTING. +# check if file exists. If not, create. +# read the files +# assign variables to read files +# if letter is less than the word letters count, increment by 1, append the letter, and echo the result. +# other than that, proceed to blinking stage. + +text="Gamer" +state_file="${XDG_RUNTIME_DIR:-/tmp}/typewriter_pos" +blink_file="${XDG_RUNTIME_DIR:-/tmp}/typewriter_blink" + +if [[ ! -f $state_file ]]; then + echo 0 >"$state_file" +fi + +if [[ ! -f $blink_file ]]; then + echo 0 >"$blink_file" +fi + +len=${#text} +letter=$(cat "$state_file") +blink=$(cat "$blink_file") + +if [[ $letter -lt $len ]]; then + letter=$((letter + 1)) + echo "$letter" >"$state_file" + echo "${text:0:$letter}_" + sleep 0.2 +else + if ((blink % 2 == 0)); then + echo "${text}_" + else + echo "${text} " + fi + sleep 1.1 +fi + +blink=$((blink + 1)) +echo "$blink" >"$blink_file" diff --git a/test/hakase-hyprlock-text-generator.sh b/test/hakase-hyprlock-text-generator.sh new file mode 100755 index 0000000..e69de29