Revert "this one works"

This reverts commit 8ac3c21228.
This commit is contained in:
kenji
2025-12-26 09:01:49 -06:00
parent 8ac3c21228
commit a9f2e86491
4 changed files with 50 additions and 83 deletions
-1
View File
@@ -12,7 +12,6 @@
enableFishIntegration = true; enableFishIntegration = true;
settings = { settings = {
confirm-close-surface = false;
window-padding-x = 15; window-padding-x = 15;
window-padding-y = 15; window-padding-y = 15;
window-padding-balance = true; window-padding-balance = true;
+3
View File
@@ -5,7 +5,10 @@
# "center, class:^(org\.hakase\..*)$" # "center, class:^(org\.hakase\..*)$"
# "size 80% 70%, class:^(org\.hakase\..*)$" # Example using percentages # "size 80% 70%, class:^(org\.hakase\..*)$" # Example using percentages
# --- POPUP RULES (Wifi, BT, Audio) --- # --- POPUP RULES (Wifi, BT, Audio) ---
"size 602 478, class:^(org\.hakase\.popup\..*)$"
"move 1312 32, class:^(org\.hakase\.popup\..*)$"
"float, class:^(org\.hakase\.popup\..*)$" "float, class:^(org\.hakase\.popup\..*)$"
"pin, class:^(org\.hakase\.popup\..*)$"
"animation slide right, class:^(org\.hakase\.popup\..*)$" "animation slide right, class:^(org\.hakase\.popup\..*)$"
"dimaround, class:^(org\.hakase\.popup\..*)$" "dimaround, class:^(org\.hakase\.popup\..*)$"
]; ];
+3 -3
View File
@@ -95,7 +95,7 @@
tooltip-format-disconnected = "Disconnected"; tooltip-format-disconnected = "Disconnected";
interval = 3; interval = 3;
spacing = 1; spacing = 1;
on-click = "hakase-popup-wifi"; on-click = "hakase-launch-wifi";
}; };
"battery" = { "battery" = {
@@ -124,12 +124,12 @@
format-connected = "󰂱"; format-connected = "󰂱";
format-no-controller = ""; format-no-controller = "";
tooltip-format = "Devices connected: {num_connections}"; tooltip-format = "Devices connected: {num_connections}";
on-click = "hakase-popup-bluetooth"; on-click = "hakase-launch-bluetooth";
}; };
"pulseaudio" = { "pulseaudio" = {
format = "{icon}"; format = "{icon}";
on-click = "hakase-popup-volume"; on-click = "hakase-focus-wrapper wiremix";
on-click-right = "pamixer -t"; on-click-right = "pamixer -t";
tooltip-format = "Playing at {volume}%"; tooltip-format = "Playing at {volume}%";
scroll-step = 5; scroll-step = 5;
+44 -79
View File
@@ -53,105 +53,71 @@
''; '';
hakase-launch-popup = pkgs.writeShellScriptBin "hakase-launch-popup" '' hakase-launch-popup = pkgs.writeShellScriptBin "hakase-launch-popup" ''
if (($# < 3)); then if (($# == 0)); then
echo "Usage: hakase-launch-popup [width] [height] [command...]" echo "Usage: hakase-launch-popup [command]"
exit 1 exit 1
fi fi
# --- ARGS & CONFIG ---
WIN_WIDTH="$1"
WIN_HEIGHT="$2"
shift 2
MARGIN=10
BAR_HEIGHT=40
# ---------------------
CMD_NAME=$(basename "$1") CMD_NAME=$(basename "$1")
TARGET_CLASS="org.hakase.popup.$CMD_NAME" # Define a specific class for popups so Hyprland rules can catch them
CLASS_NAME="org.hakase.popup.$CMD_NAME"
# 1. SINGLETON: Close any existing hakase popups first # Check if already running; if so, toggle/close it
# This ensures only one popup is ever open at a time. EXISTING_ADDR=$(${pkgs.hyprland}/bin/hyprctl clients -j | ${pkgs.jq}/bin/jq -r --arg c "$CLASS_NAME" '.[] | select(.class == $c) | .address')
EXISTING_JSON=$(${pkgs.hyprland}/bin/hyprctl clients -j | ${pkgs.jq}/bin/jq -r '.[] | select(.class | startswith("org.hakase.popup."))')
if [[ -n "$EXISTING_JSON" ]]; then if [[ -n "$EXISTING_ADDR" ]]; then
OLD_ADDR=$(echo "$EXISTING_JSON" | ${pkgs.jq}/bin/jq -r '.address') ${pkgs.hyprland}/bin/hyprctl dispatch closewindow "address:$EXISTING_ADDR"
OLD_CLASS=$(echo "$EXISTING_JSON" | ${pkgs.jq}/bin/jq -r '.class') exit 0
${pkgs.hyprland}/bin/hyprctl dispatch closewindow "address:$OLD_ADDR"
# Toggle behavior: If we clicked the same button again, just close and exit.
if [[ "$OLD_CLASS" == "$TARGET_CLASS" ]]; then
exit 0
fi
sleep 0.15
fi fi
# 2. POSITIONING # Launch the application
MONITOR_INFO=$(${pkgs.hyprland}/bin/hyprctl monitors -j | ${pkgs.jq}/bin/jq '.[] | select(.focused == true)') # We use setsid to detach, but keep the PID to kill it later
MON_X=$(echo "$MONITOR_INFO" | ${pkgs.jq}/bin/jq '.x') xdg-terminal-exec --app-id="$CLASS_NAME" -e "$@" &
MON_Y=$(echo "$MONITOR_INFO" | ${pkgs.jq}/bin/jq '.y') APP_PID=$!
MON_WIDTH=$(echo "$MONITOR_INFO" | ${pkgs.jq}/bin/jq '.width')
# Defaults to 0 if jq fails # Wait for the window to appear and grab its address
MON_X=''${MON_X:-0} TIMEOUT=0
MON_Y=''${MON_Y:-0} WINDOW_ADDR=""
MON_WIDTH=''${MON_WIDTH:-1920} 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 "$CLASS_NAME" '.[] | select(.class == $c) | .address')
((TIMEOUT++))
done
TARGET_X=$((MON_X + MON_WIDTH - WIN_WIDTH - MARGIN)) if [[ -z "$WINDOW_ADDR" ]]; then
TARGET_Y=$((MON_Y + BAR_HEIGHT + MARGIN)) echo "Failed to find window for $CLASS_NAME"
exit 1
fi
# 3. LAUNCH # Monitor Hyprland socket for focus changes
RULE="[float;pin;size $WIN_WIDTH $WIN_HEIGHT;move $TARGET_X $TARGET_Y]" # We use socat to stream events. If activewindow changes to something else, kill the app.
${pkgs.hyprland}/bin/hyprctl dispatch exec "$RULE xdg-terminal-exec --app-id=$TARGET_CLASS -e $@" ${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
# Extract the new focused address
NEW_FOCUS="0x$(echo "$line" | cut -d '>' -f3 | cut -d ',' -f1)"
# 4. BACKGROUND: Close on "Click Outside" (Blur) # If the new focus is NOT our popup window, kill the popup
( if [[ "$WINDOW_ADDR" != "$NEW_FOCUS" ]]; then
# Wait for the window to actually appear kill "$APP_PID" 2>/dev/null
TIMEOUT=0 # Also force close in Hyprland to be sure
WINDOW_ADDR="" ${pkgs.hyprland}/bin/hyprctl dispatch closewindow "address:$WINDOW_ADDR"
while [[ -z "$WINDOW_ADDR" && $TIMEOUT -lt 20 ]]; do break
sleep 0.1 fi
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
# Listen to socket for focus changes
${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
# Extract address from event: activewindow>>1234abcd,title
NEW_FOCUS=$(echo "$line" | cut -d '>' -f3 | cut -d ',' -f1)
# Normalize to 0x format to match hyprctl
if [[ "$NEW_FOCUS" != 0x* ]]; then
NEW_FOCUS="0x$NEW_FOCUS"
fi
# If the focused window is NOT our popup, kill the popup
if [[ "$WINDOW_ADDR" != "$NEW_FOCUS" ]]; then
${pkgs.hyprland}/bin/hyprctl dispatch closewindow "address:$WINDOW_ADDR"
break
fi
fi
done
fi fi
) & done
'';
exit 0 # 2. Specific Launchers using the Popup logic
''; # 1. WiFi (Impala) - Requires a larger view
hakase-popup-wifi = pkgs.writeShellScriptBin "hakase-popup-wifi" '' hakase-popup-wifi = pkgs.writeShellScriptBin "hakase-popup-wifi" ''
exec hakase-launch-popup 800 500 impala exec hakase-launch-popup impala
''; '';
# 2. Bluetooth (Bluetui) - Fits your specific test size
hakase-popup-bluetooth = pkgs.writeShellScriptBin "hakase-popup-bluetooth" '' hakase-popup-bluetooth = pkgs.writeShellScriptBin "hakase-popup-bluetooth" ''
exec hakase-launch-popup 602 478 bluetui exec hakase-launch-popup bluetui
''; '';
# 3. Volume (Wiremix) - Can be smaller
hakase-popup-volume = pkgs.writeShellScriptBin "hakase-popup-volume" '' hakase-popup-volume = pkgs.writeShellScriptBin "hakase-popup-volume" ''
exec hakase-launch-popup 800 300 wiremix exec hakase-launch-popup wiremix
''; '';
in { in {
environment.systemPackages = [ environment.systemPackages = [
@@ -162,7 +128,6 @@ in {
pkgs.impala pkgs.impala
pkgs.wiremix pkgs.wiremix
pkgs.pamixer pkgs.pamixer
pkgs.yad
hakase-launch-popup hakase-launch-popup
hakase-popup-wifi hakase-popup-wifi