Configuring/Uncommon-tips-&-tricks: Improved User-Experience of "Alt tab behaviour" (#1306)

* Configuring/Uncommon-tips-&-tricks: Improved User-Experience of "Alt tab behaviour"

The previous implementation executed the `focuswindow` and `alterzorder`
dispatchers before the footclient process terminated. This created a
timing issue that is particularly noticable during window focusing
across workspaces.

For example: A user on workspace 2 uses the alt-tab command to focus one
out of several windows on workspace 1 which was not previously focused
when the user was working on workspace 1. The focus is correctly updated
but Hyprland fails to draw the active border around the newly focused
window.

This is fixed by updating the focus after the footclient has terminated.

* Alt Tab Behaviour uses XDG_RUNTIME_DIR instead of /tmp to support multiple users on the same machine
This commit is contained in:
Leon Connor Holm 2025-12-19 12:16:31 +01:00 committed by GitHub
parent 39b4f2c566
commit a69112ddbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -294,7 +294,7 @@ Dependencies :
1. add this to your config
```ini
exec-once = foot --server
exec-once = foot --server -c $XDG_CONFIG_HOME/foot/foot.ini
bind = ALT, TAB, exec, $HOME/.config/hypr/scripts/alttab/enable.sh 'down'
bind = ALT SHIFT, TAB, exec, $HOME/.config/hypr/scripts/alttab/enable.sh 'up'
@ -322,6 +322,7 @@ windowrule = match:class alttab, border_size 0
```bash {filename="alttab.sh"}
#!/usr/bin/env bash
hyprctl -q dispatch submap alttab
start=$1
address=$(hyprctl -j clients | jq -r 'sort_by(.focusHistoryID) | .[] | select(.workspace.id >= 0) | "\(.address)\t\(.title)"' |
fzf --color prompt:green,pointer:green,current-bg:-1,current-fg:green,gutter:-1,border:bright-black,current-hl:red,hl:red \
@ -337,7 +338,7 @@ address=$(hyprctl -j clients | jq -r 'sort_by(.focusHistoryID) | .[] | select(.w
awk -F"\t" '{print $1}')
if [ -n "$address" ] ; then
hyprctl --batch -q "dispatch focuswindow address:$address ; dispatch alterzorder top"
echo "$address" > $XDG_RUNTIME_DIR/hypr/alttab/address
fi
hyprctl -q dispatch submap reset
@ -354,8 +355,8 @@ line="$1"
IFS=$'\t' read -r addr _ <<< "$line"
dim=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}
grim -t png -l 0 -w "$addr" ~/.config/hypr/scripts/alttab/preview.png
chafa --animate false -s "$dim" "$XDG_CONFIG_HOME/hypr/scripts/alttab/preview.png"
grim -t png -l 0 -w "$addr" $XDG_RUNTIME_DIR/hypr/alttab/preview.png
chafa --animate false --dither=none -s "$dim" "$XDG_RUNTIME_DIR/hypr/alttab/preview.png"
```
4. create file `touch $XDG_CONFIG_HOME/hypr/scripts/alttab/disable.sh && chmod +x $XDG_CONFIG_HOME/hypr/scripts/alttab/disable.sh` and add:
@ -370,7 +371,10 @@ hyprctl -q --batch "keyword unbind ALT, TAB ; keyword unbind ALT SHIFT, TAB ; ke
5. create file `touch $XDG_CONFIG_HOME/hypr/scripts/alttab/enable.sh && chmod +x $XDG_CONFIG_HOME/hypr/scripts/alttab/enable.sh` and add:
```bash {filename="enable.sh"}
#!/usr/bin/env bash
hyprctl -q --batch "keyword animations:enabled false ; dispatch exec footclient -a alttab ~/.config/hypr/scripts/alttab/alttab.sh $1 ; keyword unbind ALT, TAB ; keyword unbind ALT SHIFT, TAB ; dispatch submap alttab"
mkdir -p $XDG_RUNTIME_DIR/hypr/alttab
hyprctl -q --batch "keyword animations:enabled false; keyword unbind ALT, TAB ; keyword unbind ALT SHIFT, TAB"
footclient -a alttab $HOME/.config/hypr/scripts/alttab/alttab.sh $1
hyprctl --batch -q "dispatch focuswindow address:$(cat $XDG_RUNTIME_DIR/hypr/alttab/address) ; dispatch alterzorder top"
```
## Config versioning