Is there a method to get the PID of the currently focused window in wayland?
I am using the sway window manager. Thank your for your help!
swaymsg -t get_tree returns a JSON-encoded layout tree of all open windows. Generated JSON is quite large but it is easy to parse it with jq tool.
You can run this script from demnu to display focused window info:
swaymsg -t get_tree \
| jq '.. | (.nodes? // empty)[] | select(.focused==true) | {name, pid}' \
| swaynag -m "Window Info" -l
This works with floating or tiled windows:
swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true).pid'