|
|
|
@@ -70,44 +70,42 @@
|
|
|
|
|
CMD_NAME=$(basename "$1")
|
|
|
|
|
TARGET_CLASS="org.hakase.popup.$CMD_NAME"
|
|
|
|
|
|
|
|
|
|
# 1. SINGLETON: Close any existing hakase popups first
|
|
|
|
|
# This ensures only one popup is ever open at a time.
|
|
|
|
|
# 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"
|
|
|
|
|
|
|
|
|
|
# Toggle behavior: If we clicked the same button again, just close and exit.
|
|
|
|
|
# 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. POSITIONING
|
|
|
|
|
# 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')
|
|
|
|
|
|
|
|
|
|
# Defaults to 0 if jq fails
|
|
|
|
|
MON_X=''${MON_X:-0}
|
|
|
|
|
MON_Y=''${MON_Y:-0}
|
|
|
|
|
MON_WIDTH=''${MON_WIDTH:-1920}
|
|
|
|
|
|
|
|
|
|
TARGET_X=$((MON_X + MON_WIDTH - WIN_WIDTH - MARGIN))
|
|
|
|
|
TARGET_Y=$((MON_Y + BAR_HEIGHT + MARGIN))
|
|
|
|
|
|
|
|
|
|
# 3. LAUNCH
|
|
|
|
|
# 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: Close on "Click Outside" (Blur)
|
|
|
|
|
# 4. Background Listener (Close on Blur)
|
|
|
|
|
(
|
|
|
|
|
# Wait for the window to actually appear
|
|
|
|
|
TIMEOUT=0
|
|
|
|
|
WINDOW_ADDR=""
|
|
|
|
|
while [[ -z "$WINDOW_ADDR" && $TIMEOUT -lt 20 ]]; do
|
|
|
|
@@ -117,18 +115,10 @@
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
@@ -139,14 +129,16 @@
|
|
|
|
|
) &
|
|
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
|
''; # 1. WiFi (Impala) - Requires a larger view
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
# 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 602 478 bluetui
|
|
|
|
|
exec hakase-launch-popup 600 500 bluetui
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
# 3. Volume (Wiremix) - Can be smaller
|
|
|
|
@@ -162,7 +154,6 @@ in {
|
|
|
|
|
pkgs.impala
|
|
|
|
|
pkgs.wiremix
|
|
|
|
|
pkgs.pamixer
|
|
|
|
|
pkgs.yad
|
|
|
|
|
|
|
|
|
|
hakase-launch-popup
|
|
|
|
|
hakase-popup-wifi
|
|
|
|
|