diff --git a/apps/waybar/deps.nix b/apps/waybar/deps.nix index a848e1a..9f25a12 100644 --- a/apps/waybar/deps.nix +++ b/apps/waybar/deps.nix @@ -1,7 +1,4 @@ {pkgs, ...}: { home.packages = with pkgs; [ - pamixer - wiremix - impala ]; } diff --git a/apps/waybar/home.nix b/apps/waybar/home.nix index eb8d9b8..d1cb5f1 100644 --- a/apps/waybar/home.nix +++ b/apps/waybar/home.nix @@ -72,7 +72,7 @@ "cpu" = { interval = 5; format = "󰍛"; - on-click = "omarchy-launch-or-focus-tui btop"; + on-click = "omarchy-focus-wrapper btop"; on-click-right = "alacritty"; }; @@ -94,7 +94,7 @@ tooltip-format-disconnected = "Disconnected"; interval = 3; spacing = 1; - on-click = "omarchy-launch-wifi"; + on-click = "hakase-launch-wifi"; }; "battery" = { @@ -123,12 +123,12 @@ format-connected = "󰂱"; format-no-controller = ""; tooltip-format = "Devices connected: {num_connections}"; - on-click = "omarchy-launch-bluetooth"; + on-click = "hakase-launch-bluetooth"; }; "pulseaudio" = { format = "{icon}"; - on-click = "omarchy-launch-or-focus-tui wiremix"; + on-click = "hakase-focus-wrapper wiremix"; on-click-right = "pamixer -t"; tooltip-format = "Playing at {volume}%"; scroll-step = 5; diff --git a/hosts/hakase/configuration.nix b/hosts/hakase/configuration.nix index 89bc82d..47ddf6d 100644 --- a/hosts/hakase/configuration.nix +++ b/hosts/hakase/configuration.nix @@ -7,5 +7,6 @@ ./hardware-configuration.nix ../../modules/system/default.nix ../../modules/system/hyprland.nix + ../../modules/system/scripts.nix ]; } diff --git a/modules/system/scripts.nix b/modules/system/scripts.nix index 257894a..118c27d 100644 --- a/modules/system/scripts.nix +++ b/modules/system/scripts.nix @@ -1,5 +1,5 @@ { imports = [ - ../../script/hakase-lauch-or-focus-tui.nix + ../../script/hakase-scripts.nix ]; } diff --git a/script/hakase-lauch-or-focus-tui.nix b/script/hakase-lauch-or-focus-tui.nix deleted file mode 100644 index 169b7e1..0000000 --- a/script/hakase-lauch-or-focus-tui.nix +++ /dev/null @@ -1,13 +0,0 @@ -{pkgs, ...}: let - hakase-launch-or-focus-tui = pkgs.writeShellScriptBin "omarchy-focus-wrapper" '' - # The Nix version of your script - APP_ID="org.omarchy.$(basename "$1")" - LAUNCH_COMMAND="omarchy-launch-tui $@" - - exec omarchy-launch-or-focus "$APP_ID" "$LAUNCH_COMMAND" - ''; -in { - environment.systemPackages = [ - hakase-launch-or-focus-tui - ]; -} diff --git a/scripts/hakase-scripts.nix b/scripts/hakase-scripts.nix new file mode 100644 index 0000000..f4aa30e --- /dev/null +++ b/scripts/hakase-scripts.nix @@ -0,0 +1,68 @@ +{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 + ''; +in { + environment.systemPackages = [ + pkgs.jq + pkgs.util-linux # Provides rfkill + pkgs.bluetui + pkgs.impala + pkgs.wiremix + pkgs.pamixer + hakase-launch-or-focus + hakase-launch-tui + hakase-focus-wrapper + hakase-launch-wifi + hakase-launch-bluetooth + ]; +}