dump_selections.sh: print more details about the owner
[experiments/x-selection-debug.git] / dump_selections.sh
1 #!/bin/sh
2
3 [ -x ./xowner ] || make
4
5 get_owner() {
6   echo -n "$1"
7   OWNER_ID=$(./xowner $1)
8   if [ $OWNER_ID != "0x0" ];
9   then
10     OWNER="$OWNER_ID"
11     xwininfo -id $OWNER_ID > /dev/null 2>&1;
12     if [ $? -eq 0 ];
13     then
14       OWNER_NAME=$(xprop -id $OWNER_ID | grep "^WM_NAME" | cut -d ' ' -f 3-)
15       if [ -n "$OWNER_NAME" ];
16       then
17         OWNER="$OWNER $OWNER_NAME"
18       else
19         PARENT_ID=$(xwininfo -children -id $OWNER_ID | sed -n -e '/Parent window id:/s/.*window id: \([^ ]*\) .*$/\1/p')
20         if [ -n "$PARENT_ID" ];
21         then
22           OWNER="$OWNER children of $PARENT_ID"
23
24           PARENT_NAME=$(xprop -id $PARENT_ID | grep "^WM_NAME" | cut -d ' ' -f 3-)
25           if [ -n "$PARENT_NAME" ];
26           then
27             OWNER="$OWNER $PARENT_NAME"
28           fi
29         fi
30       fi
31       echo -n " owned by $OWNER"
32     fi
33   fi
34
35   echo ":"
36 }
37
38
39 get_owner "PRIMARY"
40 xclip -out -selection primary 2> /dev/null
41 echo
42 echo
43
44 get_owner "SECONDARY"
45 xclip -out -selection secondary 2> /dev/null
46 echo
47 echo
48
49 get_owner "CLIPBOARD"
50 xclip -out -selection clipboard 2> /dev/null
51 echo
52 echo
53
54 get_owner "CUT_BUFFER0"
55 xcb -p 0
56 echo
57 echo