Advertisement
Guest User

scratchpad

a guest
Sep 14th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.91 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. SCREENWIDTH=1920
  4. SCREENHEIGHT=1080
  5.  
  6. # check for number of arguments and print help
  7. if [ $# -lt 4 ]
  8. then
  9.     echo "usage: $(basename $0) <class> <width> <height> <command>"
  10.     exit
  11. fi
  12.  
  13. # process arguments
  14. CLASS=$1
  15. WIDTH=$2
  16. HEIGHT=$3
  17. shift 3
  18. CMD="$*"
  19.  
  20. # get end position for the window
  21. POSX=$(( SCREENWIDTH/2 - WIDTH/2 ))
  22. POSY=$(( SCREENHEIGHT/2 - HEIGHT/2 ))
  23.  
  24. # if there are no instances, launch one
  25. if ! pgrep -x $CMD
  26. then
  27.     exec $CMD &
  28.     # wait for the window to appear and get the ID
  29.     WID=$(xdotool search --class --onlyvisible --sync $CLASS)
  30.     # move to scratchpad and show it
  31.     i3-msg "[class=(?i)$CLASS] move scratchpad"
  32.     i3-msg "[class=(?i)$CLASS] scratchpad show"
  33.     # resize and reposition
  34.     xdotool windowsize $WID $WIDTH $HEIGHT windowmove $WID $POSX $POSY
  35. else
  36.     # show/toggle the scratchpad for this class if it's already running
  37.     i3-msg  "[class=(?i)$CLASS] scratchpad show"
  38. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement