26 lines
757 B
Bash
Executable File
26 lines
757 B
Bash
Executable File
#!/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)"
|