improved bar scripts (needs to be reliable though)

This commit is contained in:
kenji
2025-12-25 19:14:51 -06:00
parent 0ac2ceba5c
commit cf2f942f0b
3 changed files with 92 additions and 6 deletions
+4
View File
@@ -1,5 +1,9 @@
{
wayland.windowManager.hyprland.settings = {
binddm = [
"SUPER, mouse:272, Move Window via Mouse, movewindow"
"SUPER, mouse:273, Resize Window with Mouse, resizewindow"
];
bindd =
[
# essential
+10 -3
View File
@@ -1,9 +1,16 @@
{
wayland.windowManager.hyprland.settings = {
windowrulev2 = [
"float, class:^(org\.hakase\..*)$"
"center, class:^(org\.hakase\..*)$"
"size 80% 70%, class:^(org\.hakase\..*)$" # Example using percentages
# "float, class:^(org\.hakase\..*)$"
# "center, class:^(org\.hakase\..*)$"
# "size 80% 70%, class:^(org\.hakase\..*)$" # Example using percentages
# --- POPUP RULES (Wifi, BT, Audio) ---
"size 602 478, class:^(org\.hakase\.popup\..*)$"
"move 1312 32, class:^(org\.hakase\.popup\..*)$"
"float, class:^(org\.hakase\.popup\..*)$"
"pin, class:^(org\.hakase\.popup\..*)$"
"animation slide right, class:^(org\.hakase\.popup\..*)$"
"dimaround, class:^(org\.hakase\.popup\..*)$"
];
};
}
+78 -3
View File
@@ -39,7 +39,7 @@
hakase-launch-wifi = pkgs.writeShellScriptBin "hakase-launch-wifi" ''
# Unblock the WiFi radio (requires appropriate user groups/permissions)
${pkgs.util-linux}/bin/rfkill unblock wifi
# ${pkgs.util-linux}/bin/rfkill unblock wifi
# Use the focus wrapper to launch or switch to Impala
exec hakase-focus-wrapper impala
@@ -48,17 +48,92 @@
hakase-launch-bluetooth =
pkgs.writeShellScriptBin "hakase-launch-bluetooth"
''
${pkgs.util-linux}/bin/rfkill unblock wifi
# ${pkgs.util-linux}/bin/rfkill unblock wifi
exec hakase-focus-wrapper bluetui
'';
hakase-launch-popup = pkgs.writeShellScriptBin "hakase-launch-popup" ''
if (($# == 0)); then
echo "Usage: hakase-launch-popup [command]"
exit 1
fi
CMD_NAME=$(basename "$1")
# Define a specific class for popups so Hyprland rules can catch them
CLASS_NAME="org.hakase.popup.$CMD_NAME"
# Check if already running; if so, toggle/close it
EXISTING_ADDR=$(${pkgs.hyprland}/bin/hyprctl clients -j | ${pkgs.jq}/bin/jq -r --arg c "$CLASS_NAME" '.[] | select(.class == $c) | .address')
if [[ -n "$EXISTING_ADDR" ]]; then
${pkgs.hyprland}/bin/hyprctl dispatch closewindow "address:$EXISTING_ADDR"
exit 0
fi
# Launch the application
# We use setsid to detach, but keep the PID to kill it later
xdg-terminal-exec --app-id="$CLASS_NAME" -e "$@" &
APP_PID=$!
# Wait for the window to appear and grab its address
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 "$CLASS_NAME" '.[] | select(.class == $c) | .address')
((TIMEOUT++))
done
if [[ -z "$WINDOW_ADDR" ]]; then
echo "Failed to find window for $CLASS_NAME"
exit 1
fi
# Monitor Hyprland socket for focus changes
# We use socat to stream events. If activewindow changes to something else, kill the app.
${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)"
# If the new focus is NOT our popup window, kill the popup
if [[ "$WINDOW_ADDR" != "$NEW_FOCUS" ]]; then
kill "$APP_PID" 2>/dev/null
# Also force close in Hyprland to be sure
${pkgs.hyprland}/bin/hyprctl dispatch closewindow "address:$WINDOW_ADDR"
break
fi
fi
done
'';
# 2. Specific Launchers using the Popup logic
hakase-popup-wifi = pkgs.writeShellScriptBin "hakase-popup-wifi" ''
exec hakase-launch-popup impala
'';
hakase-popup-bluetooth = pkgs.writeShellScriptBin "hakase-popup-bluetooth" ''
exec hakase-launch-popup bluetui
'';
hakase-popup-volume = pkgs.writeShellScriptBin "hakase-popup-volume" ''
exec hakase-launch-popup wiremix
'';
in {
environment.systemPackages = [
pkgs.jq
pkgs.util-linux # Provides rfkill
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