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
Open
AnPod
wants to merge
2
commits into
omacom:quattro
Choose a base branch
from
AnPod:cursor/fix-close-zombie-window-e0d3
base: quattro
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #!/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 process while leaving an empty shell mapped. Clear | ||
| # that leftover surface only after confirming the XWayland PID is gone (#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 | ||
|
|
||
| # Give clients a beat to finish a cooperative close. Remaining mapped can | ||
| # also mean the client is waiting for an answer to a save/discard dialog. | ||
| 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 | ||
|
|
||
| # Only a confirmed orphaned XWayland surface warrants cleanup. Live clients | ||
| # may still be handling the close request; never signal their entire process. | ||
| if ! jq -e '.xwayland == true' <<<"$active" >/dev/null 2>&1 || | ||
| [[ ! $pid =~ ^[1-9][0-9]*$ ]] || [[ -e /proc/$pid ]]; then | ||
| exit 0 | ||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| #!/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")" | ||
| closes=$(grep -c '^dispatch ' "$log_file" || true) | ||
| (( closes == 1 )) || fail "unmapped window receives only one close" | ||
| pass "window-close dispatches a cooperative close without force-kill" | ||
|
|
||
| # A mapped live client may be waiting for a save/discard answer. | ||
| cat >"$mock_bin/kill" <<'SH' | ||
| #!/bin/bash | ||
| printf '%s\n' "$*" >>"$SIGNAL_LOG" | ||
| SH | ||
| cat >"$mock_bin/hyprctl" <<'SH' | ||
| #!/bin/bash | ||
| printf '%s\n' "$*" >>"$TEST_LOG" | ||
| case $1 in | ||
| activewindow) printf '%s\n' "$ACTIVE_WINDOW" ;; | ||
| clients) printf '[{"address":"0xdead"}]\n' ;; | ||
| esac | ||
| SH | ||
| chmod +x "$mock_bin"/* | ||
| signal_log="$tmpdir/signals" | ||
|
|
||
| assert_cooperative_only() { | ||
| : >"$log_file" | ||
| : >"$signal_log" | ||
| PATH="$mock_bin:$PATH" TEST_LOG="$log_file" SIGNAL_LOG="$signal_log" ACTIVE_WINDOW="$1" \ | ||
| bash -c 'enable -n kill; source "$1"' bash "$ROOT/bin/omarchy-hyprland-window-close" | ||
|
|
||
| [[ ! -s $signal_log ]] || | ||
| fail "$2 does not signal the process" "signals: $(< "$signal_log")" | ||
| closes=$(grep -c '^dispatch ' "$log_file" || true) | ||
| (( closes == 1 )) || | ||
| fail "$2 sends exactly one cooperative close" "log: $(< "$log_file")" | ||
| grep -q 'window.close({' "$log_file" || | ||
| fail "$2 sends a cooperative close" | ||
| if grep -q 'killwindow' "$log_file"; then | ||
| fail "$2 does not force-clear the surface" | ||
| fi | ||
| pass "$2 remains cooperative" | ||
| } | ||
|
|
||
| for xwayland in false true; do | ||
| assert_cooperative_only \ | ||
| "{\"address\":\"0xdead\",\"pid\":$$,\"xwayland\":$xwayland}" \ | ||
| "live client (xwayland=$xwayland) awaiting a save/discard answer" | ||
| done | ||
|
|
||
| for pid_data in '' ',"pid":null' ',"pid":0' ',"pid":-1' ',"pid":"invalid"'; do | ||
| assert_cooperative_only \ | ||
| "{\"address\":\"0xdead\",\"xwayland\":true$pid_data}" \ | ||
| "XWayland client with missing or invalid PID ($pid_data)" | ||
| done | ||
|
|
||
| # Choose a PID beyond the kernel's PID range and verify it is absent. | ||
| missing_pid=$(< /proc/sys/kernel/pid_max) | ||
| (( missing_pid += 1 )) | ||
| [[ ! -e /proc/$missing_pid ]] || fail "orphan fixture PID is absent" | ||
| assert_cooperative_only \ | ||
| "{\"address\":\"0xdead\",\"pid\":$missing_pid,\"xwayland\":false}" \ | ||
| "native Wayland client with absent PID" | ||
|
|
||
| # 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":%s,"xwayland":true,"fullscreen":0}\n' "$MISSING_PID" | ||
| ;; | ||
| clients) | ||
| if [[ -f $STATE_DIR/force_closed ]]; then | ||
| printf '[]\n' | ||
| else | ||
| printf '[{"address":"0xzombie","pid":%s}]\n' "$MISSING_PID" | ||
| 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" MISSING_PID="$missing_pid" \ | ||
| 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" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.