Added sways xprop replacement script.

This commit is contained in:
Sheldon Lee 2022-06-10 00:32:22 +08:00
parent f396cb08cb
commit 30bcf55790

View File

@ -0,0 +1,25 @@
#!/bin/sh
#
# Implementation of alternative to xprop for sway.
# Requires:
# - slurp
# - swaymsg
# - jq
# Get window information and store into parallel arrays.
WINDOWS=$(swaymsg -t get_tree | jq '.. | select(.pid? and .visible?)')
PIDS=($(echo $WINDOWS | jq '.pid'))
# readarray needed to handle whitespaced names.
readarray -t NAMES < <(echo $WINDOWS | jq '.name')
readarray -t GEOM < <(echo $WINDOWS | jq -r '.rect | "\(.x),\(.y) \(.width)x\(.height)"')
length=${#PIDS[@]}
array=()
for (( i=0 ; i<${length} ; i++ )); do
array[$i]="${GEOM[$i]} $i"
done
selected_index=$(printf "%s\n" "${array[@]}" | slurp -f "%l") || exit 1
PID="${PIDS[$selected_index]}"
NAME="${NAMES[$selected_index]}"
echo $WINDOWS | jq "select(.pid == $PID and .name == $NAME)"