dump_selections.sh: print more details about the owner master
authorAntonio Ospite <ao2@ao2.it>
Mon, 19 Jun 2017 14:28:59 +0000 (16:28 +0200)
committerAntonio Ospite <ao2@ao2.it>
Mon, 19 Jun 2017 14:50:51 +0000 (16:50 +0200)
Always print the ID, and optionally the window name if there is one.
Also if the window has no name try to get the parent id and name.

dump_selections.sh

index 9954a46..fcfd219 100755 (executable)
@@ -4,18 +4,31 @@
 
 get_owner() {
   echo -n "$1"
-  OWNER=$(./xowner $1)
-  if [ $OWNER != "0x0" ];
+  OWNER_ID=$(./xowner $1)
+  if [ $OWNER_ID != "0x0" ];
   then
-    xwininfo -id $OWNER > /dev/null 2>&1;
+    OWNER="$OWNER_ID"
+    xwininfo -id $OWNER_ID > /dev/null 2>&1;
     if [ $? -eq 0 ];
     then
-      OWNER_NAME=$(xprop -id $OWNER | grep "^WM_NAME" | cut -d ' ' -f 3-)
-      if [ -z "$OWNER_NAME" ];
+      OWNER_NAME=$(xprop -id $OWNER_ID | grep "^WM_NAME" | cut -d ' ' -f 3-)
+      if [ -n "$OWNER_NAME" ];
       then
-        OWNER_NAME="$OWNER"
+        OWNER="$OWNER $OWNER_NAME"
+      else
+        PARENT_ID=$(xwininfo -children -id $OWNER_ID | sed -n -e '/Parent window id:/s/.*window id: \([^ ]*\) .*$/\1/p')
+        if [ -n "$PARENT_ID" ];
+        then
+          OWNER="$OWNER children of $PARENT_ID"
+
+          PARENT_NAME=$(xprop -id $PARENT_ID | grep "^WM_NAME" | cut -d ' ' -f 3-)
+          if [ -n "$PARENT_NAME" ];
+          then
+            OWNER="$OWNER $PARENT_NAME"
+          fi
+        fi
       fi
-      echo -n " owned by $OWNER_NAME"
+      echo -n " owned by $OWNER"
     fi
   fi