koekeishiya / yabai

A tiling window manager for macOS based on binary space partitioning
MIT License
24.21k stars 645 forks source link

After a window with focus is minimized, yabai still reports that the window has focus. #1985

Open I-Want-ToBelieve opened 1 year ago

I-Want-ToBelieve commented 1 year ago

You can easily reproduce this issue using the following script

# Get the current window's ID and has-focus attribute
window_info=$(yabai -m query --windows --window)
window_id=$(echo "$window_info" | jq '.id')
window_focus=$(echo "$window_info" | jq '."has-focus"')

# Print the window's ID and has-focus attribute
echo "Window ID: $window_id"
echo "Has Focus: $window_focus"

# Minimize the window using the yabai command
yabai -m window "$window_id" --minimize

# Wait for 1.5 seconds
sleep 1.5

# Query the window's has-focus attribute
window_focus_after=$(yabai -m query --windows --window "$window_id" | jq '."has-focus"')

# Print the window's has-focus attribute after minimizing
echo "Has Focus After Minimize: $window_focus_after"
❯ nix-shell -p jq

[nix-shell:~]$ # Get the current window's ID and has-focus attribute
window_info=$(yabai -m query --windows --window)
window_id=$(echo "$window_info" | jq '.id')
window_focus=$(echo "$window_info" | jq '."has-focus"')

# Print the window's ID and has-focus attribute
echo "Window ID: $window_id"
echo "Has Focus: $window_focus"

# Minimize the window using the yabai command
yabai -m window "$window_id" --minimize

# Wait for 1.5 seconds
sleep 1.5

# Query the window's has-focus attribute
window_focus_after=$(yabai -m query --windows --window "$window_id" | jq '."has-focus"')

# Print the window's has-focus attribute after minimizing
echo "Has Focus After Minimize: $window_focus_after"
Window ID: 979
Has Focus: true
Has Focus After Minimize: true

[nix-shell:~]$ 
koekeishiya commented 1 year ago

yabai caches the id of the active window, and the cache is only updated when macOS reports that a new window has become the key window. I guess if you minimize the only available window, macOS focuses the "Finder desktop window" and we need to catch that somehow.

I-Want-ToBelieve commented 1 year ago

It seems that this is also one of the quirks of macos.

If yabai has nothing to do here, then this issue can be closed