tab.sh 922 B

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