.dotfiles/configs/sway/debug_window.sh

35 lines
1.3 KiB
Bash
Raw Normal View History

2022-03-14 19:21:46 +01:00
#!/bin/bash
ALL_NODES='recurse(.nodes[]?, .floating_nodes[]?) | select(.pid and .visible)'
WINDOW_NAME='(.app_id // .window_properties.class)'
ID_PREFIX='"\(.pid):"'
WINDOW_PROTOCOL='(if .shell == "xwayland" then "X11" else "wayland" end)'
WINDOW_GEOMETRY='(.rect | "\(.x),\(.y) \(.width)x\(.height) ")'
2022-04-08 15:47:38 +02:00
WINDOW_PID='(.id | tostring)'
CLEAR_OBJ="del(.focus, .border, .current_border_width, .window_rect, .orientation, .layout, .percent, .deco_rect, .geometry, .window, .urgent, .marks, .sticky, .fullscreen_mode, .nodes, .floating_nodes, .shell, .max_render_time, .visible, .idle_inhibitors, .inhibit_idle)"
2022-03-14 19:21:46 +01:00
# Output format, e.g. "1234 - 12:firefox (wayland)" or "5678 - 17:discord (X11)"
2022-04-08 15:47:38 +02:00
FILT="$ALL_NODES | $WINDOW_GEOMETRY + $WINDOW_PID"
2022-03-14 19:21:46 +01:00
function getprop() {
typeset -A views
local selected
while read POS GEOM INFO; do
views["$POS $GEOM"]="$INFO"
done
selected="$(printf "%s\n" "${!views[@]}" | slurp)"
if [[ -n "$selected" ]]; then
window_id=${views[${selected}]};
2022-04-08 15:47:38 +02:00
echo "SelectedId $window_id"
SELECT_ID=$(echo ".. | (.nodes? // empty)[] | select(.id == $window_id) | $CLEAR_OBJ ")
selected="$(swaymsg -t get_tree | jq -r "$ALL_NODES" | jq -c ". | select(.id==$window_id)" | jq)"
echo "Selected: $selected"
notify-send "Debug:" "$(echo $selected | jq -c "$CLEAR_OBJ" | jq)";
2022-03-14 19:21:46 +01:00
fi
}
swaymsg -t get_tree | jq -r "$FILT" | getprop