#tab.sh# 913 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Usage:
  2. # tabc.sh <tabbed-id> <command>
  3. # Commands:
  4. # add <window-id> - Add window to tabbed
  5. # remove <window-id> - Remove window from tabbed
  6. # list - List all clients of tabbed
  7. #
  8. # Functions
  9. #
  10. # Get wid of root window
  11. function get_root_wid {
  12. xwininfo -root | awk '/Window id:/{print $4}'
  13. }
  14. # Get children of tabbed
  15. function get_clients {
  16. id=$1
  17. xwininfo -id $id -children | sed -n '/[0-9]\+ \(child\|children\):/,$s/ \+\(0x[0-9a-z]\+\).*/\1/p'
  18. }
  19. # Get class of a wid
  20. function get_class {
  21. id=$1
  22. xprop -id $id | sed -n '/WM_CLASS/s/.*, "\(.*\)"/\1/p'
  23. }
  24. #
  25. # Main Program
  26. #
  27. tabbed=$1; shift
  28. if [ "$(get_class $tabbed)" != "tabbed" ]; then
  29. echo "Not an instance of tabbed" 2>&1
  30. fi
  31. cmd=$1; shift
  32. case $cmd in
  33. add)
  34. wid=$1; shift
  35. xdotool windowreparent $wid $tabbed
  36. ;;
  37. remove)
  38. wid=$1; shift
  39. xdotool windowreparent $wid $(get_root_wid)
  40. ;;
  41. list)
  42. get_clients $tabbed
  43. ;;
  44. esac