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!

2 Answers 2


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
  • 1
    Thank you for the answer. I should habe mentioned that swaymsg -t get_tree does not output the PID at the time of writing. Now this feature thankfully was implementet.
    – Marton
    Dec 14, 2018 at 11:36

This works with floating or tiled windows:

swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true).pid'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .