#!/bin/sh # the next line restarts using wish \ exec wish "$0" "$@" # TkXSet (Version 0.22) # # Copyright (C) 2000 by T.Sato # # http://member.nifty.ne.jp/tsato/tkdeskset/ # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU General Public License for more details. set program_name "TkXSet" set title "$program_name (Version 0.22)" set Xdefaults $env(HOME)/.Xdefaults set colors(normal) "black" set colors(disabled) "gray50" # set default parameters set lang "C" if { ! [ catch { kanji code "abc" } ] } { catch { set lang $env(LANG) } catch { set lang $env(LC_ALL) } catch { set lang $env(LC_MESSAGES) } set env(LC_MESSAGES) "C" } set make_backup 1 # For Japanese locale, translate messages to Japanese. # proc gettext msg { global lang Xdefaults if [ regexp {^ja_|^japanese|^ja$} $lang junk ] { switch -glob $msg { "Applying your changes *" \ { return "変更を適用すると \"$Xdefaults\" ファイルが書き換えられます。\ 適用しますか?" } "Do you want to load *" \ { return "変更した .Xdefaults ファイルを今読み込みますか?" } "Mouse Acceleration:" \ { return "マウスのアクセラレーション:" } "Acceleration Threshold:" \ { return "アクセラレーションのしきい値:" } "Mouse Buttons:" \ { return "マウスボタン:" } "Normal" \ { return "通常" } "Left Handed" \ { return "左手用" } "Beep:" \ { return "ブザー:" } "Volume:" \ { return "音量:" } "Pitch:" \ { return "音の高さ:" } "Duration:" \ { return "音の長さ:" } "SCREEN SAVER" \ { return "スクリーン・セーバー" } "Screen Saver:" \ { return "スクリーン・セーバー:" } "Disable" \ { return "無効" } "Enable" \ { return "有効" } "Blank" \ { return "ブランク" } "Logo" \ { return "ロゴの表示" } "Timeout (minutes):" \ { return "タイムアウト (分)" } "ENERGY STAR (DPMS)" \ { return "省電力機能 (DPMS)" } "Energy Star:" \ { return "省電力機能:" } "Standby (minutes):" \ { return "スタンバイ (分):" } "Suspend (minutes):" \ { return "サスペンド (分):" } "Off (minutes):" \ { return "オフ (分):" } "Apply" \ { return "適用" } "Reset" \ { return "リセット" } "Category:" \ { return "カテゴリー:" } "Mouse Settings" \ { return "マウスの設定" } "Screen Saver" \ { return "スクリーン・セーバー" } "Beep" \ { return "ブザー" } default \ { return $msg } } } return $msg } ################################################################ # Read resource from the X server (when file = "| xrdb -q") # or resouce file. # If called as "parse_resources filename true", the resource # file will be updated to store settings on the panel. # proc parse_resources { file { update false } } { global opt make_backup Xdefaults dpms_available if { $update } { foreach s [ array names opt ] { set curopt($s) $opt($s) } if { $make_backup } { set make_backup false eval exec "cp $Xdefaults $Xdefaults.bak" } set out [ open $file.new w ] } set lines 0 set in [ open $file r ] while { 0 <= [ gets $in line ] } { if { ! [ string match "|*" $file ] } { # when reading from resource file, we may need to join lines while { [ regexp {\\$} $line ] } { if { 0 <= [ gets $in line2 ] } { append line "\n" $line2 } } } scan $line "%\[^:\]:%\[^\377\]" s1 s2 if { $update } { if { [ array names curopt $s1 ] != "" } { puts $out "$s1: $curopt($s1)" unset curopt($s1) } else { puts $out $line } } else { if [ string match "tkxset.*" $line ] { regsub "^\[ \t\]*" $s2 "" s2 regsub -nocase "^(true|yes|on)\[ \t\]*$" $s2 "true" s2 regsub -nocase "^(false|no|off)\[ \t\]*$" $s2 "false" s2 set opt($s1) $s2 } } incr lines } close $in if { $update } { foreach s [ array names curopt ] { if { $curopt($s) != "" } { puts $out "$s: $curopt($s)" } } close $out eval exec "mv $Xdefaults.new $Xdefaults" } catch { if { 0 < $opt(tkxset.acceleration) } { eval exec "xset m [ expr int($opt(tkxset.acceleration) * 10) ]/10 \ $opt(tkxset.accelerationThreshold)" } } set t [ expr $opt(tkxset.screenSaverTimeout) * 60 ] eval exec "xset s $t $t" switch $opt(tkxset.screenSaver) { "disable" { eval exec "xset s off" } "blank" { eval exec "xset s blank" } "logo" { eval exec "xset s noblank" } } if { $dpms_available } { if { $opt(tkxset.dpms) == "disable" } { eval exec "xset -dpms" } else { if { $opt(tkxset.dpmsSuspend) < $opt(tkxset.dpmsStandby) } { set opt(tkxset.dpmsSuspend) $opt(tkxset.dpmsStandby) } if { $opt(tkxset.dpmsOff) < $opt(tkxset.dpmsSuspend) } { set opt(tkxset.dpmsOff) $opt(tkxset.dpmsSuspend) } set t1 [ expr $opt(tkxset.dpmsStandby) * 60 ] set t2 [ expr $opt(tkxset.dpmsSuspend) * 60 ] set t3 [ expr $opt(tkxset.dpmsOff) * 60 ] eval exec "xset +dpms dpms $t1 $t2 $t3" } } if { $opt(tkxset.beep) == "never" } { eval exec "xset b off" } else { set t1 $opt(tkxset.bellVolume) set t2 $opt(tkxset.bellPitch) set t3 $opt(tkxset.bellDuration) eval exec "xset b $t1 $t2 $t3" } switch $opt(tkxset.leftHanded) { "false" { eval exec "echo pointer = default | xmodmap -" } "true" { set f [ open "| xmodmap -pp" ] if { 0 <= [ gets $f line ] } { scan $line "There are %d" buttons set cmd "echo pointer = 3 2 1" for { set i 4 } { $i <= $buttons } { incr i } { append cmd " $i" } append cmd " | xmodmap -" eval exec "$cmd" } close $f } } return $lines } # Reset settings on the panel. # proc reset {} { global Xdefaults opt dpms_available catch { unset opt } set opt(tkxset.acceleration) 0 set opt(tkxset.accelerationThreshold) 0 set opt(tkxset.leftHanded) "false" set opt(tkxset.screenSaver) "logo" set opt(tkxset.screenSaverTimeout) 10 set opt(tkxset.dpms) "disable" set opt(tkxset.beep) "enable" set dpms_available "false" set f [ open "| xset q" r ] while { 0 <= [ gets $f line ] } { regsub {^ +} $line "" line if { [ scan $line "prefer blanking: %s" x ] } { if { $x } { set opt(tkxset.screenSaver) "blank" } } elseif { [ scan $line "timeout: %s" x ] } { set opt(tkxset.screenSaverTimeout) [ expr $x / 60 ] } elseif { [ scan $line "DPMS is %s" x ] } { set dpms_available "true" if { $x == "Enabled" } { set opt(tkxset.dpms) "enable" } } elseif { [ scan $line "Standby: %s Suspend: %s Off: %s" x1 x2 x3 ] } { set opt(tkxset.dpmsStandby) [ expr $x1 / 60 ] set opt(tkxset.dpmsSuspend) [ expr $x2 / 60 ] set opt(tkxset.dpmsOff) [ expr $x3 / 60 ] } elseif { [ scan $line "bell percent: %s bell pitch: %s bell duration: %s" x1 x2 x3 ] } { set opt(tkxset.bellVolume) $x1 set opt(tkxset.bellPitch) $x2 set opt(tkxset.bellDuration) $x3 } } close $f if { $opt(tkxset.screenSaverTimeout) <= 0 } { set opt(tkxset.screenSaver) "disable" } if [ expr { [ parse_resources "| xrdb -q" ] == 0 } ] { if [ file readable $Xdefaults ] { parse_resources $Xdefaults } } set_sensitivity trace variable opt(tkxset.screenSaver) w { set_sensitivity } trace variable opt(tkxset.dpms) w { set_sensitivity } trace variable opt(tkxset.beep) w { set_sensitivity } } # Apply settings on the panel. # .Xdefaults file will be updated, and new resouces will be loaded # to the X server. # proc apply {} { global opt Xdefaults if { [ tk_messageBox -title "TkXSet - Confirm Apply" \ -type yesno -icon question \ -message [ gettext "Applying your changes will modify \"$Xdefaults\" file.\ Do you want to do this?" ] ] == "yes" } { parse_resources $Xdefaults "true" set load_now "false" set f [ open "| xrdb -q" r ] if { 0 <= [ gets $f line ] } { set load_now "true" } close $f if { $load_now == "false" } { if { [ tk_messageBox -title "TkXSet - Load Xdefaults Now?" \ -type yesno -icon question \ -message [ gettext \ "Do you want to load the modified .Xdefaults file now?" ] ] == "yes" } { set load_now "true" } } if { $load_now } { eval exec "xrdb -merge $Xdefaults" } reset } } proc set_sensitivity { { name 1 } { op 2 } { var 3 } } { global opt colors dpms_available if [ winfo exists .form.timeout_l ] { if { $opt(tkxset.screenSaver) == "disable" } { .form.timeout_l configure -fg $colors(disabled) .form.timeout configure -fg $colors(disabled) -state disabled } else { .form.timeout_l configure -fg $colors(normal) .form.timeout configure -fg $colors(normal) -state normal } } if [ winfo exists .form.dpms_l ] { if { $dpms_available == "false" } { .form.dpms_l configure -fg $colors(disabled) .form.dpms.disable configure -fg $colors(disabled) -state disabled .form.dpms.enable configure -fg $colors(disabled) -state disabled } foreach w { standby suspend off } { set w_l $w append w_l "_l" if { $dpms_available == "false" || $opt(tkxset.dpms) == "disable" } { .form.$w_l configure -fg $colors(disabled) .form.$w configure -fg $colors(disabled) -state disabled } else { .form.$w_l configure -fg $colors(normal) .form.$w configure -fg $colors(normal) -state normal } } } if [ winfo exists .form.beep_l ] { foreach w { bell_volume bell_pitch bell_duration } { set w_l $w append w_l "_l" if { $opt(tkxset.beep) == "never" } { .form.$w_l configure -fg $colors(disabled) .form.$w configure -fg $colors(disabled) -state disabled } else { .form.$w_l configure -fg $colors(normal) .form.$w configure -fg $colors(normal) -state normal } } } } proc show_panel { { name 1 } { op 2 } { var 3 } } { global opt category set category1 $category foreach x { "Mouse Settings" "Screen Saver" "Beep" } { if { $category == [ gettext $x ] } { set category1 $x } } if [ winfo exists .form ] { destroy .form } frame .form -borderwidth 2 -relief groove reset set row 0 switch -glob $category1 { "Mouse*" { if { $opt(tkxset.acceleration) == 0 } { set opt(tkxset.acceleration) 1 } if { $opt(tkxset.accelerationThreshold) == 0 } { set opt(tkxset.accelerationThreshold) 10 } label .form.accel_l -text [ gettext "Mouse Acceleration:" ] scale .form.accel -orient horizontal -length 150 -from 0.5 -to 10 -resolution 0.1 \ -variable opt(tkxset.acceleration) grid .form.accel_l -sticky e -row $row grid .form.accel -sticky w -row $row -column 1 incr row label .form.accel_t_l -text [ gettext "Acceleration Threshold:" ] scale .form.accel_t -orient horizontal -length 150 -from 0 -to 25 \ -variable opt(tkxset.accelerationThreshold) grid .form.accel_t_l -sticky e -row $row grid .form.accel_t -sticky w -row $row -column 1 incr row label .form.vspace grid .form.vspace -sticky w -row $row incr row label .form.hand_l -text [ gettext "Mouse Buttons:" ] frame .form.hand radiobutton .form.hand.default -variable opt(tkxset.leftHanded) \ -value "false" -text [ gettext "Normal" ] radiobutton .form.hand.menu -variable opt(tkxset.leftHanded) \ -value "true" -text [ gettext "Left Handed" ] pack .form.hand.default .form.hand.menu -side left grid .form.hand_l -sticky e -row $row grid .form.hand -sticky w -row $row -column 1 } "Screen*" { label .form.saver_title -text [ gettext "SCREEN SAVER" ] -background white grid .form.saver_title -sticky we -row $row -columnspan 2 incr row label .form.saver_l -text [ gettext "Screen Saver:" ] frame .form.saver radiobutton .form.saver.disable -variable opt(tkxset.screenSaver) \ -value "disable" -text [ gettext "Disable" ] radiobutton .form.saver.blank -variable opt(tkxset.screenSaver) \ -value "blank" -text [ gettext "Blank" ] radiobutton .form.saver.logo -variable opt(tkxset.screenSaver) \ -value "logo" -text [ gettext "Logo" ] pack .form.saver.disable .form.saver.blank .form.saver.logo -side left grid .form.saver_l -sticky e -row $row grid .form.saver -sticky w -row $row -column 1 incr row label .form.timeout_l -text [ gettext "Timeout (minutes):" ] scale .form.timeout -orient horizontal -length 150 -from 1 -to 60 \ -variable opt(tkxset.screenSaverTimeout) grid .form.timeout_l -sticky e -row $row grid .form.timeout -sticky w -row $row -column 1 incr row label .form.vspace grid .form.vspace -sticky w -row $row incr row label .form.dpms_title -text [ gettext "ENERGY STAR (DPMS)" ] -background white grid .form.dpms_title -sticky we -row $row -columnspan 2 incr row label .form.dpms_l -text [ gettext "Energy Star:" ] frame .form.dpms radiobutton .form.dpms.disable -variable opt(tkxset.dpms) \ -value "disable" -text [ gettext "Disable" ] radiobutton .form.dpms.enable -variable opt(tkxset.dpms) \ -value "enable" -text [ gettext "Enable" ] pack .form.dpms.disable .form.dpms.enable -side left grid .form.dpms_l -sticky e -row $row grid .form.dpms -sticky w -row $row -column 1 incr row label .form.standby_l -text [ gettext "Standby (minutes):" ] scale .form.standby -orient horizontal -length 150 -from 1 -to 60 \ -variable opt(tkxset.dpmsStandby) grid .form.standby_l -sticky e -row $row grid .form.standby -sticky w -row $row -column 1 incr row label .form.suspend_l -text [ gettext "Suspend (minutes):" ] scale .form.suspend -orient horizontal -length 150 -from 1 -to 60 \ -variable opt(tkxset.dpmsSuspend) grid .form.suspend_l -sticky e -row $row grid .form.suspend -sticky w -row $row -column 1 incr row label .form.off_l -text [ gettext "Off (minutes):" ] scale .form.off -orient horizontal -length 150 -from 1 -to 60 \ -variable opt(tkxset.dpmsOff) grid .form.off_l -sticky e -row $row grid .form.off -sticky w -row $row -column 1 } "Beep*" { label .form.beep_l -text [ gettext "Beep:" ] frame .form.beep radiobutton .form.beep.enable -variable opt(tkxset.beep) \ -value "enable" -text [ gettext "Enable" ] radiobutton .form.beep.disable -variable opt(tkxset.beep) \ -value "disable" -text [ gettext "Disable" ] pack .form.beep.enable .form.beep.disable -side left grid .form.beep_l -sticky e -row $row grid .form.beep -sticky w -row $row -column 1 incr row label .form.bell_volume_l -text [ gettext "Volume:" ] scale .form.bell_volume -orient horizontal -length 150 -from 1 -to 100 \ -variable opt(tkxset.bellVolume) grid .form.bell_volume_l -sticky e -row $row grid .form.bell_volume -sticky w -row $row -column 1 incr row label .form.bell_pitch_l -text [ gettext "Pitch:" ] scale .form.bell_pitch -orient horizontal -length 150 -from 1 -to 5000 \ -variable opt(tkxset.bellPitch) grid .form.bell_pitch_l -sticky e -row $row grid .form.bell_pitch -sticky w -row $row -column 1 incr row label .form.bell_duration_l -text [ gettext "Duration:" ] scale .form.bell_duration -orient horizontal -length 150 -from 1 -to 1000 \ -variable opt(tkxset.bellDuration) grid .form.bell_duration_l -sticky e -row $row grid .form.bell_duration -sticky w -row $row -column 1 } } label .form.vspace2 grid .form.vspace2 -sticky w -row 998 frame .form.commands button .form.commands.apply -text [ gettext "Apply" ] -command { apply } button .form.commands.reset -text [ gettext "Reset" ] -command { reset } pack .form.commands.apply .form.commands.reset -side left -padx 3m grid .form.commands -row 999 -columnspan 999 pack .form -fill both -expand true -after .category -ipadx 4m -ipady 2m set_sensitivity } ################################################################ # The main routine. set no_window "false" while { 0 < [ llength $argv ] } { switch -- [ lindex $argv 0 ] { "-f" { set Xdefaults [ lindex $argv 1 ] set argv [ lreplace $argv 0 1 ] } "-l" { set no_window "true" set argv [ lreplace $argv 0 0 ] } default { puts "tkxset: no such option: [ lindex $argv 0 ]" set argv [ lreplace $argv 0 0 ] } } } if { $no_window } { parse_resources $Xdefaults exit 0 } wm title . $title wm iconname . $program_name frame .category label .category.label -text [ gettext "Category:" ] tk_optionMenu .category.menu category \ [ gettext "Mouse Settings" ] [ gettext "Screen Saver" ] [ gettext "Beep" ] trace variable category w { show_panel } pack .category.label .category.menu -side left pack .category -fill x -expand false -pady 2m show_panel