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!
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIs 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
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
This works with floating or tiled windows:
swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true).pid'