2014年4月5日土曜日

マウスの設定周りをまとめたい

Puppy Linuxで、あっちこっちに散らばっているマウスの設定をまとめたい、
と思った。
・ダブルクリックの設定
・マウス加速の設定
・マウスのテーマ切替
これらを、一つのツールでやりたい、って事です。
(但し、現状ではホイール関連の設定についての調べができてない)

マウスのテーマ切替をするには、予めテーマをダウンロードして解凍し、
解凍してできたディレクトリをそのまま /root/.icons へコピーしておく。
(defaultの選択では、画像が表示されません)
(今現在使用しているテーマのディレクトリを削除すると不具合が起こります)

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

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

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



  1. #!/bin/bash
  2.  
  3. #mouse_setting042
  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. mkdir -p /tmp/ao_o10yan_temp
  72. #symlinkの存在を確認する
  73. if [ -e /root/.icons/default ]; then
  74. def_symlink=$(readlink /root/.icons/default)
  75. def_symlink_dir=$(echo $def_symlink | cut -f4 -d "/")
  76. else
  77. def_symlink="/root/.icons/default"
  78. def_symlink_dir="default"
  79. fi
  80.  
  81. #lsコマンドで列挙して<list>の<item>を作成する
  82. temp_directories=$(ls /root/.icons/)
  83. #echo $temp_directories
  84. i_count=0
  85. items="<item>default</item>"
  86.  
  87. if [ "$def_symlink_dir" = "default" ]; then
  88. def_selected_rwo=0
  89. fi
  90.  
  91. for i in $temp_directories
  92. do
  93. if [ "$i" != "default" -a "$i" != "ROX" -a -e "/root/.icons/""$i""/cursors" ]; then
  94. i_count=$(( $i_count + 1 ))
  95. # echo $i_count$i
  96. if [ "$def_symlink_dir" = "$i" ]; then
  97. def_selected_row="$i_count"
  98. xcur2png -d /tmp/ao_o10yan_temp /root/.icons/"$i"/cursors/left_ptr
  99. xcur2png -d /tmp/ao_o10yan_temp /root/.icons/"$i"/cursors/hand
  100. xcur2png -d /tmp/ao_o10yan_temp /root/.icons/"$i"/cursors/watch
  101. fi
  102.  
  103. items=$items"<item>"$i"</item>"
  104. fi
  105. # echo $items
  106. done
  107.  
  108. #####################################################################
  109. #OKボタンが押された時に呼び出す
  110. export ok_action='
  111. #前処理
  112. msg_flag1=0
  113. msg_flag2=0
  114. msg_flag3=0
  115. new_time_str="gtk-double-click-time="$TIME
  116. new_distance_str="gtk-double-click-distance="$DISTANCE
  117.  
  118. #ダブルクリック、シングルクリックの切替設定
  119. if [ "'$def_single_click_boolean'" != "$CHKBOX" ]; then
  120. if [ "$CHKBOX" = "true" ]; then
  121. new_single_flag=0
  122. else
  123. new_single_flag=1
  124. fi
  125.  
  126. #ファイラとピンボードの設定を一緒に行う
  127. #どちらかがシングル、どちらかがダブルと言う設定にはしない!!
  128. sed --in-place "'$single_click_n's/'$def_single_click_value'/$new_single_flag/" '$rox_path'
  129. sed --in-place "'$single_pinboard_n's/'$def_single_pinboard_value'/$new_single_flag/" '$rox_path'
  130.  
  131. msg_flag1=1
  132. fi
  133.  
  134. #ダブルクリック間隔、反応距離の設定(文字列整形した後の比較じゃなくてもいいのに)
  135. if [ "'$def_time_str'" != "$new_time_str" -o "'$def_distance_str'" != "$new_distance_str" ]; then
  136. sed --in-place --expression=s/'$def_time_str'/$new_time_str/ /root/.gtkrc.mine
  137. sed --in-place --expression=s/'$def_distance_str'/$new_distance_str/ /root/.gtkrc.mine
  138.  
  139. msg_flag1=1
  140. fi
  141.  
  142. #加速の設定
  143. if [ "'$def_acceleration_value'" != "$ACCELERATION" -o "'$def_threshold_value'" != "$THRESHOLD" ]; then
  144. new_acceleration=$(echo $ACCELERATION | sed "s/\.//")
  145. echo $new_acceleration
  146. new_x_parameter="m "$new_acceleration"/10 "$THRESHOLD
  147. echo $new_x_parameter
  148. xset $new_x_parameter
  149. sed --in-place "s:'$def_x_parameter':$new_x_parameter:" /root/.xset.sh
  150.  
  151. msg_flag2=3
  152. fi
  153.  
  154. #テーマの変更
  155. new_symlink="/root/.icons/"$DIRECTORY
  156. echo "def_symlink="'$def_symlink'
  157. echo "new_symlink="$new_symlink
  158. if [ "$new_symlink" != "/root/.icons/" -a "'$def_symlink'" != "$new_symlink" ]; then
  159. if [ -e /root/.icons/default ]; then
  160. rm /root/.icons/default
  161. fi
  162.  
  163. if [ "'$def_symlink'" != "$new_symlink" ]; then
  164. if [ "$new_symlink" != "/root/.icons/default" ]; then
  165. ln -s $new_symlink /root/.icons/default
  166. fi
  167. msg_flag3=1
  168. fi
  169. fi
  170.  
  171. #change_msg_flagにより、表示するメッセージを変える
  172. change_msg_flag=$(( $msg_flag1 + $msg_flag2 + $msg_flag3 ))
  173.  
  174. if [ "$change_msg_flag" = "0" ]; then
  175. msg0="設定が変更されていません"
  176. msg1="何もせずに終了します"
  177. msg2="..."
  178. else
  179. msg0="マウスの設定を変更しました"
  180. msg1="Xサーバをリスタートして効果を確認してください"
  181. msg2="..."
  182. #加速調整はxのリスタートなしで反映される
  183. if [ "$change_msg_flag" = "3" ]; then
  184. msg1="..."
  185. fi
  186. if [ "$msg_flag2" = "3" ]; then
  187. msg2="加速の変更は、既に反映されています。確認してください"
  188. fi
  189. fi
  190.  
  191. export SUB_DIALOG="
  192. <window title=\"Double Click Adjust\" width_request=\"400\" height_request=\"300\">
  193. <vbox>
  194. <text height-request=\"40\">
  195. <label>"$msg0"</label>
  196. </text>
  197. <text height-request=\"40\">
  198. <label>"$msg1"</label>
  199. </text>
  200. <text height-request=\"40\">
  201. <label>"$msg2"</label>
  202. </text>
  203. <button height-request=\"100\"><label>閉じる</label>
  204. <action type=\"exit\">exit</action>
  205. </button>
  206. </vbox>
  207. </window>"
  208.  
  209. gtkdialog -c --program SUB_DIALOG
  210. '
  211. #####################################################################
  212. #マウステーマプレビュー用
  213. export list_on_change='
  214. if [ "$DIRECTORY" = "default" ]; then
  215. if [ -e /tmp/ao_o10yan_temp/left_ptr_000.png ]; then
  216. rm /tmp/ao_o10yan_temp/left_ptr_000.png
  217. rm /tmp/ao_o10yan_temp/hand_000.png
  218. rm /tmp/ao_o10yan_temp/watch_000.png
  219. fi
  220. else
  221. temp_file_dir="/tmp/ao_o10yan_temp/"$DIRECTORY
  222. if [ "$temp_file_dir" != "/tmp/ao_o10yan_temp/" ]; then
  223. xcur2png -d /tmp/ao_o10yan_temp /root/.icons/"$DIRECTORY"/cursors/left_ptr
  224. xcur2png -d /tmp/ao_o10yan_temp /root/.icons/"$DIRECTORY"/cursors/hand
  225. xcur2png -d /tmp/ao_o10yan_temp /root/.icons/"$DIRECTORY"/cursors/watch
  226. fi
  227. fi
  228. '
  229. #####################################################################
  230. #後始末
  231. export del_temp='
  232. rm -rf /tmp/ao_o10yan_temp
  233. rm -f ./left_ptr.conf
  234. rm -f ./hand.conf
  235. rm -f ./watch.conf
  236. '
  237.  
  238. #####################################################################
  239.  
  240. export MAIN_DIALOG='
  241. <window title="マウスの設定" width_request="400" height_request="300">
  242. <vbox>
  243. <notebook labels="ダブルクリック|加速|テーマ">
  244. <vbox>
  245. <text>
  246. <label>ダブルクリック調整用スライダー</label>
  247. </text>
  248. <frame>
  249. <checkbox>
  250. <label>ダブルクリックを有効にする</label>
  251. <default>'$def_single_click_boolean'</default>
  252. <variable>CHKBOX</variable>
  253. <action>if true enable:TIME</action>
  254. <action>if false disable:TIME</action>
  255. <action>if true enable:DISTANCE</action>
  256. <action>if false disable:DISTANCE</action>
  257. </checkbox>
  258. </frame>
  259. <frame 間隔(ミリ秒)>
  260. <hscale range-min="250" range-max="2000" range-step="1">
  261. <default>'$def_time_value'</default>
  262. <variable>TIME</variable>
  263. <sensitive>'$def_single_click_boolean'</sensitive>
  264. </hscale>
  265. </frame>
  266. <frame 距離(ピクセル)>
  267. <hscale range-min="5" range-max="100" range-step="1">
  268. <default>'$def_distance_value'</default>
  269. <variable>DISTANCE</variable>
  270. <sensitive>'$def_single_click_boolean'</sensitive>
  271. </hscale>
  272. </frame>
  273. </vbox>
  274. <vbox>
  275. <text>
  276. <label>加速調整用スライダー</label>
  277. </text>
  278. <frame 加速(数値が大きい程、マウスが速く動きます)>
  279. <hscale range-min="1" range-max="10" range-step="0.1">
  280. <default>'$def_acceleration_value'</default>
  281. <variable>ACCELERATION</variable>
  282. </hscale>
  283. </frame>
  284. <frame 閾値(数値が小さい程、マウスが速く動きます)>
  285. <hscale range-min="1" range-max="20" range-step="1">
  286. <default>'$def_threshold_value'</default>
  287. <variable>THRESHOLD</variable>
  288. </hscale>
  289. </frame>
  290. </vbox>
  291. <vbox>
  292. <text>
  293. <label>マウスのテーマ切替</label>
  294. </text>
  295. <hbox>
  296. <list selected-row="'$def_selected_row'">
  297. <variable>DIRECTORY</variable>
  298. <width>150</width>
  299. <height>208</height>
  300. '$items'
  301. <action>bash -c "$list_on_change"</action>
  302. <action>refresh:LEFT_PTR</action>
  303. <action>refresh:HAND</action>
  304. <action>refresh:WATCH</action>
  305. </list>
  306. <frame プレビュー>
  307. <vbox>
  308. <pixmap space-expand="true">
  309. <variable>LEFT_PTR</variable>
  310. <height>40</height>
  311. <input file>/tmp/ao_o10yan_temp/left_ptr_000.png</input>
  312. </pixmap>
  313. <pixmap space-expand="true">
  314. <variable>HAND</variable>
  315. <height>40</height>
  316. <input file>/tmp/ao_o10yan_temp/hand_000.png</input>
  317. </pixmap>
  318. <pixmap space-expand="true">
  319. <variable>WATCH</variable>
  320. <height>40</height>
  321. <input file>/tmp/ao_o10yan_temp/watch_000.png</input>
  322. </pixmap>
  323. </vbox>
  324. </frame>
  325. </hbox>
  326. </vbox>
  327. </notebook>
  328. <hbox>
  329. <button ok>
  330. <action>bash -c "$ok_action"</action>
  331. <action>bash -c "$del_temp"</action>
  332. <action type="exit">exit</action>
  333. </button>
  334. <button cancel>
  335. <action>bash -c "$del_temp"</action>
  336. <action type="exit">exit</action>
  337. </button>
  338. </hbox>
  339. </vbox>
  340. </window>
  341. '
  342.  
  343. gtkdialog -c --program MAIN_DIALOG
  344.  

0 件のコメント :

コメントを投稿