camp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #!/bin/bash
  2. # camp for fluxbox:
  3. # Convert And Make Preview
  4. # for styles to become usable with https://github.com/ohnonot/fluxStyle
  5. me="$(basename "$0")"
  6. menu="$HOME/.fluxbox/menu"
  7. init="$HOME/.fluxbox/init"
  8. overlay="$HOME/.fluxbox/overlay"
  9. s="$(date +%s)"
  10. app1="urxvt -geometry 20x3+5-70 -e dash"
  11. app2="urxvt -geometry 20x3+20-35 -e dash"
  12. offset="$(xwininfo -root|grep Height|cut -d: -f2)"
  13. offset="$((offset - 200))"
  14. counter=0
  15. movecounter=0
  16. usage() {
  17. (( $# > 0 )) && echo "$@"
  18. echo -e "\n Arguments:
  19. \$1 = Source styledir
  20. \$2 = Destination styledir (will be created if necessary)
  21. Only styles that require adjustment will be copied over.\n
  22. Convert: styles that are a single file will be moved to their
  23. own directory, and renamed theme.cfg
  24. Make Preview: The style is applied, some windows are opened
  25. and a preview is generated according to
  26. tenr.de/howto/style_fluxbox/style_fluxbox.html#rules
  27. Please make sure the bottom left 400x200px of your
  28. current desktop are uncluttered.\n
  29. Source directory is: \"$source\"\n Dest. directory is: \"$dest\"\n"
  30. exit 1
  31. }
  32. ############# USER OPTIONS ################
  33. rcs="r" # if destination exists, (r)ename or (c)lobber - everything else means skip
  34. movedir="$HOME/.fluxbox/unused_styles.$me.$s" # set to a writable directory, and it will move source styles there, if permitted
  35. mkdir "$movedir" || usage
  36. # note: mkdir here without -p option!
  37. source="$1"
  38. dest="$2"
  39. [ -w "$init" ] || usage "Write permissions are required for $init"
  40. [[ $# != 2 ]] && usage "Wrong number of arguments: $@"
  41. [ -r "$source" ] || usage "Cannot read from source directory $source"
  42. [ -d "$source" ] || usage "$source is not a directory."
  43. mkdir -p "$dest" || usage
  44. menubackup="$menu.$me.$s"
  45. cp "$menu" "$menubackup"
  46. initbackup="$init.$me.$s"
  47. cp "$init" "$initbackup"
  48. overlaybackup="$overlay.$me.$s"
  49. mv "$overlay" "$overlaybackup"
  50. finish() {
  51. kill $appid1 $appid2 >/dev/null 2>&1
  52. mv "$initbackup" "$init"
  53. mv "$menubackup" "$menu"
  54. mv "$overlaybackup" "$overlay"
  55. rmdir "movedir" >/dev/null 2>&1
  56. kill -s USR1 "$(xprop -root _BLACKBOX_PID | cut -d= -f2)" >/dev/null 2>&1
  57. }
  58. trap finish EXIT
  59. makepreview() {
  60. echo -e "session.styleFile:$1
  61. session.*.iconbar.alignment:Left
  62. session.*.iconbar.iconWidth:100
  63. session.*.workspaceNames:one,two,three,four
  64. session.*.toolbar.tools:clock,systemtray,prevworkspace,workspacename,nextworkspace,iconbar" > "$init"
  65. kill -s USR1 "$(xprop -root _BLACKBOX_PID | cut -d= -f2)"
  66. sleep 0.6
  67. $app1 & appid1=$!
  68. sleep 0.1
  69. xdotool mousemove 280 $((offset + 20)) click 3 click 1 key Up key Right
  70. sleep 0.1
  71. $app2 & appid2=$!
  72. sleep 0.1
  73. convert x:"root[400x200+0+$offset]" -quality 95 "$1/preview.jpg"
  74. kill $appid1 $appid2
  75. fbsetroot -solid grey5
  76. sleep 0.1
  77. } >/dev/null 2>&1
  78. move() {
  79. if [ -d "$movedir" ] && [ -w "$movedir" ] && [ -w "$1" ]; then
  80. mv -i "$1" "$movedir/"
  81. echo "Moved $1 to $movedir..."
  82. ((movecounter++))
  83. fi
  84. }
  85. #########################################################################
  86. xdotool key Ctrl+Alt+Right
  87. echo "[begin] (Fluxbox 1.3.7)
  88. [exec] (Terminal) {my term}
  89. [separator]
  90. [submenu] (Submenu)
  91. [exec] (Browser)
  92. [end]
  93. [end]
  94. " > "$menu"
  95. for i in $source/*
  96. do
  97. if [ -d "$i" ]; then
  98. if [ ! -r "$i/preview.jpg" ]; then
  99. echo "No preview for: $i - copying over."
  100. if [ ! -d "$dest/${i##*/}" ]; then
  101. cp -ri "$i" "$dest/${i##*/}"
  102. move "$i"
  103. ((counter++))
  104. makepreview "$dest/${i##*/}"
  105. else
  106. case $rcs in
  107. r)
  108. cp -ri "$i" "$dest/${i##*/}.$s"
  109. move "$i"
  110. ((counter++))
  111. makepreview "$dest/${i##*/}.$s"
  112. ;;
  113. c)
  114. rm -r "$dest/${i##*/}"
  115. cp -ri "$i" "$dest/${i##*/}"
  116. move "$i"
  117. ((counter++))
  118. makepreview "$dest/${i##*/}"
  119. ;;
  120. esac
  121. fi
  122. else
  123. echo " $i"
  124. fi
  125. elif [ -r "$i" ]; then
  126. echo " Is a file: $i - converting incl. preview"
  127. if [ ! -d "$dest/${i##*/}" ]; then
  128. mkdir "$dest/${i##*/}"
  129. cp -i "$i" "$dest/${i##*/}/theme.cfg"
  130. move "$i"
  131. echo " Is a file: $i - converting incl. preview"
  132. ((counter++))
  133. makepreview "$dest/${i##*/}"
  134. else
  135. case $rcs in
  136. r)
  137. mkdir "$dest/${i##*/}.$s"
  138. cp -i "$i" "$dest/${i##*/}.$s/theme.cfg"
  139. move "$i"
  140. echo " Is a file: $i - converting incl. preview"
  141. ((counter++))
  142. makepreview "$dest/${i##*/}.$s"
  143. ;;
  144. c)
  145. rm -r "$dest/${i##*/}"
  146. cp -i "$i" "$dest/${i##*/}/theme.cfg"
  147. move "$i"
  148. echo " Is a file: $i - converting incl. preview"
  149. ((counter++))
  150. makepreview "$dest/${i##*/}"
  151. ;;
  152. esac
  153. fi
  154. fi
  155. done
  156. echo "Copied over $counter styles and created previews for them.
  157. Moved $movecounter styles to $move."
  158. exit 0