From f9377d7686b6a80877f21c76d3a68940b9deb16e Mon Sep 17 00:00:00 2001 From: Myned Date: Thu, 26 Sep 2024 20:54:38 -0500 Subject: [PATCH] launch: mitigate on-created-empty race condition Signed-off-by: Myned --- options/custom/desktops/hyprland/rules.nix | 4 +++- options/custom/scripts/launch.sh | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/options/custom/desktops/hyprland/rules.nix b/options/custom/desktops/hyprland/rules.nix index fa8ce97..d85f38d 100644 --- a/options/custom/desktops/hyprland/rules.nix +++ b/options/custom/desktops/hyprland/rules.nix @@ -24,6 +24,8 @@ in { config.home-manager.users.${config.custom.username} = mkIf cfg.enable { wayland.windowManager.hyprland.settings = { + # BUG: on-created-empty race condition with delayed windows + # https://github.com/hyprwm/Hyprland/issues/5663 # https://wiki.hyprland.org/Configuring/Workspace-Rules #?? workspace = WORKSPACE, RULES workspace = [ @@ -32,7 +34,7 @@ in { "special:android, on-created-empty:${waydroid} app launch com.YoStarEN.Arknights" "special:music, on-created-empty:${youtube-music}" "special:office, on-created-empty:[tile] ${onlyoffice}" - "special:password, on-created-empty:${launch} --tile ${_1password}" + "special:password, on-created-empty:${launch} --empty --tile --workspace special:password ${_1password}" "special:steam, on-created-empty:${steam}" "special:terminal, on-created-empty:${kitty}" "special:vm, on-created-empty:${pgrep} -x vm || ${virt-manager}" diff --git a/options/custom/scripts/launch.sh b/options/custom/scripts/launch.sh index b800689..19c2f42 100644 --- a/options/custom/scripts/launch.sh +++ b/options/custom/scripts/launch.sh @@ -12,6 +12,7 @@ # @option -W --workspace Move next window to workspace # @flag -a --active Focus and raise next window (raise requires floating) # @flag -c --center Center next window (requires floating) +# @flag -e --empty Only launch if workspace is empty (requires workspace) # @flag -f --float Float next window # @flag -g --group Add next window to the active group # @flag -l --lock Lock next window's group @@ -24,6 +25,16 @@ eval "$(argc --argc-eval "$0" "$@")" +if [[ "${argc_empty:-}" ]]; then + # Delay to mitigate on-created-empty window race condition + sleep 1 + + # Silently exit if window exists on specified workspace + if hyprctl -j clients | jq -r .[].workspace.name | grep "${argc_workspace:-}"; then + exit + fi +fi + # Get initial count of open windows count="$(hyprctl -j clients | jq length)" @@ -40,7 +51,7 @@ while (("$(hyprctl -j clients | jq length)" <= "$count")); do # Time out after 60 seconds if (("$c" >= 60 * 10)); then notify-send "> launch" "Polling timed out" --urgency critical - break + exit 1 fi sleep 0.1