ixset 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. #!/bin/sh
  2. # the next line restarts using wish \
  3. exec wish "$0" ${1+"$@"}
  4. # ixset --
  5. # A nice interface to "xset" to change X server settings
  6. #
  7. # History :
  8. # 91/11/23 : pda@masi.ibp.fr, jt@ratp.fr : design
  9. # 92/08/01 : pda@masi.ibp.fr : cleaning
  10. package require Tk
  11. #
  12. # Button actions
  13. #
  14. proc quit {} {
  15. destroy .
  16. }
  17. proc ok {} {
  18. writesettings
  19. quit
  20. }
  21. proc cancel {} {
  22. readsettings
  23. dispsettings
  24. .buttons.apply configure -state disabled
  25. .buttons.cancel configure -state disabled
  26. }
  27. proc apply {} {
  28. writesettings
  29. .buttons.apply configure -state disabled
  30. .buttons.cancel configure -state disabled
  31. }
  32. #
  33. # Read current settings
  34. #
  35. proc readsettings {} {
  36. global kbdrep ; set kbdrep "on"
  37. global kbdcli ; set kbdcli 0
  38. global bellvol ; set bellvol 100
  39. global bellpit ; set bellpit 440
  40. global belldur ; set belldur 100
  41. global mouseacc ; set mouseacc "3/1"
  42. global mousethr ; set mousethr 4
  43. global screenbla ; set screenbla "blank"
  44. global screentim ; set screentim 600
  45. global screencyc ; set screencyc 600
  46. set xfd [open "|xset q" r]
  47. while {[gets $xfd line] >= 0} {
  48. switch -- [lindex $line 0] {
  49. auto {
  50. set rpt [lindex $line 1]
  51. if {$rpt eq "repeat:"} {
  52. set kbdrep [lindex $line 2]
  53. set kbdcli [lindex $line 6]
  54. }
  55. }
  56. bell {
  57. set bellvol [lindex $line 2]
  58. set bellpit [lindex $line 5]
  59. set belldur [lindex $line 8]
  60. }
  61. acceleration: {
  62. set mouseacc [lindex $line 1]
  63. set mousethr [lindex $line 3]
  64. }
  65. prefer {
  66. set bla [lindex $line 2]
  67. set screenbla [expr {$bla eq "yes" ? "blank" : "noblank"}]
  68. }
  69. timeout: {
  70. set screentim [lindex $line 1]
  71. set screencyc [lindex $line 3]
  72. }
  73. }
  74. }
  75. close $xfd
  76. # puts stdout [format "Key REPEAT = %s\n" $kbdrep]
  77. # puts stdout [format "Key CLICK = %s\n" $kbdcli]
  78. # puts stdout [format "Bell VOLUME = %s\n" $bellvol]
  79. # puts stdout [format "Bell PITCH = %s\n" $bellpit]
  80. # puts stdout [format "Bell DURATION = %s\n" $belldur]
  81. # puts stdout [format "Mouse ACCELERATION = %s\n" $mouseacc]
  82. # puts stdout [format "Mouse THRESHOLD = %s\n" $mousethr]
  83. # puts stdout [format "Screen BLANCK = %s\n" $screenbla]
  84. # puts stdout [format "Screen TIMEOUT = %s\n" $screentim]
  85. # puts stdout [format "Screen CYCLE = %s\n" $screencyc]
  86. }
  87. #
  88. # Write settings into the X server
  89. #
  90. proc writesettings {} {
  91. global kbdrep kbdcli bellvol bellpit belldur
  92. global mouseacc mousethr screenbla screentim screencyc
  93. set bellvol [.bell.vol get]
  94. set bellpit [.bell.val.pit.entry get]
  95. set belldur [.bell.val.dur.entry get]
  96. if {$kbdrep eq "on"} {
  97. set kbdcli [.kbd.val.cli get]
  98. } else {
  99. set kbdcli "off"
  100. }
  101. set mouseacc [.mouse.hor.acc.entry get]
  102. set mousethr [.mouse.hor.thr.entry get]
  103. set screentim [.screen.tim.entry get]
  104. set screencyc [.screen.cyc.entry get]
  105. exec xset \
  106. b $bellvol $bellpit $belldur \
  107. c $kbdcli \
  108. r $kbdrep \
  109. m $mouseacc $mousethr \
  110. s $screentim $screencyc \
  111. s $screenbla
  112. }
  113. #
  114. # Sends all settings to the window
  115. #
  116. proc dispsettings {} {
  117. global kbdrep kbdcli bellvol bellpit belldur
  118. global mouseacc mousethr screenbla screentim screencyc
  119. .bell.vol set $bellvol
  120. .bell.val.pit.entry delete 0 end
  121. .bell.val.pit.entry insert 0 $bellpit
  122. .bell.val.dur.entry delete 0 end
  123. .bell.val.dur.entry insert 0 $belldur
  124. .kbd.val.onoff [expr {$kbdrep eq "on" ? "select" : "deselect"}]
  125. .kbd.val.cli set $kbdcli
  126. .mouse.hor.acc.entry delete 0 end
  127. .mouse.hor.acc.entry insert 0 $mouseacc
  128. .mouse.hor.thr.entry delete 0 end
  129. .mouse.hor.thr.entry insert 0 $mousethr
  130. .screen.blank [expr {$screenbla eq "blank" ? "select" : "deselect"}]
  131. .screen.pat [expr {$screenbla ne "blank" ? "select" : "deselect"}]
  132. .screen.tim.entry delete 0 end
  133. .screen.tim.entry insert 0 $screentim
  134. .screen.cyc.entry delete 0 end
  135. .screen.cyc.entry insert 0 $screencyc
  136. }
  137. #
  138. # Create all windows, and pack them
  139. #
  140. proc labelentry {path text length {range {}}} {
  141. frame $path
  142. label $path.label -text $text
  143. if {[llength $range]} {
  144. spinbox $path.entry -width $length -relief sunken \
  145. -from [lindex $range 0] -to [lindex $range 1]
  146. } else {
  147. entry $path.entry -width $length -relief sunken
  148. }
  149. pack $path.label -side left
  150. pack $path.entry -side right -expand y -fill x
  151. }
  152. proc createwindows {} {
  153. #
  154. # Buttons
  155. #
  156. frame .buttons
  157. button .buttons.ok -default active -command ok -text "Ok"
  158. button .buttons.apply -default normal -command apply -text "Apply" \
  159. -state disabled
  160. button .buttons.cancel -default normal -command cancel -text "Cancel" \
  161. -state disabled
  162. button .buttons.quit -default normal -command quit -text "Quit"
  163. pack .buttons.ok .buttons.apply .buttons.cancel .buttons.quit \
  164. -side left -expand yes -pady 5
  165. bind . <Return> {.buttons.ok flash; .buttons.ok invoke}
  166. bind . <Escape> {.buttons.quit flash; .buttons.quit invoke}
  167. bind . <Button-1> {
  168. if {![string match .buttons* %W]} {
  169. .buttons.apply configure -state normal
  170. .buttons.cancel configure -state normal
  171. }
  172. }
  173. bind . <Key> {
  174. if {![string match .buttons* %W]} {
  175. switch -glob %K {
  176. Return - Escape - Tab - *Shift* {}
  177. default {
  178. .buttons.apply configure -state normal
  179. .buttons.cancel configure -state normal
  180. }
  181. }
  182. }
  183. }
  184. #
  185. # Bell settings
  186. #
  187. labelframe .bell -text "Bell Settings" -padx 1.5m -pady 1.5m
  188. scale .bell.vol \
  189. -from 0 -to 100 -length 200 -tickinterval 20 \
  190. -label "Volume (%)" -orient horizontal
  191. frame .bell.val
  192. labelentry .bell.val.pit "Pitch (Hz)" 6 {25 20000}
  193. labelentry .bell.val.dur "Duration (ms)" 6 {1 10000}
  194. pack .bell.val.pit -side left -padx 5
  195. pack .bell.val.dur -side right -padx 5
  196. pack .bell.vol .bell.val -side top -expand yes
  197. #
  198. # Keyboard settings
  199. #
  200. labelframe .kbd -text "Keyboard Repeat Settings" -padx 1.5m -pady 1.5m
  201. frame .kbd.val
  202. checkbutton .kbd.val.onoff \
  203. -text "On" \
  204. -onvalue "on" -offvalue "off" -variable kbdrep \
  205. -relief flat
  206. scale .kbd.val.cli \
  207. -from 0 -to 100 -length 200 -tickinterval 20 \
  208. -label "Click Volume (%)" -orient horizontal
  209. pack .kbd.val.onoff -side left -fill x -expand yes -padx {0 1m}
  210. pack .kbd.val.cli -side left -expand yes -fill x -padx {1m 0}
  211. pack .kbd.val -side top -expand yes -pady 2 -fill x
  212. #
  213. # Mouse settings
  214. #
  215. labelframe .mouse -text "Mouse Settings" -padx 1.5m -pady 1.5m
  216. frame .mouse.hor
  217. labelentry .mouse.hor.acc "Acceleration" 5
  218. labelentry .mouse.hor.thr "Threshold (pixels)" 3 {1 2000}
  219. pack .mouse.hor.acc -side left -padx {0 1m}
  220. pack .mouse.hor.thr -side right -padx {1m 0}
  221. pack .mouse.hor -side top -expand yes
  222. #
  223. # Screen Saver settings
  224. #
  225. labelframe .screen -text "Screen-saver Settings" -padx 1.5m -pady 1.5m
  226. radiobutton .screen.blank \
  227. -variable screenblank -text "Blank" -relief flat \
  228. -value "blank" -variable screenbla -anchor w
  229. radiobutton .screen.pat \
  230. -variable screenblank -text "Pattern" -relief flat \
  231. -value "noblank" -variable screenbla -anchor w
  232. labelentry .screen.tim "Timeout (s)" 5 {1 100000}
  233. labelentry .screen.cyc "Cycle (s)" 5 {1 100000}
  234. grid .screen.blank .screen.tim -sticky e
  235. grid .screen.pat .screen.cyc -sticky e
  236. grid configure .screen.blank .screen.pat -sticky ew
  237. #
  238. # Main window
  239. #
  240. pack .buttons -side top -fill both
  241. pack .bell .kbd .mouse .screen -side top -fill both -expand yes \
  242. -padx 1m -pady 1m
  243. #
  244. # Let the user resize our window
  245. #
  246. wm minsize . 10 10
  247. }
  248. ##############################################################################
  249. # Main program
  250. #
  251. # Listen what "xset" tells us...
  252. #
  253. readsettings
  254. #
  255. # Create all windows
  256. #
  257. createwindows
  258. #
  259. # Write xset parameters
  260. #
  261. dispsettings
  262. #
  263. # Now, wait for user actions...
  264. #
  265. # Local Variables:
  266. # mode: tcl
  267. # End: