3

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!

Marton
  • 151
  • 1
  • 4

2 Answers2

4

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
max taldykin
  • 141
  • 4
  • 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 '18 at 11:36
2

This works with floating or tiled windows:

swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true).pid'
wef
  • 452
  • 2
  • 6