fix(waybar): add hakase-popup-launch

This commit is contained in:
kenji
2026-01-04 22:08:11 -06:00
parent 10374ba152
commit 6167ca3d0a
2 changed files with 86 additions and 26 deletions
+52 -4
View File
@@ -4,7 +4,54 @@
myConfig,
...
}: let
# --- POPUP SCRIPTS ---
hakase-popup-launch = pkgs.writeShellScriptBin "hakase-popup-launch" ''
tui_name=$1
active_popup=$(${pkgs.hyprland}/bin/hyprctl clients -j | ${pkgs.jq}/bin/jq -r '.[] | select(.class | startswith("org.hakase.")) | .class')
if [[ -z "''${tui_name}" ]]; then
echo "Usage: $(basename "$0") [tui-name]"
exit 1
fi
popup_checker() {
if [[ -z "$active_popup" ]]; then
echo "no_popup"
elif [[ "$active_popup" != "org.hakase.popup.''${tui_name}" ]]; then
echo "different"
else
echo "same"
fi
}
launch() {
exec ${pkgs.util-linux}/bin/setsid uwsm-app -- xdg-terminal-exec --app-id=org.hakase.popup."''${tui_name}" -e "''${tui_name}"
}
focus() {
exec ${pkgs.hyprland}/bin/hyprctl dispatch focuswindow "class:org.hakase.popup.''${tui_name}"
}
replace() {
${pkgs.hyprland}/bin/hyprctl dispatch closewindow "class:''${active_popup}"
sleep 1
launch
}
run() {
local status
status=$(popup_checker)
if [[ "$status" == "no_popup" ]]; then
launch
elif [[ "$status" == "same" ]]; then
focus
elif [[ "$status" == "different" ]]; then
replace
fi
}
run
'';
in {
wayland.windowManager.hyprland.settings = {
exec-once = [
@@ -16,6 +63,7 @@ in {
];
home.packages = [
hakase-popup-launch
pkgs.jq
pkgs.socat
pkgs.util-linux
@@ -120,7 +168,7 @@ in {
tooltip-format-disconnected = "Disconnected";
interval = 3;
spacing = 1;
on-click = "hakase-popup-wifi";
on-click = "hakase-popup-launch impala";
};
"battery" = {
@@ -149,12 +197,12 @@ in {
format-connected = "󰂱";
format-no-controller = "";
tooltip-format = "Devices connected: {num_connections}";
on-click = "hakase-popup-bluetooth";
on-click = "hakase-popup-launch bluetui";
};
"pulseaudio" = {
format = "{icon}";
on-click = "hakase-popup-volume";
on-click = "hakase-popup-launch wiremix ";
on-click-right = "pamixer -t";
tooltip-format = "Playing at {volume}%";
scroll-step = 5;
+33 -21
View File
@@ -5,40 +5,52 @@ date
echo ""
tui_name=$1
active_popup=$(hyprctl clients -j | jq -r '.[] | select(.class | startswith("org.hakase.")) | .class')
if [[ -z ${tui_name} ]]; then
echo "Usage: $(basename "$0") [tui-name]"
exit 1
fi
# TODO:
# popup centered, dim-around using hypr, 70% size
# objective: on-click, open corresponding application
# must be a single-instance
# must be uwsm
# flow:
# * user clicks the icon on waybar
# * sh check for alive instance
# * if ANY INSTANCE ALIVE and INSTANCE IS SAME, focus using hyprctl
# * elif ANY INSTANCE ALIVE and INSTANCE IS DIFFERENT, exit the previous instance and launch the new one
# * else launch normally
popup_checker() {
if [[ -z "$active_popup" ]]; then
echo "no_popup"
elif [[ "$active_popup" != "org.hakase.popup.${tui_name}" ]]; then
echo "different"
else
echo "same"
fi
}
launch() {
echo "[LOG: $(date)] launching..."
}
checker() {
echo "[LOG: $(date)] checking..."
}
wrapper() {
echo "[LOG: $(date)]"
exec setsid uwsm-app -- xdg-terminal-exec --app-id=org.hakase."${tui_name}"
exec setsid uwsm-app -- xdg-terminal-exec --app-id=org.hakase.popup."${tui_name}" -e "${tui_name}"
}
focus() {
exec hyprctl dispatch focuswindow "class:org.hakase.popup.${tui_name}"
}
replace() {
hyprctl dispatch closewindow "class:${active_popup}"
sleep 1
launch
}
run() {
local status
status=$(popup_checker)
if [[ "$status" == "no_popup" ]]; then
echo "[LOG: $(date)] no popup, launching..."
launch
checker
elif [[ "$status" == "same" ]]; then
echo "[LOG: $(date)] same popup, focusing..."
focus
elif [[ "$status" == "different" ]]; then
echo "[LOG: $(date)] different popup, closing and relaunching..."
replace
fi
}
run