Given a process iD of XX, I\'d like to have a list of any window id\'s where _NET_WM_PID = XX. Even better would be the oldest still active window id if possible.
I
You can get the window ID associated with a process ID using wmctrl in a script like this:
#!/usr/bin/env bash
#
# File:
# getwindidbypid
#
# Description:
# Get the ID of a window by PID (if the process has a window).
#
# Usage:
# getwindidbypid
#
while IFS= read line; do
if [[ "${line}" =~ (0x)([0-9a-z]+)([ ][- ][0-9]+[ ])([0-9]*) ]]; then
winId="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"
pid="${BASH_REMATCH[4]}"
if [[ "${pid}" -eq "${1}" ]]; then
WIND_IDS+=("${winId}")
fi
fi
done < <(wmctrl -lp)
if [ "${#WIND_IDS[@]}" -gt 0 ]; then
echo "${WIND_IDS[@]}"
fi
Example:
user ~ $ getwindidbypid 37248
0x05a00012