Repository navigation
Force-clear zombie windows that ignore cooperative close #13638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: quattro
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #!/bin/bash | ||
|
|
||
| # omarchy:summary=Close the focused Hyprland window, force-killing XWayland zombies | ||
| # omarchy:hidden=true | ||
|
|
||
| # Some apps (notably JUCE/XWayland clients like Surge XT) accept the close | ||
| # request and quit their UI while leaving an empty shell mapped. A short wait | ||
| # followed by a force-kill clears that leftover surface (#13308). | ||
|
|
||
| active=$(hyprctl activewindow -j 2>/dev/null) || exit 0 | ||
| addr=$(jq -r '.address // empty' <<<"$active") | ||
| pid=$(jq -r '.pid // 0' <<<"$active") | ||
|
|
||
| [[ -n $addr ]] || exit 0 | ||
|
|
||
| hyprctl dispatch "hl.dsp.window.close({ window = \"address:$addr\" })" >/dev/null 2>&1 || | ||
| hyprctl dispatch closewindow "address:$addr" >/dev/null 2>&1 || true | ||
|
|
||
| # Wayland-native clients usually unmap immediately. Give XWayland a beat to | ||
| # finish a cooperative close before deciding the surface is stuck. | ||
| for _ in 1 2 3 4 5; do | ||
| sleep 0.05 | ||
| if ! hyprctl clients -j 2>/dev/null | jq -e --arg addr "$addr" \ | ||
| 'any(.[]; .address == $addr)' >/dev/null 2>&1; then | ||
| exit 0 | ||
| fi | ||
| done | ||
|
|
||
| # Still mapped: either the client ignored close, or it died and left a ghost. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please keep ordinary close requests cooperative: a window can still be mapped after 250 ms because it is waiting for the user to answer a save/discard dialog, and this path sends its entire process SIGTERM then SIGKILL (including native wayland clients). gate force-killing on an explicit user action or a positively identified zombie, otherwise super+w can discard unsaved work and close other windows of the same app. |
||
| # Prefer /proc over the kill builtin so tests and exotic PATH layouts work. | ||
| if [[ $pid =~ ^[1-9][0-9]*$ ]] && [[ -d /proc/$pid ]]; then | ||
| command kill "$pid" 2>/dev/null || true | ||
| sleep 0.1 | ||
| if [[ -d /proc/$pid ]]; then | ||
| command kill -9 "$pid" 2>/dev/null || true | ||
| fi | ||
| fi | ||
|
|
||
| if hyprctl clients -j 2>/dev/null | jq -e --arg addr "$addr" \ | ||
| 'any(.[]; .address == $addr)' >/dev/null 2>&1; then | ||
| hyprctl dispatch "hl.dsp.window.close({ window = \"address:$addr\" })" >/dev/null 2>&1 || | ||
| hyprctl dispatch killwindow "address:$addr" >/dev/null 2>&1 || | ||
|
Comment on lines
+38
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| hyprctl dispatch closewindow "address:$addr" >/dev/null 2>&1 || true | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| tmpdir=$(mktemp -d) | ||
| trap 'rm -rf "$tmpdir"' EXIT | ||
|
|
||
| mock_bin="$tmpdir/bin" | ||
| log_file="$tmpdir/log" | ||
| state_dir="$tmpdir/state" | ||
| mkdir -p "$mock_bin" "$state_dir" | ||
|
|
||
| : >"$log_file" | ||
| cat >"$mock_bin/hyprctl" <<'SH' | ||
| #!/bin/bash | ||
| printf '%s\n' "$*" >>"$TEST_LOG" | ||
| case $1 in | ||
| activewindow) | ||
| printf '{"address":"0xdead","pid":4242,"xwayland":true,"fullscreen":0}\n' | ||
| ;; | ||
| clients) | ||
| if [[ -f $STATE_DIR/closed ]]; then | ||
| printf '[]\n' | ||
| else | ||
| printf '[{"address":"0xdead","pid":4242}]\n' | ||
| fi | ||
| ;; | ||
| dispatch) | ||
| touch "$STATE_DIR/closed" | ||
| ;; | ||
| esac | ||
| SH | ||
| cat >"$mock_bin/sleep" <<'SH' | ||
| #!/bin/bash | ||
| exit 0 | ||
| SH | ||
| chmod +x "$mock_bin"/* | ||
|
|
||
| PATH="$mock_bin:$PATH" TEST_LOG="$log_file" STATE_DIR="$state_dir" \ | ||
| bash "$ROOT/bin/omarchy-hyprland-window-close" | ||
|
|
||
| grep -q 'window.close({ window = "address:0xdead" })' "$log_file" || | ||
| fail "window-close dispatches a cooperative close" "log: $(< "$log_file")" | ||
| pass "window-close dispatches a cooperative close without force-kill" | ||
|
|
||
| # Zombie path: window stays mapped; pid has no /proc entry. | ||
| : >"$log_file" | ||
| rm -f "$state_dir"/* | ||
| cat >"$mock_bin/hyprctl" <<'SH' | ||
| #!/bin/bash | ||
| printf '%s\n' "$*" >>"$TEST_LOG" | ||
| case $1 in | ||
| activewindow) | ||
| printf '{"address":"0xzombie","pid":99999,"xwayland":true,"fullscreen":0}\n' | ||
| ;; | ||
| clients) | ||
| if [[ -f $STATE_DIR/force_closed ]]; then | ||
| printf '[]\n' | ||
| else | ||
| printf '[{"address":"0xzombie","pid":99999}]\n' | ||
| fi | ||
| ;; | ||
| dispatch) | ||
| closes=0 | ||
| [[ -f $STATE_DIR/closes ]] && closes=$(wc -l <"$STATE_DIR/closes") | ||
| echo x >>"$STATE_DIR/closes" | ||
| if (( closes >= 1 )); then | ||
| touch "$STATE_DIR/force_closed" | ||
| fi | ||
| ;; | ||
| esac | ||
| SH | ||
| chmod +x "$mock_bin/hyprctl" | ||
|
|
||
| PATH="$mock_bin:$PATH" TEST_LOG="$log_file" STATE_DIR="$state_dir" \ | ||
| bash "$ROOT/bin/omarchy-hyprland-window-close" | ||
|
|
||
| grep -q 'window.close({ window = "address:0xzombie" })' "$log_file" || | ||
| fail "zombie close still sends an initial close" "log: $(< "$log_file")" | ||
| # Second close / killwindow after the surface refused to leave. | ||
| closes=$(grep -c '0xzombie' "$log_file" || true) | ||
| (( closes >= 2 )) || | ||
| fail "zombie close force-targets the stuck surface" "log: $(< "$log_file")" | ||
|
Comment on lines
+137
to
+142
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| pass "window-close force-clears an XWayland zombie that ignores close" | ||
|
|
||
| grep -q 'omarchy-hyprland-window-close' "$ROOT/default/hypr/bindings/tiling.lua" || | ||
| fail "tiling bindings use omarchy-hyprland-window-close" | ||
| pass "tiling bindings use omarchy-hyprland-window-close" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hyprctl clients -jfails or returns malformed JSON, the failed check is treated as though the window disappeared. The script exits without checking whether a still-mapped surface needs cleanup, and gives no indication that the query failed.