From ead7d8ff5fffc161da4f21db860b92bcc3d144c1 Mon Sep 17 00:00:00 2001 From: Latent Prion Date: Mon, 21 Jul 2025 23:24:53 -0400 Subject: [PATCH] Add findxwindow script --- .gitignore | 2 +- scripts/findxwindow | 54 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100755 scripts/findxwindow diff --git a/.gitignore b/.gitignore index a01e89c..fe8aca3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ aclocal.m4 autom4te.cache/ config.h.in configure - +*.swp diff --git a/scripts/findxwindow b/scripts/findxwindow new file mode 100755 index 0000000..1eb64db --- /dev/null +++ b/scripts/findxwindow @@ -0,0 +1,54 @@ +#! /usr/bin/bash + +winNameToFind=${1} + +printUsage() +{ + echo "${0}: " + exit 1 +} + +if [ "${winNameToFind}x" = "x" ]; then + printUsage +fi + +extractAllChildIdsFrom() +{ + echo $(echo "${1}" \ + | grep '^[[:space:]]*0x[0-9a-zA-Z]' \ + | awk '{print $1}') + return 0 +} + +searchOneParentByName() +{ + local thisWinId=$1 + local winNameToFind=$2 + + local thisWininfoStdout=$(xwininfo -id "${thisWinId}") + local thisWinName=$(echo "${thisWininfoStdout}" \ + | grep '[Ww]indow[[:space:]]*[iI][dD]' \ + | grep -oP '[0-9a-zA-Z]*[[:space:]]*\".*\"$' \ + | sed 's/[0-9a-zA-Z]*[[:space:]]*//') + echo "Searching win [ID=${thisWinId}, name=\"${thisWinName}\"] and its children..." + if echo "${thisWinName}" | grep -q "${winNameToFind}"; then + echo "${thisWininfoStdout}" +# return 0 + fi + + local allChildrenUnparsedOutput=$(xwininfo -id "${thisWinId}" -children) + for i in $(extractAllChildIdsFrom "${allChildrenUnparsedOutput}"); + do + searchOneParentByName "${i}" "${winNameToFind}" + done + + return 1; +} + +rootChildWindowOutput=$(xwininfo -root -children) +for i in $(extractAllChildIdsFrom "${rootChildWindowOutput}"); +do + searchOneParentByName "${i}" "${winNameToFind}" +done + +exit 1