fix: stuff
This commit is contained in:
@@ -1,143 +0,0 @@
|
||||
# In home.nix or a separate module
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
# Define the script package
|
||||
hakase-cmd-screensaver = pkgs.writeShellScriptBin "hakase-cmd-screensaver" ''
|
||||
export PATH="${lib.makeBinPath [
|
||||
pkgs.coreutils
|
||||
pkgs.procps # pkill, pgrep
|
||||
pkgs.jq
|
||||
pkgs.hyprland # hyprctl
|
||||
pkgs.terminaltexteffects # tte
|
||||
]}:$PATH"
|
||||
|
||||
screensaver_in_focus() {
|
||||
hyprctl activewindow -j | jq -e '.class == "org.hakase.screensaver"' >/dev/null 2>&1
|
||||
}
|
||||
|
||||
exit_screensaver() {
|
||||
hyprctl keyword cursor:invisible false
|
||||
pkill -x tte 2>/dev/null
|
||||
pkill -f org.hakase.screensaver 2>/dev/null
|
||||
exit 0
|
||||
}
|
||||
|
||||
trap exit_screensaver SIGINT SIGTERM SIGHUP SIGQUIT
|
||||
|
||||
printf '\e[?1000h\e[?1003h'
|
||||
while read -rsn1 -t 0.1; do :; done
|
||||
|
||||
printf '\033]11;rgb:00/00/00\007' # Black background
|
||||
hyprctl keyword cursor:invisible true &>/dev/null
|
||||
|
||||
# Note: ''${variable} is how we escape bash variables in Nix
|
||||
tty=$(tty 2>/dev/null)
|
||||
|
||||
while true; do
|
||||
tte -i "$HOME/.config/hakase/branding/screensaver.txt" \
|
||||
--frame-rate 120 \
|
||||
--canvas-width 0 \
|
||||
--canvas-height 0 \
|
||||
--reuse-canvas \
|
||||
--anchor-canvas c \
|
||||
--anchor-text c \
|
||||
--random-effect \
|
||||
--exclude-effects dev_worm \
|
||||
--no-eol \
|
||||
--no-restore-cursor &
|
||||
|
||||
while pgrep -t "''${tty#/dev/}" -x tte >/dev/null; do
|
||||
if read -rsn1 -t 1 || ! screensaver_in_focus; then
|
||||
exit_screensaver
|
||||
fi
|
||||
done
|
||||
done
|
||||
'';
|
||||
hakase-launch-screensaver = pkgs.writeShellScriptBin "hakase-launch-screensaver" ''
|
||||
# 1. Path Setup
|
||||
# We include necessary utils.
|
||||
# NOTE: We assume 'hakase-cmd-screensaver', 'walker', and your terminals
|
||||
# are already installed in your system/home profile.
|
||||
export PATH="${lib.makeBinPath [
|
||||
pkgs.coreutils
|
||||
pkgs.procps # pgrep
|
||||
pkgs.jq
|
||||
pkgs.hyprland # hyprctl
|
||||
pkgs.libnotify # notify-send
|
||||
pkgs.xdg-terminal-exec
|
||||
pkgs.terminaltexteffects # tte
|
||||
]}:$PATH"
|
||||
|
||||
if ! command -v tte &>/dev/null; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pgrep -f org.hakase.screensaver && exit 0
|
||||
|
||||
if [[ -f "$HOME/.local/state/hakase/toggles/screensaver-off" ]] && [[ "$1" != "force" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if command -v walker &>/dev/null; then
|
||||
walker -q
|
||||
fi
|
||||
|
||||
focused=$(hyprctl monitors -j | jq -r '.[] | select(.focused == true).name')
|
||||
terminal=$(xdg-terminal-exec --print-id)
|
||||
|
||||
# 4. Launch loop
|
||||
for m in $(hyprctl monitors -j | jq -r '.[] | .name'); do
|
||||
hyprctl dispatch focusmonitor "$m"
|
||||
|
||||
case "$terminal" in
|
||||
*Alacritty*)
|
||||
hyprctl dispatch exec -- \
|
||||
alacritty --class=org.hakase.screensaver \
|
||||
--config-file "$HOME/.config/alacritty/screensaver.toml" \
|
||||
-e hakase-cmd-screensaver
|
||||
;;
|
||||
*ghostty*)
|
||||
hyprctl dispatch exec -- \
|
||||
ghostty --class=org.hakase.screensaver \
|
||||
--config-file="$HOME/.config/ghostty/screensaver" \
|
||||
--font-size=18 \
|
||||
-e hakase-cmd-screensaver
|
||||
;;
|
||||
*kitty*)
|
||||
hyprctl dispatch exec -- \
|
||||
kitty --class=org.hakase.screensaver \
|
||||
--override font_size=18 \
|
||||
--override window_padding_width=0 \
|
||||
-e hakase-cmd-screensaver
|
||||
;;
|
||||
*)
|
||||
notify-send "✋ Screensaver only runs in Alacritty, Ghostty, or Kitty"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# 5. Restore focus
|
||||
hyprctl dispatch focusmonitor "$focused"
|
||||
'';
|
||||
hakase-toggle-screensaver = pkgs.writeShellScriptBin "hakase-toggle-screensaver" ''
|
||||
STATE_FILE="$HOME/.local/state/omarchy/toggles/screensaver-off"
|
||||
|
||||
if [[ -f "$STATE_FILE" ]]; then
|
||||
rm -f "$STATE_FILE"
|
||||
${pkgs.libnotify}/bin/notify-send " Screensaver enabled"
|
||||
else
|
||||
mkdir -p "$(dirname "$STATE_FILE")"
|
||||
touch "$STATE_FILE"
|
||||
${pkgs.libnotify}/bin/notify-send " Screensaver disabled"
|
||||
fi
|
||||
'';
|
||||
in {
|
||||
environment.systemPackages = with pkgs; [
|
||||
hakase-launch-screensaver
|
||||
hakase-cmd-screensaver
|
||||
hakase-toggle-screensaver
|
||||
];
|
||||
}
|
||||
@@ -1,169 +0,0 @@
|
||||
{pkgs, ...}: let
|
||||
# 1. The Brain: Logic to find a window or launch a new one
|
||||
hakase-launch-or-focus = pkgs.writeShellScriptBin "hakase-launch-or-focus" ''
|
||||
if (($# == 0)); then
|
||||
echo "Usage: hakase-launch-or-focus [window-pattern] [launch-command]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
WINDOW_PATTERN="$1"
|
||||
# Escaped Nix interpolation for shell default value logic
|
||||
LAUNCH_COMMAND="''${2:-"uwsm-app -- $WINDOW_PATTERN"}"
|
||||
|
||||
# Locate window address via hyprctl and jq
|
||||
WINDOW_ADDRESS=$(${pkgs.hyprland}/bin/hyprctl clients -j | ${pkgs.jq}/bin/jq -r --arg p "$WINDOW_PATTERN" \
|
||||
'.[] | select((.class | test("\\b" + $p + "\\b"; "i")) or (.title | test("\\b" + $p + "\\b"; "i"))) | .address' | head -n1)
|
||||
|
||||
if [[ -n $WINDOW_ADDRESS ]]; then
|
||||
# If found, focus the existing window
|
||||
${pkgs.hyprland}/bin/hyprctl dispatch focuswindow "address:$WINDOW_ADDRESS"
|
||||
else
|
||||
# If not found, execute the launch command
|
||||
eval exec setsid $LAUNCH_COMMAND
|
||||
fi
|
||||
'';
|
||||
|
||||
hakase-launch-tui = pkgs.writeShellScriptBin "hakase-launch-tui" ''
|
||||
APP_NAME=$(basename "$1")
|
||||
# Using org.hakase prefix so the focus script can find it via class name
|
||||
exec setsid uwsm-app -- xdg-terminal-exec --app-id=org.hakase."$APP_NAME" -e "$@"
|
||||
'';
|
||||
|
||||
hakase-focus-wrapper = pkgs.writeShellScriptBin "hakase-focus-wrapper" ''
|
||||
APP_NAME=$(basename "$1")
|
||||
WINDOW_PATTERN="org.hakase.$APP_NAME"
|
||||
LAUNCH_CMD="hakase-launch-tui $*"
|
||||
|
||||
exec hakase-launch-or-focus "$WINDOW_PATTERN" "$LAUNCH_CMD"
|
||||
'';
|
||||
|
||||
hakase-launch-wifi = pkgs.writeShellScriptBin "hakase-launch-wifi" ''
|
||||
# Unblock the WiFi radio (requires appropriate user groups/permissions)
|
||||
# ${pkgs.util-linux}/bin/rfkill unblock wifi
|
||||
|
||||
# Use the focus wrapper to launch or switch to Impala
|
||||
exec hakase-focus-wrapper impala
|
||||
'';
|
||||
|
||||
hakase-launch-bluetooth =
|
||||
pkgs.writeShellScriptBin "hakase-launch-bluetooth"
|
||||
''
|
||||
# ${pkgs.util-linux}/bin/rfkill unblock wifi
|
||||
exec hakase-focus-wrapper bluetui
|
||||
|
||||
'';
|
||||
hakase-launch-popup = pkgs.writeShellScriptBin "hakase-launch-popup" ''
|
||||
if (($# < 3)); then
|
||||
echo "Usage: hakase-launch-popup [width] [height] [command...]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- ARGS & CONFIG ---
|
||||
WIN_WIDTH="$1"
|
||||
WIN_HEIGHT="$2"
|
||||
shift 2
|
||||
|
||||
MARGIN=10
|
||||
BAR_HEIGHT=40
|
||||
# ---------------------
|
||||
|
||||
CMD_NAME=$(basename "$1")
|
||||
TARGET_CLASS="org.hakase.popup.$CMD_NAME"
|
||||
|
||||
# 1. SINGLETON LOGIC: Check for ANY existing hakase popup
|
||||
# We look for any client with a class starting with "org.hakase.popup."
|
||||
EXISTING_JSON=$(${pkgs.hyprland}/bin/hyprctl clients -j | ${pkgs.jq}/bin/jq -r '.[] | select(.class | startswith("org.hakase.popup."))')
|
||||
|
||||
if [[ -n "$EXISTING_JSON" ]]; then
|
||||
OLD_ADDR=$(echo "$EXISTING_JSON" | ${pkgs.jq}/bin/jq -r '.address')
|
||||
OLD_CLASS=$(echo "$EXISTING_JSON" | ${pkgs.jq}/bin/jq -r '.class')
|
||||
|
||||
# Close the existing popup
|
||||
${pkgs.hyprland}/bin/hyprctl dispatch closewindow "address:$OLD_ADDR"
|
||||
|
||||
# If the existing popup was the SAME one we are trying to launch, we are done (Toggle Off behavior)
|
||||
if [[ "$OLD_CLASS" == "$TARGET_CLASS" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# If it was a different popup, wait a tiny bit for Hyprland to process the close
|
||||
# This prevents the new window from "merging" with the closing animation of the old one
|
||||
sleep 0.15
|
||||
fi
|
||||
|
||||
# 2. Calculate Geometry (Standard logic)
|
||||
MONITOR_INFO=$(${pkgs.hyprland}/bin/hyprctl monitors -j | ${pkgs.jq}/bin/jq '.[] | select(.focused == true)')
|
||||
MON_X=$(echo "$MONITOR_INFO" | ${pkgs.jq}/bin/jq '.x')
|
||||
MON_Y=$(echo "$MONITOR_INFO" | ${pkgs.jq}/bin/jq '.y')
|
||||
MON_WIDTH=$(echo "$MONITOR_INFO" | ${pkgs.jq}/bin/jq '.width')
|
||||
|
||||
TARGET_X=$((MON_X + MON_WIDTH - WIN_WIDTH - MARGIN))
|
||||
TARGET_Y=$((MON_Y + BAR_HEIGHT + MARGIN))
|
||||
|
||||
# 3. Launch with Rules
|
||||
RULE="[float;pin;size $WIN_WIDTH $WIN_HEIGHT;move $TARGET_X $TARGET_Y]"
|
||||
${pkgs.hyprland}/bin/hyprctl dispatch exec "$RULE xdg-terminal-exec --app-id=$TARGET_CLASS -e $@"
|
||||
|
||||
# 4. Background Listener (Close on Blur)
|
||||
(
|
||||
TIMEOUT=0
|
||||
WINDOW_ADDR=""
|
||||
while [[ -z "$WINDOW_ADDR" && $TIMEOUT -lt 20 ]]; do
|
||||
sleep 0.1
|
||||
WINDOW_ADDR=$(${pkgs.hyprland}/bin/hyprctl clients -j | ${pkgs.jq}/bin/jq -r --arg c "$TARGET_CLASS" '.[] | select(.class == $c) | .address')
|
||||
((TIMEOUT++))
|
||||
done
|
||||
|
||||
if [[ -n "$WINDOW_ADDR" ]]; then
|
||||
${pkgs.socat}/bin/socat -U - UNIX-CONNECT:"$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" | while read -r line; do
|
||||
if [[ "$line" == "activewindow>>"* ]]; then
|
||||
NEW_FOCUS="0x$(echo "$line" | cut -d '>' -f3 | cut -d ',' -f1)"
|
||||
# If focus is lost to another window, close this popup
|
||||
if [[ "$WINDOW_ADDR" != "$NEW_FOCUS" ]]; then
|
||||
${pkgs.hyprland}/bin/hyprctl dispatch closewindow "address:$WINDOW_ADDR"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
) &
|
||||
|
||||
exit 0
|
||||
'';
|
||||
|
||||
# 1. WiFi (Impala) - Requires a larger view
|
||||
hakase-popup-wifi = pkgs.writeShellScriptBin "hakase-popup-wifi" ''
|
||||
exec hakase-launch-popup 800 500 impala
|
||||
'';
|
||||
|
||||
# 2. Bluetooth (Bluetui) - Fits your specific test size
|
||||
hakase-popup-bluetooth = pkgs.writeShellScriptBin "hakase-popup-bluetooth" ''
|
||||
exec hakase-launch-popup 600 500 bluetui
|
||||
'';
|
||||
|
||||
# 3. Volume (Wiremix) - Can be smaller
|
||||
hakase-popup-volume = pkgs.writeShellScriptBin "hakase-popup-volume" ''
|
||||
exec hakase-launch-popup 800 300 wiremix
|
||||
'';
|
||||
in {
|
||||
home.packages = [
|
||||
pkgs.jq
|
||||
pkgs.socat # Required for the socket listener
|
||||
pkgs.util-linux
|
||||
pkgs.bluetui
|
||||
pkgs.impala
|
||||
pkgs.wiremix
|
||||
pkgs.pamixer
|
||||
|
||||
hakase-launch-popup
|
||||
hakase-popup-wifi
|
||||
hakase-popup-bluetooth
|
||||
hakase-popup-volume
|
||||
|
||||
hakase-launch-or-focus
|
||||
hakase-launch-tui
|
||||
hakase-focus-wrapper
|
||||
hakase-launch-wifi
|
||||
hakase-launch-bluetooth
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user