2014年5月25日日曜日

マウス設定スクリプトの微調整

マウス設定のスクリプトで、Puppy Linuxの初期値(default)のポインタを、
擬似的にプレビューできるようにした。

SUB_DIALOGを表示する際に、MAIN_DIALOGにhideを与えるようにした。


※ 注意 ※
0)Precise Puppy 5.7.1JP でしか動作確認していません。
  動作には、gtkdialog0.8.3 xcur2png が必要です。
1)動作の保証はしません。
2)隠しファイルの操作をしています。
3)最悪の場合、Puppy Linux自体の不具合が起こります。

よって、スクリプトは読むだけ にしてください

以上宜しくお願いします。


  1. #!/bin/bash
  2.  
  3. #mouse_setting053
  4.  
  5. ########## Page1 ##########
  6. #設定ファイル.gtkrc.mineの存在を確認する
  7. if [ ! -e /root/.gtkrc.mine ];then
  8. touch /root/.gtkrc.mine
  9. echo "gtk-double-click-time=250" > /root/.gtkrc.mine
  10. echo "gtk-double-click-distance=5" >> /root/.gtkrc.mine
  11. fi
  12.  
  13. #/root/.config/rox.sourceforge.net/ROX-Filer/Optionsから
  14. #bind_single_clickとbind_single_pinboardの値を切り出し、変数に代入
  15. rox_path="/root/.config/rox.sourceforge.net/ROX-Filer/Options"
  16.  
  17. single_click_n=$(grep -n "bind_single_click" $rox_path)
  18. single_click_n=$(echo $single_click_n | cut -f1 -d ":")
  19.  
  20. def_single_click_str=$(grep "bind_single_click" $rox_path)
  21. def_single_click_value=$(echo $def_single_click_str | cut -c 34)
  22. single_pinboard_n=$(grep -n "bind_single_pinboard" $rox_path)
  23. single_pinboard_n=$(echo $single_pinboard_n | cut -f1 -d ":")
  24. def_single_pinboard_str=$(grep "bind_single_pinboard" $rox_path)
  25. def_single_pinboard_value=$(echo $def_single_pinboard_str | cut -c 37)
  26.  
  27. def_single_flag=`echo $(( $def_single_click_value + $def_single_pinboard_value ))`
  28.  
  29. if [ "$def_single_flag" != 0 ]; then
  30. def_single_click_boolean="false"
  31. else
  32. def_single_click_boolean="true"
  33. fi
  34.  
  35. #gtk-double-click-timeの値を.gtkrc.mineから切り出し、変数に代入
  36. def_time_str=$(grep "gtk-double-click-time" /root/.gtkrc.mine)
  37. if [ "$def_time_str" = "" ]; then
  38. echo "gtk-double-click-time=250" >> /root/.gtkrc.mine
  39. def_time_str=$(grep "gtk-double-click-time" /root/.gtkrc.mine)
  40. fi
  41. def_time_value=$(echo $def_time_str | cut -c 23-${#def_time_str})
  42. #gtk-double-click-distanceの値を.gtkrc/mineから切り出し、変数に代入
  43. def_distance_str=$(grep "gtk-double-click-distance" /root/.gtkrc.mine)
  44. if [ "$def_distance_str" = "" ]; then
  45. echo "gtk-double-click-distance=5" >> /root/.gtkrc.mine
  46. def_distance_str=$(grep "gtk-double-click-distance" /root/.gtkrc.mine)
  47. fi
  48. def_distance_value=$(echo $def_distance_str | cut -c 27-${#def_distance_str})
  49.  
  50. ########## Page2 ##########
  51. #xset -qコマンドからマウス関連の数値を切り出し、変数に代入
  52. temp_xset=$(xset -q)
  53. def_acceleration_str=$(echo "$temp_xset" | grep "acceleration")
  54. def_acceleration_value_str=$(echo $def_acceleration_str | cut -f2 -d " ")
  55. def_acceleration_value=$(echo $def_acceleration_value_str | cut -f1 -d "/")
  56. dot_point=$(echo $(( ${#def_acceleration_value} - 1 )))
  57. front_value=$(echo "$def_acceleration_value" | cut -c 1-"$dot_point")
  58. bottom_value=$(echo "$def_acceleration_value" | cut -c ${#def_acceleration_value})
  59. def_acceleration_value=$front_value"."$bottom_value
  60. def_threshold_value=$(echo $def_acceleration_str | cut -f4 -d " ")
  61. def_x_parameter="m "$def_acceleration_value_str" "$def_threshold_value
  62.  
  63. #設定ファイル/.xset.shの存在を確認する
  64. if [ ! -e /root/.xset.sh ]; then
  65. touch /root/.xset.sh
  66. chmod +x /root/.xset.sh
  67. echo "xset "$def_x_parameter > /root/.xset.sh
  68. fi
  69.  
  70. ########## Page3 ##########
  71. default_png='
  72. cat <<'EOF'>> /tmp/ao_o10yan_temp/left_ptr_000.png
  73. /* XPM */
  74. static const char * xpm_data[] = {
  75. "16 16 2 1",
  76. " c None",
  77. ". c #000000000000",
  78. " ",
  79. ". ",
  80. ".. ",
  81. "... ",
  82. ".... ",
  83. "..... ",
  84. "...... ",
  85. "....... ",
  86. "........ ",
  87. "..... ",
  88. ".. .. ",
  89. ". .. ",
  90. " .. ",
  91. " .. ",
  92. " .. ",
  93. " "};
  94. EOF
  95.  
  96. cat <<'EOF'>> /tmp/ao_o10yan_temp/hand_000.png
  97. /* XPM */
  98. static const char * xpm_data[] = {
  99. "16 16 2 1",
  100. " c None",
  101. ". c #000000000000",
  102. " ",
  103. " ",
  104. " ........ ",
  105. ". . ",
  106. " ...... . ",
  107. " . . ",
  108. " ... . ",
  109. " . . ",
  110. " ... . . ",
  111. " . . . ",
  112. " .. . . ",
  113. " .. . ",
  114. " . . . ",
  115. " . . ",
  116. " . . ",
  117. " . "};
  118. EOF
  119.  
  120. cat <<'EOF'>> /tmp/ao_o10yan_temp/watch_000.png
  121. /* XPM */
  122. static const char * xpm_data[] = {
  123. "16 16 2 1",
  124. " c None",
  125. ". c #000000000000",
  126. " ........ ",
  127. " ........ ",
  128. " ........ ",
  129. " .......... ",
  130. " .. . .. ",
  131. ".. . .. ",
  132. ". . ...",
  133. ". ... ...",
  134. ". ... ...",
  135. ". . ...",
  136. ".. . .. ",
  137. " .. .. ",
  138. " .......... ",
  139. " ........ ",
  140. " ........ ",
  141. " ........ "};
  142. EOF
  143. '
  144. mkdir -p /tmp/ao_o10yan_temp
  145. #symlinkの存在を確認する
  146. if [ -e /root/.icons/default ]; then
  147. def_symlink=$(readlink /root/.icons/default)
  148. def_symlink_dir=$(echo $def_symlink | cut -f4 -d "/")
  149. else
  150. def_symlink="/root/.icons/default"
  151. def_symlink_dir="default"
  152. fi
  153.  
  154. #lsコマンドで列挙して<list>の<item>を作成する
  155. temp_directories=$(ls /root/.icons/)
  156. #echo $temp_directories
  157. i_count=0
  158. items="<item>default</item>"
  159.  
  160. if [ "$def_symlink_dir" = "default" ]; then
  161. def_selected_rwo=0
  162. eval "$default_png"
  163. fi
  164.  
  165. for i in $temp_directories
  166. do
  167. if [ "$i" != "default" -a "$i" != "ROX" -a -e "/root/.icons/""$i""/cursors" ]; then
  168. i_count=$(( $i_count + 1 ))
  169. # echo $i_count$i
  170. if [ "$def_symlink_dir" = "$i" ]; then
  171. def_selected_row="$i_count"
  172. xcur2png -d /tmp/ao_o10yan_temp /root/.icons/"$i"/cursors/left_ptr
  173. xcur2png -d /tmp/ao_o10yan_temp /root/.icons/"$i"/cursors/hand
  174. xcur2png -d /tmp/ao_o10yan_temp /root/.icons/"$i"/cursors/watch
  175. fi
  176. items=$items"<item>"$i"</item>"
  177. fi
  178. # echo $items
  179. done
  180.  
  181. ###############################################################################
  182. #OKボタンが押された時に呼び出す
  183. export ok_action='
  184. #前処理
  185. msg_flag1=0
  186. msg_flag2=0
  187. msg_flag3=0
  188. new_time_str="gtk-double-click-time="$TIME
  189. new_distance_str="gtk-double-click-distance="$DISTANCE
  190.  
  191. #ダブルクリック、シングルクリックの切替設定
  192. if [ "'$def_single_click_boolean'" != "$CHKBOX" ]; then
  193. if [ "$CHKBOX" = "true" ]; then
  194. new_single_flag=0
  195. else
  196. new_single_flag=1
  197. fi
  198.  
  199. #ファイラとピンボードの設定を一緒に行う
  200. #どちらかがシングル、どちらかがダブルと言う設定にはしない!!
  201. sed --in-place "'$single_click_n's/'$def_single_click_value'/$new_single_flag/" '$rox_path'
  202. sed --in-place "'$single_pinboard_n's/'$def_single_pinboard_value'/$new_single_flag/" '$rox_path'
  203.  
  204. msg_flag1=1
  205. fi
  206.  
  207. #ダブルクリック間隔、反応距離の設定(文字列整形した後の比較じゃなくてもいいのに)
  208. if [ "'$def_time_str'" != "$new_time_str" -o "'$def_distance_str'" != "$new_distance_str" ]; then
  209. sed --in-place --expression=s/'$def_time_str'/$new_time_str/ /root/.gtkrc.mine
  210. sed --in-place --expression=s/'$def_distance_str'/$new_distance_str/ /root/.gtkrc.mine
  211.  
  212. msg_flag1=1
  213. fi
  214.  
  215. #加速の設定
  216. if [ "'$def_acceleration_value'" != "$ACCELERATION" -o "'$def_threshold_value'" != "$THRESHOLD" ]; then
  217. new_acceleration=$(echo $ACCELERATION | sed "s/\.//")
  218. echo $new_acceleration
  219. new_x_parameter="m "$new_acceleration"/10 "$THRESHOLD
  220. echo $new_x_parameter
  221. xset $new_x_parameter
  222. sed --in-place "s:'$def_x_parameter':$new_x_parameter:" /root/.xset.sh
  223.  
  224. msg_flag2=3
  225. fi
  226.  
  227. #テーマの変更
  228. new_symlink="/root/.icons/"$DIRECTORY
  229. echo "def_symlink="'$def_symlink'
  230. echo "new_symlink="$new_symlink
  231. if [ "$new_symlink" != "/root/.icons/" -a "'$def_symlink'" != "$new_symlink" ]; then
  232. if [ -e /root/.icons/default ]; then
  233. rm /root/.icons/default
  234. fi
  235.  
  236. if [ "'$def_symlink'" != "$new_symlink" ]; then
  237. if [ "$new_symlink" != "/root/.icons/default" ]; then
  238. ln -s $new_symlink /root/.icons/default
  239. fi
  240. msg_flag3=1
  241. fi
  242. fi
  243.  
  244. #change_msg_flagにより、表示するメッセージを変える
  245. change_msg_flag=$(( $msg_flag1 + $msg_flag2 + $msg_flag3 ))
  246.  
  247. if [ "$change_msg_flag" = "0" ]; then
  248. msg0="設定が変更されていません"
  249. msg1="何もせずに終了します"
  250. msg2="..."
  251. else
  252. msg0="マウスの設定を変更しました"
  253. msg1="Xサーバをリスタートして効果を確認してください"
  254. msg2="..."
  255. #加速調整はxのリスタートなしで反映される
  256. if [ "$change_msg_flag" = "3" ]; then
  257. msg1="..."
  258. fi
  259. if [ "$msg_flag2" = "3" ]; then
  260. msg2="加速の変更は、既に反映されています。確認してください"
  261. fi
  262. fi
  263.  
  264. export SUB_DIALOG="
  265. <window title=\"Double Click Adjust\" width_request=\"400\" height_request=\"300\">
  266. <vbox>
  267. <text height-request=\"40\">
  268. <label>"$msg0"</label>
  269. </text>
  270. <text height-request=\"40\">
  271. <label>"$msg1"</label>
  272. </text>
  273. <text height-request=\"40\">
  274. <label>"$msg2"</label>
  275. </text>
  276. <button height-request=\"100\"><label>閉じる</label>
  277. <action type=\"exit\">exit</action>
  278. </button>
  279. </vbox>
  280. </window>"
  281.  
  282. gtkdialog -c --program SUB_DIALOG
  283. '
  284. ###############################################################################
  285. #マウステーマプレビュー用
  286.  
  287. export list_on_change='
  288. if [ "$DIRECTORY" = "default" ]; then
  289. if [ -e /tmp/ao_o10yan_temp/left_ptr_000.png ]; then
  290. rm /tmp/ao_o10yan_temp/left_ptr_000.png
  291. rm /tmp/ao_o10yan_temp/hand_000.png
  292. rm /tmp/ao_o10yan_temp/watch_000.png
  293. '$default_png'
  294. fi
  295. else
  296. temp_file_dir="/tmp/ao_o10yan_temp/"$DIRECTORY
  297. if [ "$temp_file_dir" != "/tmp/ao_o10yan_temp/" ]; then
  298. xcur2png -d /tmp/ao_o10yan_temp /root/.icons/"$DIRECTORY"/cursors/left_ptr
  299. xcur2png -d /tmp/ao_o10yan_temp /root/.icons/"$DIRECTORY"/cursors/hand
  300. xcur2png -d /tmp/ao_o10yan_temp /root/.icons/"$DIRECTORY"/cursors/watch
  301. fi
  302. fi
  303. '
  304. ###############################################################################
  305. #後始末
  306. export del_temp='
  307. rm -rf /tmp/ao_o10yan_temp
  308. rm -f ./left_ptr.conf
  309. rm -f ./hand.conf
  310. rm -f ./watch.conf
  311. '
  312.  
  313. ###############################################################################
  314.  
  315. export MAIN_DIALOG='
  316. <window title="マウスの設定" width_request="400" height_request="300">
  317. <vbox>
  318. <notebook labels="ダブルクリック|加速|テーマ">
  319. <vbox>
  320. <text>
  321. <label>ダブルクリック調整用スライダー</label>
  322. </text>
  323. <frame>
  324. <checkbox>
  325. <label>ダブルクリックを有効にする</label>
  326. <default>'$def_single_click_boolean'</default>
  327. <variable>CHKBOX</variable>
  328. <action>if true enable:TIME</action>
  329. <action>if false disable:TIME</action>
  330. <action>if true enable:DISTANCE</action>
  331. <action>if false disable:DISTANCE</action>
  332. </checkbox>
  333. </frame>
  334. <frame 間隔(ミリ秒)>
  335. <hscale range-min="250" range-max="2000" range-step="1">
  336. <default>'$def_time_value'</default>
  337. <variable>TIME</variable>
  338. <sensitive>'$def_single_click_boolean'</sensitive>
  339. </hscale>
  340. </frame>
  341. <frame 距離(ピクセル)>
  342. <hscale range-min="5" range-max="100" range-step="1">
  343. <default>'$def_distance_value'</default>
  344. <variable>DISTANCE</variable>
  345. <sensitive>'$def_single_click_boolean'</sensitive>
  346. </hscale>
  347. </frame>
  348. </vbox>
  349. <vbox>
  350. <text>
  351. <label>加速調整用スライダー</label>
  352. </text>
  353. <frame 加速(数値が大きい程、マウスが速く動きます)>
  354. <hscale range-min="1" range-max="10" range-step="0.1">
  355. <default>'$def_acceleration_value'</default>
  356. <variable>ACCELERATION</variable>
  357. </hscale>
  358. </frame>
  359. <frame 閾値(数値が小さい程、マウスが速く動きます)>
  360. <hscale range-max="20" range-min="1" range-step="1">
  361. <default>'$def_threshold_value'</default>
  362. <variable>THRESHOLD</variable>
  363. </hscale>
  364. </frame>
  365. </vbox>
  366. <vbox>
  367. <text>
  368. <label>マウスのテーマ切替</label>
  369. </text>
  370. <hbox>
  371. <list selected-row="'$def_selected_row'">
  372. <variable>DIRECTORY</variable>
  373. <width>150</width>
  374. <height>208</height>
  375. '$items'
  376. <action>bash -c "$list_on_change"</action>
  377. <action>refresh:LEFT_PTR</action>
  378. <action>refresh:HAND</action>
  379. <action>refresh:WATCH</action>
  380. </list>
  381. <frame プレビュー>
  382. <vbox>
  383. <pixmap space-fill="false" space-fill="false">
  384. <variable>LEFT_PTR</variable>
  385. <height>32</height>
  386. <input file>/tmp/ao_o10yan_temp/left_ptr_000.png</input>
  387. </pixmap>
  388. <pixmap space-fill="false" space-fill="false">
  389. <variable>HAND</variable>
  390. <height>32</height>
  391. <input file>/tmp/ao_o10yan_temp/hand_000.png</input>
  392. </pixmap>
  393. <pixmap space-fill="false" space-fill="false">
  394. <variable>WATCH</variable>
  395. <height>32</height>
  396. <input file>/tmp/ao_o10yan_temp/watch_000.png</input>
  397. </pixmap>
  398. </vbox>
  399. </frame>
  400. </hbox>
  401. </vbox>
  402. </notebook>
  403. <hbox>
  404. <button ok>
  405. <action>hide:MAIN_DIALOG</action>
  406. <action>bash -c "$ok_action"</action>
  407. <action>bash -c "$del_temp"</action>
  408. <action type="exit">exit</action>
  409. </button>
  410. <button cancel>
  411. <action>bash -c "$del_temp"</action>
  412. <action type="exit">exit</action>
  413. </button>
  414. </hbox>
  415. </vbox>
  416. </window>
  417. '
  418.  
  419. gtkdialog -c --program MAIN_DIALOG
  420.  

0 件のコメント :

コメントを投稿